taler-typescript-core

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

commit fa676c4fec857e3551abcd6839562f82c1cb0a88
parent 09bae316456f49c6bac2aca6185483e1e7ab2d5a
Author: Florian Dold <florian@dold.me>
Date:   Tue, 22 Oct 2024 15:27:38 +0200

wallet-core: report scopes in preparePay response

Diffstat:
Mpackages/taler-util/src/types-taler-wallet.ts | 27+++++++++++++++++++++++----
Mpackages/taler-wallet-core/src/exchanges.ts | 3+++
Mpackages/taler-wallet-core/src/pay-merchant.ts | 11++++++++++-
3 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/packages/taler-util/src/types-taler-wallet.ts b/packages/taler-util/src/types-taler-wallet.ts @@ -753,6 +753,7 @@ export const codecForPreparePayResultPaymentPossible = .property("transactionId", codecForTransactionIdStr()) .property("proposalId", codecForString()) .property("contractTermsHash", codecForString()) + .property("scopes", codecForList(codecForScopeInfo())) .property("talerUri", codecForString()) .property( "status", @@ -901,16 +902,34 @@ export type PreparePayResult = */ export interface PreparePayResultPaymentPossible { status: PreparePayResultType.PaymentPossible; + transactionId: TransactionIdStr; + + contractTerms: MerchantContractTerms; + /** - * @deprecated use transactionId instead + * Scopes involved in this transaction. */ - proposalId: string; - contractTerms: MerchantContractTerms; - contractTermsHash: string; + scopes: ScopeInfo[]; + amountRaw: AmountString; + amountEffective: AmountString; + + /** + * FIXME: Unclear why this is needed. Remove? + */ + contractTermsHash: string; + + /** + * FIXME: Unclear why this is needed! Remove? + */ talerUri: string; + + /** + * @deprecated use transactionId instead + */ + proposalId: string; } export interface PreparePayResultInsufficientBalance { diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts @@ -288,6 +288,9 @@ export async function getScopeForAllCoins( return rs.filter((d): d is ScopeInfo => d !== undefined); } +/** + * Get a list of scope infos applicable to a list of exchanges. + */ export async function getScopeForAllExchanges( tx: WalletDbReadOnlyTransaction< [ diff --git a/packages/taler-wallet-core/src/pay-merchant.ts b/packages/taler-wallet-core/src/pay-merchant.ts @@ -1652,6 +1652,14 @@ async function checkPaymentByProposalId( logger.trace("costInfo", totalCost); logger.trace("coinsForPayment", res); + const exchanges = new Set<string>(); + + coins.map((x) => exchanges.add(x.exchangeBaseUrl)); + + const scopes = await wex.db.runAllStoresReadOnlyTx({}, async (tx) => { + return await getScopeForAllExchanges(tx, [...exchanges]); + }); + return { status: PreparePayResultType.PaymentPossible, contractTerms: d.contractTermsRaw, @@ -1659,6 +1667,7 @@ async function checkPaymentByProposalId( proposalId: proposal.proposalId, amountEffective: Amounts.stringify(totalCost), amountRaw: Amounts.stringify(instructedAmount), + scopes, contractTermsHash: d.contractData.contractTermsHash, talerUri, }; @@ -2353,7 +2362,7 @@ export async function confirmPay( ); notifyTransition(wex, transactionId, transitionInfo); - + // In case we're sharing the payment and we're long-polling wex.taskScheduler.stopShepherdTask(ctx.taskId);