diff options
author | Florian Dold <florian@dold.me> | 2022-10-05 18:31:56 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-10-05 18:31:56 +0200 |
commit | 957f9a5efb26194a7911cdaf722502ba09e5bd58 (patch) | |
tree | d7edfb20814d8f9cf418457de0a3ff86c7690308 /packages/taler-wallet-core/src/wallet.ts | |
parent | 99ace8b7d24416f2b184d66006c89b61935e132e (diff) | |
download | wallet-core-957f9a5efb26194a7911cdaf722502ba09e5bd58.tar.gz wallet-core-957f9a5efb26194a7911cdaf722502ba09e5bd58.tar.bz2 wallet-core-957f9a5efb26194a7911cdaf722502ba09e5bd58.zip |
wallet-core: fix default auditor/exchange loading logic
Diffstat (limited to 'packages/taler-wallet-core/src/wallet.ts')
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 45 |
1 files changed, 20 insertions, 25 deletions
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<void> { 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(); } } |