From 882d6b3710f82d85b2129f09c63f9db45985ef64 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 24 Jan 2022 14:12:12 -0300 Subject: last activity -> pending; fix downloadTos --- packages/taler-wallet-core/src/wallet.ts | 35 +++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'packages/taler-wallet-core/src/wallet.ts') diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 182453ff2..b53ba24c4 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -89,9 +89,12 @@ import { } from "./operations/deposits.js"; import { acceptExchangeTermsOfService, + downloadTosFromAcceptedFormat, getExchangeDetails, + getExchangeRequestTimeout, getExchangeTrust, - updateExchangeFromUrl + updateExchangeFromUrl, + updateExchangeTermsOfService } from "./operations/exchanges.js"; import { getMerchantInfo } from "./operations/merchants.js"; import { @@ -441,7 +444,6 @@ async function getExchangeTos( ws, exchangeBaseUrl, acceptedFormat, - true, ); const content = exchangeDetails.termsOfServiceText; const currentEtag = exchangeDetails.termsOfServiceLastEtag; @@ -453,12 +455,34 @@ async function getExchangeTos( ) { throw Error("exchange is in invalid state"); } + if (acceptedFormat && acceptedFormat.findIndex(f => f === contentType) !== -1) { + return { + acceptedEtag: exchangeDetails.termsOfServiceAcceptedEtag, + currentEtag, + content, + contentType, + }; + } + + const tosDownload = await downloadTosFromAcceptedFormat(ws, exchangeBaseUrl, getExchangeRequestTimeout(), acceptedFormat); + + if (tosDownload.tosContentType === contentType) { + return { + acceptedEtag: exchangeDetails.termsOfServiceAcceptedEtag, + currentEtag, + content, + contentType, + }; + } + await updateExchangeTermsOfService(ws, exchangeBaseUrl, tosDownload) + return { acceptedEtag: exchangeDetails.termsOfServiceAcceptedEtag, - currentEtag, - content, - contentType, + currentEtag: tosDownload.tosEtag, + content: tosDownload.tosText, + contentType: tosDownload.tosContentType, }; + } async function listKnownBankAccounts( @@ -1245,3 +1269,4 @@ class InternalWalletStateImpl implements InternalWalletState { } } } + -- cgit v1.2.3