Skip to content

Commit

Permalink
fixup! feat: asset tracker now uses local cache before fetching asset…
Browse files Browse the repository at this point in the history
… metadata
  • Loading branch information
AngelCastilloB committed Dec 4, 2024
1 parent 97f8e63 commit aa886ba
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/wallet/src/services/AssetsTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const bufferTick =
source$.pipe(connect((shared$) => shared$.pipe(buffer(shared$.pipe(debounceTime(1))))));

const ASSET_INFO_FETCH_CHUNK_SIZE = 100;
const ONE_WEEK = 7 * 24 * 60 * 60 * 1000;
const ONE_DAY = 24 * 60 * 60 * 1000;
const ONE_WEEK = 7 * ONE_DAY;

const isInBalance = (assetId: Cardano.AssetId, balance: Cardano.Value): boolean =>
balance.assets?.has(assetId) ?? false;
Expand All @@ -49,7 +50,7 @@ const isInBalance = (assetId: Cardano.AssetId, balance: Cardano.Value): boolean
* 1. Assets not in Balance:
* - Always use the cached version if present in the cache, ignoring freshness.
* 2. Assets in Balance:
* - Use the cached version only if it exists and its `staleAt` timestamp already expired.
* - Use the cached version only if it exists and its `staleAt` timestamp did not expire.
* 3. Uncached Assets:
* - If an asset is not in the cache or does not meet the above criteria, mark it as uncached.
*/
Expand Down Expand Up @@ -114,7 +115,7 @@ const getAssetsWithCache = async (

const now = Date.now();
const updatedFetchedAssets = fetchedAssets.map((asset) => {
const randomDelta = Math.floor(Math.random() * 2 * 24 * 60 * 60 * 1000); // Random time between 0 and 2 days
const randomDelta = Math.floor(Math.random() * 2 * ONE_DAY); // Random time between 0 and 2 days
return {
...asset,
staleAt: new Date(now + maxAssetInfoCacheAge + randomDelta)
Expand Down

0 comments on commit aa886ba

Please sign in to comment.