From a690e0497b555bc2c1e66bb24a7e2a78142c72f7 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Wed, 15 Jan 2025 11:22:09 +0100 Subject: [PATCH] feat: filter stored exchange (#1088) Signed-off-by: David Dal Busco --- src/frontend/src/lib/constants/exchange.constants.ts | 2 ++ src/frontend/src/lib/workers/exchange.worker.ts | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 src/frontend/src/lib/constants/exchange.constants.ts diff --git a/src/frontend/src/lib/constants/exchange.constants.ts b/src/frontend/src/lib/constants/exchange.constants.ts new file mode 100644 index 000000000..25f5d882e --- /dev/null +++ b/src/frontend/src/lib/constants/exchange.constants.ts @@ -0,0 +1,2 @@ +// When we load the exchange data from idb we only consider those that are relatively actual - not older than a day in milliseconds +export const PRICE_VALIDITY_TIMEFRAME = 24 * 60 * 60 * 1000; diff --git a/src/frontend/src/lib/workers/exchange.worker.ts b/src/frontend/src/lib/workers/exchange.worker.ts index 2e386bc0d..7b1df6fee 100644 --- a/src/frontend/src/lib/workers/exchange.worker.ts +++ b/src/frontend/src/lib/workers/exchange.worker.ts @@ -1,4 +1,5 @@ import { ICP_LEDGER_CANISTER_ID, SYNC_TOKENS_TIMER_INTERVAL } from '$lib/constants/constants'; +import { PRICE_VALIDITY_TIMEFRAME } from '$lib/constants/exchange.constants'; import { fetchKongSwapTokens } from '$lib/rest/kongswap.rest'; import { exchangeIdbStore } from '$lib/stores/idb.store'; import type { CanisterIdText } from '$lib/types/canister'; @@ -162,6 +163,10 @@ const cleanExchangePrice = async () => { const emitSavedExchanges = async () => { const exchanges = await entries(exchangeIdbStore); + const activeExchanges = exchanges.filter( + ([_, { updatedAt }]) => updatedAt > new Date().getTime() - PRICE_VALIDITY_TIMEFRAME + ); + if (exchanges.length === 0) { return; }