diff options
author | Florian Dold <florian@dold.me> | 2022-11-01 13:39:42 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-11-01 13:39:42 +0100 |
commit | 8e1622a915387427590899a3a515d7556d2bc665 (patch) | |
tree | 17a3e6f830eab0d9215e682222dc5b1105046f89 /packages/taler-wallet-core/src | |
parent | d751f1a267773746169c3364dfdc25ce134ad07a (diff) | |
download | wallet-core-8e1622a915387427590899a3a515d7556d2bc665.tar.xz |
wallet-core: better KYC error message
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/db.ts | 1 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/errors.ts | 3 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/withdraw.ts | 30 |
3 files changed, 33 insertions, 1 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 3abb76d60..ce0070e69 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -564,6 +564,7 @@ export interface ExchangeRecord { export enum PlanchetStatus { Pending = 10 /* ACTIVE_START */, + KycRequired = 11 /* ACTIVE_START + 1 */, WithdrawalDone = 50 /* DORMANT_START */, } diff --git a/packages/taler-wallet-core/src/errors.ts b/packages/taler-wallet-core/src/errors.ts index f8f5cef0e..3480fed3c 100644 --- a/packages/taler-wallet-core/src/errors.ts +++ b/packages/taler-wallet-core/src/errors.ts @@ -79,6 +79,9 @@ export interface DetailsMap { [TalerErrorCode.WALLET_CRYPTO_WORKER_BAD_REQUEST]: { detail: string; }; + [TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED]: { + // FIXME! + }; } type ErrBody<Y> = Y extends keyof DetailsMap ? DetailsMap[Y] : never; diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 6be7c7614..0e6bb8339 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -47,6 +47,7 @@ import { ExchangeWithdrawRequest, ForcedDenomSel, getRandomBytes, + HttpStatusCode, j2s, LibtoolVersion, Logger, @@ -527,6 +528,23 @@ async function processPlanchetExchangeRequest( try { const resp = await ws.http.postJson(reqUrl, reqBody); + if (resp.status === HttpStatusCode.UnavailableForLegalReasons) { + logger.info("withdrawal requires KYC"); + await ws.db + .mktx((x) => [x.planchets]) + .runReadWrite(async (tx) => { + let planchet = await tx.planchets.indexes.byGroupAndIndex.get([ + withdrawalGroup.withdrawalGroupId, + coinIdx, + ]); + if (!planchet) { + return; + } + planchet.planchetStatus = PlanchetStatus.KycRequired; + await tx.planchets.put(planchet); + }); + return; + } const r = await readSuccessResponseJsonOrThrow( resp, codecForWithdrawResponse(), @@ -1126,6 +1144,7 @@ export async function processWithdrawalGroup( await Promise.all(work); let numFinished = 0; + let numKycRequired = 0; let finishedForFirstTime = false; let errorsPerCoin: Record<number, TalerErrorDetail> = {}; @@ -1143,6 +1162,9 @@ export async function processWithdrawalGroup( if (x.planchetStatus === PlanchetStatus.WithdrawalDone) { numFinished++; } + if (x.planchetStatus === PlanchetStatus.KycRequired) { + numKycRequired++; + } if (x.lastError) { errorsPerCoin[x.coinIdx] = x.lastError; } @@ -1156,7 +1178,13 @@ export async function processWithdrawalGroup( await tx.withdrawalGroups.put(wg); }); - + if (numKycRequired > 0) { + throw TalerError.fromDetail( + TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED, + {}, + `KYC check required for withdrawal (not yet implemented in wallet-core)`, + ); + } if (numFinished != numTotalCoins) { throw TalerError.fromDetail( TalerErrorCode.WALLET_WITHDRAWAL_GROUP_INCOMPLETE, |