summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/withdraw.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/withdraw.ts')
-rw-r--r--packages/taler-wallet-core/src/withdraw.ts60
1 files changed, 57 insertions, 3 deletions
diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts
index 960ffa525..68ff9d494 100644
--- a/packages/taler-wallet-core/src/withdraw.ts
+++ b/packages/taler-wallet-core/src/withdraw.ts
@@ -49,6 +49,7 @@ import {
ExchangeWithdrawResponse,
ExchangeWithdrawalDetails,
ForcedDenomSel,
+ GetWithdrawalDetailsForAmountRequest,
HttpStatusCode,
LibtoolVersion,
Logger,
@@ -69,6 +70,7 @@ import {
UnblindedSignature,
WalletNotification,
WithdrawUriInfoResponse,
+ WithdrawalDetailsForAmount,
WithdrawalExchangeAccountDetails,
WithdrawalType,
addPaytoQueryParams,
@@ -1273,7 +1275,6 @@ export async function updateWithdrawalDenoms(
wex: WalletExecutionContext,
exchangeBaseUrl: string,
): Promise<void> {
-
logger.trace(
`updating denominations used for withdrawal for ${exchangeBaseUrl}`,
);
@@ -1931,7 +1932,9 @@ export async function getExchangeWithdrawalInfo(
ageRestricted: number | undefined,
): Promise<ExchangeWithdrawalDetails> {
logger.trace("updating exchange");
- const exchange = await fetchFreshExchange(wex, exchangeBaseUrl);
+ const exchange = await fetchFreshExchange(wex, exchangeBaseUrl, {
+ cancellationToken: wex.cancellationToken,
+ });
if (exchange.currency != instructedAmount.currency) {
// Specifying the amount in the conversion input currency is not yet supported.
@@ -1947,7 +1950,7 @@ export async function getExchangeWithdrawalInfo(
exchange,
instructedAmount,
},
- CancellationToken.CONTINUE,
+ wex.cancellationToken,
);
logger.trace("updating withdrawal denoms");
@@ -3152,3 +3155,54 @@ async function internalWaitWithdrawalFinal(
flag.reset();
}
}
+
+export async function getWithdrawalDetailsForAmount(
+ wex: WalletExecutionContext,
+ cts: CancellationToken.Source,
+ req: GetWithdrawalDetailsForAmountRequest,
+): Promise<WithdrawalDetailsForAmount> {
+ const clientCancelKey = req.clientCancellationId
+ ? `ccid:getWithdrawalDetailsForAmount:${req.clientCancellationId}`
+ : undefined;
+ if (clientCancelKey) {
+ const prevCts = wex.ws.clientCancellationMap.get(clientCancelKey);
+ if (prevCts) {
+ prevCts.cancel();
+ }
+ wex.ws.clientCancellationMap.set(clientCancelKey, cts);
+ }
+ try {
+ return internalGetWithdrawalDetailsForAmount(wex, req);
+ } finally {
+ if (clientCancelKey && !cts.token.isCancelled) {
+ wex.ws.clientCancellationMap.delete(clientCancelKey);
+ }
+ }
+}
+
+async function internalGetWithdrawalDetailsForAmount(
+ wex: WalletExecutionContext,
+ req: GetWithdrawalDetailsForAmountRequest,
+): Promise<WithdrawalDetailsForAmount> {
+ const wi = await getExchangeWithdrawalInfo(
+ wex,
+ req.exchangeBaseUrl,
+ Amounts.parseOrThrow(req.amount),
+ req.restrictAge,
+ );
+ let numCoins = 0;
+ for (const x of wi.selectedDenoms.selectedDenoms) {
+ numCoins += x.count;
+ }
+ const resp: WithdrawalDetailsForAmount = {
+ amountRaw: req.amount,
+ amountEffective: Amounts.stringify(wi.selectedDenoms.totalCoinValue),
+ paytoUris: wi.exchangePaytoUris,
+ tosAccepted: wi.termsOfServiceAccepted,
+ ageRestrictionOptions: wi.ageRestrictionOptions,
+ withdrawalAccountsList: wi.exchangeCreditAccountDetails,
+ numCoins,
+ scopeInfo: wi.scopeInfo,
+ };
+ return resp;
+}