From eeb3906f4f827860650ba02f1d73f979a4caec89 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 12 Dec 2023 16:30:04 +0100 Subject: wallet-core: i18n-ized terms --- .../taler-wallet-core/src/operations/exchanges.ts | 28 +++++++++++++++++----- packages/taler-wallet-core/src/wallet.ts | 20 +++++++++++----- 2 files changed, 36 insertions(+), 12 deletions(-) (limited to 'packages/taler-wallet-core') 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 { - 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 { 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 { // 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( } 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); -- cgit v1.2.3