From 957f9a5efb26194a7911cdaf722502ba09e5bd58 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 5 Oct 2022 18:31:56 +0200 Subject: wallet-core: fix default auditor/exchange loading logic --- packages/taler-wallet-core/src/wallet.ts | 45 ++++++++++++++------------------ 1 file changed, 20 insertions(+), 25 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 129ee458f..61525e476 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -155,6 +155,7 @@ import { getExchangeDetails, getExchangeRequestTimeout, getExchangeTrust, + provideExchangeRecordInTx, updateExchangeFromUrl, updateExchangeFromUrlHandler, updateExchangeTermsOfService, @@ -583,32 +584,26 @@ async function runTaskLoop( */ async function fillDefaults(ws: InternalWalletState): Promise { await ws.db - .mktx((x) => [x.config, x.auditorTrust]) + .mktx((x) => [x.config, x.auditorTrust, x.exchanges, x.exchangeDetails]) .runReadWrite(async (tx) => { - let applied = false; - await tx.config.iter().forEach((x) => { - if (x.key == "currencyDefaultsApplied" && x.value == true) { - applied = true; - } - }); - if (!applied) { - for (const c of builtinAuditors) { - await tx.auditorTrust.put(c); - } + const appliedRec = await tx.config.get("currencyDefaultsApplied"); + let alreadyApplied = appliedRec ? !!appliedRec.value : false; + if (alreadyApplied) { + logger.info("defaults already applied"); + return; + } + for (const c of builtinAuditors) { + await tx.auditorTrust.put(c); + } + for (const baseUrl of builtinExchanges) { + const now = AbsoluteTime.now(); + provideExchangeRecordInTx(ws, tx, baseUrl, now); } - // FIXME: make sure exchanges are added transactionally to - // DB in first-time default application + await tx.config.put({ + key: "currencyDefaultsApplied", + value: true, + }); }); - - for (const url of builtinExchanges) { - try { - await updateExchangeFromUrl(ws, url, { forceNow: true }); - } catch (e) { - logger.warn( - `could not update builtin exchange ${url} during wallet initialization`, - ); - } - } } async function getExchangeTos( @@ -1719,12 +1714,12 @@ class InternalWalletStateImpl implements InternalWalletState { * Stop ongoing processing. */ stop(): void { - logger.info("stopping (at internal wallet state)"); + logger.trace("stopping (at internal wallet state)"); this.stopped = true; this.timerGroup.stopCurrentAndFutureTimers(); this.cryptoDispatcher.stop(); for (const key of Object.keys(this.activeLongpoll)) { - logger.info(`cancelling active longpoll ${key}`); + logger.trace(`cancelling active longpoll ${key}`); this.activeLongpoll[key].cancel(); } } -- cgit v1.2.3