Skip to content

Commit

Permalink
convert network accessors to functions (#6219)
Browse files Browse the repository at this point in the history
* convert network accessors to functions

* backend networks store

* wrote a couple worklet functions to get swaps working

* fix other calls

* Update package.json

* Update ios/Podfile.lock

* move all functions into backendNetworksStore and replace calls

* refresh podlock

* no clue what happened during merge

* fix: APP-2021

* fix: APP-2022

* fix build and lint
  • Loading branch information
walmat committed Dec 19, 2024
1 parent d7d4176 commit f92860a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 209 deletions.
208 changes: 0 additions & 208 deletions src/chains/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/coin-icon/ChainImage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef, useMemo } from 'react';
import React, { useMemo, forwardRef } from 'react';
import { ChainId } from '@/state/backendNetworks/types';

import ApechainBadge from '@/assets/badges/apechain.png';
Expand Down
45 changes: 45 additions & 0 deletions src/state/assets/userAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,52 @@ import { swapsStore } from '@/state/swaps/swapsStore';
import { ChainId } from '@/state/backendNetworks/types';
import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks';
import { useSelector } from 'react-redux';
<<<<<<< HEAD
import { getUniqueId } from '@/utils/ethereumUtils';
=======

const SEARCH_CACHE_MAX_ENTRIES = 50;

const escapeRegExp = (string: string) => string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const getSearchQueryKey = ({ filter, searchQuery }: { filter: UserAssetFilter; searchQuery: string }) => `${filter}${searchQuery}`;

const getDefaultCacheKeys = (): Set<string> => {
const queryKeysToPreserve = new Set<string>();
queryKeysToPreserve.add('all');

for (const chainId of useBackendNetworksStore.getState().getSupportedChainIds()) {
queryKeysToPreserve.add(`${chainId}`);
}
return queryKeysToPreserve;
};

const CACHE_ITEMS_TO_PRESERVE = getDefaultCacheKeys();

export interface UserAssetsState {
chainBalances: Map<ChainId, number>;
currentAbortController: AbortController;
filter: UserAssetFilter;
idsByChain: Map<UserAssetFilter, UniqueId[]>;
inputSearchQuery: string;
searchCache: Map<string, UniqueId[]>;
userAssets: Map<UniqueId, ParsedSearchAsset>;
getBalanceSortedChainList: () => ChainId[];
getChainsWithBalance: () => ChainId[];
getFilteredUserAssetIds: () => UniqueId[];
getHighestValueNativeAsset: () => ParsedSearchAsset | null;
getUserAsset: (uniqueId: UniqueId) => ParsedSearchAsset | null;
getUserAssets: () => ParsedSearchAsset[];
selectUserAssetIds: (selector: (asset: ParsedSearchAsset) => boolean, filter?: UserAssetFilter) => Generator<UniqueId, void, unknown>;
selectUserAssets: (selector: (asset: ParsedSearchAsset) => boolean) => Generator<[UniqueId, ParsedSearchAsset], void, unknown>;
setSearchCache: (queryKey: string, filteredIds: UniqueId[]) => void;
setSearchQuery: (query: string) => void;
setUserAssets: (userAssets: Map<UniqueId, ParsedSearchAsset> | ParsedSearchAsset[]) => void;

hiddenAssets: Set<UniqueId>;
getHiddenAssetsIds: () => UniqueId[];
setHiddenAssets: (uniqueIds: UniqueId[]) => void;
}
>>>>>>> e67803ca7 (convert network accessors to functions (#6219))

type UserAssetsStateToPersist = Omit<
Partial<UserAssetsState>,
Expand Down

0 comments on commit f92860a

Please sign in to comment.