aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-12-12 16:30:04 +0100
committerFlorian Dold <florian@dold.me>2023-12-12 16:30:04 +0100
commiteeb3906f4f827860650ba02f1d73f979a4caec89 (patch)
tree86473626baca6a90000eed91703455a0a71b94d1 /packages/taler-wallet-core
parente31f18b8f129adb9cbe33158297a9cff56a7143e (diff)
downloadwallet-core-eeb3906f4f827860650ba02f1d73f979a4caec89.tar.xz
wallet-core: i18n-ized terms
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r--packages/taler-wallet-core/src/operations/exchanges.ts28
-rw-r--r--packages/taler-wallet-core/src/wallet.ts20
2 files changed, 36 insertions, 12 deletions
diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts
index 253801e93..6afafd9f5 100644
--- a/packages/taler-wallet-core/src/operations/exchanges.ts
+++ b/packages/taler-wallet-core/src/operations/exchanges.ts
@@ -122,29 +122,39 @@ interface ExchangeTosDownloadResult {
tosText: string;
tosEtag: string;
tosContentType: string;
+ tosContentLanguage: string | undefined;
}
async function downloadExchangeWithTermsOfService(
exchangeBaseUrl: string,
http: HttpRequestLibrary,
timeout: Duration,
- contentType: string,
+ acceptFormat: string,
+ acceptLanguage: string | undefined,
): Promise<ExchangeTosDownloadResult> {
- logger.trace(`downloading exchange tos (type ${contentType})`);
+ logger.trace(`downloading exchange tos (type ${acceptFormat})`);
const reqUrl = new URL("terms", exchangeBaseUrl);
- const headers = {
- Accept: contentType,
+ const headers: {
+ Accept: string;
+ "Accept-Language"?: string;
+ } = {
+ Accept: acceptFormat,
};
+ if (acceptLanguage) {
+ headers["Accept-Language"] = acceptLanguage;
+ }
+
const resp = await http.fetch(reqUrl.href, {
headers,
timeout,
});
const tosText = await readSuccessResponseTextOrThrow(resp);
const tosEtag = resp.headers.get("etag") || "unknown";
+ const tosContentLanguage = resp.headers.get("content-language") || undefined;
const tosContentType = resp.headers.get("content-type") || "text/plain";
- return { tosText, tosEtag, tosContentType };
+ return { tosText, tosEtag, tosContentType, tosContentLanguage };
}
/**
@@ -572,9 +582,10 @@ async function downloadTosFromAcceptedFormat(
baseUrl: string,
timeout: Duration,
acceptedFormat?: string[],
+ acceptLanguage?: string,
): Promise<ExchangeTosDownloadResult> {
let tosFound: ExchangeTosDownloadResult | undefined;
- //Remove this when exchange supports multiple content-type in accept header
+ // Remove this when exchange supports multiple content-type in accept header
if (acceptedFormat)
for (const format of acceptedFormat) {
const resp = await downloadExchangeWithTermsOfService(
@@ -582,6 +593,7 @@ async function downloadTosFromAcceptedFormat(
ws.http,
timeout,
format,
+ acceptLanguage,
);
if (resp.tosContentType === format) {
tosFound = resp;
@@ -597,6 +609,7 @@ async function downloadTosFromAcceptedFormat(
ws.http,
timeout,
"text/plain",
+ acceptLanguage,
);
}
@@ -1144,6 +1157,7 @@ export async function getExchangeTos(
ws: InternalWalletState,
exchangeBaseUrl: string,
acceptedFormat?: string[],
+ acceptLanguage?: string,
): Promise<GetExchangeTosResult> {
// FIXME: download ToS in acceptable format if passed!
const { exchange, exchangeDetails } = await fetchFreshExchange(
@@ -1156,6 +1170,7 @@ export async function getExchangeTos(
exchangeBaseUrl,
getExchangeRequestTimeout(),
acceptedFormat,
+ acceptLanguage,
);
await ws.db
@@ -1173,6 +1188,7 @@ export async function getExchangeTos(
currentEtag: tosDownload.tosEtag,
content: tosDownload.tosText,
contentType: tosDownload.tosContentType,
+ contentLanguage: tosDownload.tosContentLanguage,
tosStatus: getExchangeTosStatusFromRecord(exchange),
};
}
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index c9612da5f..fc4ae832d 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -187,6 +187,7 @@ import { getBalanceDetail, getBalances } from "./operations/balance.js";
import {
TaskIdentifiers,
TaskRunResult,
+ TaskRunResultType,
makeExchangeListItem,
runTaskWithErrorReporting,
} from "./operations/common.js";
@@ -511,11 +512,13 @@ async function runTaskLoop(
const res = await runTaskWithErrorReporting(ws, p.id, async () => {
return await callOperationHandler(ws, p);
});
- ws.notify({
- type: NotificationType.PendingOperationProcessed,
- id: p.id,
- taskResultType: res.type,
- });
+ if (!(ws.stopped && res.type === TaskRunResultType.Error)) {
+ ws.notify({
+ type: NotificationType.PendingOperationProcessed,
+ id: p.id,
+ taskResultType: res.type,
+ });
+ }
if (ws.stopped) {
ws.isTaskLoopRunning = false;
return {
@@ -1106,7 +1109,12 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
}
case WalletApiOperation.GetExchangeTos: {
const req = codecForGetExchangeTosRequest().decode(payload);
- return getExchangeTos(ws, req.exchangeBaseUrl, req.acceptedFormat);
+ return getExchangeTos(
+ ws,
+ req.exchangeBaseUrl,
+ req.acceptedFormat,
+ req.acceptLanguage,
+ );
}
case WalletApiOperation.GetContractTermsDetails: {
const req = codecForGetContractTermsDetails().decode(payload);