summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/withdraw.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/operations/withdraw.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/withdraw.ts75
1 files changed, 48 insertions, 27 deletions
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts
index 58df75964..6c7e8c37a 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.ts
@@ -45,6 +45,7 @@ import {
LibtoolVersion,
Logger,
NotificationType,
+ TalerBankIntegrationHttpClient,
TalerError,
TalerErrorCode,
TalerErrorDetail,
@@ -556,19 +557,11 @@ export async function getBankWithdrawalInfo(
throw Error(`can't parse URL ${talerWithdrawUri}`);
}
- const configReqUrl = new URL("config", uriResult.bankIntegrationApiBaseUrl);
+ const bankApi = new TalerBankIntegrationHttpClient(uriResult.bankIntegrationApiBaseUrl, http);
- const configResp = await http.fetch(configReqUrl.href);
- const config = await readSuccessResponseJsonOrThrow(
- configResp,
- codecForIntegrationBankConfig(),
- );
+ const { body: config } = await bankApi.getConfig()
- const versionRes = LibtoolVersion.compare(
- WALLET_BANK_INTEGRATION_PROTOCOL_VERSION,
- config.version,
- );
- if (versionRes?.compatible != true) {
+ if (!bankApi.isCompatible(config.version)) {
throw TalerError.fromDetail(
TalerErrorCode.WALLET_BANK_INTEGRATION_PROTOCOL_VERSION_INCOMPATIBLE,
{
@@ -579,29 +572,24 @@ export async function getBankWithdrawalInfo(
);
}
- const reqUrl = new URL(
- `withdrawal-operation/${uriResult.withdrawalOperationId}`,
- uriResult.bankIntegrationApiBaseUrl,
- );
-
- logger.info(`bank withdrawal status URL: ${reqUrl.href}}`);
+ const resp = await bankApi.getWithdrawalOperationById(uriResult.withdrawalOperationId)
- const resp = await http.fetch(reqUrl.href);
- const status = await readSuccessResponseJsonOrThrow(
- resp,
- codecForWithdrawOperationStatusResponse(),
- );
+ if (resp.type === "fail") {
+ throw TalerError.fromUncheckedDetail(resp.detail);
+ }
+ const { body: status } = resp
logger.info(`bank withdrawal operation status: ${j2s(status)}`);
return {
+ operationId: uriResult.withdrawalOperationId,
+ apiBaseUrl: uriResult.bankIntegrationApiBaseUrl,
amount: Amounts.parseOrThrow(status.amount),
confirmTransferUrl: status.confirm_transfer_url,
- selectionDone: status.selection_done,
senderWire: status.sender_wire,
suggestedExchange: status.suggested_exchange,
- transferDone: status.transfer_done,
wireTypes: status.wire_types,
+ status: status.status,
};
}
@@ -1226,8 +1214,7 @@ export async function updateWithdrawalDenoms(
denom.verificationStatus === DenominationVerificationStatus.Unverified
) {
logger.trace(
- `Validating denomination (${current + 1}/${
- denominations.length
+ `Validating denomination (${current + 1}/${denominations.length
}) signature of ${denom.denomPubHash}`,
);
let valid = false;
@@ -1872,7 +1859,7 @@ export async function getExchangeWithdrawalInfo(
) {
logger.warn(
`wallet's support for exchange protocol version ${WALLET_EXCHANGE_PROTOCOL_VERSION} might be outdated ` +
- `(exchange has ${exchange.protocolVersionRange}), checking for updates`,
+ `(exchange has ${exchange.protocolVersionRange}), checking for updates`,
);
}
}
@@ -1915,6 +1902,7 @@ export async function getExchangeWithdrawalInfo(
export interface GetWithdrawalDetailsForUriOpts {
restrictAge?: number;
+ notifyChangeFromPendingTimeoutMs?: number;
}
/**
@@ -1957,7 +1945,40 @@ export async function getWithdrawalDetailsForUri(
);
});
+ if (info.status === "pending" && opts.notifyChangeFromPendingTimeoutMs !== undefined) {
+ const bankApi = new TalerBankIntegrationHttpClient(info.apiBaseUrl, ws.http);
+ console.log(
+ `waiting operation (${info.operationId}) to change from pending`,
+ );
+ bankApi.getWithdrawalOperationById(info.operationId, {
+ old_state: "pending",
+ timeoutMs: opts.notifyChangeFromPendingTimeoutMs
+ }).then(resp => {
+ console.log(
+ `operation (${info.operationId}) to change to ${JSON.stringify(resp, undefined, 2)}`,
+ );
+ if (resp.type === "fail") {
+ //not found, this is rare since the previous request succeed
+ ws.notify({
+ type: NotificationType.WithdrawalOperationTransition,
+ operationId: info.operationId,
+ state: info.status,
+ })
+ return;
+ }
+
+ ws.notify({
+ type: NotificationType.WithdrawalOperationTransition,
+ operationId: info.operationId,
+ state: resp.body.status,
+ });
+ })
+ }
+
return {
+ operationId: info.operationId,
+ confirmTransferUrl: info.confirmTransferUrl,
+ status: info.status,
amount: Amounts.stringify(info.amount),
defaultExchangeBaseUrl: info.suggestedExchange,
possibleExchanges,