summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/withdraw.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-11-15 12:07:03 +0100
committerFlorian Dold <florian@dold.me>2023-11-15 12:07:03 +0100
commit1fe13cc8a3f06cf006b826a1a4f5f387b978ee7f (patch)
tree9bfec313cfd855d2070274c243004ecece87cf66 /packages/taler-wallet-core/src/operations/withdraw.ts
parent3c03ed931cc2be8081528a3f4ebec55e92c8eca6 (diff)
downloadwallet-core-1fe13cc8a3f06cf006b826a1a4f5f387b978ee7f.tar.gz
wallet-core-1fe13cc8a3f06cf006b826a1a4f5f387b978ee7f.tar.bz2
wallet-core-1fe13cc8a3f06cf006b826a1a4f5f387b978ee7f.zip
wallet-core: store changed KYC URL on subsequent KYC queries
Diffstat (limited to 'packages/taler-wallet-core/src/operations/withdraw.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/withdraw.ts59
1 files changed, 58 insertions, 1 deletions
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts
index c83993816..9819ae6a9 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.ts
@@ -727,6 +727,58 @@ enum AmlStatus {
fronzen = 2,
}
+/**
+ * Transition a withdrawal transaction with a (new) KYC URL.
+ *
+ * Emit a notification for the (self-)transition.
+ */
+async function transitionKycUrlUpdate(
+ ws: InternalWalletState,
+ withdrawalGroupId: string,
+ kycUrl: string,
+): Promise<void> {
+ let notificationKycUrl: string | undefined = undefined;
+ const transactionId = constructTransactionIdentifier({
+ tag: TransactionType.Withdrawal,
+ withdrawalGroupId,
+ });
+
+ const transitionInfo = await ws.db
+ .mktx((x) => [x.planchets, x.withdrawalGroups])
+ .runReadWrite(async (tx) => {
+ const wg2 = await tx.withdrawalGroups.get(withdrawalGroupId);
+ if (!wg2) {
+ return;
+ }
+ const oldTxState = computeWithdrawalTransactionStatus(wg2);
+ switch (wg2.status) {
+ case WithdrawalGroupStatus.PendingReady: {
+ wg2.kycUrl = kycUrl;
+ notificationKycUrl = kycUrl;
+ await tx.withdrawalGroups.put(wg2);
+ const newTxState = computeWithdrawalTransactionStatus(wg2);
+ return {
+ oldTxState,
+ newTxState,
+ };
+ }
+ default:
+ return undefined;
+ }
+ });
+ if (transitionInfo) {
+ // Always notify, even on self-transition, as the KYC URL might have changed.
+ ws.notify({
+ type: NotificationType.TransactionStateTransition,
+ oldTxState: transitionInfo.oldTxState,
+ newTxState: transitionInfo.newTxState,
+ transactionId,
+ experimentalUserData: notificationKycUrl,
+ });
+ }
+ ws.workAvailable.trigger();
+}
+
async function handleKycRequired(
ws: InternalWalletState,
withdrawalGroup: WithdrawalGroupRecord,
@@ -1400,6 +1452,8 @@ async function processWithdrawalGroupPendingKyc(
);
url.searchParams.set("timeout_ms", "30000");
+ const withdrawalGroupId = withdrawalGroup.withdrawalGroupId;
+
const retryTag = TaskIdentifiers.forWithdrawal(withdrawalGroup);
runLongpollAsync(ws, retryTag, async (cancellationToken) => {
logger.info(`long-polling for withdrawal KYC status via ${url.href}`);
@@ -1421,7 +1475,10 @@ async function processWithdrawalGroupPendingKyc(
} else if (kycStatusRes.status === HttpStatusCode.Accepted) {
const kycStatus = await kycStatusRes.json();
logger.info(`kyc status: ${j2s(kycStatus)}`);
- // FIXME: do we need to update the KYC url, or does it always stay constant?
+ const kycUrl = kycStatus.kyc_url;
+ if (typeof kycUrl === "string") {
+ await transitionKycUrlUpdate(ws, withdrawalGroupId, kycUrl);
+ }
return { ready: false };
} else if (
kycStatusRes.status === HttpStatusCode.UnavailableForLegalReasons