From 9875714a026484af1d20fea7aa8762432ce022b9 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 17 Jan 2024 16:19:10 -0300 Subject: do not add a new request if there is one already --- .../taler-wallet-core/src/operations/withdraw.ts | 23 +++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 6c7e8c37a..29c2cae40 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -1905,6 +1905,11 @@ export interface GetWithdrawalDetailsForUriOpts { notifyChangeFromPendingTimeoutMs?: number; } +type WithdrawalOperationMemoryMap = { + [uri: string]: boolean | undefined; +} +const ongoingChecks: WithdrawalOperationMemoryMap = { +} /** * Get more information about a taler://withdraw URI. * @@ -1945,7 +1950,10 @@ export async function getWithdrawalDetailsForUri( ); }); - if (info.status === "pending" && opts.notifyChangeFromPendingTimeoutMs !== undefined) { + // FIXME: this should be removed after the extended version of + // withdrawal state machine. issue #8099 + if (info.status === "pending" && opts.notifyChangeFromPendingTimeoutMs !== undefined && !ongoingChecks[talerWithdrawUri]) { + ongoingChecks[talerWithdrawUri] = true; const bankApi = new TalerBankIntegrationHttpClient(info.apiBaseUrl, ws.http); console.log( `waiting operation (${info.operationId}) to change from pending`, @@ -1957,21 +1965,12 @@ export async function getWithdrawalDetailsForUri( console.log( `operation (${info.operationId}) to change to ${JSON.stringify(resp, undefined, 2)}`, ); - if (resp.type === "fail") { - //not found, this is rare since the previous request succeed - ws.notify({ - type: NotificationType.WithdrawalOperationTransition, - operationId: info.operationId, - state: info.status, - }) - return; - } - ws.notify({ type: NotificationType.WithdrawalOperationTransition, operationId: info.operationId, - state: resp.body.status, + state: resp.type === "fail" ? info.status : resp.body.status, }); + ongoingChecks[talerWithdrawUri] = false }) } -- cgit v1.2.3