diff options
author | Florian Dold <florian@dold.me> | 2021-06-10 16:32:37 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-06-10 16:32:37 +0200 |
commit | 8ad36d89f55783c34043ee9ef37759cd94bcec7c (patch) | |
tree | 1e638b45e59ef50985f799b57590032a57ac7049 /packages/taler-wallet-core/src/operations/refresh.ts | |
parent | 7b7e3b4565169835ad04062d5c76ba655abd770a (diff) | |
download | wallet-core-8ad36d89f55783c34043ee9ef37759cd94bcec7c.tar.xz |
simplify pending transactions, make more tests pass again
Diffstat (limited to 'packages/taler-wallet-core/src/operations/refresh.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/refresh.ts | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts index 8d21e811d..21c92c1b7 100644 --- a/packages/taler-wallet-core/src/operations/refresh.ts +++ b/packages/taler-wallet-core/src/operations/refresh.ts @@ -32,6 +32,7 @@ import { RefreshGroupId, RefreshReason, TalerErrorDetails, + timestampToIsoString, } from "@gnu-taler/taler-util"; import { AmountJson, Amounts } from "@gnu-taler/taler-util"; import { amountToPretty } from "@gnu-taler/taler-util"; @@ -864,7 +865,12 @@ export async function autoRefresh( ws: InternalWalletState, exchangeBaseUrl: string, ): Promise<void> { + logger.info(`doing auto-refresh check for '${exchangeBaseUrl}'`); await updateExchangeFromUrl(ws, exchangeBaseUrl, true); + let minCheckThreshold = timestampAddDuration( + getTimestampNow(), + durationFromSpec({ days: 1 }), + ); await ws.db .mktx((x) => ({ coins: x.coins, @@ -899,28 +905,20 @@ export async function autoRefresh( const executeThreshold = getAutoRefreshExecuteThreshold(denom); if (isTimestampExpired(executeThreshold)) { refreshCoins.push(coin); + } else { + const checkThreshold = getAutoRefreshCheckThreshold(denom); + minCheckThreshold = timestampMin(minCheckThreshold, checkThreshold); } } if (refreshCoins.length > 0) { await createRefreshGroup(ws, tx, refreshCoins, RefreshReason.Scheduled); } - - const denoms = await tx.denominations.indexes.byExchangeBaseUrl - .iter(exchangeBaseUrl) - .toArray(); - let minCheckThreshold = timestampAddDuration( - getTimestampNow(), - durationFromSpec({ days: 1 }), + logger.info( + `current wallet time: ${timestampToIsoString(getTimestampNow())}`, + ); + logger.info( + `next refresh check at ${timestampToIsoString(minCheckThreshold)}`, ); - for (const denom of denoms) { - const checkThreshold = getAutoRefreshCheckThreshold(denom); - const executeThreshold = getAutoRefreshExecuteThreshold(denom); - if (isTimestampExpired(executeThreshold)) { - // No need to consider this denomination, we already did an auto refresh check. - continue; - } - minCheckThreshold = timestampMin(minCheckThreshold, checkThreshold); - } exchange.nextRefreshCheck = minCheckThreshold; await tx.exchanges.put(exchange); }); |