taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 69d2bd5c2c1af47450d5170cc33309562c95ad12
parent 90eaa718692a614981c3befda42bdfc2e2fc47d5
Author: Iván Ávalos <avalos@disroot.org>
Date:   Fri, 28 Mar 2025 13:10:03 +0100

addGlobalCurrencyExchange now adds currency info to global scope

Diffstat:
Mpackages/taler-wallet-core/src/wallet.ts | 23+++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts @@ -100,6 +100,7 @@ import { RecoverStoredBackupRequest, RemoveGlobalCurrencyAuditorRequest, RemoveGlobalCurrencyExchangeRequest, + ScopeType, SharePaymentRequest, SharePaymentResult, StartRefundQueryRequest, @@ -226,6 +227,8 @@ import { performanceNow, safeStringifyException, setDangerousTimetravel, + stringifyAddExchange, + stringifyScopeInfo, validateIban, } from "@gnu-taler/taler-util"; import { @@ -1463,7 +1466,7 @@ async function handleAddGlobalCurrencyExchange( req: AddGlobalCurrencyExchangeRequest, ): Promise<EmptyObject> { await wex.db.runReadWriteTx( - { storeNames: ["globalCurrencyExchanges"] }, + { storeNames: ["globalCurrencyExchanges", "currencyInfo"] }, async (tx) => { const key = [req.currency, req.exchangeBaseUrl, req.exchangeMasterPub]; const existingRec = @@ -1474,6 +1477,18 @@ async function handleAddGlobalCurrencyExchange( return; } wex.ws.exchangeCache.clear(); + const info = await tx.currencyInfo.get(stringifyScopeInfo({ + type: ScopeType.Exchange, + currency: req.currency, + url: req.exchangeBaseUrl, + })); + if (info) { + info.scopeInfoStr = stringifyScopeInfo({ + type: ScopeType.Global, + currency: req.currency, + }); + await tx.currencyInfo.put(info); + } await tx.globalCurrencyExchanges.add({ currency: req.currency, exchangeBaseUrl: req.exchangeBaseUrl, @@ -1510,7 +1525,7 @@ async function handleRemoveGlobalCurrencyExchange( req: RemoveGlobalCurrencyExchangeRequest, ): Promise<EmptyObject> { await wex.db.runReadWriteTx( - { storeNames: ["globalCurrencyExchanges"] }, + { storeNames: ["globalCurrencyExchanges", "currencyInfo"] }, async (tx) => { const key = [req.currency, req.exchangeBaseUrl, req.exchangeMasterPub]; const existingRec = @@ -1522,6 +1537,10 @@ async function handleRemoveGlobalCurrencyExchange( } wex.ws.exchangeCache.clear(); checkDbInvariant(!!existingRec.id, `no global exchange for ${j2s(key)}`); + await tx.currencyInfo.delete(stringifyScopeInfo({ + type: ScopeType.Global, + currency: req.currency, + })); await tx.globalCurrencyExchanges.delete(existingRec.id); }, );