diff options
5 files changed, 45 insertions, 51 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/update/UpdatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/update/UpdatePage.tsx index 6bdcf6d18..32c5637aa 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/update/UpdatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/update/UpdatePage.tsx @@ -92,7 +92,6 @@ export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { function updateState(up: (s: Partial<Entity>) => Partial<Entity>) { setState((old) => { const newState = up(old); - console.log("====", newState.amount) if (!newState.amount_editable) { newState.currency_editable = false; } @@ -152,7 +151,6 @@ export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { const template_contract: TalerMerchantApi.TemplateContractDetails = { minimum_age: state.minimum_age!, pay_duration: Duration.toTalerProtocolDuration(state.pay_duration!), - // FIXME: Check if amount_editable is a plain currency, in that case the user must specify it. amount: contract_amount, summary: contract_summary, currency: diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 8671db0da..4bff23fd5 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -551,9 +551,9 @@ async function dumpCoins(wex: WalletExecutionContext): Promise<CoinDumpJson> { ageCommitmentProof: c.ageCommitmentProof, spend_allocation: c.spendAllocation ? { - amount: c.spendAllocation.amount, - id: c.spendAllocation.id, - } + amount: c.spendAllocation.amount, + id: c.spendAllocation.id, + } : undefined, }); } @@ -906,9 +906,7 @@ async function dispatchRequestInternal( } case WalletApiOperation.GetWithdrawalDetailsForUri: { const req = codecForGetWithdrawalDetailsForUri().decode(payload); - return await getWithdrawalDetailsForUri(wex, req.talerWithdrawUri, { - restrictAge: req.restrictAge, - }); + return await getWithdrawalDetailsForUri(wex, req.talerWithdrawUri); } case WalletApiOperation.TestingGetReserveHistory: { const req = codecForTestingGetReserveHistoryRequest().decode(payload); @@ -1654,7 +1652,7 @@ async function handleCoreApiRequest( wex = getObservedWalletExecutionContext(ws, cts.token, oc); } else { oc = { - observe(evt) {}, + observe(evt) { }, }; wex = getNormalWalletExecutionContext(ws, cts.token, oc); } @@ -1791,7 +1789,7 @@ export class Cache<T> { constructor( private maxCapacity: number, private cacheDuration: Duration, - ) {} + ) { } get(key: string): T | undefined { const r = this.map.get(key); @@ -1827,7 +1825,7 @@ export class Cache<T> { * Implementation of triggers for the wallet DB. */ class WalletDbTriggerSpec implements TriggerSpec { - constructor(public ws: InternalWalletState) {} + constructor(public ws: InternalWalletState) { } afterCommit(info: AfterCommitInfo): void { if (info.mode !== "readwrite") { diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts index bc19dc1f6..d14689b12 100644 --- a/packages/taler-wallet-core/src/withdraw.ts +++ b/packages/taler-wallet-core/src/withdraw.ts @@ -2269,7 +2269,6 @@ export interface GetWithdrawalDetailsForUriOpts { export async function getWithdrawalDetailsForUri( wex: WalletExecutionContext, talerWithdrawUri: string, - opts: GetWithdrawalDetailsForUriOpts = {}, ): Promise<WithdrawUriInfoResponse> { logger.trace(`getting withdrawal details for URI ${talerWithdrawUri}`); const info = await getBankWithdrawalInfo(wex.http, talerWithdrawUri); @@ -2937,11 +2936,13 @@ export async function prepareBankIntegratedWithdrawal( ) { url = existingWithdrawalGroup.wgInfo.bankInfo.confirmUrl; } + const info = await getWithdrawalDetailsForUri(wex, req.talerWithdrawUri); return { transactionId: constructTransactionIdentifier({ tag: TransactionType.Withdrawal, withdrawalGroupId: existingWithdrawalGroup.withdrawalGroupId, }), + info, }; } @@ -2965,6 +2966,8 @@ export async function prepareBankIntegratedWithdrawal( reserveStatus: WithdrawalGroupStatus.DialogProposed, }); + const info = await getWithdrawalDetailsForUri(wex, req.talerWithdrawUri); + const withdrawalGroupId = withdrawalGroup.withdrawalGroupId; const ctx = new WithdrawTransactionContext(wex, withdrawalGroupId); @@ -2973,6 +2976,7 @@ export async function prepareBankIntegratedWithdrawal( return { transactionId: ctx.transactionId, + info, }; } diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts index 0b36be1fd..65c000741 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts @@ -16,6 +16,7 @@ import { AmountJson, + AmountString, Amounts, ExchangeFullDetails, ExchangeListItem, @@ -156,6 +157,7 @@ export function useComponentStateFromParams({ async function doManualWithdraw( exchange: string, ageRestricted: number | undefined, + amount: AmountString, ): Promise<{ transactionId: string; confirmTransferUrl: string | undefined; @@ -164,7 +166,7 @@ export function useComponentStateFromParams({ WalletApiOperation.AcceptManualWithdrawal, { exchangeBaseUrl: exchange, - amount: Amounts.stringify(chosenAmount), + amount, restrictAge: ageRestricted, }, ); @@ -203,10 +205,9 @@ export function useComponentStateFromURI({ : maybeTalerUri; const uriInfo = await api.wallet.call( - WalletApiOperation.GetWithdrawalDetailsForUri, + WalletApiOperation.PrepareBankIntegratedWithdrawal, { talerWithdrawUri, - // notifyChangeFromPendingTimeoutMs: 30 * 1000, }, ); const { @@ -216,16 +217,12 @@ export function useComponentStateFromURI({ operationId, confirmTransferUrl, status, - } = uriInfo; - const transaction = await api.wallet.call( - WalletApiOperation.GetWithdrawalTransactionByUri, - { talerWithdrawUri }, - ); + } = uriInfo.info; return { talerWithdrawUri, operationId, status, - transaction, + transactionId: uriInfo.transactionId, confirmTransferUrl, amount: Amounts.parseOrThrow(amount), thisExchange: defaultExchangeBaseUrl, @@ -259,6 +256,7 @@ export function useComponentStateFromURI({ } const uri = uriInfoHook.response.talerWithdrawUri; + const txId = uriInfoHook.response.transactionId; const chosenAmount = uriInfoHook.response.amount; const defaultExchange = uriInfoHook.response.thisExchange; const exchangeList = uriInfoHook.response.exchanges; @@ -266,16 +264,18 @@ export function useComponentStateFromURI({ async function doManagedWithdraw( exchange: string, ageRestricted: number | undefined, + amount: AmountString, ): Promise<{ transactionId: string; confirmTransferUrl: string | undefined; }> { const res = await api.wallet.call( - WalletApiOperation.AcceptBankIntegratedWithdrawal, + WalletApiOperation.ConfirmWithdrawal, { exchangeBaseUrl: exchange, - talerWithdrawUri: uri, + amount, restrictAge: ageRestricted, + transactionId: txId, }, ); return { @@ -285,9 +285,9 @@ export function useComponentStateFromURI({ } if (uriInfoHook.response.status !== "pending") { - if (uriInfoHook.response.transaction) { - onSuccess(uriInfoHook.response.transaction.transactionId); - } + // if (uriInfoHook.response.transactionId) { + // onSuccess(uriInfoHook.response.transactionId); + // } return { status: "already-completed", operationState: uriInfoHook.response.status, @@ -312,6 +312,7 @@ export function useComponentStateFromURI({ type ManualOrManagedWithdrawFunction = ( exchange: string, ageRestricted: number | undefined, + amount: AmountString, ) => Promise<{ transactionId: string; confirmTransferUrl: string | undefined }>; function exchangeSelectionState( @@ -380,6 +381,7 @@ function exchangeSelectionState( const res = await doWithdraw( currentExchange.exchangeBaseUrl, !ageRestricted ? undefined : ageRestricted, + Amounts.stringify(Amounts.zeroOfCurrency(selectedCurrency)), ); if (res.confirmTransferUrl) { document.location.href = res.confirmTransferUrl; diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts index f90f7bed7..70d40ec1c 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts @@ -108,22 +108,18 @@ describe("Withdraw CTA states", () => { }; handler.addWalletCallResponse( - WalletApiOperation.GetWithdrawalDetailsForUri, + WalletApiOperation.PrepareBankIntegratedWithdrawal, undefined, { - status: "pending", - operationId: "123", - amount: "EUR:2" as AmountString, - possibleExchanges: [], + transactionId: "123", + info: { + status: "pending", + operationId: "123", + amount: "EUR:2" as AmountString, + possibleExchanges: [], + } }, ); - handler.addWalletCallResponse( - WalletApiOperation.GetWithdrawalTransactionByUri, - undefined, - { - transactionId: "123" - } as any, - ); const hookBehavior = await tests.hookBehaveLikeThis( useComponentStateFromURI, @@ -153,24 +149,20 @@ describe("Withdraw CTA states", () => { }; handler.addWalletCallResponse( - WalletApiOperation.GetWithdrawalDetailsForUri, + WalletApiOperation.PrepareBankIntegratedWithdrawal, undefined, { - status: "pending", - operationId: "123", - amount: "ARS:2" as AmountString, - possibleExchanges: exchanges, - defaultExchangeBaseUrl: exchanges[0].exchangeBaseUrl, + transactionId: "123", + info: { + status: "pending", + operationId: "123", + amount: "ARS:2" as AmountString, + possibleExchanges: exchanges, + defaultExchangeBaseUrl: exchanges[0].exchangeBaseUrl, + } }, ); handler.addWalletCallResponse( - WalletApiOperation.GetWithdrawalTransactionByUri, - undefined, - { - transactionId: "123" - } as any, - ); - handler.addWalletCallResponse( WalletApiOperation.GetWithdrawalDetailsForAmount, undefined, { |