aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/exchanges.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-01-24 14:12:12 -0300
committerSebastian <sebasjm@gmail.com>2022-01-24 14:12:12 -0300
commit882d6b3710f82d85b2129f09c63f9db45985ef64 (patch)
treef6304b6bb539e78d3ca4711fa5483dc6657f2163 /packages/taler-wallet-core/src/operations/exchanges.ts
parentec059d42d77a5f092135635f478790e77a2685df (diff)
downloadwallet-core-882d6b3710f82d85b2129f09c63f9db45985ef64.tar.xz
last activity -> pending; fix downloadTos
Diffstat (limited to 'packages/taler-wallet-core/src/operations/exchanges.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/exchanges.ts84
1 files changed, 56 insertions, 28 deletions
diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts
index d73d593e8..87200c2f9 100644
--- a/packages/taler-wallet-core/src/operations/exchanges.ts
+++ b/packages/taler-wallet-core/src/operations/exchanges.ts
@@ -138,7 +138,7 @@ async function handleExchangeUpdateError(
}
}
-function getExchangeRequestTimeout(e: ExchangeRecord): Duration {
+export function getExchangeRequestTimeout(): Duration {
return { d_ms: 5000 };
}
@@ -199,6 +199,27 @@ getExchangeDetails.makeContext = (db: DbAccess<typeof WalletStoresV1>) =>
exchangeDetails: x.exchangeDetails,
}));
+export async function updateExchangeTermsOfService(
+ ws: InternalWalletState,
+ exchangeBaseUrl: string,
+ tos: ExchangeTosDownloadResult,
+): Promise<void> {
+ await ws.db
+ .mktx((x) => ({
+ exchanges: x.exchanges,
+ exchangeDetails: x.exchangeDetails,
+ }))
+ .runReadWrite(async (tx) => {
+ const d = await getExchangeDetails(tx, exchangeBaseUrl);
+ if (d) {
+ d.termsOfServiceText = tos.tosText;
+ d.termsOfServiceContentType = tos.tosContentType;
+ d.termsOfServiceLastEtag = tos.tosEtag;
+ await tx.exchangeDetails.put(d);
+ }
+ });
+}
+
export async function acceptExchangeTermsOfService(
ws: InternalWalletState,
exchangeBaseUrl: string,
@@ -434,6 +455,36 @@ async function downloadKeysInfo(
};
}
+export async function downloadTosFromAcceptedFormat(
+ ws: InternalWalletState,
+ baseUrl: string,
+ timeout: Duration,
+ acceptedFormat?: string[]): Promise<ExchangeTosDownloadResult> {
+ let tosFound: ExchangeTosDownloadResult | undefined;
+ //Remove this when exchange supports multiple content-type in accept header
+ if (acceptedFormat)
+ for (const format of acceptedFormat) {
+ const resp = await downloadExchangeWithTermsOfService(
+ baseUrl,
+ ws.http,
+ timeout,
+ format,
+ );
+ if (resp.tosContentType === format) {
+ tosFound = resp;
+ break;
+ }
+ }
+ if (tosFound !== undefined) return tosFound
+ // If none of the specified format was found try text/plain
+ return await downloadExchangeWithTermsOfService(
+ baseUrl,
+ ws.http,
+ timeout,
+ "text/plain",
+ );
+}
+
/**
* Update or add exchange DB entry by fetching the /keys and /wire information.
* Optionally link the reserve entry to the new or existing
@@ -479,7 +530,7 @@ async function updateExchangeFromUrlImpl(
logger.info("updating exchange /keys info");
- const timeout = getExchangeRequestTimeout(r);
+ const timeout = getExchangeRequestTimeout();
const keysInfo = await downloadKeysInfo(baseUrl, ws.http, timeout);
@@ -507,33 +558,10 @@ async function updateExchangeFromUrlImpl(
logger.info("finished validating exchange /wire info");
- let tosFound: ExchangeTosDownloadResult | undefined;
- //Remove this when exchange supports multiple content-type in accept header
- if (acceptedFormat)
- for (const format of acceptedFormat) {
- const resp = await downloadExchangeWithTermsOfService(
- baseUrl,
- ws.http,
- timeout,
- format,
- );
- if (resp.tosContentType === format) {
- tosFound = resp;
- break;
- }
- }
- // If none of the specified format was found try text/plain
- const tosDownload =
- tosFound !== undefined
- ? tosFound
- : await downloadExchangeWithTermsOfService(
- baseUrl,
- ws.http,
- timeout,
- "text/plain",
- );
- let recoupGroupId: string | undefined = undefined;
+ const tosDownload = await downloadTosFromAcceptedFormat(ws, baseUrl, timeout, acceptedFormat)
+
+ let recoupGroupId: string | undefined;
logger.trace("updating exchange info in database");