diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-12-16 16:59:09 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-12-16 17:00:46 +0100 |
commit | c2ee8fd9ab6754275d7423152681236a46cf36a9 (patch) | |
tree | c7306f6575f89e3b66226fdaf7af342b0dc973c2 /src/operations/reserves.ts | |
parent | 35a7b76a7d935dc2c749fd39ac80c6af1096b795 (diff) | |
download | wallet-core-c2ee8fd9ab6754275d7423152681236a46cf36a9.tar.xz |
cleanup, avoid some circular deps
Diffstat (limited to 'src/operations/reserves.ts')
-rw-r--r-- | src/operations/reserves.ts | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/operations/reserves.ts b/src/operations/reserves.ts index 7b0a6886e..649bf75f2 100644 --- a/src/operations/reserves.ts +++ b/src/operations/reserves.ts @@ -20,6 +20,7 @@ import { getTimestampNow, ConfirmReserveRequest, OperationError, + AcceptWithdrawalResponse, } from "../types/walletTypes"; import { canonicalizeBaseUrl } from "../util/helpers"; import { InternalWalletState } from "./state"; @@ -38,7 +39,7 @@ import { } from "../util/query"; import { Logger } from "../util/logging"; import * as Amounts from "../util/amounts"; -import { updateExchangeFromUrl, getExchangeTrust } from "./exchanges"; +import { updateExchangeFromUrl, getExchangeTrust, getExchangePaytoUri } from "./exchanges"; import { WithdrawOperationStatusResponse } from "../types/talerTypes"; import { assertUnreachable } from "../util/assertUnreachable"; import { encodeCrock, getRandomBytes } from "../crypto/talerCrypto"; @@ -46,6 +47,7 @@ import { randomBytes } from "../crypto/primitives/nacl-fast"; import { getVerifiedWithdrawDenomList, processWithdrawSession, + getBankWithdrawalInfo, } from "./withdraw"; import { guardOperationException, OperationFailedAndReportedError } from "./errors"; import { NotificationType } from "../types/notifications"; @@ -652,3 +654,33 @@ async function depleteReserve( console.trace("withdraw session already existed"); } } + + + +export async function createTalerWithdrawReserve( + ws: InternalWalletState, + talerWithdrawUri: string, + selectedExchange: string, +): Promise<AcceptWithdrawalResponse> { + const withdrawInfo = await getBankWithdrawalInfo(ws, talerWithdrawUri); + const exchangeWire = await getExchangePaytoUri( + ws, + selectedExchange, + withdrawInfo.wireTypes, + ); + const reserve = await createReserve(ws, { + amount: withdrawInfo.amount, + bankWithdrawStatusUrl: withdrawInfo.extractedStatusUrl, + exchange: selectedExchange, + senderWire: withdrawInfo.senderWire, + exchangeWire: exchangeWire, + }); + // We do this here, as the reserve should be registered before we return, + // so that we can redirect the user to the bank's status page. + await processReserveBankStatus(ws, reserve.reservePub); + console.log("acceptWithdrawal: returning"); + return { + reservePub: reserve.reservePub, + confirmTransferUrl: withdrawInfo.confirmTransferUrl, + }; +}
\ No newline at end of file |