diff --git a/src/__swaps__/screens/Swap/components/TokenList/TokenToBuyList.tsx b/src/__swaps__/screens/Swap/components/TokenList/TokenToBuyList.tsx index 0f8cfb1ef06..859a7593310 100644 --- a/src/__swaps__/screens/Swap/components/TokenList/TokenToBuyList.tsx +++ b/src/__swaps__/screens/Swap/components/TokenList/TokenToBuyList.tsx @@ -8,7 +8,7 @@ import { SearchAsset } from '@/__swaps__/types/search'; import { SwapAssetType } from '@/__swaps__/types/swap'; import { parseSearchAsset } from '@/__swaps__/utils/assets'; import { getChainColorWorklet } from '@/__swaps__/utils/swaps'; -import { getUniqueIdWorklet } from '@/utils/ethereumUtils'; +import { getUniqueId } from '@/utils/ethereumUtils'; import { analyticsV2 } from '@/analytics'; import { AnimatedTextIcon } from '@/components/AnimatedComponents/AnimatedTextIcon'; import { TIMING_CONFIGS } from '@/components/animations/animationConfigs'; @@ -100,10 +100,7 @@ export const TokenToBuyList = () => { const handleSelectToken = useCallback( (token: SearchAsset) => { runOnUI(() => { - if ( - internalSelectedInputAsset.value && - getUniqueIdWorklet(token.address, token.chainId) !== internalSelectedOutputAsset.value?.uniqueId - ) { + if (internalSelectedInputAsset.value && getUniqueId(token.address, token.chainId) !== internalSelectedOutputAsset.value?.uniqueId) { isQuoteStale.value = 1; isFetching.value = true; } diff --git a/src/__swaps__/screens/Swap/components/TokenList/TokenToSellList.tsx b/src/__swaps__/screens/Swap/components/TokenList/TokenToSellList.tsx index ece4631b1ec..064a9fd09e4 100644 --- a/src/__swaps__/screens/Swap/components/TokenList/TokenToSellList.tsx +++ b/src/__swaps__/screens/Swap/components/TokenList/TokenToSellList.tsx @@ -4,7 +4,7 @@ import { ListEmpty } from '@/__swaps__/screens/Swap/components/TokenList/ListEmp import { useSwapContext } from '@/__swaps__/screens/Swap/providers/swap-provider'; import { ParsedSearchAsset } from '@/__swaps__/types/assets'; import { SwapAssetType } from '@/__swaps__/types/swap'; -import { getUniqueIdWorklet } from '@/utils/ethereumUtils'; +import { getUniqueId } from '@/utils/ethereumUtils'; import { analyticsV2 } from '@/analytics'; import { useDelayedMount } from '@/hooks/useDelayedMount'; import * as i18n from '@/languages'; @@ -45,10 +45,7 @@ const TokenToSellListComponent = () => { if (!token) return; runOnUI(() => { - if ( - internalSelectedOutputAsset.value && - getUniqueIdWorklet(token.address, token.chainId) !== internalSelectedInputAsset.value?.uniqueId - ) { + if (internalSelectedOutputAsset.value && getUniqueId(token.address, token.chainId) !== internalSelectedInputAsset.value?.uniqueId) { isQuoteStale.value = 1; isFetching.value = true; } diff --git a/src/__swaps__/screens/Swap/hooks/useSearchCurrencyLists.ts b/src/__swaps__/screens/Swap/hooks/useSearchCurrencyLists.ts index 1b38200ae46..82e78bed66c 100644 --- a/src/__swaps__/screens/Swap/hooks/useSearchCurrencyLists.ts +++ b/src/__swaps__/screens/Swap/hooks/useSearchCurrencyLists.ts @@ -3,7 +3,7 @@ import { ChainId } from '@/chains/types'; import { SearchAsset, TokenSearchAssetKey, TokenSearchThreshold } from '@/__swaps__/types/search'; import { addHexPrefix } from '@/handlers/web3'; import { isLowerCaseMatch, filterList } from '@/utils'; -import { getUniqueIdWorklet } from '@/utils/ethereumUtils'; +import { getUniqueId } from '@/utils/ethereumUtils'; import { useFavorites } from '@/resources/favorites'; import { useSwapsStore } from '@/state/swaps/swapsStore'; import { isAddress } from '@ethersproject/address'; @@ -346,7 +346,7 @@ export function useSearchCurrencyLists() { chainId: state.toChainId, favorite: true, mainnetAddress: favToken.networks?.[ChainId.mainnet]?.address || favToken.mainnet_address, - uniqueId: getUniqueIdWorklet(favToken.networks[state.toChainId]?.address || favToken.address, state.toChainId), + uniqueId: getUniqueId(favToken.networks[state.toChainId]?.address || favToken.address, state.toChainId), })) as SearchAsset[]; }, [favorites, state.toChainId]); diff --git a/src/__swaps__/utils/swaps.ts b/src/__swaps__/utils/swaps.ts index 130f1908d6f..99c554c3289 100644 --- a/src/__swaps__/utils/swaps.ts +++ b/src/__swaps__/utils/swaps.ts @@ -39,7 +39,7 @@ import { inputKeys } from '../types/swap'; import { valueBasedDecimalFormatter } from './decimalFormatter'; import { convertAmountToRawAmount } from '@/helpers/utilities'; import { chainsName } from '@/chains'; -import { getUniqueIdWorklet } from '@/utils/ethereumUtils'; +import { getUniqueId } from '@/utils/ethereumUtils'; // /---- 🎨 Color functions 🎨 ----/ // // @@ -548,7 +548,7 @@ export const parseAssetAndExtend = ({ colors: (isAssetEth ? ETH_COLORS : asset.colors) as TokenColors, }); - const uniqueId = getUniqueIdWorklet(asset.address, asset.chainId); + const uniqueId = getUniqueId(asset.address, asset.chainId); const balance = insertUserAssetBalance ? userAssetsStore.getState().getUserAsset(uniqueId)?.balance || asset.balance : asset.balance; return { diff --git a/src/migrations/migrations/migrateFavorites.ts b/src/migrations/migrations/migrateFavorites.ts index 4a6e98856dd..80915b63322 100644 --- a/src/migrations/migrations/migrateFavorites.ts +++ b/src/migrations/migrations/migrateFavorites.ts @@ -1,5 +1,5 @@ -import { AddressOrEth, UniqueId } from '@/__swaps__/types/assets'; -import { getUniqueIdWorklet } from '@/utils/ethereumUtils'; +import { UniqueId } from '@/__swaps__/types/assets'; +import { getUniqueId } from '@/utils/ethereumUtils'; import { EthereumAddress, RainbowToken } from '@/entities'; import { createQueryKey, persistOptions, queryClient } from '@/react-query'; import { favoritesQueryKey } from '@/resources/favorites'; @@ -22,7 +22,7 @@ export function migrateFavoritesV2(): Migration { const migratedFavorites: Record = {}; for (const favorite of Object.values(v1Data)) { - const uniqueId = getUniqueIdWorklet(favorite.address, favorite.chainId); + const uniqueId = getUniqueId(favorite.address, favorite.chainId); favorite.uniqueId = uniqueId; // v2 unique uses chainId instead of Network migratedFavorites[uniqueId] = favorite; } diff --git a/src/resources/favorites.ts b/src/resources/favorites.ts index c9470275384..70f3cb23bf5 100644 --- a/src/resources/favorites.ts +++ b/src/resources/favorites.ts @@ -1,6 +1,6 @@ import { AddressOrEth, UniqueId } from '@/__swaps__/types/assets'; import { ChainId, Network } from '@/chains/types'; -import { getUniqueIdWorklet } from '@/utils/ethereumUtils'; +import { getUniqueId } from '@/utils/ethereumUtils'; import { NativeCurrencyKeys, RainbowToken } from '@/entities'; import { createQueryKey, queryClient } from '@/react-query'; import { DAI_ADDRESS, ETH_ADDRESS, SOCKS_ADDRESS, WBTC_ADDRESS, WETH_ADDRESS } from '@/references'; @@ -34,7 +34,7 @@ async function fetchMetadata(addresses: string[], chainId = ChainId.mainnet) { ); if (externalAsset) { - const uniqueId = getUniqueIdWorklet(externalAsset?.networks[chainId]?.address, chainId); + const uniqueId = getUniqueId(externalAsset?.networks[chainId]?.address, chainId); newFavoritesMeta[uniqueId] = { ...externalAsset, chainId, @@ -54,10 +54,10 @@ async function fetchMetadata(addresses: string[], chainId = ChainId.mainnet) { const ethIsFavorited = addresses.includes(ETH_ADDRESS); const wethIsFavorited = addresses.includes(WETH_ADDRESS); if (newFavoritesMeta) { - const WETH_uniqueId = getUniqueIdWorklet(WETH_ADDRESS, ChainId.mainnet); + const WETH_uniqueId = getUniqueId(WETH_ADDRESS, ChainId.mainnet); if (newFavoritesMeta[WETH_uniqueId] && ethIsFavorited) { const favorite = newFavoritesMeta[WETH_uniqueId]; - const uniqueId = getUniqueIdWorklet(ETH_ADDRESS, ChainId.mainnet); + const uniqueId = getUniqueId(ETH_ADDRESS, ChainId.mainnet); newFavoritesMeta[uniqueId] = { ...favorite, address: ETH_ADDRESS, @@ -117,7 +117,7 @@ export async function refreshFavorites() { export async function toggleFavorite(address: string, chainId = ChainId.mainnet) { const favorites = queryClient.getQueryData>(favoritesQueryKey); const lowercasedAddress = address.toLowerCase() as AddressOrEth; - const uniqueId = getUniqueIdWorklet(lowercasedAddress, chainId); + const uniqueId = getUniqueId(lowercasedAddress, chainId); if (Object.keys(favorites || {}).includes(uniqueId)) { queryClient.setQueryData(favoritesQueryKey, omit(favorites, uniqueId)); } else { diff --git a/src/utils/ethereumUtils.ts b/src/utils/ethereumUtils.ts index 48f1f07ab9b..4e73ba1dc68 100644 --- a/src/utils/ethereumUtils.ts +++ b/src/utils/ethereumUtils.ts @@ -442,9 +442,7 @@ async function parseEthereumUrl(data: string) { export const getUniqueIdNetwork = (address: EthereumAddress, network: Network) => `${address}_${network}`; -export const getUniqueId = (address: EthereumAddress, chainId: ChainId) => `${address}_${chainId}`; - -export const getUniqueIdWorklet = (address: EthereumAddress, chainId: ChainId) => { +export const getUniqueId = (address: EthereumAddress, chainId: ChainId) => { 'worklet'; return `${address}_${chainId}`; };