From 2c14a180c12229623a64e1626da6b05777a7b397 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 17 Jan 2023 15:59:30 -0300 Subject: re-use the same kyc function from withdrawal for deposits --- .../taler-wallet-core/src/operations/withdraw.ts | 82 +++++++++++++--------- 1 file changed, 48 insertions(+), 34 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/withdraw.ts') diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index a1a39bf32..c1cc94413 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -26,7 +26,6 @@ import { AmountJson, AmountLike, Amounts, - AmountString, BankWithdrawDetails, CancellationToken, canonicalizeBaseUrl, @@ -70,13 +69,14 @@ import { CoinSourceType, DenominationRecord, DenominationVerificationStatus, + KycPendingInfo, + KycUserType, PlanchetRecord, PlanchetStatus, WalletStoresV1, WgInfo, WithdrawalGroupRecord, WithdrawalGroupStatus, - WithdrawalKycPendingInfo, WithdrawalRecordType, } from "../db.js"; import { @@ -86,7 +86,6 @@ import { } from "../errors.js"; import { InternalWalletState } from "../internal-wallet-state.js"; import { - getExchangeTosStatus, makeCoinAvailable, makeExchangeListItem, runOperationWithErrorReporting, @@ -927,7 +926,7 @@ async function queryReserve( ); reserveUrl.searchParams.set("timeout_ms", "30000"); - logger.info(`querying reserve status via ${reserveUrl}`); + logger.info(`querying reserve status via ${reserveUrl.href}`); const resp = await ws.http.get(reserveUrl.href, { timeout: getReserveRequestTimeout(withdrawalGroup), @@ -1165,9 +1164,9 @@ export async function processWithdrawalGroup( let numFinished = 0; let numKycRequired = 0; let finishedForFirstTime = false; - let errorsPerCoin: Record = {}; + const errorsPerCoin: Record = {}; - let res = await ws.db + const res = await ws.db .mktx((x) => [x.coins, x.withdrawalGroups, x.planchets]) .runReadWrite(async (tx) => { const wg = await tx.withdrawalGroups.get(withdrawalGroupId); @@ -1210,39 +1209,22 @@ export async function processWithdrawalGroup( if (numKycRequired > 0) { if (kycInfo) { - const url = new URL( - `kyc-check/${kycInfo.requirementRow}/${kycInfo.paytoHash}/individual`, + await checkKycStatus( + ws, withdrawalGroup.exchangeBaseUrl, + kycInfo, + "individual", ); - logger.info(`kyc url ${url.href}`); - const kycStatusReq = await ws.http.fetch(url.href, { - method: "GET", - }); - logger.warn("kyc requested, but already fulfilled"); - if (kycStatusReq.status === HttpStatusCode.Ok) { - return { - type: OperationAttemptResultType.Pending, - result: undefined, - }; - } else if (kycStatusReq.status === HttpStatusCode.Accepted) { - const kycStatus = await kycStatusReq.json(); - logger.info(`kyc status: ${j2s(kycStatus)}`); - throw TalerError.fromDetail( - TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED, - { - kycUrl: kycStatus.kyc_url, - }, - `KYC check required for withdrawal`, - ); - } else { - throw Error( - `unexpected response from kyc-check (${kycStatusReq.status})`, - ); - } + return { + type: OperationAttemptResultType.Pending, + result: undefined, + }; } else { throw TalerError.fromDetail( TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED, - {}, + { + //FIXME we can't rise KYC error here since we don't have the url + } as any, `KYC check required for withdrawal (not yet implemented in wallet-core)`, ); } @@ -1270,6 +1252,38 @@ export async function processWithdrawalGroup( }; } +export async function checkKycStatus( + ws: InternalWalletState, + exchangeUrl: string, + kycInfo: KycPendingInfo, + userType: KycUserType, +): Promise { + const url = new URL( + `kyc-check/${kycInfo.requirementRow}/${kycInfo.paytoHash}/${userType}`, + exchangeUrl, + ); + logger.info(`kyc url ${url.href}`); + const kycStatusReq = await ws.http.fetch(url.href, { + method: "GET", + }); + logger.warn("kyc requested, but already fulfilled"); + if (kycStatusReq.status === HttpStatusCode.Ok) { + return; + } else if (kycStatusReq.status === HttpStatusCode.Accepted) { + const kycStatus = await kycStatusReq.json(); + logger.info(`kyc status: ${j2s(kycStatus)}`); + throw TalerError.fromDetail( + TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED, + { + kycUrl: kycStatus.kyc_url, + }, + `KYC check required for withdrawal`, + ); + } else { + throw Error(`unexpected response from kyc-check (${kycStatusReq.status})`); + } +} + const AGE_MASK_GROUPS = "8:10:12:14:16:18" .split(":") .map((n) => parseInt(n, 10)); -- cgit v1.2.3