diff options
author | Florian Dold <florian@dold.me> | 2023-11-28 19:17:38 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-11-28 19:17:38 +0100 |
commit | 27578b07404370351b5b511b3d3af0e8b2c77223 (patch) | |
tree | 7107dfb90e6424411da61e2228c1cfd17e0e2012 | |
parent | 629cb08490adf1be26a811d743d8152de48a3c2a (diff) |
wallet-core: only specify transfer amount for currency conversion withdrawals
4 files changed, 36 insertions, 10 deletions
diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-conversion.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-conversion.ts index 08ae38bf2..69c6427ca 100644 --- a/packages/taler-harness/src/integrationtests/test-withdrawal-conversion.ts +++ b/packages/taler-harness/src/integrationtests/test-withdrawal-conversion.ts @@ -196,10 +196,9 @@ export async function runWithdrawalConversionTest(t: GlobalTestState) { console.log(`withdrawal details: ${j2s(infoRes)}`); - t.assertAmountEquals( - infoRes.withdrawalAccountList[0].transferAmount, - "FOO:123", - ); + const checkTransferAmount = infoRes.withdrawalAccountList[0].transferAmount; + t.assertTrue(checkTransferAmount != null); + t.assertAmountEquals(checkTransferAmount, "FOO:123"); const tStart = AbsoluteTime.now(); @@ -217,10 +216,10 @@ export async function runWithdrawalConversionTest(t: GlobalTestState) { logger.info("AcceptManualWithdrawal finished"); logger.info(`result: ${j2s(wres)}`); - t.assertAmountEquals( - wres.withdrawalAccountsList[0].transferAmount, - "FOO:123", - ); + const acceptedTransferAmount = wres.withdrawalAccountsList[0].transferAmount; + t.assertTrue(acceptedTransferAmount != null); + + t.assertAmountEquals(acceptedTransferAmount, "FOO:123"); const txInfo = await walletClient.call( WalletApiOperation.GetTransactionById, diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index 022f42f13..c67c59646 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -1395,6 +1395,8 @@ export const codecForExchangesListResponse = (): Codec<ExchangesListResponse> => export interface AcceptManualWithdrawalResult { /** * Payto URIs that can be used to fund the withdrawal. + * + * @deprecated in favor of withdrawalAccountsList */ exchangePaytoUris: string[]; @@ -1449,6 +1451,11 @@ export interface ManualWithdrawalDetails { * the array of ages. */ ageRestrictionOptions?: number[]; + + /** + * Scope info of the currency withdrawn. + */ + scopeInfo: ScopeInfo; } /** @@ -2779,8 +2786,17 @@ export interface WithdrawalExchangeAccountDetails { * amount for withdrawal. * * Redundant with the amount in paytoUri, just included to avoid parsing. + * + * Only included if this account does a currency conversion. + */ + transferAmount?: AmountString; + + /** + * Currency specification for the external currency. + * + * Only included if this account requires a currency conversion. */ - transferAmount: AmountString; + currencySpecification?: CurrencySpecification; /** * Further restrictions for sending money to the diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index c7a44bf0f..9c798e813 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -2589,7 +2589,7 @@ async function fetchWithdrawalAccountInfo( const withdrawalAccounts: WithdrawalExchangeAccountDetails[] = []; for (let acct of exchangeDetails.wireInfo.accounts) { let paytoUri: string; - let transferAmount: AmountString; + let transferAmount: AmountString | undefined = undefined; if (acct.conversion_url != null) { const reqUrl = new URL("cashin-rate", acct.conversion_url); reqUrl.searchParams.set( @@ -2622,6 +2622,9 @@ async function fetchWithdrawalAccountInfo( transferAmount, creditRestrictions: acct.credit_restrictions, }; + if (transferAmount != null) { + acctInfo.transferAmount = transferAmount; + } withdrawalAccounts.push(acctInfo); } return withdrawalAccounts; diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 6b9e960ce..507d72cce 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -52,6 +52,7 @@ import { NotificationType, RecoverStoredBackupRequest, RefreshReason, + ScopeType, StoredBackupList, TalerError, TalerErrorCode, @@ -1209,6 +1210,7 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>( for (const x of wi.selectedDenoms.selectedDenoms) { numCoins += x.count; } + const amt = Amounts.parseOrThrow(req.amount); const resp: ManualWithdrawalDetails = { amountRaw: req.amount, amountEffective: Amounts.stringify(wi.selectedDenoms.totalCoinValue), @@ -1217,6 +1219,12 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>( ageRestrictionOptions: wi.ageRestrictionOptions, withdrawalAccountList: wi.exchangeCreditAccountDetails, numCoins, + // FIXME: Once we have proper scope info support, return correct info here. + scopeInfo: { + type: ScopeType.Exchange, + currency: amt.currency, + url: req.exchangeBaseUrl, + }, }; return resp; } |