taler-typescript-core

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

commit a60f1c6c9e834c9ca87a4a70e6d25a508619bab4
parent 33dcef9cbf2871f58db5d473fcbe1753d9a872de
Author: Florian Dold <dold@taler.net>
Date:   Tue, 10 Nov 2026 22:08:49 +0100

wallet-core: cache bank withdrawal details

Keep bank presentation available to observations without network reads.

Diffstat:
Mpackages/taler-util/src/types-taler-wallet-observations.ts | 16++++++++++++++++
Mpackages/taler-wallet-core/src/db/records.ts | 3+++
Mpackages/taler-wallet-core/src/db/sqlite/transaction.ts | 4+++-
Mpackages/taler-wallet-core/src/withdraw.ts | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
4 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/packages/taler-util/src/types-taler-wallet-observations.ts b/packages/taler-util/src/types-taler-wallet-observations.ts @@ -18,6 +18,7 @@ import type { ExchangeUpdateStatus, ScopeInfo, TransactionIdStr, + WithdrawUriInfoResponse, } from "./types-taler-wallet.js"; import type { PeerInfoShort, @@ -113,3 +114,18 @@ export interface PeerPushCreditSnapshot { unavailableReasons: PeerPushCreditConfirmationUnavailableReason[]; }; } + +/** Latest known bank presentation. Transaction state remains authoritative. */ +export type ObservedBankWithdrawal = Pick< + WithdrawUriInfoResponse, + | "operationId" + | "status" + | "confirmTransferUrl" + | "currency" + | "amount" + | "editableAmount" + | "maxAmount" + | "wireFee" + | "defaultExchangeBaseUrl" + | "editableExchange" +>; diff --git a/packages/taler-wallet-core/src/db/records.ts b/packages/taler-wallet-core/src/db/records.ts @@ -16,6 +16,7 @@ import { AmountString, + ObservedBankWithdrawal, TalerProtocolTimestamp, MerchantContractTokenKind, TokenIssuePublicKey, @@ -554,6 +555,8 @@ export const enum WithdrawalRecordType { * with a bank-integrated withdrawal. */ export interface ReserveBankInfo { + /** Last bank presentation, updated by preparation and the withdrawal task. */ + presentation?: ObservedBankWithdrawal; talerWithdrawUri: string; /** diff --git a/packages/taler-wallet-core/src/db/sqlite/transaction.ts b/packages/taler-wallet-core/src/db/sqlite/transaction.ts @@ -4735,7 +4735,9 @@ export class SqliteWalletTransaction implements WalletDbTransaction { src: contact.source, pet: contact.petname, self: boolToDb(contact.isSelf ?? false), - exp: timestampProtocolToDb(contact.expiration ?? TalerProtocolTimestamp.zero()), + exp: timestampProtocolToDb( + contact.expiration ?? TalerProtocolTimestamp.zero(), + ), }, ); } diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts @@ -1351,6 +1351,37 @@ async function transitionSimple( }); } +/** Retain bank presentation independently of the wallet transaction state. */ +async function storeObservedBankStatus( + ctx: WithdrawTransactionContext, + status: BankWithdrawalOperationStatus, +): Promise<void> { + await ctx.wex.runWalletDbTx(async (tx) => { + const r = await tx.getWithdrawalGroup(ctx.withdrawalGroupId); + if (r?.wgInfo.withdrawalType !== WithdrawalRecordType.BankIntegrated) + return; + const bank = r.wgInfo.bankInfo; + if (!bank.presentation) return; // Older records are initialized on preparation. + bank.presentation = { + ...bank.presentation, + status: status.status, + confirmTransferUrl: status.confirm_transfer_url, + amount: + status.amount ?? + (status.no_amount_to_wallet ? undefined : status.suggested_amount), + editableAmount: + status.amount === undefined && !status.no_amount_to_wallet, + editableExchange: status.required_exchange === undefined, + defaultExchangeBaseUrl: + status.required_exchange ?? status.suggested_exchange, + maxAmount: status.max_amount, + wireFee: status.card_fees, + }; + bank.confirmUrl = status.confirm_transfer_url; + await tx.upsertWithdrawalGroup(r); + }); +} + /** * Handle state "dialog(proposed)" for a withdrawal transaction. * @@ -1414,6 +1445,7 @@ async function processWithdrawalGroupDialogProposed( break; } case "ok": { + await storeObservedBankStatus(ctx, resp.body); // If the bank claims that the withdrawal operation is already // pending, but we're still in DialogProposed, some other wallet // must've completed the withdrawal, we're giving up. @@ -3967,8 +3999,15 @@ async function registerReserveWithBank( AbsoluteTime.toPreciseTimestamp(AbsoluteTime.now()), ); const now = AbsoluteTime.toPreciseTimestamp(AbsoluteTime.now()); + const bank = r.wgInfo.bankInfo; + bank.confirmUrl = bankWopStatus.confirm_transfer_url; + if (bank.presentation) { + bank.presentation.status = bankWopStatus.status; + bank.presentation.confirmTransferUrl = bankWopStatus.confirm_transfer_url; + } switch (bankWopStatus.status) { case "confirmed": + bank.timestampBankConfirmed = timestampPreciseToDb(now); r.status = WithdrawalGroupStatus.PendingQueryingStatus; break; case "aborted": @@ -4098,14 +4137,13 @@ async function processBankRegisterReserve( } const status = statusResp.body; + await storeObservedBankStatus(ctx, status); // Legacy libeufin-bank behavior if (status.status === "aborted") { return transitionBankAborted(ctx); } - // FIXME: Put confirm transfer URL in the DB! - const isFlexibleAmount = status.amount == null; return await registerReserveWithBank( @@ -4263,6 +4301,7 @@ async function processReserveBankStatus( } }); if (outcome.type === "confirmed") { + await storeObservedBankStatus(ctx, outcome.status); return processConfirmedBankWithdrawal( wex, ctx, @@ -4276,6 +4315,8 @@ async function processReserveBankStatus( ? bankPoll.value.body : undefined; + if (bankStatus) await storeObservedBankStatus(ctx, bankStatus); + // A funded reserve is definitive. Prefer it even if the bank request // failed or reports an abort: the wallet controls the reserve key and must // recover the value that reached the exchange. @@ -4584,8 +4625,20 @@ export async function prepareBankIntegratedWithdrawal( ); const info = await getWithdrawalDetailsForBankInfo(wex, withdrawInfo); + const { possibleExchanges, ...presentation } = info; if (existingWithdrawalGroup) { + await wex.runWalletDbTx(async (tx) => { + const current = await tx.getWithdrawalGroup( + existingWithdrawalGroup.withdrawalGroupId, + ); + if ( + current?.wgInfo.withdrawalType === WithdrawalRecordType.BankIntegrated + ) { + current.wgInfo.bankInfo.presentation = presentation; + await tx.upsertWithdrawalGroup(current); + } + }); return { transactionId: constructTransactionIdentifier({ tag: TransactionType.Withdrawal, @@ -4620,6 +4673,7 @@ export async function prepareBankIntegratedWithdrawal( wgInfo: { withdrawalType: WithdrawalRecordType.BankIntegrated, bankInfo: { + presentation, talerWithdrawUri: req.talerWithdrawUri, confirmUrl: withdrawInfo.confirmTransferUrl, timestampBankConfirmed: undefined,