diff options
author | Florian Dold <florian@dold.me> | 2023-05-25 19:11:03 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-05-25 19:11:03 +0200 |
commit | 8624d798b799d78a4b6393493a0750027094904d (patch) | |
tree | 2ed70812786bc7fc28efb1879e7d13b44a6c0d22 /packages/taler-wallet-core/src/operations/deposits.ts | |
parent | 485f7d3603bb3c9f563cf6c5fdaabdf474e9c4d5 (diff) | |
download | wallet-core-8624d798b799d78a4b6393493a0750027094904d.tar.xz |
wallet-core: fix issues with aborting deposits
Diffstat (limited to 'packages/taler-wallet-core/src/operations/deposits.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/deposits.ts | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/packages/taler-wallet-core/src/operations/deposits.ts b/packages/taler-wallet-core/src/operations/deposits.ts index c3d24cbf3..6c41d76f6 100644 --- a/packages/taler-wallet-core/src/operations/deposits.ts +++ b/packages/taler-wallet-core/src/operations/deposits.ts @@ -89,6 +89,7 @@ import { import { selectPayCoinsNew } from "../util/coinSelection.js"; import { constructTransactionIdentifier, + notifyTransition, parseTransactionIdentifier, stopLongpolling, } from "./transactions.js"; @@ -158,8 +159,16 @@ export function computeDepositTransactionStatus( return { major: TransactionMajorState.Suspended, }; + case DepositOperationStatus.Aborting: + return { + major: TransactionMajorState.Aborting, + }; + case DepositOperationStatus.Aborted: + return { + major: TransactionMajorState.Aborted, + } default: - throw Error("unexpected deposit group state"); + throw Error(`unexpected deposit group state (${dg.operationStatus})`); } } @@ -379,8 +388,11 @@ async function waitForRefreshOnDepositGroup( ): Promise<OperationAttemptResult> { const abortRefreshGroupId = depositGroup.abortRefreshGroupId; checkLogicInvariant(!!abortRefreshGroupId); - // FIXME: Emit notification on state transition! - const res = await ws.db + const transactionId = constructTransactionIdentifier({ + tag: TransactionType.Deposit, + depositGroupId: depositGroup.depositGroupId, + }); + const transitionInfo = await ws.db .mktx((x) => [x.refreshGroups, x.depositGroups]) .runReadWrite(async (tx) => { const refreshGroup = await tx.refreshGroups.get(abortRefreshGroupId); @@ -405,30 +417,17 @@ async function waitForRefreshOnDepositGroup( if (!newDg) { return; } - const oldDepositTxStatus = computeDepositTransactionStatus(newDg); + const oldTxState = computeDepositTransactionStatus(newDg); newDg.operationStatus = newOpState; - const newDepositTxStatus = computeDepositTransactionStatus(newDg); + const newTxState = computeDepositTransactionStatus(newDg); await tx.depositGroups.put(newDg); - return { oldDepositTxStatus, newDepositTxStatus }; + return { oldTxState, newTxState }; } return undefined; }); - if (res) { - const transactionId = constructTransactionIdentifier({ - tag: TransactionType.Deposit, - depositGroupId: depositGroup.depositGroupId, - }); - ws.notify({ - type: NotificationType.TransactionStateTransition, - transactionId, - oldTxState: res.oldDepositTxStatus, - newTxState: res.newDepositTxStatus, - }); - return OperationAttemptResult.pendingEmpty(); - } else { - return OperationAttemptResult.pendingEmpty(); - } + notifyTransition(ws, transactionId, transitionInfo); + return OperationAttemptResult.pendingEmpty(); } async function refundDepositGroup( @@ -436,6 +435,7 @@ async function refundDepositGroup( depositGroup: DepositGroupRecord, ): Promise<OperationAttemptResult> { const newTxPerCoin = [...depositGroup.transactionPerCoin]; + logger.info(`status per coin: ${j2s(depositGroup.transactionPerCoin)}`); for (let i = 0; i < depositGroup.transactionPerCoin.length; i++) { const st = depositGroup.transactionPerCoin[i]; switch (st) { @@ -475,6 +475,7 @@ async function refundDepositGroup( method: "POST", body: refundReq, }); + logger.info(`coin ${i} refund HTTP status for coin: ${httpResp.status}`); let newStatus: DepositElementStatus; if (httpResp.status === 200) { // FIXME: validate response @@ -492,7 +493,7 @@ async function refundDepositGroup( let isDone = true; for (let i = 0; i < newTxPerCoin.length; i++) { if ( - newTxPerCoin[i] != DepositElementStatus.RefundFailed || + newTxPerCoin[i] != DepositElementStatus.RefundFailed && newTxPerCoin[i] != DepositElementStatus.RefundSuccess ) { isDone = false; @@ -535,6 +536,7 @@ async function refundDepositGroup( await tx.depositGroups.put(newDg); }); + return OperationAttemptResult.pendingEmpty(); } @@ -775,10 +777,13 @@ export async function processDepositGroup( } if (depositGroup.operationStatus === DepositOperationStatus.Aborting) { + logger.info("processing deposit tx in 'aborting'"); const abortRefreshGroupId = depositGroup.abortRefreshGroupId; if (!abortRefreshGroupId) { + logger.info("refunding deposit group"); return refundDepositGroup(ws, depositGroup); } + logger.info("waiting for refresh"); return waitForRefreshOnDepositGroup(ws, depositGroup); } return OperationAttemptResult.finishedEmpty(); |