Skip to content

Commit

Permalink
feat: filter stored exchange (#1088)
Browse files Browse the repository at this point in the history
Signed-off-by: David Dal Busco <[email protected]>
  • Loading branch information
peterpeterparker authored Jan 15, 2025
1 parent 17bc38c commit a690e04
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/frontend/src/lib/constants/exchange.constants.ts
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions src/frontend/src/lib/workers/exchange.worker.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -162,6 +163,10 @@ const cleanExchangePrice = async () => {
const emitSavedExchanges = async () => {
const exchanges = await entries<CanisterIdText, ExchangePrice>(exchangeIdbStore);

const activeExchanges = exchanges.filter(
([_, { updatedAt }]) => updatedAt > new Date().getTime() - PRICE_VALIDITY_TIMEFRAME
);

if (exchanges.length === 0) {
return;
}
Expand Down

0 comments on commit a690e04

Please sign in to comment.