From 85a095fa7d4d31e1e84e5e096fa28c59f3cd1918 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 16 Jul 2020 22:52:56 +0530 Subject: manual withdrawal --- src/wallet.ts | 58 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'src/wallet.ts') diff --git a/src/wallet.ts b/src/wallet.ts index 737704fd6..5412a0fd2 100644 --- a/src/wallet.ts +++ b/src/wallet.ts @@ -56,9 +56,6 @@ import { MerchantRefundDetails, CoinDumpJson } from "./types/talerTypes"; import { BenchmarkResult, ConfirmPayResult, - ConfirmReserveRequest, - CreateReserveRequest, - CreateReserveResponse, ReturnCoinsRequest, SenderWireInfos, TipStatus, @@ -72,6 +69,7 @@ import { ExchangesListRespose, ManualWithdrawalDetails, GetExchangeTosResult, + AcceptManualWithdrawalResult, } from "./types/walletTypes"; import { Logger } from "./util/logging"; @@ -87,10 +85,11 @@ import { processReserve, createTalerWithdrawReserve, forceQueryReserve, + getFundingPaytoUris, } from "./operations/reserves"; import { InternalWalletState } from "./operations/state"; -import { createReserve, confirmReserve } from "./operations/reserves"; +import { createReserve } from "./operations/reserves"; import { processRefreshGroup, createRefreshGroup } from "./operations/refresh"; import { processWithdrawGroup } from "./operations/withdraw"; import { getHistory } from "./operations/history"; @@ -171,8 +170,14 @@ export class Wallet { exchangeBaseUrl: string, amount: AmountJson, ): Promise { - const wi = await getExchangeWithdrawalInfo(this.ws, exchangeBaseUrl, amount); - const paytoUris = wi.exchangeInfo.wireInfo?.accounts.map((x) => x.payto_uri); + const wi = await getExchangeWithdrawalInfo( + this.ws, + exchangeBaseUrl, + amount, + ); + const paytoUris = wi.exchangeInfo.wireInfo?.accounts.map( + (x) => x.payto_uri, + ); if (!paytoUris) { throw Error("exchange is in invalid state"); } @@ -437,28 +442,23 @@ export class Wallet { * Adds the corresponding exchange as a trusted exchange if it is neither * audited nor trusted already. */ - async createReserve( - req: CreateReserveRequest, - ): Promise { - try { - return createReserve(this.ws, req); - } finally { - this.latch.trigger(); - } - } - - /** - * Mark an existing reserve as confirmed. The wallet will start trying - * to withdraw from that reserve. This may not immediately succeed, - * since the exchange might not know about the reserve yet, even though the - * bank confirmed its creation. - * - * A confirmed reserve should be shown to the user in the UI, while - * an unconfirmed reserve should be hidden. - */ - async confirmReserve(req: ConfirmReserveRequest): Promise { + async acceptManualWithdrawal( + exchangeBaseUrl: string, + amount: AmountJson, + ): Promise { try { - return confirmReserve(this.ws, req); + const resp = await createReserve(this.ws, { + amount, + exchange: exchangeBaseUrl, + }); + const exchangePaytoUris = await this.db.runWithReadTransaction( + [Stores.exchanges, Stores.reserves], + (tx) => getFundingPaytoUris(tx, resp.reservePub), + ); + return { + reservePub: resp.reservePub, + exchangePaytoUris, + }; } finally { this.latch.trigger(); } @@ -511,7 +511,7 @@ export class Wallet { acceptedEtag: exchange.termsOfServiceAcceptedEtag, currentEtag, tos, - } + }; } /** @@ -602,7 +602,7 @@ export class Wallet { return { exchangeBaseUrl: x.baseUrl, currency: details.currency, - paytoUris: x.wireInfo.accounts.map(x => x.payto_uri), + paytoUris: x.wireInfo.accounts.map((x) => x.payto_uri), }; }); return { -- cgit v1.2.3