commit f3d1231f71e004367a8c66faf70916f92fc9fc51
parent 784c73923e768dda7e3f04de802fc1144f164923
Author: Florian Dold <dold@taler.net>
Date: Thu, 23 Jul 2026 02:33:14 +0200
wallet: use typed bank-conversion client in withdraw
Diffstat:
2 files changed, 22 insertions(+), 26 deletions(-)
diff --git a/packages/taler-util/src/http-client/bank-conversion.ts b/packages/taler-util/src/http-client/bank-conversion.ts
@@ -18,6 +18,7 @@
* Imports.
*/
import { AmountJson, Amounts } from "../amounts.js";
+import { CancellationToken } from "../CancellationToken.js";
import { HttpRequestLibrary } from "../http-common.js";
import { HttpStatusCode } from "../http-status-codes.js";
import { createPlatformHttpLib } from "../http.js";
@@ -68,14 +69,17 @@ export class TalerBankConversionHttpClient {
httpLib: HttpRequestLibrary;
cacheEvictor: CacheEvictor<TalerBankConversionCacheEviction>;
+ cancellationToken?: CancellationToken;
constructor(
readonly baseUrl: string,
httpClient?: HttpRequestLibrary,
cacheEvictor?: CacheEvictor<TalerBankConversionCacheEviction>,
+ cancellationToken?: CancellationToken,
) {
this.httpLib = httpClient ?? createPlatformHttpLib();
this.cacheEvictor = cacheEvictor ?? nullEvictor;
+ this.cancellationToken = cancellationToken;
}
static isCompatible(version: string): boolean {
@@ -91,6 +95,7 @@ export class TalerBankConversionHttpClient {
const url = new URL(`config`, this.baseUrl);
const resp = await this.httpLib.fetch(url.href, {
method: "GET",
+ cancellationToken: this.cancellationToken,
});
switch (resp.status) {
case HttpStatusCode.Ok:
@@ -148,6 +153,7 @@ export class TalerBankConversionHttpClient {
const resp = await this.httpLib.fetch(url.href, {
method: "GET",
headers: authHeaders(auth),
+ cancellationToken: this.cancellationToken,
});
switch (resp.status) {
case HttpStatusCode.Ok:
diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts
@@ -63,6 +63,7 @@ import {
PrepareBankIntegratedWithdrawalResponse,
Result,
ScopeInfo,
+ TalerBankConversionHttpClient,
TalerBankIntegrationHttpClient,
TalerError,
TalerErrorCode,
@@ -94,8 +95,6 @@ import {
checkDbInvariant,
checkLogicInvariant,
checkProtocolInvariant,
- codecForCashinConversionResponse,
- codecForConversionBankConfig,
codecForExchangeLegacyWithdrawBatchResponse,
codecForLegitimizationNeededResponse,
encodeCrock,
@@ -107,7 +106,6 @@ import {
} from "@gnu-taler/taler-util";
import {
HttpRequestLibrary,
- readSuccessResponseJsonOrErrorCode,
readSuccessResponseJsonOrThrow,
readTalerErrorResponse,
throwUnexpectedRequestError,
@@ -4110,42 +4108,34 @@ async function fetchAccount(
let transferAmount: AmountString | undefined;
let currencySpecification: CurrencySpecification | undefined = undefined;
if (acct.conversion_url != null) {
- const reqUrl = new URL("cashin-rate", acct.conversion_url);
- reqUrl.searchParams.set(
- "amount_credit",
- Amounts.stringify(instructedAmount),
- );
- const httpResp = await cancelableFetch(wex, reqUrl);
- const respOrErr = await readSuccessResponseJsonOrErrorCode(
- httpResp,
- codecForCashinConversionResponse(),
+ const conversionClient = new TalerBankConversionHttpClient(
+ acct.conversion_url,
+ wex.http,
+ undefined,
+ wex.cancellationToken,
);
- if (respOrErr.isError) {
+ const rateResp = await conversionClient.getCashinRate(undefined, {
+ credit: instructedAmount,
+ });
+ if (rateResp.case !== "ok") {
return {
status: "error",
paytoUri: acct.payto_uri,
- conversionError: respOrErr.talerErrorResponse,
+ conversionError: rateResp.detail!,
transferOptions: [],
};
}
- const resp = respOrErr.response;
- transferAmount = resp.amount_debit;
- const configUrl = new URL("config", acct.conversion_url);
- const configResp = await cancelableFetch(wex, configUrl);
- const configRespOrError = await readSuccessResponseJsonOrErrorCode(
- configResp,
- codecForConversionBankConfig(),
- );
- if (configRespOrError.isError) {
+ transferAmount = rateResp.body.amount_debit;
+ const configResp = await conversionClient.getConfig();
+ if (configResp.case !== "ok") {
return {
status: "error",
paytoUri: acct.payto_uri,
- conversionError: configRespOrError.talerErrorResponse,
+ conversionError: configResp.detail!,
transferOptions: [],
};
}
- const configParsed = configRespOrError.response;
- currencySpecification = configParsed.fiat_currency_specification;
+ currencySpecification = configResp.body.fiat_currency_specification;
} else {
transferAmount = Amounts.stringify(instructedAmount);