taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit fab9a1176a1f5f42c9b9385c09f0d1571ad7e3e3
parent 043b7aefa91234f73209e810c85cf0d1ee7ca8d0
Author: Florian Dold <florian@dold.me>
Date:   Fri, 21 Jun 2024 18:42:59 +0200

wallet-core: use correct wallet-selected amount in withdrawal

Diffstat:
Mpackages/taler-wallet-cli/src/index.ts | 17++++++++++++++++-
Mpackages/taler-wallet-core/src/withdraw.ts | 16++++++++++------
2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts @@ -21,6 +21,7 @@ import { AbsoluteTime, addPaytoQueryParams, AgeRestriction, + Amounts, AmountString, codecForList, codecForString, @@ -75,7 +76,7 @@ import * as fs from "node:fs"; // thread worker, and thus must expose these two handlers. export { handleWorkerError, - handleWorkerMessage, + handleWorkerMessage } from "@gnu-taler/taler-wallet-core"; const logger = new Logger("taler-wallet-cli.ts"); @@ -722,6 +723,16 @@ walletCli }, ); console.log("withdrawInfo", withdrawInfo); + let amount: AmountString | undefined = undefined; + if (withdrawInfo.editableAmount) { + if (withdrawInfo.amount) { + console.log(`Default amount: ${withdrawInfo.amount}`); + } + const res = await readlinePrompt( + `Amount (in ${withdrawInfo.currency}): `, + ); + amount = Amounts.stringify(Amounts.parseOrThrow(res)); + } const selectedExchange = args.handleUri.withdrawalExchange ?? withdrawInfo.defaultExchangeBaseUrl; @@ -732,6 +743,10 @@ walletCli processExit(1); return; } + // FIXME: Maybe prompt for this? + await wallet.client.call(WalletApiOperation.SetExchangeTosAccepted, { + exchangeBaseUrl: selectedExchange, + }); const res = await wallet.client.call( WalletApiOperation.AcceptBankIntegratedWithdrawal, { diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts @@ -3303,14 +3303,18 @@ export async function acceptWithdrawalFromUri( "amount required, as withdrawal operation has flexible amount", ); } - amount = req.amount as AmountString; + amount = Amounts.stringify(req.amount); } else { - if (req.amount != null && !p.info.editableAmount) { - throw Error( - `mismatched amount, amount is fixed by bank (${p.info.amount}) but client provided different amount (${req.amount})`, - ); + if (req.amount == null) { + amount = p.info.amount; + } else { + if (!p.info.editableAmount) { + throw Error( + `mismatched amount, amount is fixed by bank (${p.info.amount}) but client provided different amount (${req.amount})`, + ); + } + amount = Amounts.stringify(req.amount); } - amount = p.info.amount; } logger.info(`confirming withdrawal with tx ${p.transactionId}`);