summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/reserves.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-08-20 14:34:56 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-08-20 14:34:56 +0530
commita8fb16021d6f71e6d0c7fae6b440e5c3197b8867 (patch)
treeff893a899e34d7f94dad420b0a6907e95f2942cb /packages/taler-wallet-core/src/operations/reserves.ts
parent786976e5a8e10f6a3eab50cacbefe98d8b2364f5 (diff)
downloadwallet-core-a8fb16021d6f71e6d0c7fae6b440e5c3197b8867.tar.gz
wallet-core-a8fb16021d6f71e6d0c7fae6b440e5c3197b8867.tar.bz2
wallet-core-a8fb16021d6f71e6d0c7fae6b440e5c3197b8867.zip
handle withdrawals aborted by the bank, add test
Diffstat (limited to 'packages/taler-wallet-core/src/operations/reserves.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/reserves.ts32
1 files changed, 31 insertions, 1 deletions
diff --git a/packages/taler-wallet-core/src/operations/reserves.ts b/packages/taler-wallet-core/src/operations/reserves.ts
index fb525da45..8adaeea81 100644
--- a/packages/taler-wallet-core/src/operations/reserves.ts
+++ b/packages/taler-wallet-core/src/operations/reserves.ts
@@ -60,6 +60,7 @@ import {
guardOperationException,
OperationFailedAndReportedError,
makeErrorDetails,
+ OperationFailedError,
} from "./errors";
import { NotificationType } from "../types/notifications";
import { codecForReserveStatus } from "../types/ReserveStatus";
@@ -358,7 +359,7 @@ async function registerReserveWithBank(
return processReserveBankStatus(ws, reservePub);
}
-export async function processReserveBankStatus(
+async function processReserveBankStatus(
ws: InternalWalletState,
reservePub: string,
): Promise<void> {
@@ -393,6 +394,25 @@ async function processReserveBankStatusImpl(
codecForWithdrawOperationStatusResponse(),
);
+ if (status.aborted) {
+ logger.trace("bank aborted the withdrawal");
+ await ws.db.mutate(Stores.reserves, reservePub, (r) => {
+ switch (r.reserveStatus) {
+ case ReserveRecordStatus.REGISTERING_BANK:
+ case ReserveRecordStatus.WAIT_CONFIRM_BANK:
+ break;
+ default:
+ return;
+ }
+ const now = getTimestampNow();
+ r.timestampBankConfirmed = now;
+ r.reserveStatus = ReserveRecordStatus.BANK_ABORTED;
+ r.retryInfo = initRetryInfo();
+ return r;
+ });
+ return;
+ }
+
if (status.selection_done) {
if (reserve.reserveStatus === ReserveRecordStatus.REGISTERING_BANK) {
await registerReserveWithBank(ws, reservePub);
@@ -612,6 +632,8 @@ async function processReserveImpl(
case ReserveRecordStatus.WAIT_CONFIRM_BANK:
await processReserveBankStatus(ws, reservePub);
break;
+ case ReserveRecordStatus.BANK_ABORTED:
+ break;
default:
console.warn("unknown reserve record status:", reserve.reserveStatus);
assertUnreachable(reserve.reserveStatus);
@@ -802,6 +824,14 @@ export async function createTalerWithdrawReserve(
// We do this here, as the reserve should be registered before we return,
// so that we can redirect the user to the bank's status page.
await processReserveBankStatus(ws, reserve.reservePub);
+ const processedReserve = await ws.db.get(Stores.reserves, reserve.reservePub);
+ if (processedReserve?.reserveStatus === ReserveRecordStatus.BANK_ABORTED) {
+ throw OperationFailedError.fromCode(
+ TalerErrorCode.WALLET_WITHDRAWAL_OPERATION_ABORTED_BY_BANK,
+ "withdrawal aborted by bank",
+ {},
+ );
+ }
return {
reservePub: reserve.reservePub,
confirmTransferUrl: withdrawInfo.confirmTransferUrl,