diff --git a/ios/Podfile.lock b/ios/Podfile.lock index af7eb5f5407..8621c8b854b 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -2529,4 +2529,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 98c3fc206d7041ac7388693bb0753109d1884b57 -COCOAPODS: 1.14.3 +COCOAPODS: 1.16.1 diff --git a/src/__swaps__/screens/Swap/Swap.tsx b/src/__swaps__/screens/Swap/Swap.tsx index 0d5db8bb3eb..22d71dc3cc5 100644 --- a/src/__swaps__/screens/Swap/Swap.tsx +++ b/src/__swaps__/screens/Swap/Swap.tsx @@ -18,7 +18,7 @@ import { SwapInputAsset } from '@/__swaps__/screens/Swap/components/SwapInputAss import { SwapNavbar } from '@/__swaps__/screens/Swap/components/SwapNavbar'; import { SwapOutputAsset } from '@/__swaps__/screens/Swap/components/SwapOutputAsset'; import { SwapSheetGestureBlocker } from '@/__swaps__/screens/Swap/components/SwapSheetGestureBlocker'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { SwapAssetType } from '@/__swaps__/types/swap'; import { parseSearchAsset } from '@/__swaps__/utils/assets'; import { AbsolutePortalRoot } from '@/components/AbsolutePortal'; diff --git a/src/__swaps__/screens/Swap/components/AnimatedChainImage.android.tsx b/src/__swaps__/screens/Swap/components/AnimatedChainImage.android.tsx index 49d30869f71..19f39bac85c 100644 --- a/src/__swaps__/screens/Swap/components/AnimatedChainImage.android.tsx +++ b/src/__swaps__/screens/Swap/components/AnimatedChainImage.android.tsx @@ -14,7 +14,7 @@ const OptimismBadge = require('@/assets/badges/optimism.png'); const PolygonBadge = require('@/assets/badges/polygon.png'); const ZoraBadge = require('@/assets/badges/zora.png'); -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { globalColors } from '@/design-system'; import { PIXEL_RATIO } from '@/utils/deviceUtils'; import { useSwapsStore } from '@/state/swaps/swapsStore'; diff --git a/src/__swaps__/screens/Swap/components/AnimatedChainImage.ios.tsx b/src/__swaps__/screens/Swap/components/AnimatedChainImage.ios.tsx index cad0369a89a..56eea037e15 100644 --- a/src/__swaps__/screens/Swap/components/AnimatedChainImage.ios.tsx +++ b/src/__swaps__/screens/Swap/components/AnimatedChainImage.ios.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { Image, StyleSheet, View } from 'react-native'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { useAnimatedProps, useDerivedValue } from 'react-native-reanimated'; import { AnimatedFasterImage } from '@/components/AnimatedComponents/AnimatedFasterImage'; import { DEFAULT_FASTER_IMAGE_CONFIG } from '@/components/images/ImgixImage'; diff --git a/src/__swaps__/screens/Swap/components/CoinRow.tsx b/src/__swaps__/screens/Swap/components/CoinRow.tsx index 6a1be01ed47..c3fb98919b1 100644 --- a/src/__swaps__/screens/Swap/components/CoinRow.tsx +++ b/src/__swaps__/screens/Swap/components/CoinRow.tsx @@ -1,7 +1,7 @@ import { BalancePill } from '@/__swaps__/screens/Swap/components/BalancePill'; import { CoinRowButton } from '@/__swaps__/screens/Swap/components/CoinRowButton'; -import { AddressOrEth, ParsedSearchAsset } from '@/__swaps__/types/assets'; -import { ChainId } from '@/chains/types'; +import { AddressOrEth, ParsedSearchAsset, UniqueId } from '@/__swaps__/types/assets'; +import { ChainId } from '@/state/backendNetworks/types'; import { SearchAsset } from '@/__swaps__/types/search'; import { ButtonPressAnimation } from '@/components/animations'; import { ContextMenuButton } from '@/components/context-menu'; @@ -17,7 +17,7 @@ import React, { useCallback, useMemo } from 'react'; import { GestureResponderEvent } from 'react-native'; import { OnPressMenuItemEventObject } from 'react-native-ios-context-menu'; import { SwapCoinIcon } from './SwapCoinIcon'; -import { SUPPORTED_CHAIN_IDS } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export const COIN_ROW_WITH_PADDING_HEIGHT = 56; @@ -44,7 +44,7 @@ interface InputCoinRowProps { nativePriceChange?: string; onPress: (asset: ParsedSearchAsset | null) => void; output?: false | undefined; - uniqueId: string; + uniqueId: UniqueId; testID?: string; } @@ -178,7 +178,8 @@ export function CoinRow({ isFavorite, onPress, output, uniqueId, testID, ...asse } const InfoButton = ({ address, chainId }: { address: string; chainId: ChainId }) => { - const supportedChain = SUPPORTED_CHAIN_IDS.includes(chainId); + const getSupportedChainIds = useBackendNetworksStore(state => state.getSupportedChainIds); + const supportedChain = getSupportedChainIds().includes(chainId); const handleCopy = useCallback(() => { haptics.selection(); diff --git a/src/__swaps__/screens/Swap/components/FlipButton.tsx b/src/__swaps__/screens/Swap/components/FlipButton.tsx index 3baa0974095..b31fa07eb52 100644 --- a/src/__swaps__/screens/Swap/components/FlipButton.tsx +++ b/src/__swaps__/screens/Swap/components/FlipButton.tsx @@ -14,7 +14,7 @@ import { TIMING_CONFIGS } from '@/components/animations/animationConfigs'; import { SwapAssetType } from '@/__swaps__/types/swap'; import { GestureHandlerButton } from './GestureHandlerButton'; import { useSwapsStore } from '@/state/swaps/swapsStore'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; export const FlipButton = () => { const { isDarkMode } = useColorMode(); diff --git a/src/__swaps__/screens/Swap/components/GasButton.tsx b/src/__swaps__/screens/Swap/components/GasButton.tsx index 59cee69c319..eb5ccbd7638 100644 --- a/src/__swaps__/screens/Swap/components/GasButton.tsx +++ b/src/__swaps__/screens/Swap/components/GasButton.tsx @@ -22,7 +22,7 @@ import { NavigationSteps, useSwapContext } from '../providers/swap-provider'; import { EstimatedSwapGasFee, EstimatedSwapGasFeeSlot } from './EstimatedSwapGasFee'; import { GestureHandlerButton } from './GestureHandlerButton'; import { UnmountOnAnimatedReaction } from './UnmountOnAnimatedReaction'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const { SWAP_GAS_ICONS } = gasUtils; const GAS_BUTTON_HIT_SLOP = 16; diff --git a/src/__swaps__/screens/Swap/components/GasPanel.tsx b/src/__swaps__/screens/Swap/components/GasPanel.tsx index ed1e8dc646d..0bd16ddc8a4 100644 --- a/src/__swaps__/screens/Swap/components/GasPanel.tsx +++ b/src/__swaps__/screens/Swap/components/GasPanel.tsx @@ -4,7 +4,7 @@ import Animated, { runOnJS, useAnimatedReaction, useAnimatedStyle, withDelay, wi import { MIN_FLASHBOTS_PRIORITY_FEE, THICK_BORDER_WIDTH } from '@/__swaps__/screens/Swap/constants'; import { NavigationSteps, useSwapContext } from '@/__swaps__/screens/Swap/providers/swap-provider'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { GasSpeed } from '@/__swaps__/types/gas'; import { gweiToWei, weiToGwei } from '@/parsers'; import { diff --git a/src/__swaps__/screens/Swap/components/ReviewPanel.tsx b/src/__swaps__/screens/Swap/components/ReviewPanel.tsx index 504fd18b672..d05136440fa 100644 --- a/src/__swaps__/screens/Swap/components/ReviewPanel.tsx +++ b/src/__swaps__/screens/Swap/components/ReviewPanel.tsx @@ -42,8 +42,8 @@ import { NavigationSteps, useSwapContext } from '../providers/swap-provider'; import { AnimatedSwitch } from './AnimatedSwitch'; import { EstimatedSwapGasFee, EstimatedSwapGasFeeSlot } from './EstimatedSwapGasFee'; import { UnmountOnAnimatedReaction } from './UnmountOnAnimatedReaction'; -import { chainsLabel, chainsNativeAsset } from '@/chains'; -import { ChainId } from '@/chains/types'; +import { getChainsLabelWorklet, useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; +import { ChainId } from '@/state/backendNetworks/types'; const UNKNOWN_LABEL = i18n.t(i18n.l.swap.unknown); const REVIEW_LABEL = i18n.t(i18n.l.expanded_state.swap_details.review); @@ -312,6 +312,7 @@ export const SlippageRow = () => { export function ReviewPanel() { const { navigate } = useNavigation(); const { isDarkMode } = useColorMode(); + const backendNetworks = useBackendNetworksStore(state => state.backendNetworksSharedValue); const { configProgress, lastTypedInput, internalSelectedInputAsset, internalSelectedOutputAsset, quote } = useSwapContext(); const labelTertiary = useForegroundColor('labelTertiary'); @@ -319,7 +320,9 @@ export function ReviewPanel() { const unknown = i18n.t(i18n.l.swap.unknown); - const chainName = useDerivedValue(() => chainsLabel[internalSelectedInputAsset.value?.chainId ?? ChainId.mainnet]); + const chainName = useDerivedValue( + () => getChainsLabelWorklet(backendNetworks)[internalSelectedInputAsset.value?.chainId ?? ChainId.mainnet] + ); const minReceivedOrMaxSoldLabel = useDerivedValue(() => { const isInputBasedTrade = lastTypedInput.value === 'inputAmount' || lastTypedInput.value === 'inputNativeValue'; @@ -348,6 +351,7 @@ export function ReviewPanel() { }); const openGasExplainer = useCallback(async () => { + const chainsNativeAsset = useBackendNetworksStore.getState().getChainsNativeAsset(); const nativeAsset = chainsNativeAsset[swapsStore.getState().inputAsset?.chainId ?? ChainId.mainnet]; navigate(Routes.EXPLAIN_SHEET, { chainId: swapsStore.getState().inputAsset?.chainId ?? ChainId.mainnet, diff --git a/src/__swaps__/screens/Swap/components/SwapCoinIcon.tsx b/src/__swaps__/screens/Swap/components/SwapCoinIcon.tsx index d65c2af7408..bb5069c5092 100644 --- a/src/__swaps__/screens/Swap/components/SwapCoinIcon.tsx +++ b/src/__swaps__/screens/Swap/components/SwapCoinIcon.tsx @@ -10,7 +10,7 @@ import { FallbackIcon as CoinIconTextFallback, isETH } from '@/utils'; import { FastFallbackCoinIconImage } from '@/components/asset-list/RecyclerAssetList2/FastComponents/FastFallbackCoinIconImage'; import Animated from 'react-native-reanimated'; import FastImage, { Source } from 'react-native-fast-image'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; // TODO: Delete this and replace with RainbowCoinIcon // ⚠️ When replacing this component with RainbowCoinIcon, make sure diff --git a/src/__swaps__/screens/Swap/components/SwapOutputAsset.tsx b/src/__swaps__/screens/Swap/components/SwapOutputAsset.tsx index e3a5557ead5..591addf78fd 100644 --- a/src/__swaps__/screens/Swap/components/SwapOutputAsset.tsx +++ b/src/__swaps__/screens/Swap/components/SwapOutputAsset.tsx @@ -17,7 +17,7 @@ import { TokenList } from '@/__swaps__/screens/Swap/components/TokenList/TokenLi import { BASE_INPUT_WIDTH, INPUT_INNER_WIDTH, INPUT_PADDING, THICK_BORDER_WIDTH } from '@/__swaps__/screens/Swap/constants'; import { IS_ANDROID, IS_IOS } from '@/env'; import { useSwapContext } from '@/__swaps__/screens/Swap/providers/swap-provider'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import * as i18n from '@/languages'; import { useNavigation } from '@/navigation'; import Routes from '@/navigation/routesNames'; diff --git a/src/__swaps__/screens/Swap/components/TokenList/ChainSelection.tsx b/src/__swaps__/screens/Swap/components/TokenList/ChainSelection.tsx index 2fb3f5a389d..6e803ae4904 100644 --- a/src/__swaps__/screens/Swap/components/TokenList/ChainSelection.tsx +++ b/src/__swaps__/screens/Swap/components/TokenList/ChainSelection.tsx @@ -6,7 +6,7 @@ import { Text as RNText, StyleSheet } from 'react-native'; import Animated, { useDerivedValue, useSharedValue } from 'react-native-reanimated'; import { useSwapContext } from '@/__swaps__/screens/Swap/providers/swap-provider'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { opacity } from '@/__swaps__/utils/swaps'; import { analyticsV2 } from '@/analytics'; import { ChainImage } from '@/components/coin-icon/ChainImage'; @@ -18,7 +18,7 @@ import { userAssetsStore, useUserAssetsStore } from '@/state/assets/userAssets'; import { swapsStore } from '@/state/swaps/swapsStore'; import { showActionSheetWithOptions } from '@/utils'; import { OnPressMenuItemEventObject } from 'react-native-ios-context-menu'; -import { chainsLabel, chainsName } from '@/chains'; +import { getChainsLabelWorklet, getChainsNameWorklet, useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; type ChainSelectionProps = { allText?: string; @@ -29,6 +29,7 @@ export const ChainSelection = memo(function ChainSelection({ allText, output }: const { isDarkMode } = useColorMode(); const { accentColor: accountColor } = useAccountAccentColor(); const { selectedOutputChainId, setSelectedOutputChainId } = useSwapContext(); + const backendNetworks = useBackendNetworksStore(state => state.backendNetworksSharedValue); // chains sorted by balance on output, chains without balance hidden on input const { balanceSortedChainList, filter } = useUserAssetsStore(state => ({ @@ -47,11 +48,13 @@ export const ChainSelection = memo(function ChainSelection({ allText, output }: }, [accountColor, isDarkMode]); const chainName = useDerivedValue(() => { + const chainLabels = getChainsLabelWorklet(backendNetworks); + return output - ? chainsLabel[selectedOutputChainId.value] + ? chainLabels[selectedOutputChainId.value] : inputListFilter.value === 'all' ? allText - : chainsLabel[inputListFilter.value as ChainId]; + : chainLabels[inputListFilter.value as ChainId]; }); const handleSelectChain = useCallback( @@ -78,11 +81,11 @@ export const ChainSelection = memo(function ChainSelection({ allText, output }: const supportedChains = balanceSortedChainList.map(chainId => { return { actionKey: `${chainId}`, - actionTitle: chainsLabel[chainId], + actionTitle: getChainsLabelWorklet(backendNetworks)[chainId], icon: { iconType: 'ASSET', // NOTE: chainsName[chainId] for mainnet is 'mainnet' and we need it to be 'ethereum' - iconValue: chainId === ChainId.mainnet ? 'ethereumBadge' : `${chainsName[chainId]}BadgeNoShadow`, + iconValue: chainId === ChainId.mainnet ? 'ethereumBadge' : `${getChainsNameWorklet(backendNetworks)[chainId]}BadgeNoShadow`, }, }; }); @@ -101,7 +104,7 @@ export const ChainSelection = memo(function ChainSelection({ allText, output }: return { menuItems: supportedChains, }; - }, [balanceSortedChainList, output]); + }, [backendNetworks, balanceSortedChainList, output]); const onShowActionSheet = useCallback(() => { const chainTitles = menuConfig.menuItems.map(chain => chain.actionTitle); diff --git a/src/__swaps__/screens/Swap/components/TokenList/TokenToBuyList.tsx b/src/__swaps__/screens/Swap/components/TokenList/TokenToBuyList.tsx index 42bbfa26ff3..cf2fc29c7e2 100644 --- a/src/__swaps__/screens/Swap/components/TokenList/TokenToBuyList.tsx +++ b/src/__swaps__/screens/Swap/components/TokenList/TokenToBuyList.tsx @@ -3,7 +3,7 @@ import { COIN_ROW_WITH_PADDING_HEIGHT, CoinRow } from '@/__swaps__/screens/Swap/ import { ListEmpty } from '@/__swaps__/screens/Swap/components/TokenList/ListEmpty'; import { AssetToBuySectionId, useSearchCurrencyLists } from '@/__swaps__/screens/Swap/hooks/useSearchCurrencyLists'; import { useSwapContext } from '@/__swaps__/screens/Swap/providers/swap-provider'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { SearchAsset } from '@/__swaps__/types/search'; import { SwapAssetType } from '@/__swaps__/types/swap'; import { parseSearchAsset } from '@/__swaps__/utils/assets'; diff --git a/src/__swaps__/screens/Swap/hooks/useAnimatedSwapStyles.ts b/src/__swaps__/screens/Swap/hooks/useAnimatedSwapStyles.ts index d7ff8bf21ec..82b200227eb 100644 --- a/src/__swaps__/screens/Swap/hooks/useAnimatedSwapStyles.ts +++ b/src/__swaps__/screens/Swap/hooks/useAnimatedSwapStyles.ts @@ -23,7 +23,7 @@ import { safeAreaInsetValues } from '@/utils'; import { getSoftMenuBarHeight } from 'react-native-extra-dimensions-android'; import { DerivedValue, SharedValue, interpolate, useAnimatedStyle, useDerivedValue, withSpring, withTiming } from 'react-native-reanimated'; import { NavigationSteps } from './useSwapNavigation'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { SPRING_CONFIGS, TIMING_CONFIGS } from '@/components/animations/animationConfigs'; const INSET_BOTTOM = IS_ANDROID ? getSoftMenuBarHeight() - 24 : safeAreaInsetValues.bottom + 16; diff --git a/src/__swaps__/screens/Swap/hooks/useCustomGas.ts b/src/__swaps__/screens/Swap/hooks/useCustomGas.ts index 74559a1e1e3..00c0f0bbe22 100644 --- a/src/__swaps__/screens/Swap/hooks/useCustomGas.ts +++ b/src/__swaps__/screens/Swap/hooks/useCustomGas.ts @@ -1,4 +1,4 @@ -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { createRainbowStore } from '@/state/internal/createRainbowStore'; export type EIP1159GasSettings = { diff --git a/src/__swaps__/screens/Swap/hooks/useEstimatedGasFee.ts b/src/__swaps__/screens/Swap/hooks/useEstimatedGasFee.ts index 26d89a65f44..8582dc2b018 100644 --- a/src/__swaps__/screens/Swap/hooks/useEstimatedGasFee.ts +++ b/src/__swaps__/screens/Swap/hooks/useEstimatedGasFee.ts @@ -1,4 +1,4 @@ -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { weiToGwei } from '@/parsers'; import { convertAmountToNativeDisplayWorklet, formatNumber, multiply } from '@/helpers/utilities'; import { useNativeAsset } from '@/utils/ethereumUtils'; diff --git a/src/__swaps__/screens/Swap/hooks/useSearchCurrencyLists.ts b/src/__swaps__/screens/Swap/hooks/useSearchCurrencyLists.ts index 82e78bed66c..4033417ed62 100644 --- a/src/__swaps__/screens/Swap/hooks/useSearchCurrencyLists.ts +++ b/src/__swaps__/screens/Swap/hooks/useSearchCurrencyLists.ts @@ -1,5 +1,5 @@ import { TokenSearchResult, useTokenSearch } from '@/__swaps__/screens/Swap/resources/search/search'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { SearchAsset, TokenSearchAssetKey, TokenSearchThreshold } from '@/__swaps__/types/search'; import { addHexPrefix } from '@/handlers/web3'; import { isLowerCaseMatch, filterList } from '@/utils'; diff --git a/src/__swaps__/screens/Swap/hooks/useSelectedGas.ts b/src/__swaps__/screens/Swap/hooks/useSelectedGas.ts index 4fa9145a0b7..2323417d28b 100644 --- a/src/__swaps__/screens/Swap/hooks/useSelectedGas.ts +++ b/src/__swaps__/screens/Swap/hooks/useSelectedGas.ts @@ -1,4 +1,4 @@ -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { GasSpeed } from '@/__swaps__/types/gas'; import { getCachedGasSuggestions, useMeteorologySuggestions } from '@/__swaps__/utils/meteorology'; import { createRainbowStore } from '@/state/internal/createRainbowStore'; diff --git a/src/__swaps__/screens/Swap/hooks/useSwapEstimatedGasLimit.ts b/src/__swaps__/screens/Swap/hooks/useSwapEstimatedGasLimit.ts index d061ca5fe3f..1c77056a6ff 100644 --- a/src/__swaps__/screens/Swap/hooks/useSwapEstimatedGasLimit.ts +++ b/src/__swaps__/screens/Swap/hooks/useSwapEstimatedGasLimit.ts @@ -2,7 +2,7 @@ import { CrosschainQuote, Quote, QuoteError, SwapType } from '@rainbow-me/swaps' import { useQuery } from '@tanstack/react-query'; import { ParsedSearchAsset } from '@/__swaps__/types/assets'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { estimateUnlockAndCrosschainSwap } from '@/raps/actions/crosschainSwap'; import { estimateUnlockAndSwap } from '@/raps/actions/swap'; import { QueryConfigWithSelect, QueryFunctionArgs, QueryFunctionResult, createQueryKey } from '@/react-query'; diff --git a/src/__swaps__/screens/Swap/hooks/useSwapInputsController.ts b/src/__swaps__/screens/Swap/hooks/useSwapInputsController.ts index 6472a89fbf7..4da55baff56 100644 --- a/src/__swaps__/screens/Swap/hooks/useSwapInputsController.ts +++ b/src/__swaps__/screens/Swap/hooks/useSwapInputsController.ts @@ -1,7 +1,7 @@ import { divWorklet, equalWorklet, greaterThanWorklet, isNumberStringWorklet, mulWorklet, toFixedWorklet } from '@/safe-math/SafeMath'; import { SCRUBBER_WIDTH, SLIDER_WIDTH, snappySpringConfig } from '@/__swaps__/screens/Swap/constants'; import { ExtendedAnimatedAssetWithColors } from '@/__swaps__/types/assets'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { RequestNewQuoteParams, inputKeys, inputMethods, inputValuesType } from '@/__swaps__/types/swap'; import { valueBasedDecimalFormatter } from '@/__swaps__/utils/decimalFormatter'; import { getInputValuesForSliderPositionWorklet, updateInputValuesAfterFlip } from '@/__swaps__/utils/flipAssets'; @@ -40,6 +40,7 @@ import { SharedValue, runOnJS, runOnUI, useAnimatedReaction, useDerivedValue, us import { useDebouncedCallback } from 'use-debounce'; import { NavigationSteps } from './useSwapNavigation'; import { deepEqualWorklet } from '@/worklets/comparisons'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const REMOTE_CONFIG = getRemoteConfig(); @@ -649,7 +650,7 @@ export function useSwapInputsController({ () => ({ assetToBuyId: internalSelectedOutputAsset.value?.uniqueId, assetToSellId: internalSelectedInputAsset.value?.uniqueId, - assetToSellNetwork: internalSelectedInputAsset.value?.chainId, + assetToSellChainId: internalSelectedInputAsset.value?.chainId, }), (current, previous) => { const didInputAssetChange = current.assetToSellId !== previous?.assetToSellId; @@ -657,12 +658,12 @@ export function useSwapInputsController({ if (!didInputAssetChange && !didOutputAssetChange) return; - if (current.assetToSellNetwork !== previous?.assetToSellNetwork) { - const previousDefaultSlippage = getDefaultSlippageWorklet(previous?.assetToSellNetwork || ChainId.mainnet, REMOTE_CONFIG); + if (current.assetToSellChainId !== previous?.assetToSellChainId) { + const previousDefaultSlippage = getDefaultSlippageWorklet(previous?.assetToSellChainId || ChainId.mainnet, REMOTE_CONFIG); // If the user has not overridden the default slippage, update it if (slippage.value === previousDefaultSlippage) { - const newSlippage = getDefaultSlippageWorklet(current.assetToSellNetwork || ChainId.mainnet, REMOTE_CONFIG); + const newSlippage = getDefaultSlippageWorklet(current.assetToSellChainId || ChainId.mainnet, REMOTE_CONFIG); slippage.value = newSlippage; runOnJS(setSlippage)(newSlippage); } diff --git a/src/__swaps__/screens/Swap/hooks/useSwapOutputQuotesDisabled.ts b/src/__swaps__/screens/Swap/hooks/useSwapOutputQuotesDisabled.ts index 63649915485..cf3259ab0eb 100644 --- a/src/__swaps__/screens/Swap/hooks/useSwapOutputQuotesDisabled.ts +++ b/src/__swaps__/screens/Swap/hooks/useSwapOutputQuotesDisabled.ts @@ -1,6 +1,10 @@ import { SharedValue, useDerivedValue } from 'react-native-reanimated'; import { ExtendedAnimatedAssetWithColors } from '@/__swaps__/types/assets'; -import { supportedSwapExactOutputChainIds, supportedBridgeExactOutputChainIds } from '@/chains'; +import { + useBackendNetworksStore, + getSwapExactOutputSupportedChainIdsWorklet, + getBridgeExactOutputSupportedChainIdsWorklet, +} from '@/state/backendNetworks/backendNetworks'; export const useSwapOutputQuotesDisabled = ({ inputAsset, @@ -9,13 +13,15 @@ export const useSwapOutputQuotesDisabled = ({ inputAsset: SharedValue; outputAsset: SharedValue; }): SharedValue => { + const backendNetworks = useBackendNetworksStore(state => state.backendNetworksSharedValue); + const outputQuotesAreDisabled = useDerivedValue(() => { if (!inputAsset.value || !outputAsset.value) return false; if (inputAsset.value.chainId === outputAsset.value.chainId) { - return !supportedSwapExactOutputChainIds.includes(inputAsset.value.chainId); + return !getSwapExactOutputSupportedChainIdsWorklet(backendNetworks).includes(inputAsset.value.chainId); } else { - return !supportedBridgeExactOutputChainIds.includes(inputAsset.value.chainId); + return !getBridgeExactOutputSupportedChainIdsWorklet(backendNetworks).includes(inputAsset.value.chainId); } }); diff --git a/src/__swaps__/screens/Swap/providers/SyncSwapStateAndSharedValues.tsx b/src/__swaps__/screens/Swap/providers/SyncSwapStateAndSharedValues.tsx index 65476eb5fd6..beee83e8b3e 100644 --- a/src/__swaps__/screens/Swap/providers/SyncSwapStateAndSharedValues.tsx +++ b/src/__swaps__/screens/Swap/providers/SyncSwapStateAndSharedValues.tsx @@ -13,7 +13,7 @@ import { toScaledIntegerWorklet, } from '@/safe-math/SafeMath'; import { ExtendedAnimatedAssetWithColors } from '@/__swaps__/types/assets'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { ParsedAddressAsset } from '@/entities'; import { useUserNativeNetworkAsset } from '@/resources/assets/useUserAsset'; import { CrosschainQuote, Quote, QuoteError } from '@rainbow-me/swaps'; diff --git a/src/__swaps__/screens/Swap/providers/swap-provider.tsx b/src/__swaps__/screens/Swap/providers/swap-provider.tsx index 9d82264a1d5..cb2d83acc5b 100644 --- a/src/__swaps__/screens/Swap/providers/swap-provider.tsx +++ b/src/__swaps__/screens/Swap/providers/swap-provider.tsx @@ -24,7 +24,7 @@ import { useSwapTextStyles } from '@/__swaps__/screens/Swap/hooks/useSwapTextSty import { SwapWarningType, useSwapWarning } from '@/__swaps__/screens/Swap/hooks/useSwapWarning'; import { userAssetsQueryKey as swapsUserAssetsQueryKey } from '@/__swaps__/screens/Swap/resources/assets/userAssets'; import { AddressOrEth, ExtendedAnimatedAssetWithColors, ParsedSearchAsset } from '@/__swaps__/types/assets'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { inputKeys, SwapAssetType } from '@/__swaps__/types/swap'; import { getDefaultSlippageWorklet, parseAssetAndExtend } from '@/__swaps__/utils/swaps'; import { analyticsV2 } from '@/analytics'; @@ -58,7 +58,11 @@ import { SyncGasStateToSharedValues, SyncQuoteSharedValuesToState } from './Sync import { performanceTracking, Screens, TimeToSignOperation } from '@/state/performance/performance'; import { getRemoteConfig } from '@/model/remoteConfig'; import { useConnectedToHardhatStore } from '@/state/connectedToHardhat'; -import { chainsNativeAsset, supportedFlashbotsChainIds } from '@/chains'; +import { + useBackendNetworksStore, + getFlashbotsSupportedChainIdsWorklet, + getChainsNativeAssetWorklet, +} from '@/state/backendNetworks/backendNetworks'; import { LedgerSigner } from '@/handlers/LedgerSigner'; const swapping = i18n.t(i18n.l.swap.actions.swapping); @@ -138,6 +142,9 @@ interface SwapProviderProps { export const SwapProvider = ({ children }: SwapProviderProps) => { const { nativeCurrency } = useAccountSettings(); + const backendNetworks = useBackendNetworksStore(state => state.backendNetworksSharedValue); + const getFlashbotsSupportedChainIds = useBackendNetworksStore(state => state.getFlashbotsSupportedChainIds); + const isFetching = useSharedValue(false); const isQuoteStale = useSharedValue(0); // TODO: Convert this to a boolean const isSwapping = useSharedValue(false); @@ -203,7 +210,7 @@ export const SwapProvider = ({ children }: SwapProviderProps) => { NotificationManager?.postNotification('rapInProgress'); const provider = - parameters.flashbots && supportedFlashbotsChainIds.includes(parameters.chainId) + parameters.flashbots && getFlashbotsSupportedChainIds().includes(parameters.chainId) ? getFlashbotsProvider() : getProvider({ chainId: parameters.chainId }); const connectedToHardhat = useConnectedToHardhatStore.getState().connectedToHardhat; @@ -410,7 +417,8 @@ export const SwapProvider = ({ children }: SwapProviderProps) => { const type = inputAsset.chainId !== outputAsset.chainId ? 'crosschainSwap' : 'swap'; const quoteData = q as QuoteTypeMap[typeof type]; - const flashbots = (SwapSettings.flashbots.value && !!supportedFlashbotsChainIds.includes(inputAsset.chainId)) ?? false; + const flashbots = + (SwapSettings.flashbots.value && !!getFlashbotsSupportedChainIdsWorklet(backendNetworks).includes(inputAsset.chainId)) ?? false; const isNativeWrapOrUnwrap = quoteData.swapType === SwapType.wrap || quoteData.swapType === SwapType.unwrap; @@ -761,7 +769,7 @@ export const SwapProvider = ({ children }: SwapProviderProps) => { } if (hasEnoughFundsForGas.value === false) { - const nativeCurrency = chainsNativeAsset[sellAsset?.chainId || ChainId.mainnet]; + const nativeCurrency = getChainsNativeAssetWorklet(backendNetworks)[sellAsset?.chainId || ChainId.mainnet]; return { label: `${insufficient} ${nativeCurrency.symbol}`, disabled: true, diff --git a/src/__swaps__/screens/Swap/resources/_selectors/assets.ts b/src/__swaps__/screens/Swap/resources/_selectors/assets.ts index 4ca4805c1c7..390045d369c 100644 --- a/src/__swaps__/screens/Swap/resources/_selectors/assets.ts +++ b/src/__swaps__/screens/Swap/resources/_selectors/assets.ts @@ -1,5 +1,5 @@ import { ParsedAssetsDict, ParsedAssetsDictByChain, ParsedUserAsset, UniqueId } from '@/__swaps__/types/assets'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { getAddressAndChainIdFromUniqueId } from '@/utils/ethereumUtils'; import { add } from '@/helpers/utilities'; diff --git a/src/__swaps__/screens/Swap/resources/assets/userAssets.ts b/src/__swaps__/screens/Swap/resources/assets/userAssets.ts index 5eecd6bf551..c724db135af 100644 --- a/src/__swaps__/screens/Swap/resources/assets/userAssets.ts +++ b/src/__swaps__/screens/Swap/resources/assets/userAssets.ts @@ -8,14 +8,14 @@ import { RainbowError, logger } from '@/logger'; import { RainbowFetchClient } from '@/rainbow-fetch'; import { SupportedCurrencyKey } from '@/references'; import { ParsedAssetsDictByChain, ZerionAsset } from '@/__swaps__/types/assets'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { AddressAssetsReceivedMessage } from '@/__swaps__/types/refraction'; import { parseUserAsset } from '@/__swaps__/utils/assets'; import { greaterThan } from '@/helpers/utilities'; import { fetchUserAssetsByChain } from './userAssetsByChain'; import { fetchHardhatBalancesByChainId } from '@/resources/assets/hardhatAssets'; -import { SUPPORTED_CHAIN_IDS } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { useConnectedToHardhatStore } from '@/state/connectedToHardhat'; const addysHttp = new RainbowFetchClient({ @@ -113,7 +113,7 @@ async function userAssetsQueryFunction({ const cachedUserAssets = (cache.find(userAssetsQueryKey({ address, currency, testnetMode }))?.state?.data || {}) as ParsedAssetsDictByChain; try { - const url = `/${SUPPORTED_CHAIN_IDS.join(',')}/${address}/assets`; + const url = `/${useBackendNetworksStore.getState().getSupportedChainIds().join(',')}/${address}/assets`; const res = await addysHttp.get(url, { params: { currency: currency.toLowerCase(), diff --git a/src/__swaps__/screens/Swap/resources/assets/userAssetsByChain.ts b/src/__swaps__/screens/Swap/resources/assets/userAssetsByChain.ts index 8a3260fa188..723334cce51 100644 --- a/src/__swaps__/screens/Swap/resources/assets/userAssetsByChain.ts +++ b/src/__swaps__/screens/Swap/resources/assets/userAssetsByChain.ts @@ -3,7 +3,7 @@ import { Address } from 'viem'; import { QueryConfigWithSelect, QueryFunctionArgs, QueryFunctionResult, createQueryKey, queryClient } from '@/react-query'; import { SupportedCurrencyKey } from '@/references'; import { ParsedAssetsDictByChain, ParsedUserAsset } from '@/__swaps__/types/assets'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { AddressAssetsReceivedMessage } from '@/__swaps__/types/refraction'; import { RainbowError, logger } from '@/logger'; diff --git a/src/__swaps__/screens/Swap/resources/search/discovery.ts b/src/__swaps__/screens/Swap/resources/search/discovery.ts index 5c8565facfd..ebb15d0f59b 100644 --- a/src/__swaps__/screens/Swap/resources/search/discovery.ts +++ b/src/__swaps__/screens/Swap/resources/search/discovery.ts @@ -1,4 +1,4 @@ -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { SearchAsset } from '@/__swaps__/types/search'; import { RainbowError, logger } from '@/logger'; import { RainbowFetchClient } from '@/rainbow-fetch'; diff --git a/src/__swaps__/screens/Swap/resources/search/search.ts b/src/__swaps__/screens/Swap/resources/search/search.ts index 2cfe70ebda0..0c9b94ba58f 100644 --- a/src/__swaps__/screens/Swap/resources/search/search.ts +++ b/src/__swaps__/screens/Swap/resources/search/search.ts @@ -1,5 +1,5 @@ /* eslint-disable no-nested-ternary */ -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { SearchAsset, TokenSearchAssetKey, TokenSearchListId, TokenSearchThreshold } from '@/__swaps__/types/search'; import { RainbowError, logger } from '@/logger'; import { RainbowFetchClient } from '@/rainbow-fetch'; diff --git a/src/__swaps__/screens/Swap/resources/search/utils.ts b/src/__swaps__/screens/Swap/resources/search/utils.ts index 288fa9302bc..975c0c3e8f4 100644 --- a/src/__swaps__/screens/Swap/resources/search/utils.ts +++ b/src/__swaps__/screens/Swap/resources/search/utils.ts @@ -1,4 +1,4 @@ -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { SearchAsset } from '@/__swaps__/types/search'; import { Address } from 'viem'; import { isNativeAsset } from '@/handlers/assets'; diff --git a/src/__swaps__/types/assets.ts b/src/__swaps__/types/assets.ts index f6bd292a44d..c6f7bcd84a5 100644 --- a/src/__swaps__/types/assets.ts +++ b/src/__swaps__/types/assets.ts @@ -1,7 +1,7 @@ import type { Address } from 'viem'; import { ETH_ADDRESS } from '@/references'; -import { ChainId, ChainName } from '@/chains/types'; +import { ChainId, ChainName } from '@/state/backendNetworks/types'; import { SearchAsset } from '@/__swaps__/types/search'; import { ResponseByTheme } from '../utils/swaps'; diff --git a/src/__swaps__/types/refraction.ts b/src/__swaps__/types/refraction.ts index 802b8fc0f33..674027f9324 100644 --- a/src/__swaps__/types/refraction.ts +++ b/src/__swaps__/types/refraction.ts @@ -1,5 +1,5 @@ import { ZerionAsset } from '@/__swaps__/types/assets'; -import { ChainId, ChainName } from '@/chains/types'; +import { ChainId, ChainName } from '@/state/backendNetworks/types'; import { PaginatedTransactionsApiResponse } from '@/entities'; /** diff --git a/src/__swaps__/types/search.ts b/src/__swaps__/types/search.ts index e108655d0d0..c11d1a6f920 100644 --- a/src/__swaps__/types/search.ts +++ b/src/__swaps__/types/search.ts @@ -1,7 +1,7 @@ import { Address } from 'viem'; import { AddressOrEth, AssetType, ParsedAsset, UniqueId } from '@/__swaps__/types/assets'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { AssetToBuySectionId } from '../screens/Swap/hooks/useSearchCurrencyLists'; export type TokenSearchAssetKey = keyof ParsedAsset; diff --git a/src/__swaps__/utils/assets.ts b/src/__swaps__/utils/assets.ts index 87a135deec8..98e45ff44e4 100644 --- a/src/__swaps__/utils/assets.ts +++ b/src/__swaps__/utils/assets.ts @@ -10,7 +10,7 @@ import { ZerionAsset, ZerionAssetPrice, } from '@/__swaps__/types/assets'; -import { ChainId, ChainName } from '@/chains/types'; +import { ChainId, ChainName } from '@/state/backendNetworks/types'; import * as i18n from '@/languages'; import { SearchAsset } from '@/__swaps__/types/search'; @@ -24,7 +24,7 @@ import { convertRawAmountToDecimalFormat, } from '@/helpers/utilities'; import { isLowerCaseMatch } from '@/utils'; -import { chainsIdByName, chainsName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export const isSameAsset = (a1: Pick, a2: Pick) => +a1.chainId === +a2.chainId && isLowerCaseMatch(a1.address, a2.address); @@ -62,7 +62,10 @@ const getUniqueIdForAsset = ({ asset }: { asset: ZerionAsset | AssetApiResponse const address = asset.asset_code; const chainName = asset.network ?? ChainName.mainnet; const networks = 'networks' in asset ? asset.networks || {} : {}; - const chainId = ('chain_id' in asset && asset.chain_id) || chainsIdByName[chainName] || Number(Object.keys(networks)[0]); + const chainId = + ('chain_id' in asset && asset.chain_id) || + useBackendNetworksStore.getState().getChainsIdByName()[chainName] || + Number(Object.keys(networks)[0]); // ZerionAsset should be removed when we move fully away from websckets/refraction api const mainnetAddress = isZerionAsset(asset) @@ -76,7 +79,10 @@ export function parseAsset({ asset, currency }: { asset: ZerionAsset | AssetApiR const address = asset.asset_code; const chainName = asset.network ?? ChainName.mainnet; const networks = 'networks' in asset ? asset.networks || {} : {}; - const chainId = ('chain_id' in asset && asset.chain_id) || chainsIdByName[chainName] || Number(Object.keys(networks)[0]); + const chainId = + ('chain_id' in asset && asset.chain_id) || + useBackendNetworksStore.getState().getChainsIdByName()[chainName] || + Number(Object.keys(networks)[0]); // ZerionAsset should be removed when we move fully away from websckets/refraction api const mainnetAddress = isZerionAsset(asset) @@ -154,7 +160,7 @@ export function parseAssetMetadata({ const parsedAsset = { address, chainId, - chainName: chainsName[chainId], + chainName: useBackendNetworksStore.getState().getChainsName()[chainId], colors: asset?.colors, decimals: asset?.decimals, icon_url: asset?.iconUrl, @@ -272,7 +278,7 @@ export const parseSearchAsset = ({ isNativeAsset: isNativeAsset(searchAsset.address, searchAsset.chainId), address: searchAsset.address, chainId: searchAsset.chainId, - chainName: chainsName[searchAsset.chainId], + chainName: useBackendNetworksStore.getState().getChainsName()[searchAsset.chainId], native: { balance: userAsset?.native.balance || { amount: '0', diff --git a/src/__swaps__/utils/gasUtils.ts b/src/__swaps__/utils/gasUtils.ts index c3fc6c3d4dd..58a106eb5c5 100644 --- a/src/__swaps__/utils/gasUtils.ts +++ b/src/__swaps__/utils/gasUtils.ts @@ -11,7 +11,7 @@ import * as i18n from '@/languages'; import { OVM_GAS_PRICE_ORACLE, gasUnits, supportedNativeCurrencies, optimismGasOracleAbi, SupportedCurrencyKey } from '@/references'; import { ParsedAsset } from '@/__swaps__/types/assets'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { BlocksToConfirmation, GasFeeLegacyParams, GasFeeParam, GasFeeParams, GasSpeed } from '@/__swaps__/types/gas'; import { gweiToWei, weiToGwei } from '@/parsers'; diff --git a/src/__swaps__/utils/meteorology.ts b/src/__swaps__/utils/meteorology.ts index 64c03986f14..3b710cad24e 100644 --- a/src/__swaps__/utils/meteorology.ts +++ b/src/__swaps__/utils/meteorology.ts @@ -1,6 +1,6 @@ import { useQuery } from '@tanstack/react-query'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { rainbowMeteorologyGetData } from '@/handlers/gasFees'; import { abs, lessThan, subtract } from '@/helpers/utilities'; import { gweiToWei } from '@/parsers'; diff --git a/src/__swaps__/utils/swaps.ts b/src/__swaps__/utils/swaps.ts index 514c9d63240..4d9ec3982ea 100644 --- a/src/__swaps__/utils/swaps.ts +++ b/src/__swaps__/utils/swaps.ts @@ -9,12 +9,11 @@ import { SLIDER_WIDTH, STABLECOIN_MINIMUM_SIGNIFICANT_DECIMALS, } from '@/__swaps__/screens/Swap/constants'; -import { ChainId } from '@/chains/types'; import { globalColors } from '@/design-system'; import { ForegroundColor, palettes } from '@/design-system/color/palettes'; import { TokenColors } from '@/graphql/__generated__/metadata'; import * as i18n from '@/languages'; -import { RainbowConfig } from '@/model/remoteConfig'; +import { DEFAULT_CONFIG, RainbowConfig } from '@/model/remoteConfig'; import store from '@/redux/store'; import { supportedNativeCurrencies } from '@/references'; import { userAssetsStore } from '@/state/assets/userAssets'; @@ -38,7 +37,7 @@ import { ExtendedAnimatedAssetWithColors, ParsedSearchAsset } from '../types/ass import { inputKeys } from '../types/swap'; import { valueBasedDecimalFormatter } from './decimalFormatter'; import { convertAmountToRawAmount } from '@/helpers/utilities'; -import { chainsName } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; import { getUniqueId } from '@/utils/ethereumUtils'; // DO NOT REMOVE THESE COMMENTED ENV VARS @@ -346,20 +345,6 @@ export const opacityWorklet = (color: string, opacity: number) => { // // /---- END worklet utils ----/ // -export const DEFAULT_SLIPPAGE_BIPS = { - [ChainId.apechain]: 200, - [ChainId.arbitrum]: 200, - [ChainId.avalanche]: 200, - [ChainId.base]: 200, - [ChainId.blast]: 200, - [ChainId.bsc]: 200, - [ChainId.degen]: 200, - [ChainId.mainnet]: 100, - [ChainId.optimism]: 200, - [ChainId.polygon]: 200, - [ChainId.zora]: 200, -}; - export const slippageInBipsToString = (slippageInBips: number) => (slippageInBips / 100).toFixed(1); export const slippageInBipsToStringWorklet = (slippageInBips: number) => { @@ -368,18 +353,24 @@ export const slippageInBipsToStringWorklet = (slippageInBips: number) => { }; export const getDefaultSlippage = (chainId: ChainId, config: RainbowConfig) => { - return slippageInBipsToString( - // NOTE: JSON.parse doesn't type the result as a Record - (config.default_slippage_bips as unknown as Record)[chainsName[chainId]] || DEFAULT_SLIPPAGE_BIPS[chainId] + const amount = +( + (config.default_slippage_bips_chainId as unknown as { [key: number]: number })[chainId] || + DEFAULT_CONFIG.default_slippage_bips_chainId[chainId] || + 200 ); + + return slippageInBipsToString(amount); }; export const getDefaultSlippageWorklet = (chainId: ChainId, config: RainbowConfig) => { 'worklet'; - - return slippageInBipsToStringWorklet( - (config.default_slippage_bips as unknown as { [key: string]: number })[chainsName[chainId]] || DEFAULT_SLIPPAGE_BIPS[chainId] + const amount = +( + (config.default_slippage_bips_chainId as unknown as { [key: number]: number })[chainId] || + DEFAULT_CONFIG.default_slippage_bips_chainId[chainId] || + 200 ); + + return slippageInBipsToStringWorklet(amount); }; export type Colors = { diff --git a/src/analytics/event.ts b/src/analytics/event.ts index 8beb36d4e45..7c56e53a697 100644 --- a/src/analytics/event.ts +++ b/src/analytics/event.ts @@ -1,5 +1,5 @@ import { AddressOrEth, ExtendedAnimatedAssetWithColors, ParsedSearchAsset } from '@/__swaps__/types/assets'; -import { ChainId, Network } from '@/chains/types'; +import { ChainId, Network } from '@/state/backendNetworks/types'; import { SwapAssetType } from '@/__swaps__/types/swap'; import { UnlockableAppIconKey } from '@/appIcons/appIcons'; import { CardType } from '@/components/cards/GenericCard'; diff --git a/src/appIcons/appIcons.ts b/src/appIcons/appIcons.ts index a4429006d58..97ae364095a 100644 --- a/src/appIcons/appIcons.ts +++ b/src/appIcons/appIcons.ts @@ -14,7 +14,7 @@ import AppIconPoolboy from '@/assets/appIconPoolboy.png'; import AppIconAdworld from '@/assets/appIconAdworld.png'; import AppIconFarcaster from '@/assets/appIconFarcaster.png'; import { TokenGateCheckerNetwork } from '@/featuresToUnlock/tokenGatedUtils'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; // optimism app icon unlocking NFTs const OPTIMISTIC_EXPLORER_NFT_ADDRESS: EthereumAddress = '0x81b30ff521D1fEB67EDE32db726D95714eb00637'; diff --git a/src/chains/index.ts b/src/chains/index.ts deleted file mode 100644 index ace5273f2de..00000000000 --- a/src/chains/index.ts +++ /dev/null @@ -1,206 +0,0 @@ -import { Chain } from 'viem/chains'; -import { queryClient } from '@/react-query'; -import { backendNetworksQueryKey, BackendNetworksResponse } from '@/resources/metadata/backendNetworks'; -import { ChainId, BackendNetwork, BackendNetworkServices, chainHardhat, chainHardhatOptimism } from './types'; -import { transformBackendNetworksToChains } from './utils/backendNetworks'; -import { gasUtils } from '@/utils'; -import { useConnectedToHardhatStore } from '@/state/connectedToHardhat'; -import { IS_TEST } from '@/env'; -import buildTimeNetworks from '@/references/networks.json'; - -// NOTE: Prefer runtime data from backendNetworksQueryKey, but fallback to buildTimeNetworks if needed -const backendNetworks = queryClient.getQueryData(backendNetworksQueryKey()) ?? buildTimeNetworks; - -const BACKEND_CHAINS = transformBackendNetworksToChains(backendNetworks.networks); - -export const SUPPORTED_CHAINS: Chain[] = IS_TEST ? [...BACKEND_CHAINS, chainHardhat, chainHardhatOptimism] : BACKEND_CHAINS; - -export const defaultChains: Record = SUPPORTED_CHAINS.reduce( - (acc, chain) => { - acc[chain.id] = chain; - return acc; - }, - {} as Record -); - -export const SUPPORTED_CHAIN_IDS = SUPPORTED_CHAINS.map(chain => chain.id); - -export const SUPPORTED_MAINNET_CHAINS: Chain[] = SUPPORTED_CHAINS.filter(chain => !chain.testnet); - -export const SUPPORTED_MAINNET_CHAIN_IDS: ChainId[] = SUPPORTED_MAINNET_CHAINS.map(chain => chain.id); - -export const needsL1SecurityFeeChains = backendNetworks.networks - .filter((backendNetwork: BackendNetwork) => backendNetwork.opStack) - .map((backendNetwork: BackendNetwork) => parseInt(backendNetwork.id, 10)); - -export const chainsNativeAsset: Record = backendNetworks.networks.reduce( - (acc, backendNetwork: BackendNetwork) => { - acc[parseInt(backendNetwork.id, 10)] = backendNetwork.nativeAsset; - return acc; - }, - {} as Record -); - -export const chainsLabel: Record = backendNetworks.networks.reduce( - (acc, backendNetwork: BackendNetwork) => { - acc[parseInt(backendNetwork.id, 10)] = backendNetwork.label; - return acc; - }, - {} as Record -); - -export const chainsName: Record = backendNetworks.networks.reduce( - (acc, backendNetwork: BackendNetwork) => { - acc[parseInt(backendNetwork.id, 10)] = backendNetwork.name; - return acc; - }, - {} as Record -); - -export const chainsIdByName: Record = backendNetworks.networks.reduce( - (acc, backendNetwork: BackendNetwork) => { - acc[backendNetwork.name] = parseInt(backendNetwork.id, 10); - return acc; - }, - {} as Record -); - -const defaultGasSpeeds = (chainId: ChainId) => { - switch (chainId) { - case ChainId.bsc: - case ChainId.goerli: - case ChainId.polygon: - return [gasUtils.NORMAL, gasUtils.FAST, gasUtils.URGENT]; - case ChainId.gnosis: - return [gasUtils.NORMAL]; - default: - return [gasUtils.NORMAL, gasUtils.FAST, gasUtils.URGENT, gasUtils.CUSTOM]; - } -}; - -export const chainsGasSpeeds: Record = backendNetworks.networks.reduce( - (acc, backendNetwork: BackendNetwork) => { - acc[parseInt(backendNetwork.id, 10)] = defaultGasSpeeds(parseInt(backendNetwork.id, 10)); - return acc; - }, - {} as Record -); - -const defaultPollingIntervals = (chainId: ChainId) => { - switch (chainId) { - case ChainId.polygon: - return 2_000; - case ChainId.arbitrum: - case ChainId.bsc: - return 3_000; - default: - return 5_000; - } -}; - -export const chainsSwapPollingInterval: Record = backendNetworks.networks.reduce( - (acc, backendNetwork: BackendNetwork) => { - acc[parseInt(backendNetwork.id, 10)] = defaultPollingIntervals(parseInt(backendNetwork.id, 10)); - return acc; - }, - {} as Record -); - -const defaultSimplehashNetworks = (chainId: ChainId) => { - switch (chainId) { - case ChainId.apechain: - return 'apechain'; - case ChainId.arbitrum: - return 'arbitrum'; - case ChainId.avalanche: - return 'avalanche'; - case ChainId.base: - return 'base'; - case ChainId.blast: - return 'blast'; - case ChainId.bsc: - return 'bsc'; - case ChainId.degen: - return 'degen'; - case ChainId.gnosis: - return 'gnosis'; - case ChainId.goerli: - return 'ethereum-goerli'; - case ChainId.mainnet: - return 'ethereum'; - case ChainId.optimism: - return 'optimism'; - case ChainId.polygon: - return 'polygon'; - case ChainId.zora: - return 'zora'; - default: - return ''; - } -}; - -export const chainsSimplehashNetwork: Record = backendNetworks.networks.reduce( - (acc, backendNetwork: BackendNetwork) => { - acc[parseInt(backendNetwork.id, 10)] = defaultSimplehashNetworks(parseInt(backendNetwork.id, 10)); - return acc; - }, - {} as Record -); - -const filterChainIdsByService = (servicePath: (services: BackendNetworkServices) => boolean): number[] => { - return backendNetworks.networks - .filter((network: BackendNetwork) => { - const services = network?.enabledServices; - return services && servicePath(services); - }) - .map((network: BackendNetwork) => parseInt(network.id, 10)); -}; - -export const meteorologySupportedChainIds = filterChainIdsByService(services => services.meteorology.enabled); - -export const supportedSwapChainIds = filterChainIdsByService(services => services.swap.enabled); - -export const supportedSwapExactOutputChainIds = filterChainIdsByService(services => services.swap.swapExactOutput); - -export const supportedBridgeExactOutputChainIds = filterChainIdsByService(services => services.swap.bridgeExactOutput); - -export const supportedNotificationsChainIds = filterChainIdsByService(services => services.notifications.enabled); - -export const supportedApprovalsChainIds = filterChainIdsByService(services => services.addys.approvals); - -export const supportedTransactionsChainIds = filterChainIdsByService(services => services.addys.transactions); - -export const supportedAssetsChainIds = filterChainIdsByService(services => services.addys.assets); - -export const supportedPositionsChainIds = filterChainIdsByService(services => services.addys.positions); - -export const supportedTokenSearchChainIds = filterChainIdsByService(services => services.tokenSearch.enabled); - -export const supportedNftChainIds = filterChainIdsByService(services => services.nftProxy.enabled); - -export const supportedFlashbotsChainIds = [ChainId.mainnet]; - -export const shouldDefaultToFastGasChainIds = [ChainId.mainnet, ChainId.polygon, ChainId.goerli]; - -const chainsGasUnits = backendNetworks.networks.reduce( - (acc, backendNetwork: BackendNetwork) => { - acc[parseInt(backendNetwork.id, 10)] = backendNetwork.gasUnits; - return acc; - }, - {} as Record -); - -export const getChainGasUnits = (chainId?: number) => { - return (chainId ? chainsGasUnits[chainId] : undefined) || chainsGasUnits[ChainId.mainnet]; -}; - -export const getChainDefaultRpc = (chainId: ChainId) => { - switch (chainId) { - case ChainId.mainnet: - return useConnectedToHardhatStore.getState().connectedToHardhat - ? 'http://127.0.0.1:8545' - : defaultChains[ChainId.mainnet].rpcUrls.default.http[0]; - default: - return defaultChains[chainId].rpcUrls.default.http[0]; - } -}; diff --git a/src/components/AddFundsInterstitial.js b/src/components/AddFundsInterstitial.js index 01128c72803..4a7c315a0b6 100644 --- a/src/components/AddFundsInterstitial.js +++ b/src/components/AddFundsInterstitial.js @@ -19,7 +19,7 @@ import styled from '@/styled-thing'; import { padding, position } from '@/styles'; import ShadowStack from '@/react-native-shadow-stack'; import { useRoute } from '@react-navigation/native'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; const ContainerWidth = 261; diff --git a/src/components/BackendNetworks.tsx b/src/components/BackendNetworks.tsx index 9ff6747ddd2..ba1d9e6337f 100644 --- a/src/components/BackendNetworks.tsx +++ b/src/components/BackendNetworks.tsx @@ -1,7 +1,12 @@ import { useBackendNetworks } from '@/resources/metadata/backendNetworks'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export const BackendNetworks = () => { - useBackendNetworks(); + useBackendNetworks({ + onSuccess(data) { + useBackendNetworksStore.getState().setBackendNetworks(data); + }, + }); return null; }; diff --git a/src/components/ChainLogo.js b/src/components/ChainLogo.js index 04b56e1e2b4..3c7efd4c8ff 100644 --- a/src/components/ChainLogo.js +++ b/src/components/ChainLogo.js @@ -21,7 +21,7 @@ import BaseBadgeNoShadow from '../assets/badges/baseBadgeNoShadow.png'; import { Centered } from './layout'; import styled from '@/styled-thing'; import { position } from '@/styles'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const ChainIcon = styled(FastImage)({ height: ({ size }) => size, diff --git a/src/components/DappBrowser/control-panel/ControlPanel.tsx b/src/components/DappBrowser/control-panel/ControlPanel.tsx index 5f56da1ba00..e020914a5cd 100644 --- a/src/components/DappBrowser/control-panel/ControlPanel.tsx +++ b/src/components/DappBrowser/control-panel/ControlPanel.tsx @@ -58,8 +58,8 @@ import { addressSetSelected, walletsSetSelected } from '@/redux/wallets'; import { swapsStore } from '@/state/swaps/swapsStore'; import { userAssetsStore } from '@/state/assets/userAssets'; import { greaterThan } from '@/helpers/utilities'; -import { ChainId } from '@/chains/types'; -import { chainsLabel, defaultChains } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const PAGES = { HOME: 'home', @@ -182,12 +182,12 @@ export const ControlPanel = () => { const { testnetsEnabled } = store.getState().settings; const allNetworkItems = useMemo(() => { - return Object.values(defaultChains) + return Object.values(useBackendNetworksStore.getState().getDefaultChains()) .filter(({ testnet }) => testnetsEnabled || !testnet) .map(chain => { return { IconComponent: , - label: chainsLabel[chain.id], + label: useBackendNetworksStore.getState().getChainsLabel()[chain.id], secondaryLabel: i18n.t( isConnected && chain.id === currentChainId ? i18n.l.dapp_browser.control_panel.connected diff --git a/src/components/DappBrowser/handleProviderRequest.ts b/src/components/DappBrowser/handleProviderRequest.ts index c8466c853a4..c56b9e5cd17 100644 --- a/src/components/DappBrowser/handleProviderRequest.ts +++ b/src/components/DappBrowser/handleProviderRequest.ts @@ -11,8 +11,8 @@ import { Tab } from '@rainbow-me/provider/dist/references/messengers'; import { getDappMetadata } from '@/resources/metadata/dapp'; import { useAppSessionsStore } from '@/state/appSessions'; import { BigNumber } from '@ethersproject/bignumber'; -import { ChainId } from '@/chains/types'; -import { chainsNativeAsset, defaultChains, SUPPORTED_CHAIN_IDS } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export type ProviderRequestPayload = RequestArguments & { id: number; @@ -162,7 +162,10 @@ const messengerProviderRequestFn = async (messenger: Messenger, request: Provide const isSupportedChainId = (chainId: number | string) => { const numericChainId = BigNumber.from(chainId).toNumber(); - return !!SUPPORTED_CHAIN_IDS.find(chainId => chainId === numericChainId); + return !!useBackendNetworksStore + .getState() + .getSupportedChainIds() + .find(chainId => chainId === numericChainId); }; const getActiveSession = ({ host }: { host: string }): ActiveSession => { const hostSessions = useAppSessionsStore.getState().getActiveSession({ host }); @@ -265,7 +268,7 @@ export const handleProviderRequestApp = ({ messenger, data, meta }: { messenger: callbackOptions?: CallbackOptions; }): { chainAlreadyAdded: boolean } => { const { chainId } = proposedChain; - if (defaultChains[Number(chainId)]) { + if (useBackendNetworksStore.getState().getDefaultChains()[Number(chainId)]) { // TODO - Open add / switch ethereum chain return { chainAlreadyAdded: true }; } else { @@ -320,7 +323,7 @@ export const handleProviderRequestApp = ({ messenger, data, meta }: { messenger: callbackOptions?: CallbackOptions; }) => { const { chainId } = proposedChain; - const supportedChainId = SUPPORTED_CHAIN_IDS.includes(Number(chainId)); + const supportedChainId = useBackendNetworksStore.getState().getSupportedChainIds().includes(Number(chainId)); if (supportedChainId) { const host = getDappHost(callbackOptions?.sender.url) || ''; const activeSession = getActiveSession({ host }); @@ -343,7 +346,7 @@ export const handleProviderRequestApp = ({ messenger, data, meta }: { messenger: onSwitchEthereumChainSupported, getProvider, getActiveSession, - getChainNativeCurrency: chainId => chainsNativeAsset[chainId], + getChainNativeCurrency: chainId => useBackendNetworksStore.getState().getChainsNativeAsset()[chainId], }); // @ts-ignore diff --git a/src/components/ExchangeTokenRow.tsx b/src/components/ExchangeTokenRow.tsx index 2b70fe2d35a..0e509debbe4 100644 --- a/src/components/ExchangeTokenRow.tsx +++ b/src/components/ExchangeTokenRow.tsx @@ -9,7 +9,7 @@ import { IS_IOS } from '@/env'; import { FavStar, Info } from '@/components/asset-list/RecyclerAssetList2/FastComponents/FastCurrencySelectionRow'; import { View } from 'react-native'; import RainbowCoinIcon from '@/components/coin-icon/RainbowCoinIcon'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { ParsedAddressAsset } from '@/entities'; interface ExchangeTokenRowProps { diff --git a/src/components/L2Disclaimer.js b/src/components/L2Disclaimer.js index 3e44506a096..38305bcb90a 100644 --- a/src/components/L2Disclaimer.js +++ b/src/components/L2Disclaimer.js @@ -10,7 +10,7 @@ import { darkModeThemeColors } from '@/styles/colors'; import * as lang from '@/languages'; import { isL2Chain } from '@/handlers/web3'; import { EthCoinIcon } from './coin-icon/EthCoinIcon'; -import { chainsName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const L2Disclaimer = ({ chainId, @@ -57,7 +57,7 @@ const L2Disclaimer = ({ ? customText : lang.t(lang.l.expanded_state.asset.l2_disclaimer, { symbol, - network: chainsName[chainId], + network: useBackendNetworksStore.getState().getChainsName()[chainId], })} diff --git a/src/components/Transactions/TransactionDetailsCard.tsx b/src/components/Transactions/TransactionDetailsCard.tsx index 96d0af6092b..8e90144e879 100644 --- a/src/components/Transactions/TransactionDetailsCard.tsx +++ b/src/components/Transactions/TransactionDetailsCard.tsx @@ -7,7 +7,7 @@ import { TextColor } from '@/design-system/color/palettes'; import { abbreviations, ethereumUtils } from '@/utils'; import { TransactionSimulationMeta } from '@/graphql/__generated__/metadataPOST'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { TransactionDetailsRow } from '@/components/Transactions/TransactionDetailsRow'; import { FadedScrollCard } from '@/components/FadedScrollCard'; @@ -20,7 +20,7 @@ import { CARD_BORDER_WIDTH, EXPANDED_CARD_TOP_INSET, } from '@/components/Transactions/constants'; -import { chainsName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; interface TransactionDetailsCardProps { chainId: ChainId; @@ -93,7 +93,13 @@ export const TransactionDetailsCard = ({ - {} + { + + } {!!(meta?.to?.address || toAddress || showTransferToRow) && ( {i18n.t(i18n.l.walletconnect.simulation.simulation_card.messages.need_more_native, { symbol: walletBalance?.symbol, - network: chainsName[chainId], + network: useBackendNetworksStore.getState().getChainsName()[chainId], })} ) : ( diff --git a/src/components/asset-list/RecyclerAssetList2/FastComponents/FastBalanceCoinRow.tsx b/src/components/asset-list/RecyclerAssetList2/FastComponents/FastBalanceCoinRow.tsx index 4aea3213bd9..62a58656b2e 100644 --- a/src/components/asset-list/RecyclerAssetList2/FastComponents/FastBalanceCoinRow.tsx +++ b/src/components/asset-list/RecyclerAssetList2/FastComponents/FastBalanceCoinRow.tsx @@ -12,7 +12,7 @@ import Routes from '@/navigation/routesNames'; import { borders, colors, padding, shadow } from '@/styles'; import RainbowCoinIcon from '@/components/coin-icon/RainbowCoinIcon'; import { NativeCurrencyKey } from '@/entities'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; interface CoinCheckButtonProps { isHidden: boolean; diff --git a/src/components/asset-list/RecyclerAssetList2/FastComponents/FastCoinBadge.tsx b/src/components/asset-list/RecyclerAssetList2/FastComponents/FastCoinBadge.tsx index 5eba92ba6fa..dd948ecd527 100644 --- a/src/components/asset-list/RecyclerAssetList2/FastComponents/FastCoinBadge.tsx +++ b/src/components/asset-list/RecyclerAssetList2/FastComponents/FastCoinBadge.tsx @@ -20,7 +20,7 @@ import DegenBadge from '@/assets/badges/degenBadge.png'; import DegenBadgeDark from '@/assets/badges/degenBadgeDark.png'; import ApechainBadge from '@/assets/badges/apechainBadge.png'; import ApechainBadgeDark from '@/assets/badges/apechainBadgeDark.png'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; interface FastChainBadgeProps { chainId: ChainId; diff --git a/src/components/asset-list/RecyclerAssetList2/FastComponents/FastCurrencySelectionRow.tsx b/src/components/asset-list/RecyclerAssetList2/FastComponents/FastCurrencySelectionRow.tsx index d9c41c51347..d122b9a622e 100644 --- a/src/components/asset-list/RecyclerAssetList2/FastComponents/FastCurrencySelectionRow.tsx +++ b/src/components/asset-list/RecyclerAssetList2/FastComponents/FastCurrencySelectionRow.tsx @@ -13,7 +13,7 @@ import { colors, fonts, fontWithWidth, getFontSize } from '@/styles'; import { deviceUtils } from '@/utils'; import RainbowCoinIcon from '@/components/coin-icon/RainbowCoinIcon'; import { useExternalToken } from '@/resources/assets/externalAssetsQuery'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const SafeRadialGradient = (IS_TESTING === 'true' ? View : RadialGradient) as typeof RadialGradient; diff --git a/src/components/cards/EthCard.tsx b/src/components/cards/EthCard.tsx index 17719704d4e..b4504d62421 100644 --- a/src/components/cards/EthCard.tsx +++ b/src/components/cards/EthCard.tsx @@ -22,7 +22,7 @@ import * as i18n from '@/languages'; import { ButtonPressAnimationTouchEvent } from '@/components/animations/ButtonPressAnimation/types'; import { useExternalToken } from '@/resources/assets/externalAssetsQuery'; import assetTypes from '@/entities/assetTypes'; -import { Network, ChainId } from '@/chains/types'; +import { Network, ChainId } from '@/state/backendNetworks/types'; import { getUniqueId } from '@/utils/ethereumUtils'; import { EthCoinIcon } from '../coin-icon/EthCoinIcon'; diff --git a/src/components/cards/NFTOffersCard/Offer.tsx b/src/components/cards/NFTOffersCard/Offer.tsx index c9c0afd6f64..85452eab6c6 100644 --- a/src/components/cards/NFTOffersCard/Offer.tsx +++ b/src/components/cards/NFTOffersCard/Offer.tsx @@ -21,9 +21,9 @@ import Svg, { Path } from 'react-native-svg'; import RainbowCoinIcon from '@/components/coin-icon/RainbowCoinIcon'; import { useExternalToken } from '@/resources/assets/externalAssetsQuery'; import { useAccountSettings } from '@/hooks'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; import { AddressOrEth } from '@/__swaps__/types/assets'; -import { chainsIdByName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const TWO_HOURS_MS = 2 * 60 * 60 * 1000; export const CELL_HORIZONTAL_PADDING = 7; @@ -68,7 +68,7 @@ export const Offer = ({ offer }: { offer: NftOffer }) => { const { colorMode } = useColorMode(); const theme = useTheme(); const { nativeCurrency } = useAccountSettings(); - const offerChainId = chainsIdByName[offer.network as Network]; + const offerChainId = useBackendNetworksStore.getState().getChainsIdByName()[offer.network as Network]; const { data: externalAsset } = useExternalToken({ address: offer.paymentToken.address as AddressOrEth, chainId: offerChainId, diff --git a/src/components/cards/OpRewardsCard.tsx b/src/components/cards/OpRewardsCard.tsx index 9c6c1ca601b..3c1251010b3 100644 --- a/src/components/cards/OpRewardsCard.tsx +++ b/src/components/cards/OpRewardsCard.tsx @@ -8,7 +8,7 @@ import * as i18n from '@/languages'; import { useNavigation } from '@/navigation'; import Routes from '@/navigation/routesNames'; import { colors } from '@/styles'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const GRADIENT: Gradient = { colors: ['#520907', '#B22824'], diff --git a/src/components/change-wallet/WalletList.tsx b/src/components/change-wallet/WalletList.tsx index 5d08e917f60..8f35108db8d 100644 --- a/src/components/change-wallet/WalletList.tsx +++ b/src/components/change-wallet/WalletList.tsx @@ -18,7 +18,7 @@ import { position } from '@/styles'; import { EditWalletContextMenuActions } from '@/screens/ChangeWalletSheet'; import { HARDWARE_WALLETS, useExperimentalFlag } from '@/config'; import { Inset, Stack } from '@/design-system'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; const listTopPadding = 7.5; const rowHeight = 59; diff --git a/src/components/coin-icon/ChainBadge.js b/src/components/coin-icon/ChainBadge.js index 7aa789def16..0eafa651841 100644 --- a/src/components/coin-icon/ChainBadge.js +++ b/src/components/coin-icon/ChainBadge.js @@ -44,7 +44,7 @@ import { Centered } from '../layout'; import styled from '@/styled-thing'; import { position as positions } from '@/styles'; import { ChainBadgeSizeConfigs } from '@/components/coin-icon/ChainBadgeSizeConfigs'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const ChainIcon = styled(FastImage)({ height: ({ containerSize }) => containerSize, diff --git a/src/components/coin-icon/ChainIcon.js b/src/components/coin-icon/ChainIcon.js index 626ef5f53d7..2cf0988854a 100644 --- a/src/components/coin-icon/ChainIcon.js +++ b/src/components/coin-icon/ChainIcon.js @@ -10,7 +10,7 @@ import BscBadge from '../../assets/badges/bscBadge.png'; import BscBadgeDark from '../../assets/badges/bscBadgeDark.png'; import { Centered } from '../layout'; import styled from '@/styled-thing'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; const sizeConfigs = { large: { diff --git a/src/components/coin-icon/ChainImage.tsx b/src/components/coin-icon/ChainImage.tsx index 4db59d9c61f..0be5f993fa5 100644 --- a/src/components/coin-icon/ChainImage.tsx +++ b/src/components/coin-icon/ChainImage.tsx @@ -1,5 +1,5 @@ import React, { useMemo } from 'react'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import ArbitrumBadge from '@/assets/badges/arbitrum.png'; import BaseBadge from '@/assets/badges/base.png'; diff --git a/src/components/coin-icon/EthCoinIcon.tsx b/src/components/coin-icon/EthCoinIcon.tsx index a1b23be263f..3d9aa81a1c4 100644 --- a/src/components/coin-icon/EthCoinIcon.tsx +++ b/src/components/coin-icon/EthCoinIcon.tsx @@ -3,7 +3,7 @@ import { useTheme } from '@/theme'; import { useNativeAsset } from '@/utils/ethereumUtils'; import RainbowCoinIcon from './RainbowCoinIcon'; import { ETH_SYMBOL } from '@/references'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; type EthCoinIconProps = { size?: number; diff --git a/src/components/coin-icon/RainbowCoinIcon.tsx b/src/components/coin-icon/RainbowCoinIcon.tsx index f47cfb57a07..118c9445f42 100644 --- a/src/components/coin-icon/RainbowCoinIcon.tsx +++ b/src/components/coin-icon/RainbowCoinIcon.tsx @@ -7,7 +7,7 @@ import { FallbackIcon as CoinIconTextFallback } from '@/utils'; import { FastFallbackCoinIconImage } from '../asset-list/RecyclerAssetList2/FastComponents/FastFallbackCoinIconImage'; import { FastChainBadge } from '../asset-list/RecyclerAssetList2/FastComponents/FastCoinBadge'; import { TokenColors } from '@/graphql/__generated__/metadata'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const fallbackTextStyles = { fontFamily: fonts.family.SFProRounded, diff --git a/src/components/coin-icon/TwoCoinsIcon.tsx b/src/components/coin-icon/TwoCoinsIcon.tsx index e84d15062cc..d70e91b6d75 100644 --- a/src/components/coin-icon/TwoCoinsIcon.tsx +++ b/src/components/coin-icon/TwoCoinsIcon.tsx @@ -4,7 +4,7 @@ import { ParsedAddressAsset } from '@/entities'; import { useTheme } from '@/theme'; import ChainBadge from './ChainBadge'; import RainbowCoinIcon from './RainbowCoinIcon'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; export function TwoCoinsIcon({ size = 45, diff --git a/src/components/coin-row/FastTransactionCoinRow.tsx b/src/components/coin-row/FastTransactionCoinRow.tsx index 588255a4409..a7764a02d04 100644 --- a/src/components/coin-row/FastTransactionCoinRow.tsx +++ b/src/components/coin-row/FastTransactionCoinRow.tsx @@ -10,7 +10,7 @@ import Routes from '@rainbow-me/routes'; import { ImgixImage } from '../images'; import { CardSize } from '../unique-token/CardSize'; import { ChainBadge } from '../coin-icon'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { address } from '@/utils/abbreviations'; import { convertAmountAndPriceToNativeDisplay, diff --git a/src/components/context-menu-buttons/ChainContextMenu.tsx b/src/components/context-menu-buttons/ChainContextMenu.tsx index 3492fbf5eb7..d323684cc12 100644 --- a/src/components/context-menu-buttons/ChainContextMenu.tsx +++ b/src/components/context-menu-buttons/ChainContextMenu.tsx @@ -5,8 +5,8 @@ import { Bleed, Box, Inline, Text, TextProps } from '@/design-system'; import * as i18n from '@/languages'; import { useUserAssetsStore } from '@/state/assets/userAssets'; import { showActionSheetWithOptions } from '@/utils'; -import { ChainId } from '@/chains/types'; -import { chainsLabel, chainsName } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; interface DefaultButtonOptions { iconColor?: TextProps['color']; @@ -56,12 +56,13 @@ export const ChainContextMenu = ({ const menuConfig = useMemo(() => { const chainItems = balanceSortedChains.map(chainId => { + const chainName = useBackendNetworksStore.getState().getChainsName()[chainId]; return { actionKey: `${chainId}`, - actionTitle: chainsLabel[chainId], + actionTitle: useBackendNetworksStore.getState().getChainsLabel()[chainId], icon: { iconType: 'ASSET', - iconValue: chainId === ChainId.mainnet ? 'ethereumBadge' : `${chainsName[chainId]}BadgeNoShadow`, + iconValue: chainId === ChainId.mainnet ? 'ethereumBadge' : `${chainName}BadgeNoShadow`, }, }; }); @@ -111,7 +112,7 @@ export const ChainContextMenu = ({ const displayName = useMemo(() => { if (!selectedChainId) return allNetworksText; - const name = chainsLabel[selectedChainId]; + const name = useBackendNetworksStore.getState().getChainsLabel()[selectedChainId]; return name.endsWith(' Chain') ? name.slice(0, -6) : name; }, [allNetworksText, selectedChainId]); diff --git a/src/components/ens-profile/ActionButtons/MoreButton.tsx b/src/components/ens-profile/ActionButtons/MoreButton.tsx index 2d161ceddc5..af0a3c83e3a 100644 --- a/src/components/ens-profile/ActionButtons/MoreButton.tsx +++ b/src/components/ens-profile/ActionButtons/MoreButton.tsx @@ -11,7 +11,7 @@ import { RAINBOW_PROFILES_BASE_URL } from '@/references'; import Routes from '@/navigation/routesNames'; import { ethereumUtils } from '@/utils'; import { formatAddressForDisplay } from '@/utils/abbreviations'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const ACTIONS = { ADD_CONTACT: 'add-contact', diff --git a/src/components/exchangeAssetRowContextMenuProps.ts b/src/components/exchangeAssetRowContextMenuProps.ts index e16a28ec471..cc0cb066edd 100644 --- a/src/components/exchangeAssetRowContextMenuProps.ts +++ b/src/components/exchangeAssetRowContextMenuProps.ts @@ -3,8 +3,8 @@ import { startCase } from 'lodash'; import { NativeSyntheticEvent } from 'react-native'; import { setClipboard } from '@/hooks/useClipboard'; import { abbreviations, ethereumUtils, haptics, showActionSheetWithOptions } from '@/utils'; -import { ChainId } from '@/chains/types'; -import { chainsIdByName } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const buildBlockExplorerAction = (chainId: ChainId) => { const blockExplorerText = lang.t('exchange.coin_row.view_on', { @@ -44,7 +44,7 @@ export default function contextMenuProps(item: any, onCopySwapDetailsText: (addr }; const onPressAndroid = () => { - const blockExplorerText = `View on ${startCase(ethereumUtils.getBlockExplorer({ chainId: chainsIdByName[item?.network] }))}`; + const blockExplorerText = `View on ${startCase(ethereumUtils.getBlockExplorer({ chainId: useBackendNetworksStore.getState().getChainsIdByName()[item?.network] }))}`; const androidContractActions = [lang.t('wallet.action.copy_contract_address'), blockExplorerText, lang.t('button.cancel')]; showActionSheetWithOptions( @@ -59,13 +59,16 @@ export default function contextMenuProps(item: any, onCopySwapDetailsText: (addr handleCopyContractAddress(item?.address); } if (idx === 1) { - ethereumUtils.openTokenEtherscanURL({ address: item?.address, chainId: chainsIdByName[item?.network] }); + ethereumUtils.openTokenEtherscanURL({ + address: item?.address, + chainId: useBackendNetworksStore.getState().getChainsIdByName()[item?.network], + }); } } ); }; - const blockExplorerAction = buildBlockExplorerAction(chainsIdByName[item?.network]); + const blockExplorerAction = buildBlockExplorerAction(useBackendNetworksStore.getState().getChainsIdByName()[item?.network]); const menuConfig = { menuItems: [ blockExplorerAction, @@ -81,7 +84,10 @@ export default function contextMenuProps(item: any, onCopySwapDetailsText: (addr if (actionKey === CoinRowActionsEnum.copyAddress) { handleCopyContractAddress(item?.address); } else if (actionKey === CoinRowActionsEnum.blockExplorer) { - ethereumUtils.openTokenEtherscanURL({ address: item?.address, chainId: chainsIdByName[item?.network] }); + ethereumUtils.openTokenEtherscanURL({ + address: item?.address, + chainId: useBackendNetworksStore.getState().getChainsIdByName()[item?.network], + }); } }; return { diff --git a/src/components/expanded-state/AvailableNetworks.js b/src/components/expanded-state/AvailableNetworks.js index 29ac98354ca..5b469892f3d 100644 --- a/src/components/expanded-state/AvailableNetworks.js +++ b/src/components/expanded-state/AvailableNetworks.js @@ -13,8 +13,8 @@ import { ChainBadge } from '../coin-icon'; import Divider from '@/components/Divider'; import { Text } from '../text'; import { EthCoinIcon } from '../coin-icon/EthCoinIcon'; -import { ChainId } from '@/chains/types'; -import { defaultChains } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const AvailableNetworksv1 = ({ asset, networks, hideDivider, marginBottom = 24, marginHorizontal = 19, prominent }) => { const { colors } = useTheme(); @@ -87,7 +87,7 @@ const AvailableNetworksv1 = ({ asset, networks, hideDivider, marginBottom = 24, availableNetworks: availableChainIds?.length, }) : lang.t('expanded_state.asset.available_network', { - availableNetwork: defaultChains[availableChainIds[0]]?.name, + availableNetwork: useBackendNetworksStore.getState().getChainsName()[availableChainIds[0]], })} diff --git a/src/components/expanded-state/AvailableNetworksv2.tsx b/src/components/expanded-state/AvailableNetworksv2.tsx index 0f07a751d1a..b597edf481a 100644 --- a/src/components/expanded-state/AvailableNetworksv2.tsx +++ b/src/components/expanded-state/AvailableNetworksv2.tsx @@ -21,8 +21,8 @@ import { parseSearchAsset } from '@/__swaps__/utils/assets'; import { AddressOrEth, AssetType } from '@/__swaps__/types/assets'; import { swapsStore } from '@/state/swaps/swapsStore'; import { InteractionManager } from 'react-native'; -import { ChainId } from '@/chains/types'; -import { chainsLabel, chainsName, defaultChains, supportedSwapChainIds } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const NOOP = () => null; @@ -68,6 +68,7 @@ const AvailableNetworksv2 = ({ goBack(); const uniqueId = `${newAsset.address}_${asset.chainId}`; + const chainsName = useBackendNetworksStore.getState().getChainsName(); const userAsset = userAssetsStore.getState().userAssets.get(uniqueId); const parsedAsset = parseSearchAsset({ @@ -134,15 +135,17 @@ const AvailableNetworksv2 = ({ convertAssetAndNavigate(availableChainIds[0]); }, [availableChainIds, convertAssetAndNavigate]); - const networkMenuItems = supportedSwapChainIds - .filter(chainId => chainId !== ChainId.mainnet && availableChainIds.includes(chainId)) - .map(chainId => defaultChains[chainId]) + const networkMenuItems = useBackendNetworksStore + .getState() + .getSupportedChainIds() + .filter(chainId => chainId !== ChainId.mainnet) + .map(chainId => useBackendNetworksStore.getState().getDefaultChains()[chainId]) .map(chain => ({ actionKey: `${chain.id}`, - actionTitle: chainsLabel[chain.id], + actionTitle: useBackendNetworksStore.getState().getChainsLabel()[chain.id], icon: { iconType: 'ASSET', - iconValue: `${chainsName[chain.id]}Badge${chain.id === ChainId.mainnet ? '' : 'NoShadow'}`, + iconValue: `${useBackendNetworksStore.getState().getChainsName()[chain.id]}Badge${chain.id === ChainId.mainnet ? '' : 'NoShadow'}`, }, })); @@ -204,7 +207,7 @@ const AvailableNetworksv2 = ({ availableNetworks: availableChainIds?.length, }) : lang.t('expanded_state.asset.available_networkv2', { - availableNetwork: chainsName[availableChainIds[0]], + availableNetwork: useBackendNetworksStore.getState().getChainsName()[availableChainIds[0]], })} diff --git a/src/components/expanded-state/UniqueTokenExpandedState.tsx b/src/components/expanded-state/UniqueTokenExpandedState.tsx index 61d244ecb00..0bf5cdae75f 100644 --- a/src/components/expanded-state/UniqueTokenExpandedState.tsx +++ b/src/components/expanded-state/UniqueTokenExpandedState.tsx @@ -65,7 +65,7 @@ import { buildRainbowUrl } from '@/utils/buildRainbowUrl'; import isHttpUrl from '@/helpers/isHttpUrl'; import { useNFTOffers } from '@/resources/reservoir/nftOffersQuery'; import { convertAmountToNativeDisplay } from '@/helpers/utilities'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const BackgroundBlur = styled(BlurView).attrs({ blurAmount: 100, diff --git a/src/components/expanded-state/asset/ChartExpandedState.js b/src/components/expanded-state/asset/ChartExpandedState.js index 1626e0363cf..2913d2a3967 100644 --- a/src/components/expanded-state/asset/ChartExpandedState.js +++ b/src/components/expanded-state/asset/ChartExpandedState.js @@ -36,8 +36,8 @@ import { Box } from '@/design-system'; import { useExternalToken } from '@/resources/assets/externalAssetsQuery'; import { bigNumberFormat } from '@/helpers/bigNumberFormat'; import { greaterThanOrEqualTo } from '@/helpers/utilities'; -import { chainsName, supportedSwapChainIds } from '@/chains'; -import { ChainId } from '@/chains/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; +import { ChainId } from '@/state/backendNetworks/types'; const defaultCarouselHeight = 60; const baseHeight = 386 + (android && 20 - getSoftMenuBarHeight()) - defaultCarouselHeight; @@ -166,7 +166,7 @@ export default function ChartExpandedState({ asset }) { chainId: asset.chainId, network: asset.network, address: asset.address, - mainnetAddress: asset?.networks?.[chainsName[ChainId.mainnet]]?.address, + mainnetAddress: asset?.networks?.[useBackendNetworksStore.getState().getChainsName()[ChainId.mainnet]]?.address, } : asset; }, [asset, genericAsset, hasBalance]); @@ -243,7 +243,7 @@ export default function ChartExpandedState({ asset }) { const assetChainId = assetWithPrice.chainId; const { swagg_enabled, f2c_enabled } = useRemoteConfig(); - const swapEnabled = swagg_enabled && supportedSwapChainIds.includes(assetChainId); + const swapEnabled = swagg_enabled && useBackendNetworksStore.getState().getSwapSupportedChainIds().includes(assetChainId); const addCashEnabled = f2c_enabled; const format = useCallback( diff --git a/src/components/expanded-state/unique-token/NFTBriefTokenInfoRow.tsx b/src/components/expanded-state/unique-token/NFTBriefTokenInfoRow.tsx index c437402f328..269fc3a8191 100644 --- a/src/components/expanded-state/unique-token/NFTBriefTokenInfoRow.tsx +++ b/src/components/expanded-state/unique-token/NFTBriefTokenInfoRow.tsx @@ -13,7 +13,7 @@ import { UniqueAsset } from '@/entities'; import { fetchReservoirNFTFloorPrice } from '@/resources/nfts/utils'; import { handleReviewPromptAction } from '@/utils/reviewAlert'; import { ReviewPromptAction } from '@/storage/schema'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const NONE = 'None'; diff --git a/src/components/expanded-state/unique-token/UniqueTokenExpandedStateHeader.tsx b/src/components/expanded-state/unique-token/UniqueTokenExpandedStateHeader.tsx index 990158f132b..7e5126d1b84 100644 --- a/src/components/expanded-state/unique-token/UniqueTokenExpandedStateHeader.tsx +++ b/src/components/expanded-state/unique-token/UniqueTokenExpandedStateHeader.tsx @@ -21,7 +21,7 @@ import isSVGImage from '@/utils/isSVG'; import { refreshNFTContractMetadata, reportNFT } from '@/resources/nfts/simplehash'; import { ContextCircleButton } from '@/components/context-menu'; import { IS_ANDROID, IS_IOS } from '@/env'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const AssetActionsEnum = { copyTokenID: 'copyTokenID', diff --git a/src/components/gas/GasSpeedButton.tsx b/src/components/gas/GasSpeedButton.tsx index 80176d8ab14..f9f468803e8 100644 --- a/src/components/gas/GasSpeedButton.tsx +++ b/src/components/gas/GasSpeedButton.tsx @@ -25,8 +25,8 @@ import { gasUtils } from '@/utils'; import { IS_ANDROID } from '@/env'; import { ContextMenu } from '../context-menu'; import { EthCoinIcon } from '../coin-icon/EthCoinIcon'; -import { ChainId } from '@/chains/types'; -import { chainsGasSpeeds, chainsNativeAsset } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { ThemeContextProps, useTheme } from '@/theme'; import { ParsedAddressAsset } from '@/entities'; import { GasSpeed } from '@/__swaps__/types/gas'; @@ -305,7 +305,7 @@ const GasSpeedButton = ({ const openGasHelper = useCallback(async () => { Keyboard.dismiss(); - const nativeAsset = chainsNativeAsset[chainId]; + const nativeAsset = useBackendNetworksStore.getState().getChainsNativeAsset()[chainId]; navigate(Routes.EXPLAIN_SHEET, { chainId, type: 'gas', @@ -339,7 +339,7 @@ const GasSpeedButton = ({ const speedOptions = useMemo(() => { if (speeds) return speeds; - return chainsGasSpeeds[chainId]; + return useBackendNetworksStore.getState().getChainsGasSpeeds()[chainId]; }, [chainId, speeds]); const menuConfig = useMemo(() => { diff --git a/src/components/positions/PositionsCard.tsx b/src/components/positions/PositionsCard.tsx index 6a49be54cf8..94a80ed60f4 100644 --- a/src/components/positions/PositionsCard.tsx +++ b/src/components/positions/PositionsCard.tsx @@ -13,12 +13,12 @@ import { event } from '@/analytics/event'; import { IS_ANDROID } from '@/env'; import { capitalize, uniqBy } from 'lodash'; import { RainbowDeposit, RainbowPosition } from '@/resources/defi/types'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; import RainbowCoinIcon from '../coin-icon/RainbowCoinIcon'; import { useAccountSettings } from '@/hooks'; import { useExternalToken } from '@/resources/assets/externalAssetsQuery'; import { AddressOrEth } from '@/__swaps__/types/assets'; -import { chainsIdByName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; type PositionCardProps = { position: RainbowPosition; @@ -33,7 +33,7 @@ type CoinStackToken = { function CoinIconForStack({ token }: { token: CoinStackToken }) { const theme = useTheme(); const { nativeCurrency } = useAccountSettings(); - const chainId = chainsIdByName[token.network]; + const chainId = useBackendNetworksStore.getState().getChainsIdByName()[token.network]; const { data: externalAsset } = useExternalToken({ address: token.address as AddressOrEth, chainId, currency: nativeCurrency }); return ( diff --git a/src/components/remote-promo-sheet/check-fns/hasSwapTxn.ts b/src/components/remote-promo-sheet/check-fns/hasSwapTxn.ts index 738e33cdf58..17c4d22b04d 100644 --- a/src/components/remote-promo-sheet/check-fns/hasSwapTxn.ts +++ b/src/components/remote-promo-sheet/check-fns/hasSwapTxn.ts @@ -1,5 +1,5 @@ import type { EthereumAddress, RainbowTransaction } from '@/entities'; -import { SUPPORTED_MAINNET_CHAIN_IDS } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { queryClient } from '@/react-query/queryClient'; import store from '@/redux/store'; import { consolidatedTransactionsQueryKey } from '@/resources/transactions/consolidatedTransactions'; @@ -16,7 +16,7 @@ export const hasSwapTxn = async (): Promise => { const paginatedTransactionsKey = consolidatedTransactionsQueryKey({ address: accountAddress, currency: nativeCurrency, - chainIds: SUPPORTED_MAINNET_CHAIN_IDS, + chainIds: useBackendNetworksStore.getState().getSupportedMainnetChainIds(), }); const queryData = queryClient.getQueryData(paginatedTransactionsKey); const pages = queryData?.pages || []; diff --git a/src/components/sheet/sheet-action-buttons/SwapActionButton.tsx b/src/components/sheet/sheet-action-buttons/SwapActionButton.tsx index 8e38433a4ab..9a7ea341748 100644 --- a/src/components/sheet/sheet-action-buttons/SwapActionButton.tsx +++ b/src/components/sheet/sheet-action-buttons/SwapActionButton.tsx @@ -11,8 +11,8 @@ import { SwapAssetType } from '@/__swaps__/types/swap'; import { swapsStore } from '@/state/swaps/swapsStore'; import { InteractionManager } from 'react-native'; import { AddressOrEth, AssetType, ParsedSearchAsset } from '@/__swaps__/types/assets'; -import { chainsIdByName, chainsName } from '@/chains'; import useNavigationForNonReadOnlyWallets from '@/hooks/useNavigationForNonReadOnlyWallets'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; type SwapActionButtonProps = { asset: RainbowToken; @@ -29,6 +29,8 @@ function SwapActionButton({ asset, color: givenColor, inputType, label, weight = const color = givenColor || colors.swapPurple; const goToSwap = useCallback(async () => { + const chainsIdByName = useBackendNetworksStore.getState().getChainsIdByName(); + const chainsName = useBackendNetworksStore.getState().getChainsName(); const chainId = chainsIdByName[asset.network]; const uniqueId = `${asset.address}_${chainId}`; const userAsset = userAssetsStore.getState().userAssets.get(uniqueId); diff --git a/src/components/toasts/OfflineToast.js b/src/components/toasts/OfflineToast.js index b86c3904823..053791ce854 100644 --- a/src/components/toasts/OfflineToast.js +++ b/src/components/toasts/OfflineToast.js @@ -2,7 +2,7 @@ import lang from 'i18n-js'; import React from 'react'; import Toast from './Toast'; import { useAccountSettings, useInternetStatus } from '@/hooks'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { useConnectedToHardhatStore } from '@/state/connectedToHardhat'; const OfflineToast = () => { diff --git a/src/components/toasts/TestnetToast.js b/src/components/toasts/TestnetToast.js index b31eb9befea..5618d0706d4 100644 --- a/src/components/toasts/TestnetToast.js +++ b/src/components/toasts/TestnetToast.js @@ -3,15 +3,15 @@ import { Icon } from '../icons'; import { Nbsp, Text } from '../text'; import Toast from './Toast'; import { useInternetStatus } from '@/hooks'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { useConnectedToHardhatStore } from '@/state/connectedToHardhat'; -import { chainsName, chainsNativeAsset } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const TestnetToast = ({ chainId }) => { const { connectedToHardhat } = useConnectedToHardhatStore(); const isConnected = useInternetStatus(); - const nativeAsset = chainsNativeAsset[chainId]; - const name = chainsName[chainId]; + const nativeAsset = useBackendNetworksStore.getState().getChainsNativeAsset()[chainId]; + const name = useBackendNetworksStore.getState().getChainsName()[chainId]; const color = isDarkMode ? nativeAsset.colors.primary : nativeAsset.colors.fallback || nativeAsset.colors.primary; const [visible, setVisible] = useState(chainId !== ChainId.mainnet); const [networkName, setNetworkName] = useState(name); diff --git a/src/components/walletconnect-list/WalletConnectV2ListItem.tsx b/src/components/walletconnect-list/WalletConnectV2ListItem.tsx index 56a9d22b4cf..ee1fdf35660 100644 --- a/src/components/walletconnect-list/WalletConnectV2ListItem.tsx +++ b/src/components/walletconnect-list/WalletConnectV2ListItem.tsx @@ -24,8 +24,8 @@ import { changeAccount, disconnectSession } from '@/walletConnect'; import { Box, Inline } from '@/design-system'; import ChainBadge from '@/components/coin-icon/ChainBadge'; import { EthCoinIcon } from '../coin-icon/EthCoinIcon'; -import { ChainId } from '@/chains/types'; -import { SUPPORTED_CHAIN_IDS } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const CONTAINER_PADDING = 15; const VENDOR_LOGO_ICON_SIZE = 50; @@ -78,7 +78,9 @@ export function WalletConnectV2ListItem({ session, reload }: { session: SessionT const chains = useMemo(() => namespaces?.eip155?.chains || [], [namespaces]); const chainIds = useMemo( () => - (chains?.map(chain => parseInt(chain.split(':')[1]))?.filter(chainId => SUPPORTED_CHAIN_IDS.includes(chainId)) ?? []) as ChainId[], + chains + ?.map(chain => parseInt(chain.split(':')[1])) + ?.filter(chainId => useBackendNetworksStore.getState().getSupportedChainIds().includes(chainId)) ?? [], [chains] ); diff --git a/src/entities/tokens.ts b/src/entities/tokens.ts index c8f2eddc099..bd67a05eaeb 100644 --- a/src/entities/tokens.ts +++ b/src/entities/tokens.ts @@ -1,6 +1,6 @@ import { EthereumAddress } from '.'; import { Chain } from '@wagmi/chains'; -import { Network, ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { TokenColors } from '@/graphql/__generated__/metadata'; export interface ZerionAssetPrice { diff --git a/src/entities/transactions/transaction.ts b/src/entities/transactions/transaction.ts index 00d2bb26e10..fe4d6cab39c 100644 --- a/src/entities/transactions/transaction.ts +++ b/src/entities/transactions/transaction.ts @@ -7,7 +7,7 @@ import { SwapType } from '@rainbow-me/swaps'; import { SwapMetadata } from '@/raps/references'; import { UniqueAsset } from '../uniqueAssets'; import { ParsedAsset, AddysAsset } from '@/resources/assets/types'; -import { ChainId, Network } from '@/chains/types'; +import { ChainId, Network } from '@/state/backendNetworks/types'; import { TransactionResponse } from '@ethersproject/providers'; import { BytesLike } from '@ethersproject/bytes'; diff --git a/src/entities/uniqueAssets.ts b/src/entities/uniqueAssets.ts index 78f9f5ad4b7..9876d2e971a 100644 --- a/src/entities/uniqueAssets.ts +++ b/src/entities/uniqueAssets.ts @@ -1,4 +1,4 @@ -import { Network, ChainId } from '@/chains/types'; +import { ChainId, Network } from '@/state/backendNetworks/types'; import { AssetContract, AssetType } from '.'; interface UniqueAssetLastSale { diff --git a/src/featuresToUnlock/tokenGatedUtils.ts b/src/featuresToUnlock/tokenGatedUtils.ts index 014f178732a..2b4b532ff8b 100644 --- a/src/featuresToUnlock/tokenGatedUtils.ts +++ b/src/featuresToUnlock/tokenGatedUtils.ts @@ -2,8 +2,8 @@ import { Contract } from '@ethersproject/contracts'; import { EthereumAddress } from '@/entities'; import { getProvider } from '@/handlers/web3'; import { tokenGateCheckerAbi } from '@/references'; -import { Network } from '@/chains/types'; -import { chainsIdByName } from '@/chains'; +import { Network } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export type TokenGateCheckerNetwork = | Network.arbitrum @@ -29,7 +29,7 @@ export const checkIfWalletsOwnNft = async ( network: TokenGateCheckerNetwork, walletsToCheck: EthereumAddress[] ) => { - const p = await getProvider({ chainId: chainsIdByName[network] }); + const p = getProvider({ chainId: useBackendNetworksStore.getState().getChainsIdByName()[network] }); const contractInstance = new Contract(TOKEN_GATE_CHECKER_ADDRESS[network], tokenGateCheckerAbi, p); diff --git a/src/handlers/assets.ts b/src/handlers/assets.ts index 1fb241b4e6f..64c7cf65f6f 100644 --- a/src/handlers/assets.ts +++ b/src/handlers/assets.ts @@ -2,13 +2,13 @@ import { Contract } from '@ethersproject/contracts'; import { erc20ABI } from '@/references'; import { convertAmountToBalanceDisplay, convertRawAmountToDecimalFormat } from '@/helpers/utilities'; -import { ChainId } from '@/chains/types'; -import { chainsNativeAsset } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { isLowerCaseMatch } from '@/utils'; import { AddressOrEth } from '@/__swaps__/types/assets'; export function isNativeAsset(address: AddressOrEth | string, chainId: ChainId) { - return isLowerCaseMatch(chainsNativeAsset[chainId].address, address); + return isLowerCaseMatch(useBackendNetworksStore.getState().getChainsNativeAsset()[chainId].address, address); } export async function getOnchainAssetBalance({ address, decimals, symbol }: any, userAddress: any, chainId: ChainId, provider: any) { diff --git a/src/handlers/ens.ts b/src/handlers/ens.ts index 0686f977e57..fcb14c14fb5 100644 --- a/src/handlers/ens.ts +++ b/src/handlers/ens.ts @@ -24,7 +24,7 @@ import { prefetchENSAddress } from '@/resources/ens/ensAddressQuery'; import { MimeType, handleNFTImages } from '@/utils/handleNFTImages'; import store from '@/redux/store'; import { logger, RainbowError } from '@/logger'; -import { ChainId, Network } from '@/chains/types'; +import { ChainId, Network } from '@/state/backendNetworks/types'; const DUMMY_RECORDS = { description: 'description', diff --git a/src/handlers/gasFees.ts b/src/handlers/gasFees.ts index 8a63ce38bf6..9b63ae789b1 100644 --- a/src/handlers/gasFees.ts +++ b/src/handlers/gasFees.ts @@ -1,6 +1,6 @@ -import { chainsName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { RainbowFetchClient } from '../rainbow-fetch'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const rainbowMeteorologyApi = new RainbowFetchClient({ baseURL: 'https://metadata.p.rainbow.me', @@ -11,4 +11,5 @@ const rainbowMeteorologyApi = new RainbowFetchClient({ timeout: 30000, // 30 secs }); -export const rainbowMeteorologyGetData = (chainId: ChainId) => rainbowMeteorologyApi.get(`/meteorology/v1/gas/${chainsName[chainId]}`, {}); +export const rainbowMeteorologyGetData = (chainId: ChainId) => + rainbowMeteorologyApi.get(`/meteorology/v1/gas/${useBackendNetworksStore.getState().getChainsName()[chainId]}`, {}); diff --git a/src/handlers/localstorage/globalSettings.ts b/src/handlers/localstorage/globalSettings.ts index 2338baccdf0..5a64f1c605d 100644 --- a/src/handlers/localstorage/globalSettings.ts +++ b/src/handlers/localstorage/globalSettings.ts @@ -1,4 +1,4 @@ -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { getGlobal, saveGlobal } from './common'; import { NativeCurrencyKeys } from '@/entities'; import { Language } from '@/languages'; diff --git a/src/handlers/localstorage/removeWallet.ts b/src/handlers/localstorage/removeWallet.ts index 95ccf7ccc43..4559e5e5e8b 100644 --- a/src/handlers/localstorage/removeWallet.ts +++ b/src/handlers/localstorage/removeWallet.ts @@ -4,7 +4,7 @@ import { accountLocalKeys } from './accountLocal'; import { getKey } from './common'; import { logger, RainbowError } from '@/logger'; import { removeNotificationSettingsForWallet } from '@/notifications/settings'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; export const removeWalletData = async (accountAddress: any) => { logger.debug('[localstorage/removeWallet]: removing wallet data', { accountAddress }); diff --git a/src/handlers/swap.ts b/src/handlers/swap.ts index 9a537286856..7d811afc0d4 100644 --- a/src/handlers/swap.ts +++ b/src/handlers/swap.ts @@ -12,7 +12,7 @@ import { add, convertRawAmountToDecimalFormat, divide, lessThan, multiply, subtr import { erc20ABI, ethUnits } from '@/references'; import { ethereumUtils } from '@/utils'; import { logger, RainbowError } from '@/logger'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; export enum Field { INPUT = 'INPUT', diff --git a/src/handlers/tokenSearch.ts b/src/handlers/tokenSearch.ts index 6626776c55a..0d60eb5d8fb 100644 --- a/src/handlers/tokenSearch.ts +++ b/src/handlers/tokenSearch.ts @@ -5,7 +5,7 @@ import { TokenSearchThreshold, TokenSearchTokenListId, TokenSearchUniswapAssetKe import { logger, RainbowError } from '@/logger'; import { EthereumAddress } from '@rainbow-me/swaps'; import { RainbowToken, TokenSearchToken } from '@/entities/tokens'; -import { chainsName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; type TokenSearchApiResponse = { data: TokenSearchToken[]; @@ -55,7 +55,7 @@ export const tokenSearch = async (searchParams: { return tokenSearch.data.data.map(token => { const networkKeys = Object.keys(token.networks); const chainId = Number(networkKeys[0]); - const network = chainsName[chainId]; + const network = useBackendNetworksStore.getState().getChainsName()[chainId]; return { ...token, chainId, diff --git a/src/handlers/web3.ts b/src/handlers/web3.ts index fd5ad561fd4..3cab093598a 100644 --- a/src/handlers/web3.ts +++ b/src/handlers/web3.ts @@ -24,9 +24,9 @@ import { import { ethereumUtils } from '@/utils'; import { logger, RainbowError } from '@/logger'; import { IS_IOS, RPC_PROXY_API_KEY, RPC_PROXY_BASE_URL } from '@/env'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { useConnectedToHardhatStore } from '@/state/connectedToHardhat'; -import { defaultChains } from '@/chains'; export enum TokenStandard { ERC1155 = 'ERC1155', @@ -91,7 +91,8 @@ export type NewTransactionNonNullable = { * @return Whether or not the network is a L2 network. */ export const isL2Chain = ({ chainId = ChainId.mainnet }: { chainId?: ChainId }): boolean => { - return defaultChains[chainId].id !== ChainId.mainnet && !defaultChains[chainId].testnet; + const defaultChains = useBackendNetworksStore.getState().getDefaultChains(); + return defaultChains[chainId]?.id !== ChainId.mainnet && !defaultChains[chainId]?.testnet; }; /** @@ -100,7 +101,7 @@ export const isL2Chain = ({ chainId = ChainId.mainnet }: { chainId?: ChainId }): * @return Whether or not the network is a testnet. */ export const isTestnetChain = ({ chainId = ChainId.mainnet }: { chainId?: ChainId }): boolean => { - return !!defaultChains[chainId].testnet; + return !!useBackendNetworksStore.getState().getDefaultChains()[chainId]?.testnet; }; // TODO: should figure out better way to include this in networks @@ -127,7 +128,7 @@ export const getProvider = ({ chainId = ChainId.mainnet }: { chainId?: number }) const cachedProvider = chainsProviders.get(chainId); - const providerUrl = defaultChains[chainId]?.rpcUrls?.default?.http?.[0]; + const providerUrl = useBackendNetworksStore.getState().getDefaultChains()[chainId]?.rpcUrls?.default?.http?.[0]; if (cachedProvider && cachedProvider?.connection.url === providerUrl) { return cachedProvider; diff --git a/src/helpers/SharedValuesContext.tsx b/src/helpers/SharedValuesContext.tsx index d7d2035c8db..08dee0b4544 100644 --- a/src/helpers/SharedValuesContext.tsx +++ b/src/helpers/SharedValuesContext.tsx @@ -22,3 +22,11 @@ export function SharedValuesProvider({ children }: PropsWithChildren) { ); return {children}; } + +export const useSharedValuesContext = () => { + const context = React.useContext(Context); + if (context === undefined) { + throw new Error('useSharedValuesContext must be used within a SharedValuesProvider'); + } + return context; +}; diff --git a/src/helpers/ens.ts b/src/helpers/ens.ts index d3611b2beb1..f4e09e55064 100644 --- a/src/helpers/ens.ts +++ b/src/helpers/ens.ts @@ -25,7 +25,7 @@ import { import { colors } from '@/styles'; import { labelhash } from '@/utils'; import { encodeContenthash, isValidContenthash } from '@/utils/contenthash'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; export const ENS_SECONDS_WAIT = 60; export const ENS_SECONDS_PADDING = 5; diff --git a/src/helpers/gas.ts b/src/helpers/gas.ts index e9d3f17939b..08c8756ed28 100644 --- a/src/helpers/gas.ts +++ b/src/helpers/gas.ts @@ -1,6 +1,6 @@ import { memoFn } from '../utils/memoFn'; import { gasUtils } from '@/utils'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { isL2Chain } from '@/handlers/web3'; const { GasTrends } = gasUtils; diff --git a/src/helpers/networkInfo.ts b/src/helpers/networkInfo.ts index cd8f6bcc139..4668c35288b 100644 --- a/src/helpers/networkInfo.ts +++ b/src/helpers/networkInfo.ts @@ -1,4 +1,4 @@ -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; // TODO: networkInfo is DEPRECATED after the new network support changes const networkInfo = { diff --git a/src/helpers/signingWallet.ts b/src/helpers/signingWallet.ts index 769bb1cadf0..10532dd3e95 100644 --- a/src/helpers/signingWallet.ts +++ b/src/helpers/signingWallet.ts @@ -3,7 +3,7 @@ import { generateMnemonic } from 'bip39'; import { default as LibWallet } from 'ethereumjs-wallet'; import { RAINBOW_MASTER_KEY } from 'react-native-dotenv'; import { loadString, publicAccessControlOptions, saveString } from '../model/keychain'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { loadWallet } from '../model/wallet'; import { signingWalletAddress, signingWallet as signingWalletKeychain } from '../utils/keychainConstants'; import { EthereumAddress } from '@/entities'; diff --git a/src/helpers/validators.ts b/src/helpers/validators.ts index c2c5fce0942..e2ceccd5c0a 100644 --- a/src/helpers/validators.ts +++ b/src/helpers/validators.ts @@ -2,7 +2,7 @@ import { isValidAddress } from 'ethereumjs-util'; import { memoFn } from '../utils/memoFn'; import { getProvider, isHexStringIgnorePrefix, isValidMnemonic, resolveUnstoppableDomain } from '@/handlers/web3'; import { sanitizeSeedPhrase } from '@/utils/formatters'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; // Currently supported Top Level Domains from Unstoppable Domains const supportedUnstoppableDomains = ['888', 'bitcoin', 'blockchain', 'coin', 'crypto', 'dao', 'nft', 'wallet', 'x', 'zil']; diff --git a/src/helpers/walletConnectNetworks.ts b/src/helpers/walletConnectNetworks.ts index 69fb67ee2c1..662191d0eb4 100644 --- a/src/helpers/walletConnectNetworks.ts +++ b/src/helpers/walletConnectNetworks.ts @@ -1,14 +1,14 @@ import store from '@/redux/store'; import { showActionSheetWithOptions } from '@/utils'; import * as i18n from '@/languages'; -import { ChainId } from '@/chains/types'; -import { chainsLabel, defaultChains } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { isL2Chain } from '@/handlers/web3'; import { MenuActionConfig } from 'react-native-ios-context-menu'; const androidNetworkActions = () => { const { testnetsEnabled } = store.getState().settings; - return Object.values(defaultChains) + return Object.values(useBackendNetworksStore.getState().getDefaultChains()) .filter(chain => testnetsEnabled || !chain.testnet) .map(chain => chain.id); }; @@ -18,11 +18,11 @@ export const NETWORK_MENU_ACTION_KEY_FILTER = 'switch-to-network-'; export const networksMenuItems: () => MenuActionConfig[] = () => { const { testnetsEnabled } = store.getState().settings; - return Object.values(defaultChains) + return Object.values(useBackendNetworksStore.getState().getDefaultChains()) .filter(chain => testnetsEnabled || !chain.testnet) .map(chain => ({ actionKey: `${NETWORK_MENU_ACTION_KEY_FILTER}${chain.id}`, - actionTitle: chainsLabel[chain.id], + actionTitle: useBackendNetworksStore.getState().getChainsLabel()[chain.id], icon: { iconType: 'ASSET', iconValue: `${isL2Chain({ chainId: chain.id }) ? `${chain.name}BadgeNoShadow` : 'ethereumBadge'}`, @@ -78,6 +78,7 @@ export const androidShowNetworksActionSheet = (callback: any) => { }, (idx: number) => { if (idx !== undefined) { + const defaultChains = useBackendNetworksStore.getState().getDefaultChains(); const networkActions = androidNetworkActions(); const chain = defaultChains[networkActions[idx]] || defaultChains[ChainId.mainnet]; callback({ chainId: chain.id }); diff --git a/src/hooks/charts/useChartInfo.ts b/src/hooks/charts/useChartInfo.ts index dd1c6f91ad3..09159ab38a5 100644 --- a/src/hooks/charts/useChartInfo.ts +++ b/src/hooks/charts/useChartInfo.ts @@ -5,7 +5,7 @@ import { metadataClient } from '@/graphql'; import { useQuery } from '@tanstack/react-query'; import { createQueryKey } from '@/react-query'; import { SupportedCurrencyKey } from '@/references'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const chartTimes = ['hour', 'day', 'week', 'month', 'year'] as const; type ChartTime = (typeof chartTimes)[number]; diff --git a/src/hooks/useAccountTransactions.ts b/src/hooks/useAccountTransactions.ts index b8d388f8b1a..3cd0d585764 100644 --- a/src/hooks/useAccountTransactions.ts +++ b/src/hooks/useAccountTransactions.ts @@ -9,8 +9,8 @@ import { RainbowTransaction } from '@/entities'; import { pendingTransactionsStore, usePendingTransactionsStore } from '@/state/pendingTransactions'; import { getSortedWalletConnectRequests } from '@/state/walletConnectRequests'; import { nonceStore } from '@/state/nonces'; -import { ChainId } from '@/chains/types'; -import { SUPPORTED_CHAIN_IDS, SUPPORTED_MAINNET_CHAIN_IDS } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export const NOE_PAGE = 30; @@ -44,7 +44,12 @@ export default function useAccountTransactions() { } return latestTxMap; }, - new Map(SUPPORTED_CHAIN_IDS.map(chainId => [chainId, null as RainbowTransaction | null])) + new Map( + useBackendNetworksStore + .getState() + .getSupportedChainIds() + .map(chainId => [chainId, null as RainbowTransaction | null]) + ) ); watchForPendingTransactionsReportedByRainbowBackend({ currentAddress: accountAddress, @@ -62,7 +67,7 @@ export default function useAccountTransactions() { const { setNonce } = nonceStore.getState(); const { setPendingTransactions, pendingTransactions: storePendingTransactions } = pendingTransactionsStore.getState(); const pendingTransactions = storePendingTransactions[currentAddress] || []; - for (const chainId of SUPPORTED_MAINNET_CHAIN_IDS) { + for (const chainId of useBackendNetworksStore.getState().getSupportedMainnetChainIds()) { const latestTxConfirmedByBackend = latestTransactions.get(chainId); if (latestTxConfirmedByBackend) { const latestNonceConfirmedByBackend = latestTxConfirmedByBackend.nonce || 0; diff --git a/src/hooks/useAdditionalAssetData.ts b/src/hooks/useAdditionalAssetData.ts index 0a89867ccf8..271d75819df 100644 --- a/src/hooks/useAdditionalAssetData.ts +++ b/src/hooks/useAdditionalAssetData.ts @@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query'; import { NativeCurrencyKey } from '@/entities'; import { metadataClient } from '@/graphql'; import { Token } from '@/graphql/__generated__/metadata'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; // Types type TokenMetadata = Pick< diff --git a/src/hooks/useAsset.ts b/src/hooks/useAsset.ts index cea27883fff..663c50858a5 100644 --- a/src/hooks/useAsset.ts +++ b/src/hooks/useAsset.ts @@ -4,7 +4,7 @@ import { getUniqueId } from '@/utils/ethereumUtils'; import { useExternalToken } from '@/resources/assets/externalAssetsQuery'; import { useSelector } from 'react-redux'; import { AppState } from '@/redux/store'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { Address } from 'viem'; // To fetch an asset from account assets, diff --git a/src/hooks/useCalculateGasLimit.ts b/src/hooks/useCalculateGasLimit.ts index 34f6b89b92f..703d073a268 100644 --- a/src/hooks/useCalculateGasLimit.ts +++ b/src/hooks/useCalculateGasLimit.ts @@ -9,8 +9,8 @@ import { InteractionManager } from 'react-native'; import { GasFeeParamsBySpeed } from '@/entities'; import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { useGas } from '@/hooks'; -import { ChainId } from '@/chains/types'; -import { needsL1SecurityFeeChains } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; type CalculateGasLimitProps = { isMessageRequest: boolean; @@ -52,7 +52,7 @@ export const useCalculateGasLimit = ({ } finally { logger.debug('WC: Setting gas limit to', { gas: convertHexToString(gas) }, logger.DebugContext.walletconnect); - const needsL1SecurityFee = needsL1SecurityFeeChains.includes(chainId); + const needsL1SecurityFee = useBackendNetworksStore.getState().getNeedsL1SecurityFeeChains().includes(chainId); if (needsL1SecurityFee) { const l1GasFeeOptimism = await ethereumUtils.calculateL1FeeOptimism(txPayload, provider); updateTxFee(gas, null, l1GasFeeOptimism); diff --git a/src/hooks/useENSRegistrationActionHandler.ts b/src/hooks/useENSRegistrationActionHandler.ts index 95337c4d4b9..a61bf71ee92 100644 --- a/src/hooks/useENSRegistrationActionHandler.ts +++ b/src/hooks/useENSRegistrationActionHandler.ts @@ -25,7 +25,7 @@ import store from '@/redux/store'; import { performanceTracking, Screens, TimeToSignOperation } from '@/state/performance/performance'; import { noop } from 'lodash'; import { logger, RainbowError } from '@/logger'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { IS_IOS } from '@/env'; // Generic type for action functions diff --git a/src/hooks/useENSRegistrationCosts.ts b/src/hooks/useENSRegistrationCosts.ts index 95ce537981e..a2653f3c86d 100644 --- a/src/hooks/useENSRegistrationCosts.ts +++ b/src/hooks/useENSRegistrationCosts.ts @@ -27,7 +27,7 @@ import { import { add, addBuffer, addDisplay, fromWei, greaterThanOrEqualTo, multiply } from '@/helpers/utilities'; import { ethUnits, timeUnits } from '@/references'; import { ethereumUtils, gasUtils } from '@/utils'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; enum QUERY_KEYS { GET_COMMIT_GAS_LIMIT = 'GET_COMMIT_GAS_LIMIT', diff --git a/src/hooks/useENSRegistrationStepHandler.tsx b/src/hooks/useENSRegistrationStepHandler.tsx index 24b9ceea113..d99183c9bec 100644 --- a/src/hooks/useENSRegistrationStepHandler.tsx +++ b/src/hooks/useENSRegistrationStepHandler.tsx @@ -14,7 +14,7 @@ import { REGISTRATION_STEPS, } from '@/helpers/ens'; import { updateTransactionRegistrationParameters } from '@/redux/ensRegistration'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { useConnectedToHardhatStore } from '@/state/connectedToHardhat'; const checkRegisterBlockTimestamp = async ({ diff --git a/src/hooks/useENSSearch.ts b/src/hooks/useENSSearch.ts index 5e9d207375d..6fc3e3451f7 100644 --- a/src/hooks/useENSSearch.ts +++ b/src/hooks/useENSSearch.ts @@ -6,7 +6,7 @@ import { fetchRegistrationDate } from '@/handlers/ens'; import { ENS_DOMAIN, formatRentPrice, getAvailable, getENSRegistrarControllerContract, getNameExpires, getRentPrice } from '@/helpers/ens'; import { timeUnits } from '@/references'; import { ethereumUtils, validateENS } from '@/utils'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const formatTime = (timestamp: string, abbreviated = true) => { const style = abbreviated ? 'MMM d, y' : 'MMMM d, y'; diff --git a/src/hooks/useGas.ts b/src/hooks/useGas.ts index 2be5a4bf210..781165210b7 100644 --- a/src/hooks/useGas.ts +++ b/src/hooks/useGas.ts @@ -30,9 +30,9 @@ import { fetchExternalToken, } from '@/resources/assets/externalAssetsQuery'; import useAccountSettings from './useAccountSettings'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { useQueries } from '@tanstack/react-query'; -import { chainsNativeAsset } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const checkSufficientGas = (txFee: LegacyGasFee | GasFee, chainId: ChainId, nativeAsset?: ParsedAddressAsset) => { const isLegacyGasNetwork = !(txFee as GasFee)?.maxFee; @@ -66,6 +66,8 @@ export default function useGas({ nativeAsset }: { nativeAsset?: ParsedAddressAss const dispatch = useDispatch(); const { nativeCurrency } = useAccountSettings(); + const chainsNativeAsset = useBackendNetworksStore.getState().getChainsNativeAsset(); + // keep native assets up to date for gas price calculations // NOTE: We only fetch the native asset for mainnet and chains that don't use ETH as their native token const chainsToFetch = Object.entries(chainsNativeAsset).filter( diff --git a/src/hooks/useHasEnoughBalance.ts b/src/hooks/useHasEnoughBalance.ts index f9179628c22..491a9c2c70e 100644 --- a/src/hooks/useHasEnoughBalance.ts +++ b/src/hooks/useHasEnoughBalance.ts @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'; import { fromWei, greaterThanOrEqualTo } from '@/helpers/utilities'; import BigNumber from 'bignumber.js'; import { SelectedGasFee } from '@/entities'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; type WalletBalance = { amount: string | number; diff --git a/src/hooks/useImportingWallet.ts b/src/hooks/useImportingWallet.ts index e78fa43a2e8..d0f92e12a3a 100644 --- a/src/hooks/useImportingWallet.ts +++ b/src/hooks/useImportingWallet.ts @@ -31,7 +31,7 @@ import { handleReviewPromptAction } from '@/utils/reviewAlert'; import { ReviewPromptAction } from '@/storage/schema'; import { checkWalletsForBackupStatus } from '@/screens/SettingsSheet/utils'; import walletBackupTypes from '@/helpers/walletBackupTypes'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; export default function useImportingWallet({ showImportModal = true } = {}) { const { accountAddress } = useAccountSettings(); diff --git a/src/hooks/useNonceForDisplay.ts b/src/hooks/useNonceForDisplay.ts index 8308bc460e9..98376442019 100644 --- a/src/hooks/useNonceForDisplay.ts +++ b/src/hooks/useNonceForDisplay.ts @@ -1,6 +1,6 @@ import { useEffect, useState } from 'react'; import { getNextNonce } from '@/state/nonces'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { logger, RainbowError } from '@/logger'; type UseNonceParams = { diff --git a/src/hooks/useSearchCurrencyList.ts b/src/hooks/useSearchCurrencyList.ts index f740de45000..6c414079be7 100644 --- a/src/hooks/useSearchCurrencyList.ts +++ b/src/hooks/useSearchCurrencyList.ts @@ -17,8 +17,8 @@ import { CROSSCHAIN_SWAPS, useExperimentalFlag } from '@/config'; import { IS_TEST } from '@/env'; import { useFavorites } from '@/resources/favorites'; import { getUniqueId } from '@/utils/ethereumUtils'; -import { chainsName } from '@/chains'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; type swapCurrencyListType = | 'verifiedAssets' @@ -70,7 +70,7 @@ const searchCurrencyList = async (searchParams: { } }; -const useSearchCurrencyList = (searchQuery: string, searchChainId = ChainId.mainnet, isDiscover = false) => { +const useSearchCurrencyList = (searchQuery: string, searchChainId = ChainId.mainnet) => { const previousChainId = usePrevious(searchChainId); const searching = useMemo(() => searchQuery !== '' || ChainId.mainnet !== searchChainId, [searchChainId, searchQuery]); @@ -189,7 +189,7 @@ const useSearchCurrencyList = (searchQuery: string, searchChainId = ChainId.main }, }, symbol, - network: chainsName[chainId], + network: useBackendNetworksStore.getState().getChainsName()[chainId], uniqueId, } as RainbowToken, ]; @@ -434,7 +434,6 @@ const useSearchCurrencyList = (searchQuery: string, searchChainId = ChainId.main const currentNetworkChainId = Number(chainId); if (currentNetworkChainId !== searchChainId) { // including goerli in our networks type is causing this type issue - // @ts-ignore const exactMatch = crosschainVerifiedAssets[currentNetworkChainId].find((asset: RainbowToken) => { const symbolMatch = isLowerCaseMatch(asset?.symbol, searchQuery); const nameMatch = isLowerCaseMatch(asset?.name, searchQuery); diff --git a/src/hooks/useTransactionSetup.ts b/src/hooks/useTransactionSetup.ts index 0eb1542e66e..28bdf4d4989 100644 --- a/src/hooks/useTransactionSetup.ts +++ b/src/hooks/useTransactionSetup.ts @@ -6,7 +6,7 @@ import { methodRegistryLookupAndParse } from '@/utils/methodRegistry'; import { analytics } from '@/analytics'; import { event } from '@/analytics/event'; import { RequestSource } from '@/utils/requestNavigationHandlers'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; type TransactionSetupParams = { chainId: ChainId; diff --git a/src/hooks/useWatchPendingTxs.ts b/src/hooks/useWatchPendingTxs.ts index afffad810da..72284234036 100644 --- a/src/hooks/useWatchPendingTxs.ts +++ b/src/hooks/useWatchPendingTxs.ts @@ -9,14 +9,14 @@ import { getProvider } from '@/handlers/web3'; import { consolidatedTransactionsQueryKey } from '@/resources/transactions/consolidatedTransactions'; import { queryClient } from '@/react-query/queryClient'; import { getTransactionFlashbotStatus } from '@/handlers/transactions'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { invalidateAddressNftsQueries } from '@/resources/nfts'; import { useNonceStore } from '@/state/nonces'; import { usePendingTransactionsStore } from '@/state/pendingTransactions'; import { Address } from 'viem'; import { staleBalancesStore } from '@/state/staleBalances'; import { useConnectedToHardhatStore } from '@/state/connectedToHardhat'; -import { SUPPORTED_MAINNET_CHAIN_IDS } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export const useWatchPendingTransactions = ({ address }: { address: string }) => { const { storePendingTransactions, setPendingTransactions } = usePendingTransactionsStore(state => ({ @@ -205,11 +205,13 @@ export const useWatchPendingTransactions = ({ address }: { address: string }) => queryKey: userAssetsQueryKey({ address, currency: nativeCurrency, connectedToHardhat }), }); + const supportedMainnetChainIds = useBackendNetworksStore.getState().getSupportedMainnetChainIds(); + await queryClient.refetchQueries({ queryKey: consolidatedTransactionsQueryKey({ address, currency: nativeCurrency, - chainIds: SUPPORTED_MAINNET_CHAIN_IDS, + chainIds: supportedMainnetChainIds, }), }); @@ -219,7 +221,7 @@ export const useWatchPendingTransactions = ({ address }: { address: string }) => queryKey: consolidatedTransactionsQueryKey({ address, currency: nativeCurrency, - chainIds: SUPPORTED_MAINNET_CHAIN_IDS, + chainIds: supportedMainnetChainIds, }), }); }, 2000); diff --git a/src/migrations/migrations/migratePinnedAndHiddenTokenUniqueIds.ts b/src/migrations/migrations/migratePinnedAndHiddenTokenUniqueIds.ts index abff230dbbb..20f8fe20986 100644 --- a/src/migrations/migrations/migratePinnedAndHiddenTokenUniqueIds.ts +++ b/src/migrations/migrations/migratePinnedAndHiddenTokenUniqueIds.ts @@ -1,7 +1,7 @@ import { BooleanMap } from '@/hooks/useCoinListEditOptions'; import { Migration, MigrationName } from '@/migrations/types'; import { loadAddress } from '@/model/wallet'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; import { MMKV } from 'react-native-mmkv'; const mmkv = new MMKV(); diff --git a/src/model/remoteConfig.ts b/src/model/remoteConfig.ts index 3481092be7e..a8d78b68a5d 100644 --- a/src/model/remoteConfig.ts +++ b/src/model/remoteConfig.ts @@ -6,6 +6,7 @@ import { useQuery } from '@tanstack/react-query'; export interface RainbowConfig extends Record { default_slippage_bips: string; + default_slippage_bips_chainId: string; f2c_enabled: boolean; flashbots_enabled: boolean; op_nft_network: string; @@ -73,6 +74,19 @@ export const DEFAULT_CONFIG: RainbowConfig = { polygon: 200, zora: 200, }), + default_slippage_bips_chainId: JSON.stringify({ + '33139': 200, + '42161': 200, + '43114': 200, + '8453': 200, + '81457': 200, + '56': 200, + '666666666': 200, + '1': 100, + '10': 200, + '137': 200, + '7777777': 200, + }), f2c_enabled: true, flashbots_enabled: true, op_nft_network: 'op-mainnet', @@ -138,7 +152,7 @@ export async function fetchRemoteConfig(): Promise { const parameters = remoteConfig().getAll(); Object.entries(parameters).forEach($ => { const [key, entry] = $; - if (key === 'default_slippage_bips') { + if (key === 'default_slippage_bips' || key === 'default_slippage_bips_chainId') { config[key] = JSON.parse(entry.asString()); } else if ( key === 'flashbots_enabled' || diff --git a/src/model/wallet.ts b/src/model/wallet.ts index 1f7d833d014..da67e97fdbd 100644 --- a/src/model/wallet.ts +++ b/src/model/wallet.ts @@ -50,7 +50,7 @@ import { setHardwareTXError } from '@/navigation/HardwareWalletTxNavigator'; import { Signer } from '@ethersproject/abstract-signer'; import { sanitizeTypedData } from '@/utils/signingUtils'; import { ExecuteFnParamsWithoutFn, performanceTracking, Screen } from '@/state/performance/performance'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; export type EthereumPrivateKey = string; type EthereumMnemonic = string; diff --git a/src/navigation/config.tsx b/src/navigation/config.tsx index 4de26c91662..5428d27e37b 100644 --- a/src/navigation/config.tsx +++ b/src/navigation/config.tsx @@ -28,8 +28,8 @@ import { Box } from '@/design-system'; import { IS_ANDROID } from '@/env'; import { SignTransactionSheetRouteProp } from '@/screens/SignTransactionSheet'; import { RequestSource } from '@/utils/requestNavigationHandlers'; -import { ChainId } from '@/chains/types'; -import { chainsName } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export const sharedCoolModalTopOffset = safeAreaInsetValues.top; @@ -491,7 +491,7 @@ export const ensAdditionalRecordsSheetConfig: PartialNavigatorConfigOptions = { }; export const explainSheetConfig: PartialNavigatorConfigOptions = { - options: ({ route: { params = { network: chainsName[ChainId.mainnet] } } }) => { + options: ({ route: { params = { network: useBackendNetworksStore.getState().getChainsName()[ChainId.mainnet] } } }) => { // @ts-ignore const explainerConfig = explainers(params.network)[params?.type]; return buildCoolModalConfig({ diff --git a/src/parsers/transactions.ts b/src/parsers/transactions.ts index 013c3c82865..487552c0ec8 100644 --- a/src/parsers/transactions.ts +++ b/src/parsers/transactions.ts @@ -21,8 +21,8 @@ import { NewTransaction, RainbowTransactionFee } from '@/entities/transactions/t import { parseAddressAsset, parseAsset } from '@/resources/assets/assets'; import { ParsedAsset } from '@/resources/assets/types'; -import { ChainId } from '@/chains/types'; -import { chainsNativeAsset } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const TransactionOutTypes = [ 'burn', @@ -169,7 +169,7 @@ const getTransactionFee = ( return undefined; } - const chainNativeAsset = chainsNativeAsset[chainId]; + const chainNativeAsset = useBackendNetworksStore.getState().getChainsNativeAsset()[chainId]; const zerionFee = txn.fee; return { diff --git a/src/raps/actions/claimBridge.ts b/src/raps/actions/claimBridge.ts index e410d7c1565..181d3288be1 100644 --- a/src/raps/actions/claimBridge.ts +++ b/src/raps/actions/claimBridge.ts @@ -14,12 +14,12 @@ import { REFERRER_CLAIM } from '@/references'; import { addNewTransaction } from '@/state/pendingTransactions'; import ethereumUtils from '@/utils/ethereumUtils'; import { AddressZero } from '@ethersproject/constants'; -import { CrosschainQuote, QuoteError, SwapType, getClaimBridgeQuote } from '@rainbow-me/swaps'; +import { CrosschainQuote, QuoteError, getClaimBridgeQuote } from '@rainbow-me/swaps'; import { Address } from 'viem'; import { ActionProps } from '../references'; import { executeCrosschainSwap } from './crosschainSwap'; -import { ChainId } from '@/chains/types'; -import { chainsName } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; // This action is used to bridge the claimed funds to another chain export async function claimBridge({ parameters, wallet, baseNonce }: ActionProps<'claimBridge'>) { @@ -158,6 +158,8 @@ export async function claimBridge({ parameters, wallet, baseNonce }: ActionProps throw new Error('[CLAIM-BRIDGE]: executeCrosschainSwap returned undefined'); } + const chainsName = useBackendNetworksStore.getState().getChainsName(); + const typedAssetToBuy: ParsedAddressAsset = { ...parameters.assetToBuy, network: chainsName[parameters.assetToBuy.chainId], diff --git a/src/raps/actions/crosschainSwap.ts b/src/raps/actions/crosschainSwap.ts index 4ce949d8582..99160c26ac5 100644 --- a/src/raps/actions/crosschainSwap.ts +++ b/src/raps/actions/crosschainSwap.ts @@ -6,7 +6,7 @@ import { add } from '@/helpers/utilities'; import { assetNeedsUnlocking, estimateApprove } from './unlock'; import { REFERRER, gasUnits, ReferrerType } from '@/references'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { NewTransaction, TransactionDirection, TransactionStatus, TxHash } from '@/entities'; import { addNewTransaction } from '@/state/pendingTransactions'; import { RainbowError, logger } from '@/logger'; @@ -26,7 +26,7 @@ import { AddysNetworkDetails, ParsedAsset } from '@/resources/assets/types'; import { ExtendedAnimatedAssetWithColors } from '@/__swaps__/types/assets'; import { Screens, TimeToSignOperation, performanceTracking } from '@/state/performance/performance'; import { swapsStore } from '@/state/swaps/swapsStore'; -import { chainsName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const getCrosschainSwapDefaultGasLimit = (quote: CrosschainQuote) => quote?.routes?.[0]?.userTxs?.[0]?.gasFees?.gasLimit; @@ -242,6 +242,8 @@ export const crosschainSwap = async ({ } : parameters.assetToSell.price; + const chainsName = useBackendNetworksStore.getState().getChainsName(); + const assetToBuy = { ...parameters.assetToBuy, network: chainsName[parameters.assetToBuy.chainId], diff --git a/src/raps/actions/ens.ts b/src/raps/actions/ens.ts index d0466d77149..e4e315c98a4 100644 --- a/src/raps/actions/ens.ts +++ b/src/raps/actions/ens.ts @@ -12,7 +12,7 @@ import store from '@/redux/store'; import { logger, RainbowError } from '@/logger'; import { parseGasParamAmounts } from '@/parsers'; import { addNewTransaction } from '@/state/pendingTransactions'; -import { ChainId, Network } from '@/chains/types'; +import { ChainId, Network } from '@/state/backendNetworks/types'; import { createRegisterENSRap, createRenewENSRap, diff --git a/src/raps/actions/swap.ts b/src/raps/actions/swap.ts index cc0c6d35550..3bf848b4193 100644 --- a/src/raps/actions/swap.ts +++ b/src/raps/actions/swap.ts @@ -16,7 +16,7 @@ import { estimateGasWithPadding, getProvider, toHex } from '@/handlers/web3'; import { Address } from 'viem'; import { metadataPOSTClient } from '@/graphql'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { NewTransaction, TxHash, TransactionStatus, TransactionDirection } from '@/entities'; import { add } from '@/helpers/utilities'; import { addNewTransaction } from '@/state/pendingTransactions'; @@ -41,7 +41,7 @@ import { AddysNetworkDetails, ParsedAsset } from '@/resources/assets/types'; import { ExtendedAnimatedAssetWithColors } from '@/__swaps__/types/assets'; import { Screens, TimeToSignOperation, performanceTracking } from '@/state/performance/performance'; import { swapsStore } from '@/state/swaps/swapsStore'; -import { chainsName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const WRAP_GAS_PADDING = 1.002; @@ -373,6 +373,8 @@ export const swap = async ({ } : parameters.assetToSell.price; + const chainsName = useBackendNetworksStore.getState().getChainsName(); + const assetToBuy = { ...parameters.assetToBuy, network: chainsName[parameters.assetToBuy.chainId], diff --git a/src/raps/actions/unlock.ts b/src/raps/actions/unlock.ts index f12aa0c91b7..2ede72a1b7e 100644 --- a/src/raps/actions/unlock.ts +++ b/src/raps/actions/unlock.ts @@ -5,7 +5,7 @@ import { parseUnits } from '@ethersproject/units'; import { getProvider, toHex } from '@/handlers/web3'; import { Address, erc20Abi, erc721Abi } from 'viem'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { TransactionGasParams, TransactionLegacyGasParams } from '@/__swaps__/types/gas'; import { NewTransaction, TransactionStatus, TxHash } from '@/entities'; import { addNewTransaction } from '@/state/pendingTransactions'; @@ -19,7 +19,7 @@ import { ActionProps, RapActionResult } from '../references'; import { overrideWithFastSpeedIfNeeded } from './../utils'; import { TokenColors } from '@/graphql/__generated__/metadata'; import { ParsedAsset } from '@/resources/assets/types'; -import { chainsName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export const getAssetRawAllowance = async ({ owner, @@ -266,6 +266,8 @@ export const unlock = async ({ if (!approval) throw new RainbowError('[raps/unlock]: error executeApprove'); + const chainsName = useBackendNetworksStore.getState().getChainsName(); + const transaction = { asset: { ...assetToUnlock, diff --git a/src/raps/references.ts b/src/raps/references.ts index 259b8fe330c..c2bc3160caa 100644 --- a/src/raps/references.ts +++ b/src/raps/references.ts @@ -4,7 +4,7 @@ import { Address } from 'viem'; import { ParsedAsset } from '@/__swaps__/types/assets'; import { GasFeeParamsBySpeed, LegacyGasFeeParamsBySpeed, LegacyTransactionGasParamAmounts, TransactionGasParamAmounts } from '@/entities'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; export enum SwapModalField { input = 'inputAmount', diff --git a/src/raps/utils.ts b/src/raps/utils.ts index 6da90630263..3967b999f07 100644 --- a/src/raps/utils.ts +++ b/src/raps/utils.ts @@ -8,7 +8,7 @@ import { Chain, erc20Abi } from 'viem'; import { GasFeeParamsBySpeed, LegacyGasFeeParamsBySpeed, LegacyTransactionGasParamAmounts, TransactionGasParamAmounts } from '@/entities'; import { gasUtils } from '@/utils'; import { add, greaterThan, multiply } from '@/helpers/utilities'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { gasUnits } from '@/references'; import { toHexNoLeadingZeros } from '@/handlers/web3'; diff --git a/src/rapsV2/actions/claimTransactionClaimableAction.ts b/src/rapsV2/actions/claimTransactionClaimableAction.ts index 7874b9e295b..a516182fcdf 100644 --- a/src/rapsV2/actions/claimTransactionClaimableAction.ts +++ b/src/rapsV2/actions/claimTransactionClaimableAction.ts @@ -4,7 +4,7 @@ import { getProvider } from '@/handlers/web3'; import { RainbowError } from '@/logger'; import { addNewTransaction } from '@/state/pendingTransactions'; import { NewTransaction, TransactionStatus } from '@/entities'; -import { chainsName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export async function claimTransactionClaimable({ parameters, wallet }: ActionProps<'claimTransactionClaimableAction'>) { const { claimTx, asset } = parameters; @@ -23,7 +23,7 @@ export async function claimTransactionClaimable({ parameters, wallet }: ActionPr to: result.result.to ?? null, chainId: result.result.chainId, hash: result.result.hash, - network: chainsName[result.result.chainId], + network: useBackendNetworksStore.getState().getChainsName()[result.result.chainId], status: TransactionStatus.pending, type: 'claim', nonce: result.result.nonce, diff --git a/src/redux/ensRegistration.ts b/src/redux/ensRegistration.ts index ea2158ec215..33a5b23c844 100644 --- a/src/redux/ensRegistration.ts +++ b/src/redux/ensRegistration.ts @@ -5,7 +5,7 @@ import { ENSRegistrations, ENSRegistrationState, Records, RegistrationParameters import { getLocalENSRegistrations, saveLocalENSRegistrations } from '@/handlers/localstorage/accountLocal'; import { ENS_RECORDS, REGISTRATION_MODES } from '@/helpers/ens'; import { omitFlatten } from '@/helpers/utilities'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; const ENS_REGISTRATION_SET_CHANGED_RECORDS = 'ensRegistration/ENS_REGISTRATION_SET_CHANGED_RECORDS'; const ENS_REGISTRATION_SET_INITIAL_RECORDS = 'ensRegistration/ENS_REGISTRATION_SET_INITIAL_RECORDS'; diff --git a/src/redux/gas.ts b/src/redux/gas.ts index 9ce8fe4aac1..bbbf0264940 100644 --- a/src/redux/gas.ts +++ b/src/redux/gas.ts @@ -36,9 +36,9 @@ import { } from '@/parsers'; import { ethUnits } from '@/references'; import { ethereumUtils, gasUtils } from '@/utils'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { useConnectedToHardhatStore } from '@/state/connectedToHardhat'; -import { chainsNativeAsset, chainsSwapPollingInterval, meteorologySupportedChainIds, needsL1SecurityFeeChains } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { MeteorologyLegacyResponse, MeteorologyResponse } from '@/entities/gas'; import { addBuffer } from '@/helpers/utilities'; @@ -124,6 +124,8 @@ const getUpdatedGasFeeParams = ( ) => { let nativeTokenPriceUnit = ethereumUtils.getPriceOfNativeAssetForNetwork({ chainId: ChainId.mainnet }); + const chainsNativeAsset = useBackendNetworksStore.getState().getChainsNativeAsset(); + // we want to fetch the specific chain native token if anything but ETH const networkNativeAsset = chainsNativeAsset[chainId]; if (networkNativeAsset.symbol.toLowerCase() !== 'eth') { @@ -191,6 +193,7 @@ export const gasUpdateToCustomGasFee = (gasParams: GasFeeParams) => async (dispa const _gasLimit = gasLimit || getDefaultGasLimit(chainId, defaultGasLimit); let nativeTokenPriceUnit = ethereumUtils.getPriceOfNativeAssetForNetwork({ chainId: ChainId.mainnet }); + const chainsNativeAsset = useBackendNetworksStore.getState().getChainsNativeAsset(); // we want to fetch the specific chain native token if anything but ETH const networkNativeAsset = chainsNativeAsset[chainId]; @@ -320,7 +323,7 @@ export const gasPricesStartPolling = const { nativeCurrency } = getState().settings; let dataIsReady = true; - const meteorologySupportsChainId = meteorologySupportedChainIds.includes(chainId); + const meteorologySupportsChainId = useBackendNetworksStore.getState().getMeteorologySupportedChainIds().includes(chainId); if (!meteorologySupportsChainId) { const adjustedGasFees = await getProviderGasPrices({ chainId }); if (!adjustedGasFees) return; @@ -356,7 +359,7 @@ export const gasPricesStartPolling = } else { try { // OP chains have an additional fee we need to load - if (needsL1SecurityFeeChains.includes(chainId)) { + if (useBackendNetworksStore.getState().getNeedsL1SecurityFeeChains().includes(chainId)) { dataIsReady = l1GasFeeOptimism !== null; } const meteorologyGasParams = await getMeteorologyGasParams(chainId); @@ -492,7 +495,7 @@ export const gasPricesStartPolling = } }; - const pollingInterval = chainsSwapPollingInterval[chainId]; + const pollingInterval = useBackendNetworksStore.getState().getChainsPollingInterval()[chainId]; watchGasPrices(chainId, pollingInterval); }; @@ -528,7 +531,10 @@ export const gasUpdateTxFee = const { defaultGasLimit, gasLimit, gasFeeParamsBySpeed, selectedGasFee, chainId, currentBlockParams } = getState().gas; const { nativeCurrency } = getState().settings; - if (isEmpty(gasFeeParamsBySpeed) || (needsL1SecurityFeeChains.includes(chainId) && l1GasFeeOptimism === null)) { + if ( + isEmpty(gasFeeParamsBySpeed) || + (useBackendNetworksStore.getState().getNeedsL1SecurityFeeChains().includes(chainId) && l1GasFeeOptimism === null) + ) { // if fee prices not ready, we need to store the gas limit for future calculations // the rest is as the initial state value if (updatedGasLimit) { diff --git a/src/redux/settings.ts b/src/redux/settings.ts index 30fb517b016..4d8ed57a335 100644 --- a/src/redux/settings.ts +++ b/src/redux/settings.ts @@ -25,7 +25,7 @@ import { import { getProvider } from '@/handlers/web3'; import { AppState } from '@/redux/store'; import { logger, RainbowError } from '@/logger'; -import { Network, ChainId } from '@/chains/types'; +import { Network, ChainId } from '@/state/backendNetworks/types'; // -- Constants ------------------------------------------------------------- // const SETTINGS_UPDATE_SETTINGS_ADDRESS = 'settings/SETTINGS_UPDATE_SETTINGS_ADDRESS'; diff --git a/src/redux/showcaseTokens.ts b/src/redux/showcaseTokens.ts index 062d292c68f..1ca4bf8db8e 100644 --- a/src/redux/showcaseTokens.ts +++ b/src/redux/showcaseTokens.ts @@ -5,7 +5,7 @@ import { getPreference } from '../model/preferences'; import { AppGetState } from './store'; import { getShowcaseTokens, getWebDataEnabled, saveShowcaseTokens, saveWebDataEnabled } from '@/handlers/localstorage/accountLocal'; import WalletTypes from '@/helpers/walletTypes'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; // -- Constants --------------------------------------- // diff --git a/src/references/gasUnits.ts b/src/references/gasUnits.ts index 75be1c71e93..a9517837ca8 100644 --- a/src/references/gasUnits.ts +++ b/src/references/gasUnits.ts @@ -1,4 +1,4 @@ -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; export const gasUnits = { basic_approval: '55000', diff --git a/src/references/rainbow-token-list/index.ts b/src/references/rainbow-token-list/index.ts index cdda1dcae0f..b8ad0db4687 100644 --- a/src/references/rainbow-token-list/index.ts +++ b/src/references/rainbow-token-list/index.ts @@ -6,7 +6,7 @@ import RAINBOW_TOKEN_LIST_DATA from './rainbow-token-list.json'; import { RainbowToken } from '@/entities'; import { STORAGE_IDS } from '@/model/mmkv'; import { logger, RainbowError } from '@/logger'; -import { Network, ChainId } from '@/chains/types'; +import { Network, ChainId } from '@/state/backendNetworks/types'; export const rainbowListStorage = new MMKV({ id: STORAGE_IDS.RAINBOW_TOKEN_LIST, diff --git a/src/references/testnet-assets-by-chain.ts b/src/references/testnet-assets-by-chain.ts index 8f0eedac9ba..141a195f022 100644 --- a/src/references/testnet-assets-by-chain.ts +++ b/src/references/testnet-assets-by-chain.ts @@ -1,5 +1,5 @@ import { UniqueId, ZerionAsset } from '@/__swaps__/types/assets'; -import { ChainId, ChainName } from '@/chains/types'; +import { ChainId, ChainName } from '@/state/backendNetworks/types'; type ChainAssets = { [uniqueId: UniqueId]: { diff --git a/src/resources/addys/claimables/query.ts b/src/resources/addys/claimables/query.ts index 311da649a50..b1e3d14e87e 100644 --- a/src/resources/addys/claimables/query.ts +++ b/src/resources/addys/claimables/query.ts @@ -9,7 +9,7 @@ import { parseClaimables } from './utils'; import { useRemoteConfig } from '@/model/remoteConfig'; import { CLAIMABLES, useExperimentalFlag } from '@/config'; import { IS_TEST } from '@/env'; -import { SUPPORTED_CHAIN_IDS } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export const ADDYS_BASE_URL = 'https://addys.p.rainbow.me/v3'; @@ -41,7 +41,7 @@ type ClaimablesQueryKey = ReturnType; async function claimablesQueryFunction({ queryKey: [{ address, currency }] }: QueryFunctionArgs) { try { - const url = `/${SUPPORTED_CHAIN_IDS.join(',')}/${address}/claimables`; + const url = `/${useBackendNetworksStore.getState().getSupportedChainIds().join(',')}/${address}/claimables`; const { data } = await addysHttp.get(url, { params: { currency: currency.toLowerCase(), diff --git a/src/resources/addys/claimables/types.ts b/src/resources/addys/claimables/types.ts index 426ed6e4523..2004563c6de 100644 --- a/src/resources/addys/claimables/types.ts +++ b/src/resources/addys/claimables/types.ts @@ -1,6 +1,6 @@ import { Address } from 'viem'; import { AddysAsset, AddysConsolidatedError, AddysResponseStatus } from '../types'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { ParsedAddressAsset } from '@/entities'; interface Colors { diff --git a/src/resources/addys/claimables/utils.ts b/src/resources/addys/claimables/utils.ts index 5b047644c97..c50b2e0d1fd 100644 --- a/src/resources/addys/claimables/utils.ts +++ b/src/resources/addys/claimables/utils.ts @@ -2,8 +2,8 @@ import { NativeCurrencyKey } from '@/entities'; import { AddysClaimable, Claimable } from './types'; import { convertRawAmountToBalance, convertRawAmountToNativeDisplay, greaterThan } from '@/helpers/utilities'; import { parseAsset } from '@/resources/assets/assets'; -import { Network } from '@/chains/types'; -import { chainsName } from '@/chains'; +import { Network } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export const parseClaimables = (claimables: AddysClaimable[], currency: NativeCurrencyKey): Claimable[] => { return claimables @@ -20,7 +20,7 @@ export const parseClaimables = (claimables: AddysClaimable[], currency: NativeCu address: claimable.asset.asset_code, asset: { ...claimable.asset, - network: chainsName[claimable.network] as Network, + network: useBackendNetworksStore.getState().getChainsName()[claimable.network] as Network, transferable: claimable.asset.transferable ?? false, }, }), diff --git a/src/resources/addys/types.ts b/src/resources/addys/types.ts index 6da5c2cc4d7..17d330b9927 100644 --- a/src/resources/addys/types.ts +++ b/src/resources/addys/types.ts @@ -1,4 +1,4 @@ -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { Address } from 'viem'; interface BridgeableNetwork { diff --git a/src/resources/assets/UserAssetsQuery.ts b/src/resources/assets/UserAssetsQuery.ts index e9c345ca8d2..5616163e903 100644 --- a/src/resources/assets/UserAssetsQuery.ts +++ b/src/resources/assets/UserAssetsQuery.ts @@ -9,9 +9,9 @@ import { useQuery } from '@tanstack/react-query'; import { filterPositionsData, parseAddressAsset } from './assets'; import { fetchHardhatBalances } from './hardhatAssets'; import { AddysAccountAssetsMeta, AddysAccountAssetsResponse, RainbowAddressAssets } from './types'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; import { staleBalancesStore } from '@/state/staleBalances'; -import { SUPPORTED_MAINNET_CHAIN_IDS } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; // /////////////////////////////////////////////// // Query Types @@ -80,7 +80,7 @@ async function userAssetsQueryFunction({ const { erroredChainIds, results } = await fetchAndParseUserAssetsForChainIds({ address, currency, - chainIds: SUPPORTED_MAINNET_CHAIN_IDS, + chainIds: useBackendNetworksStore.getState().getSupportedMainnetChainIds(), staleBalanceParam, }); let parsedSuccessResults = results; diff --git a/src/resources/assets/assets.ts b/src/resources/assets/assets.ts index f8c9eb9abfb..057963856bb 100644 --- a/src/resources/assets/assets.ts +++ b/src/resources/assets/assets.ts @@ -8,8 +8,8 @@ import { positionsQueryKey } from '@/resources/defi/PositionsQuery'; import { RainbowPositions } from '@/resources/defi/types'; import { AddysAddressAsset, AddysAsset, ParsedAsset, RainbowAddressAssets } from './types'; import { getUniqueId } from '@/utils/ethereumUtils'; -import { chainsIdByName } from '@/chains'; -import { ChainId } from '@/chains/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; +import { ChainId } from '@/state/backendNetworks/types'; export const filterPositionsData = ( address: string, @@ -34,7 +34,7 @@ export const filterPositionsData = ( export function parseAsset({ address, asset }: { address: string; asset: AddysAsset }): ParsedAsset { const network = asset?.network; - const chainId = chainsIdByName[network]; + const chainId = useBackendNetworksStore.getState().getChainsIdByName()[network]; const mainnetAddress = asset?.networks?.[ChainId.mainnet]?.address; const uniqueId = getUniqueId(address, chainId); diff --git a/src/resources/assets/externalAssetsQuery.ts b/src/resources/assets/externalAssetsQuery.ts index 03ef2f5e1cf..7abbddd523f 100644 --- a/src/resources/assets/externalAssetsQuery.ts +++ b/src/resources/assets/externalAssetsQuery.ts @@ -4,7 +4,7 @@ import { createQueryKey, queryClient, QueryConfig, QueryFunctionArgs, QueryFunct import { convertAmountAndPriceToNativeDisplay, convertAmountToPercentageDisplay } from '@/helpers/utilities'; import { NativeCurrencyKey } from '@/entities'; import { Token } from '@/graphql/__generated__/metadata'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { isNativeAsset } from '@/handlers/assets'; import { AddressOrEth } from '@/__swaps__/types/assets'; diff --git a/src/resources/assets/hardhatAssets.ts b/src/resources/assets/hardhatAssets.ts index a559414041c..409a3ee1a1c 100644 --- a/src/resources/assets/hardhatAssets.ts +++ b/src/resources/assets/hardhatAssets.ts @@ -8,8 +8,8 @@ import { logger, RainbowError } from '@/logger'; import { AddressOrEth, UniqueId, ZerionAsset } from '@/__swaps__/types/assets'; import { AddressZero } from '@ethersproject/constants'; import chainAssetsByChainId from '@/references/testnet-assets-by-chain'; -import { ChainId, ChainName, Network } from '@/chains/types'; -import { SUPPORTED_CHAIN_IDS } from '@/chains'; +import { ChainId, ChainName, Network } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const MAINNET_BALANCE_CHECKER = '0x4dcf4562268dd384fe814c00fad239f06c2a0c2b'; @@ -125,6 +125,6 @@ export const fetchHardhatBalancesByChainId = async ( return { assets: updatedAssets, - chainIdsInResponse: SUPPORTED_CHAIN_IDS, + chainIdsInResponse: useBackendNetworksStore.getState().getSupportedChainIds(), }; }; diff --git a/src/resources/assets/types.ts b/src/resources/assets/types.ts index 3a37f1a76b9..ad5c3a62285 100644 --- a/src/resources/assets/types.ts +++ b/src/resources/assets/types.ts @@ -1,6 +1,6 @@ import { NativeCurrencyKey, ParsedAddressAsset } from '@/entities'; import { TokenColors } from '@/graphql/__generated__/metadata'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; export type AddysAccountAssetsResponse = { meta: AddysAccountAssetsMeta; diff --git a/src/resources/assets/useUserAsset.ts b/src/resources/assets/useUserAsset.ts index e6033701e58..4ee1dea9de1 100644 --- a/src/resources/assets/useUserAsset.ts +++ b/src/resources/assets/useUserAsset.ts @@ -1,10 +1,10 @@ -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { useAccountSettings } from '@/hooks'; import { useUserAssets } from '@/resources/assets/UserAssetsQuery'; import { selectUserAssetWithUniqueId } from '@/resources/assets/assetSelectors'; import { getUniqueId } from '@/utils/ethereumUtils'; import { useConnectedToHardhatStore } from '@/state/connectedToHardhat'; -import { chainsNativeAsset } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export function useUserAsset(uniqueId: string) { const { accountAddress, nativeCurrency } = useAccountSettings(); @@ -23,7 +23,7 @@ export function useUserAsset(uniqueId: string) { } export function useUserNativeNetworkAsset(chainId: ChainId) { - const nativeCurrency = chainsNativeAsset[chainId]; + const nativeCurrency = useBackendNetworksStore.getState().getChainsNativeAsset()[chainId]; const { address } = nativeCurrency; const uniqueId = getUniqueId(address, chainId); return useUserAsset(uniqueId); diff --git a/src/resources/defi/PositionsQuery.ts b/src/resources/defi/PositionsQuery.ts index a3b2f7ddb15..99282066fe4 100644 --- a/src/resources/defi/PositionsQuery.ts +++ b/src/resources/defi/PositionsQuery.ts @@ -7,12 +7,12 @@ import { rainbowFetch } from '@/rainbow-fetch'; import { ADDYS_API_KEY } from 'react-native-dotenv'; import { AddysPositionsResponse, PositionsArgs } from './types'; import { parsePositions } from './utils'; -import { SUPPORTED_CHAIN_IDS } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { DEFI_POSITIONS, useExperimentalFlag } from '@/config'; import { IS_TEST } from '@/env'; export const buildPositionsUrl = (address: string) => { - const networkString = SUPPORTED_CHAIN_IDS.join(','); + const networkString = useBackendNetworksStore.getState().getSupportedChainIds().join(','); return `https://addys.p.rainbow.me/v3/${networkString}/${address}/positions`; }; diff --git a/src/resources/defi/types.ts b/src/resources/defi/types.ts index 56c25596204..b190da524c9 100644 --- a/src/resources/defi/types.ts +++ b/src/resources/defi/types.ts @@ -1,5 +1,5 @@ import { NativeCurrencyKey, ZerionAsset } from '@/entities'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; export type AddysPositionsResponse = | { diff --git a/src/resources/defi/utils.ts b/src/resources/defi/utils.ts index 87f570f8a93..ac959440ae5 100644 --- a/src/resources/defi/utils.ts +++ b/src/resources/defi/utils.ts @@ -14,7 +14,7 @@ import { import { add, convertAmountToNativeDisplay, convertRawAmountToNativeDisplay, subtract } from '@/helpers/utilities'; import { maybeSignUri } from '@/handlers/imgix'; import { ethereumUtils } from '@/utils'; -import { chainsIdByName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export const parsePosition = (position: Position, currency: NativeCurrencyKey): RainbowPosition => { let totalLocked = '0'; @@ -137,6 +137,8 @@ export const parsePositions = (data: AddysPositionsResponse, currency: NativeCur const positionTokens: string[] = []; + const chainsIdByName = useBackendNetworksStore.getState().getChainsIdByName(); + parsedPositions.forEach(({ deposits }) => { deposits.forEach(({ asset }) => { const uniqueId = ethereumUtils.getUniqueId(asset.asset_code.toLowerCase(), chainsIdByName[asset.network]); diff --git a/src/resources/ens/ensAddressQuery.ts b/src/resources/ens/ensAddressQuery.ts index 717b2616a2a..a35a7d11a8e 100644 --- a/src/resources/ens/ensAddressQuery.ts +++ b/src/resources/ens/ensAddressQuery.ts @@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query'; import { createQueryKey, queryClient, QueryFunctionArgs } from '@/react-query'; import { getProvider } from '@/handlers/web3'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; // Set a default stale time of 10 seconds so we don't over-fetch // (query will serve cached data & invalidate after 10s). diff --git a/src/resources/favorites.ts b/src/resources/favorites.ts index f27044c7f5c..f6d897f84bb 100644 --- a/src/resources/favorites.ts +++ b/src/resources/favorites.ts @@ -1,7 +1,6 @@ import { AddressOrEth, UniqueId } from '@/__swaps__/types/assets'; -import { ChainId, Network } from '@/chains/types'; +import { ChainId, Network } from '@/state/backendNetworks/types'; import { getUniqueId } from '@/utils/ethereumUtils'; -import { chainsIdByName, chainsName } from '@/chains'; import { NativeCurrencyKeys, RainbowToken } from '@/entities'; import { createQueryKey, queryClient } from '@/react-query'; import { DAI_ADDRESS, ETH_ADDRESS, SOCKS_ADDRESS, WBTC_ADDRESS, WETH_ADDRESS } from '@/references'; @@ -9,6 +8,7 @@ import { promiseUtils } from '@/utils'; import { useQuery } from '@tanstack/react-query'; import { omit } from 'lodash'; import { externalTokenQueryKey, fetchExternalToken } from './assets/externalAssetsQuery'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { analyticsV2 } from '@/analytics'; export const favoritesQueryKey = createQueryKey('favorites', {}, { persisterVersion: 4 }); @@ -21,7 +21,7 @@ const DEFAULT_FAVORITES = [DAI_ADDRESS, ETH_ADDRESS, SOCKS_ADDRESS, WBTC_ADDRESS async function fetchMetadata(addresses: string[], chainId = ChainId.mainnet) { const favoritesMetadata: Record = {}; const newFavoritesMeta: Record = {}; - const network = chainsName[chainId]; + const network = useBackendNetworksStore.getState().getChainsName()[chainId]; // Map addresses to an array of promises returned by fetchExternalToken const fetchPromises: Promise[] = addresses.map(async address => { @@ -92,6 +92,8 @@ export async function refreshFavorites() { {} as Record ); + const chainsIdByName = useBackendNetworksStore.getState().getChainsIdByName(); + const updatedMetadataByNetwork = await Promise.all( Object.entries(favoritesByNetwork).map(async ([network, networkFavorites]) => fetchMetadata(networkFavorites, chainsIdByName[network as Network]) diff --git a/src/resources/metadata/backendNetworks.ts b/src/resources/metadata/backendNetworks.ts index 4e36f816300..623d6f5d23c 100644 --- a/src/resources/metadata/backendNetworks.ts +++ b/src/resources/metadata/backendNetworks.ts @@ -1,6 +1,6 @@ import { useQuery } from '@tanstack/react-query'; import { QueryConfigWithSelect, QueryFunctionArgs, createQueryKey, queryClient } from '@/react-query'; -import { BackendNetwork } from '@/chains/types'; +import { BackendNetwork } from '@/state/backendNetworks/types'; import { BACKEND_NETWORKS_QUERY } from './sharedQueries'; // /////////////////////////////////////////////// @@ -50,13 +50,13 @@ export async function backendNetworksQueryFunction({ // /////////////////////////////////////////////// // Query Hook -export function useBackendNetworks( - config: QueryConfigWithSelect = {} +export function useBackendNetworks( + config: QueryConfigWithSelect = {} ) { return useQuery(backendNetworksQueryKey(), backendNetworksQueryFunction, { ...config, - cacheTime: 1000 * 60 * 60 * 24, // 24 hours - staleTime: 1000 * 60 * 15, // 15 minutes + refetchInterval: 60_000, + staleTime: process.env.IS_TESTING === 'true' ? 0 : 1000, }); } diff --git a/src/resources/nfts/index.ts b/src/resources/nfts/index.ts index d5585f29197..2c448365e97 100644 --- a/src/resources/nfts/index.ts +++ b/src/resources/nfts/index.ts @@ -8,7 +8,7 @@ import { UniqueAsset } from '@/entities'; import { arcClient } from '@/graphql'; import { NftCollectionSortCriterion, SortDirection } from '@/graphql/__generated__/arc'; import { createSelector } from 'reselect'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const NFTS_STALE_TIME = 600000; // 10 minutes const NFTS_CACHE_TIME_EXTERNAL = 3600000; // 1 hour diff --git a/src/resources/nfts/simplehash/index.ts b/src/resources/nfts/simplehash/index.ts index 83ffac0574b..dfa305925a8 100644 --- a/src/resources/nfts/simplehash/index.ts +++ b/src/resources/nfts/simplehash/index.ts @@ -3,8 +3,8 @@ import { RainbowFetchClient } from '@/rainbow-fetch'; import { SimpleHashListing, SimpleHashNFT, SimpleHashMarketplaceId } from '@/resources/nfts/simplehash/types'; import { UniqueAsset } from '@/entities'; import { RainbowError, logger } from '@/logger'; -import { ChainId } from '@/chains/types'; -import { chainsSimplehashNetwork } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export const START_CURSOR = 'start'; @@ -19,7 +19,7 @@ export async function fetchSimpleHashNFT( tokenId: string, chainId: Omit = ChainId.mainnet ): Promise { - const simplehashNetwork = chainsSimplehashNetwork[chainId as ChainId]; + const simplehashNetwork = useBackendNetworksStore.getState().getChainsSimplehashNetwork()[chainId as ChainId]; if (!simplehashNetwork) { logger.warn(`[simplehash]: no SimpleHash for chainId: ${chainId}`); @@ -44,7 +44,7 @@ export async function fetchSimpleHashNFTListing( // array of all eth listings on OpenSea for this token let listings: SimpleHashListing[] = []; let cursor = START_CURSOR; - const simplehashNetwork = chainsSimplehashNetwork[chainId as ChainId]; + const simplehashNetwork = useBackendNetworksStore.getState().getChainsSimplehashNetwork()[chainId as ChainId]; if (!simplehashNetwork) { logger.warn(`[simplehash]: no SimpleHash for chainId: ${chainId}`); @@ -83,7 +83,7 @@ export async function fetchSimpleHashNFTListing( * @param nft */ export async function refreshNFTContractMetadata(nft: UniqueAsset) { - const simplehashNetwork = chainsSimplehashNetwork[nft.isPoap ? ChainId.gnosis : nft.chainId]; + const simplehashNetwork = useBackendNetworksStore.getState().getChainsSimplehashNetwork()[nft.isPoap ? ChainId.gnosis : nft.chainId]; if (!simplehashNetwork) { logger.warn(`[simplehash]: no SimpleHash for chainId: ${nft.chainId}`); @@ -135,7 +135,7 @@ export async function refreshNFTContractMetadata(nft: UniqueAsset) { * @param nft */ export async function reportNFT(nft: UniqueAsset) { - const simplehashNetwork = chainsSimplehashNetwork[nft.isPoap ? ChainId.gnosis : nft.chainId]; + const simplehashNetwork = useBackendNetworksStore.getState().getChainsSimplehashNetwork()[nft.isPoap ? ChainId.gnosis : nft.chainId]; if (!simplehashNetwork) { logger.warn(`[simplehash]: no SimpleHash for chainId: ${nft.chainId}`); diff --git a/src/resources/nfts/simplehash/types.ts b/src/resources/nfts/simplehash/types.ts index 9c769c72e80..1aad59dba5b 100644 --- a/src/resources/nfts/simplehash/types.ts +++ b/src/resources/nfts/simplehash/types.ts @@ -1,4 +1,4 @@ -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; /** * @see https://docs.simplehash.com/reference/sale-model diff --git a/src/resources/nfts/simplehash/utils.ts b/src/resources/nfts/simplehash/utils.ts index ab3c0fc3f56..0c62afa97db 100644 --- a/src/resources/nfts/simplehash/utils.ts +++ b/src/resources/nfts/simplehash/utils.ts @@ -20,8 +20,8 @@ import { deviceUtils } from '@/utils'; import { TokenStandard } from '@/handlers/web3'; import { handleNFTImages } from '@/utils/handleNFTImages'; import { SimpleHashNft } from '@/graphql/__generated__/arc'; -import { Network } from '@/chains/types'; -import { chainsIdByName } from '@/chains'; +import { Network } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const ENS_COLLECTION_NAME = 'ENS'; const SVG_MIME_TYPE = 'image/svg+xml'; @@ -60,6 +60,8 @@ export function simpleHashNFTToUniqueAsset(nft: SimpleHashNft, address: string): const ownerEntry = nft.owners?.find(o => o.owner_address === address); + const chainsIdByName = useBackendNetworksStore.getState().getChainsIdByName(); + return { animation_url: nft?.video_url ?? nft.audio_url ?? nft.model_url ?? nft.extra_metadata?.animation_original_url ?? undefined, asset_contract: { diff --git a/src/resources/nfts/types.ts b/src/resources/nfts/types.ts index 88459dce3af..6f77ce7614d 100644 --- a/src/resources/nfts/types.ts +++ b/src/resources/nfts/types.ts @@ -1,5 +1,5 @@ import { Asset, AssetContract, AssetType } from '@/entities'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; import { UniqueTokenType } from '@/utils/uniqueTokens'; export enum NFTMarketplaceId { diff --git a/src/resources/nfts/utils.ts b/src/resources/nfts/utils.ts index 7b558cd849d..a8c806a4906 100644 --- a/src/resources/nfts/utils.ts +++ b/src/resources/nfts/utils.ts @@ -5,7 +5,7 @@ import { RainbowError, logger } from '@/logger'; import { handleSignificantDecimals } from '@/helpers/utilities'; import { IS_PROD } from '@/env'; import { RESERVOIR_API_KEY_DEV, RESERVOIR_API_KEY_PROD } from 'react-native-dotenv'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; const SUPPORTED_NETWORKS = [Network.mainnet, Network.polygon, Network.bsc, Network.arbitrum, Network.optimism, Network.base, Network.zora]; diff --git a/src/resources/reservoir/client.ts b/src/resources/reservoir/client.ts index cb3021e5258..43b74b03c1c 100644 --- a/src/resources/reservoir/client.ts +++ b/src/resources/reservoir/client.ts @@ -1,7 +1,7 @@ import { createClient } from '@reservoir0x/reservoir-sdk'; import { IS_PROD } from '@/env'; import { RESERVOIR_API_KEY_PROD, RESERVOIR_API_KEY_DEV } from 'react-native-dotenv'; -import { ChainId, Network } from '@/chains/types'; +import { ChainId, Network } from '@/state/backendNetworks/types'; const RESERVOIR_API_KEY = IS_PROD ? RESERVOIR_API_KEY_PROD : RESERVOIR_API_KEY_DEV; diff --git a/src/resources/reservoir/mints.ts b/src/resources/reservoir/mints.ts index 7f28aaca8cc..361786328b8 100644 --- a/src/resources/reservoir/mints.ts +++ b/src/resources/reservoir/mints.ts @@ -6,7 +6,7 @@ import { logger } from '@/logger'; import { WrappedAlert as Alert } from '@/helpers/alert'; import * as lang from '@/languages'; import { BigNumberish } from '@ethersproject/bignumber'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const showAlert = () => { Alert.alert( diff --git a/src/resources/reservoir/utils.ts b/src/resources/reservoir/utils.ts index 69145106e9d..e1991297161 100644 --- a/src/resources/reservoir/utils.ts +++ b/src/resources/reservoir/utils.ts @@ -1,4 +1,4 @@ -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const RAINBOW_FEE_ADDRESS_MAINNET = '0x69d6d375de8c7ade7e44446df97f49e661fdad7d'; const RAINBOW_FEE_ADDRESS_POLYGON = '0xfb9af3db5e19c4165f413f53fe3bbe6226834548'; diff --git a/src/resources/transactions/consolidatedTransactions.ts b/src/resources/transactions/consolidatedTransactions.ts index 616af75da8e..a749e2f72d0 100644 --- a/src/resources/transactions/consolidatedTransactions.ts +++ b/src/resources/transactions/consolidatedTransactions.ts @@ -5,7 +5,7 @@ import { RainbowError, logger } from '@/logger'; import { rainbowFetch } from '@/rainbow-fetch'; import { ADDYS_API_KEY } from 'react-native-dotenv'; import { parseTransaction } from '@/parsers/transactions'; -import { chainsIdByName, SUPPORTED_MAINNET_CHAIN_IDS } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const CONSOLIDATED_TRANSACTIONS_INTERVAL = 30000; const CONSOLIDATED_TRANSACTIONS_TIMEOUT = 20000; @@ -106,6 +106,8 @@ async function parseConsolidatedTransactions( ): Promise { const data = message?.payload?.transactions || []; + const chainsIdByName = useBackendNetworksStore.getState().getChainsIdByName(); + const parsedTransactionPromises = data.map((tx: TransactionApiResponse) => parseTransaction(tx, currency, chainsIdByName[tx.network])); // Filter out undefined values immediately @@ -125,7 +127,7 @@ export function useConsolidatedTransactions( consolidatedTransactionsQueryKey({ address, currency, - chainIds: SUPPORTED_MAINNET_CHAIN_IDS, + chainIds: useBackendNetworksStore.getState().getSupportedMainnetChainIds(), }), consolidatedTransactionsQueryFunction, { diff --git a/src/resources/transactions/transaction.ts b/src/resources/transactions/transaction.ts index a320b3d9eef..8280e63975d 100644 --- a/src/resources/transactions/transaction.ts +++ b/src/resources/transactions/transaction.ts @@ -7,8 +7,8 @@ import { rainbowFetch } from '@/rainbow-fetch'; import { ADDYS_API_KEY } from 'react-native-dotenv'; import { parseTransaction } from '@/parsers/transactions'; import { RainbowError, logger } from '@/logger'; -import { ChainId } from '@/chains/types'; -import { SUPPORTED_MAINNET_CHAIN_IDS } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export type ConsolidatedTransactionsResult = QueryFunctionResult; export type PaginatedTransactions = { pages: ConsolidatedTransactionsResult[] }; @@ -81,7 +81,7 @@ export function useBackendTransaction({ hash, chainId }: BackendTransactionArgs) const paginatedTransactionsKey = consolidatedTransactionsQueryKey({ address: accountAddress, currency: nativeCurrency, - chainIds: SUPPORTED_MAINNET_CHAIN_IDS, + chainIds: useBackendNetworksStore.getState().getSupportedMainnetChainIds(), }); const params: TransactionArgs = { diff --git a/src/resources/transactions/transactionSimulation.ts b/src/resources/transactions/transactionSimulation.ts index e9bb37df9ec..2f26fa2ec3e 100644 --- a/src/resources/transactions/transactionSimulation.ts +++ b/src/resources/transactions/transactionSimulation.ts @@ -5,7 +5,7 @@ import { metadataPOSTClient } from '@/graphql'; import { TransactionErrorType, TransactionScanResultType, TransactionSimulationResult } from '@/graphql/__generated__/metadataPOST'; import { isNil } from 'lodash'; import { RequestData } from '@/walletConnect/types'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; type SimulationArgs = { address: string; diff --git a/src/screens/AddCash/components/ProviderCard.tsx b/src/screens/AddCash/components/ProviderCard.tsx index 7ff2e135dae..9cc19003cd2 100644 --- a/src/screens/AddCash/components/ProviderCard.tsx +++ b/src/screens/AddCash/components/ProviderCard.tsx @@ -16,7 +16,7 @@ import { convertAPINetworkToInternalChainIds } from '@/screens/AddCash/utils'; import { ProviderConfig, CalloutType, PaymentMethod } from '@/screens/AddCash/types'; import * as i18n from '@/languages'; import { EthCoinIcon } from '@/components/coin-icon/EthCoinIcon'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; type PaymentMethodConfig = { name: string; diff --git a/src/screens/AddCash/utils.ts b/src/screens/AddCash/utils.ts index 1cc7a37c6f7..4d334137128 100644 --- a/src/screens/AddCash/utils.ts +++ b/src/screens/AddCash/utils.ts @@ -1,4 +1,4 @@ -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { Network as APINetwork } from '@/screens/AddCash/types'; export function convertAPINetworkToInternalChainIds(network: APINetwork): ChainId | undefined { diff --git a/src/screens/ENSConfirmRegisterSheet.tsx b/src/screens/ENSConfirmRegisterSheet.tsx index 600d160b929..2a1105933f4 100644 --- a/src/screens/ENSConfirmRegisterSheet.tsx +++ b/src/screens/ENSConfirmRegisterSheet.tsx @@ -39,7 +39,7 @@ import { usePersistentDominantColorFromImage } from '@/hooks/usePersistentDomina import { handleReviewPromptAction } from '@/utils/reviewAlert'; import { ReviewPromptAction } from '@/storage/schema'; import { ActionTypes } from '@/hooks/useENSRegistrationActionHandler'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; export const ENSConfirmRegisterSheetHeight = 600; export const ENSConfirmRenewSheetHeight = 560; diff --git a/src/screens/ExplainSheet.js b/src/screens/ExplainSheet.js index 281878962bf..bc46b4ea9c4 100644 --- a/src/screens/ExplainSheet.js +++ b/src/screens/ExplainSheet.js @@ -22,8 +22,8 @@ import { isL2Chain } from '@/handlers/web3'; import { IS_ANDROID } from '@/env'; import { EthCoinIcon } from '@/components/coin-icon/EthCoinIcon'; import RainbowCoinIcon from '@/components/coin-icon/RainbowCoinIcon'; -import { ChainId } from '@/chains/types'; -import { chainsLabel } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const { GAS_TRENDS } = gasUtils; export const ExplainSheetHeight = android ? 454 : 434; @@ -76,7 +76,7 @@ const SENDING_FUNDS_TO_CONTRACT = lang.t('explain.sending_to_contract.text'); const FLOOR_PRICE_EXPLAINER = lang.t('explain.floor_price.text'); const networkExplainer = ({ emoji = '⛽️', chainId, ...props }) => { - const chainName = chainsLabel[chainId]; + const chainName = useBackendNetworksStore.getState().getChainsLabel()[chainId]; let title = lang.t(`explain.default_network_explainer.title`, { chainName }); let text = lang.t(`explain.default_network_explainer.text`, { chainName }); @@ -107,6 +107,7 @@ const networkExplainer = ({ emoji = '⛽️', chainId, ...props }) => { const gasExplainer = network => lang.t('explain.gas.text', { networkName: network }); const availableNetworksExplainer = (tokenSymbol, chainIds) => { + const chainsLabel = useBackendNetworksStore.getState().getChainsLabel(); const readableNetworks = chainIds?.map(chainId => chainsLabel[chainId])?.join(', '); return lang.t('explain.available_networks.text', { @@ -171,6 +172,9 @@ export const explainers = (params, theme) => { const chainId = params?.chainId; const fromChainId = params?.fromChainId; const toChainId = params?.toChainId; + + const chainsLabel = useBackendNetworksStore.getState().getChainsLabel(); + return { op_rewards_airdrop_timing: { emoji: '📦', diff --git a/src/screens/MintsSheet/card/Card.tsx b/src/screens/MintsSheet/card/Card.tsx index c0317d7fc0f..a268ad94090 100644 --- a/src/screens/MintsSheet/card/Card.tsx +++ b/src/screens/MintsSheet/card/Card.tsx @@ -12,8 +12,8 @@ import * as i18n from '@/languages'; import ChainBadge from '@/components/coin-icon/ChainBadge'; import { navigateToMintCollection } from '@/resources/reservoir/mints'; import { EthCoinIcon } from '@/components/coin-icon/EthCoinIcon'; -import { ChainId } from '@/chains/types'; -import { chainsNativeAsset } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export const NUM_NFTS = 3; @@ -28,7 +28,7 @@ export function Card({ collection }: { collection: MintableCollection }) { const separatorTertiary = useForegroundColor('separatorTertiary'); const price = convertRawAmountToRoundedDecimal(collection.mintStatus.price, 18, 6); - const currencySymbol = chainsNativeAsset[collection.chainId].symbol; + const currencySymbol = useBackendNetworksStore.getState().getChainsNativeAsset()[collection.chainId].symbol; const isFree = !price; // update elapsed time every minute if it's less than an hour diff --git a/src/screens/NFTOffersSheet/OfferRow.tsx b/src/screens/NFTOffersSheet/OfferRow.tsx index 9707e780a89..7983c7edd33 100644 --- a/src/screens/NFTOffersSheet/OfferRow.tsx +++ b/src/screens/NFTOffersSheet/OfferRow.tsx @@ -14,11 +14,11 @@ import { CardSize } from '@/components/unique-token/CardSize'; import { View } from 'react-native'; import Svg, { Path } from 'react-native-svg'; import { useExternalToken } from '@/resources/assets/externalAssetsQuery'; -import { Network } from '@/chains/types'; +import { Network } from '@/state/backendNetworks/types'; import { useAccountSettings } from '@/hooks'; import RainbowCoinIcon from '@/components/coin-icon/RainbowCoinIcon'; import { AddressOrEth } from '@/__swaps__/types/assets'; -import { chainsIdByName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const NFT_SIZE = 50; const MARKETPLACE_ORB_SIZE = 18; @@ -99,7 +99,7 @@ export const OfferRow = ({ offer }: { offer: NftOffer }) => { const { colorMode } = useColorMode(); const theme = useTheme(); const bgColor = useBackgroundColor('surfaceSecondaryElevated'); - const chainId = chainsIdByName[offer.network as Network]; + const chainId = useBackendNetworksStore.getState().getChainsIdByName()[offer.network as Network]; const { data: externalAsset } = useExternalToken({ address: offer.paymentToken.address as AddressOrEth, chainId, diff --git a/src/screens/NFTSingleOfferSheet/index.tsx b/src/screens/NFTSingleOfferSheet/index.tsx index fec9ccad360..89dc64f2fa6 100644 --- a/src/screens/NFTSingleOfferSheet/index.tsx +++ b/src/screens/NFTSingleOfferSheet/index.tsx @@ -39,7 +39,7 @@ import { createWalletClient, http } from 'viem'; import { RainbowError, logger } from '@/logger'; import { useTheme } from '@/theme'; -import { Network, ChainId } from '@/chains/types'; +import { Network, ChainId } from '@/state/backendNetworks/types'; import { CardSize } from '@/components/unique-token/CardSize'; import { queryClient } from '@/react-query'; import { nftOffersQueryKey } from '@/resources/reservoir/nftOffersQuery'; @@ -48,11 +48,11 @@ import { useExternalToken } from '@/resources/assets/externalAssetsQuery'; import RainbowCoinIcon from '@/components/coin-icon/RainbowCoinIcon'; import { addNewTransaction } from '@/state/pendingTransactions'; import { getUniqueId } from '@/utils/ethereumUtils'; -import { chainsIdByName, chainsNativeAsset, defaultChains, getChainDefaultRpc } from '@/chains'; import { getNextNonce } from '@/state/nonces'; import { metadataPOSTClient } from '@/graphql'; import { ethUnits } from '@/references'; import { Transaction } from '@/graphql/__generated__/metadataPOST'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const NFT_IMAGE_HEIGHT = 160; const TWO_HOURS_MS = 2 * 60 * 60 * 1000; @@ -94,7 +94,7 @@ export function NFTSingleOfferSheet() { } = useLegacyNFTs({ address: accountAddress }); const { offer } = params as { offer: NftOffer }; - const offerChainId = chainsIdByName[offer.network as Network]; + const offerChainId = useBackendNetworksStore.getState().getChainsIdByName()[offer.network as Network]; const { data: externalAsset } = useExternalToken({ address: offer.paymentToken.address, chainId: offerChainId, @@ -164,8 +164,6 @@ export function NFTSingleOfferSheet() { const feesPercentage = Math.floor(offer.feesPercentage * 10) / 10; const royaltiesPercentage = Math.floor(offer.royaltiesPercentage * 10) / 10; - const chain = defaultChains[offerChainId]; - useEffect(() => { setParams({ longFormHeight: height }); }, [height, setParams]); @@ -184,8 +182,8 @@ export function NFTSingleOfferSheet() { const signer = createWalletClient({ // @ts-ignore account: accountAddress, - chain, - transport: http(getChainDefaultRpc(offerChainId)), + chain: useBackendNetworksStore.getState().getDefaultChains()[offerChainId], + transport: http(useBackendNetworksStore.getState().getChainDefaultRpc(offerChainId)), }); getClient()?.actions.acceptOffer({ items: [ @@ -243,7 +241,7 @@ export function NFTSingleOfferSheet() { } catch { logger.error(new RainbowError('[NFTSingleOfferSheet]: Failed to estimate gas')); } - }, [accountAddress, feeParam, offerChainId, offer, updateTxFee]); + }, [accountAddress, feeParam, offer.nft.contractAddress, offer.nft.tokenId, offerChainId, updateTxFee]); // estimate gas useEffect(() => { @@ -254,7 +252,7 @@ export function NFTSingleOfferSheet() { return () => { stopPollingGasFees(); }; - }, [estimateGas, isExpired, isReadOnlyWallet, offer.network, offerChainId, startPollingGasFees, stopPollingGasFees, updateTxFee]); + }, [estimateGas, isExpired, isReadOnlyWallet, offerChainId, startPollingGasFees, stopPollingGasFees]); const acceptOffer = useCallback(async () => { logger.debug(`[NFTSingleOfferSheet]: Initiating sale of NFT ${offer.nft.contractAddress}:${offer.nft.tokenId}`); @@ -284,8 +282,8 @@ export function NFTSingleOfferSheet() { const signer = createWalletClient({ account, - chain, - transport: http(getChainDefaultRpc(offerChainId)), + chain: useBackendNetworksStore.getState().getDefaultChains()[offerChainId], + transport: http(useBackendNetworksStore.getState().getChainDefaultRpc(offerChainId)), }); const nonce = await getNextNonce({ address: accountAddress, chainId: offerChainId }); try { @@ -425,13 +423,13 @@ export function NFTSingleOfferSheet() { } finally { setIsAccepting(false); } - }, [offer, rainbowFeeDecimal, accountAddress, chain, offerChainId, feeParam, navigate, nft]); + }, [offer, rainbowFeeDecimal, accountAddress, offerChainId, feeParam, navigate, nft]); let buttonLabel = ''; if (!isAccepting) { if (insufficientEth) { buttonLabel = lang.t('button.confirm_exchange.insufficient_token', { - tokenName: chainsNativeAsset[offerChainId].symbol, + tokenName: useBackendNetworksStore.getState().getChainsNativeAsset()[offerChainId].symbol, }); } else { buttonLabel = i18n.t(i18n.l.nft_offers.single_offer_sheet.hold_to_sell); diff --git a/src/screens/SendConfirmationSheet.tsx b/src/screens/SendConfirmationSheet.tsx index 6edead99ea4..b150c5cbe9a 100644 --- a/src/screens/SendConfirmationSheet.tsx +++ b/src/screens/SendConfirmationSheet.tsx @@ -61,8 +61,8 @@ import { IS_ANDROID, IS_IOS } from '@/env'; import { useConsolidatedTransactions } from '@/resources/transactions/consolidatedTransactions'; import RainbowCoinIcon from '@/components/coin-icon/RainbowCoinIcon'; import { performanceTracking, TimeToSignOperation, Screens } from '@/state/performance/performance'; -import { ChainId } from '@/chains/types'; -import { chainsLabel } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const Container = styled(Centered).attrs({ direction: 'column', @@ -133,7 +133,7 @@ export function getDefaultCheckboxes({ checked: false, id: 'has-wallet-that-supports', label: lang.t('wallet.transaction.checkboxes.has_a_wallet_that_supports', { - networkName: chainsLabel[chainId], + networkName: useBackendNetworksStore.getState().getChainsLabel()[chainId], }), }, ]; @@ -602,7 +602,7 @@ export const SendConfirmationSheet = () => { onPress={handleL2DisclaimerPress} prominent customText={i18n.t(i18n.l.expanded_state.asset.l2_disclaimer_send, { - network: chainsLabel[asset.chainId], + network: useBackendNetworksStore.getState().getChainsLabel()[asset.chainId], })} symbol={asset.symbol} /> diff --git a/src/screens/SendSheet.tsx b/src/screens/SendSheet.tsx index eca3f922fa2..1369c2ec051 100644 --- a/src/screens/SendSheet.tsx +++ b/src/screens/SendSheet.tsx @@ -63,8 +63,8 @@ import { getNextNonce } from '@/state/nonces'; import { usePersistentDominantColorFromImage } from '@/hooks/usePersistentDominantColorFromImage'; import { performanceTracking, Screens, TimeToSignOperation } from '@/state/performance/performance'; import { REGISTRATION_STEPS } from '@/helpers/ens'; -import { ChainId } from '@/chains/types'; -import { chainsName, chainsNativeAsset, needsL1SecurityFeeChains } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { RootStackParamList } from '@/navigation/types'; import { ThemeContextProps, useTheme } from '@/theme'; import { StaticJsonRpcProvider } from '@ethersproject/providers'; @@ -418,7 +418,7 @@ export default function SendSheet() { }); if (!wallet) return; - const currentChainIdNetwork = chainsName[currentChainId ?? ChainId.mainnet]; + const currentChainIdNetwork = useBackendNetworksStore.getState().getChainsName()[currentChainId ?? ChainId.mainnet]; const validTransaction = isValidAddress && amountDetails.isSufficientBalance && isSufficientGas && isValidGas; if (!selectedGasFee?.gasFee?.estimatedFee || !validTransaction) { @@ -450,7 +450,7 @@ export default function SendSheet() { ); if (updatedGasLimit && !lessThan(updatedGasLimit, gasLimit)) { - if (needsL1SecurityFeeChains.includes(currentChainId)) { + if (useBackendNetworksStore.getState().getNeedsL1SecurityFeeChains().includes(currentChainId)) { updateTxFeeForOptimism(updatedGasLimit); } else { updateTxFee(updatedGasLimit, null); @@ -672,14 +672,14 @@ export default function SendSheet() { !selectedGasFee || isEmpty(selectedGasFee?.gasFee) || !toAddress || - (needsL1SecurityFeeChains.includes(currentChainId) && l1GasFeeOptimism === null) + (useBackendNetworksStore.getState().getNeedsL1SecurityFeeChains().includes(currentChainId) && l1GasFeeOptimism === null) ) { label = lang.t('button.confirm_exchange.loading'); disabled = true; } else if (!isZeroAssetAmount && !isSufficientGas) { disabled = true; label = lang.t('button.confirm_exchange.insufficient_token', { - tokenName: chainsNativeAsset[currentChainId || ChainId.mainnet].symbol, + tokenName: useBackendNetworksStore.getState().getChainsNativeAsset()[currentChainId || ChainId.mainnet].symbol, }); } else if (!isValidGas) { disabled = true; @@ -856,7 +856,7 @@ export default function SendSheet() { currentChainId ) .then(async gasLimit => { - if (gasLimit && needsL1SecurityFeeChains.includes(currentChainId)) { + if (gasLimit && useBackendNetworksStore.getState().getNeedsL1SecurityFeeChains().includes(currentChainId)) { updateTxFeeForOptimism(gasLimit); } else { updateTxFee(gasLimit, null); diff --git a/src/screens/SettingsSheet/components/CurrencySection.tsx b/src/screens/SettingsSheet/components/CurrencySection.tsx index 337d3cd4c47..c523cebb00c 100644 --- a/src/screens/SettingsSheet/components/CurrencySection.tsx +++ b/src/screens/SettingsSheet/components/CurrencySection.tsx @@ -10,7 +10,7 @@ import { ETH_ADDRESS, WBTC_ADDRESS, emojis, supportedNativeCurrencies } from '@/ import { useExternalToken } from '@/resources/assets/externalAssetsQuery'; import RainbowCoinIcon from '@/components/coin-icon/RainbowCoinIcon'; import { useTheme } from '@/theme'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const emojiData = Object.entries(emojis).map(([emoji, { name }]) => [name, emoji]); diff --git a/src/screens/SettingsSheet/components/NetworkSection.tsx b/src/screens/SettingsSheet/components/NetworkSection.tsx index df337be22ec..fb3ead755fe 100644 --- a/src/screens/SettingsSheet/components/NetworkSection.tsx +++ b/src/screens/SettingsSheet/components/NetworkSection.tsx @@ -8,8 +8,8 @@ import { analytics } from '@/analytics'; import { Separator, Stack } from '@/design-system'; import { useAccountSettings, useLoadAccountData } from '@/hooks'; import { settingsUpdateNetwork } from '@/redux/settings'; -import { ChainId } from '@/chains/types'; -import { defaultChains } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { isL2Chain } from '@/handlers/web3'; interface NetworkSectionProps { @@ -33,7 +33,7 @@ const NetworkSection = ({ inDevSection }: NetworkSectionProps) => { ); const renderNetworkList = useCallback(() => { - return Object.values(defaultChains) + return Object.values(useBackendNetworksStore.getState().getDefaultChains()) .filter(({ id }) => !isL2Chain({ chainId: id })) .map(({ name, id, testnet }) => ( { } catch (e) { logger.error(new RainbowError(`[SignTransactionSheet]: Error while ${sendInsteadOfSign ? 'sending' : 'signing'} transaction`)); } + const chainsName = useBackendNetworksStore.getState().getChainsName(); if (response?.result) { const signResult = response.result as string; @@ -519,7 +520,7 @@ export const SignTransactionSheet = () => { dappName: transactionDetails?.dappName, dappUrl: transactionDetails?.dappUrl, isHardwareWallet: accountInfo.isHardwareWallet, - network: chainsName[chainId] as Network, + network: useBackendNetworksStore.getState().getChainsName()[chainId] as Network, }); onSuccessCallback?.(response.result); @@ -707,7 +708,7 @@ export const SignTransactionSheet = () => { {`${walletBalance?.display} ${i18n.t(i18n.l.walletconnect.simulation.profile_section.on_network, { - network: defaultChains[chainId]?.name, + network: useBackendNetworksStore.getState().getChainsName()[chainId], })}`} diff --git a/src/screens/SpeedUpAndCancelSheet.tsx b/src/screens/SpeedUpAndCancelSheet.tsx index 8fda0f1441a..181a86843bc 100644 --- a/src/screens/SpeedUpAndCancelSheet.tsx +++ b/src/screens/SpeedUpAndCancelSheet.tsx @@ -30,8 +30,8 @@ import { gasUtils, safeAreaInsetValues } from '@/utils'; import * as i18n from '@/languages'; import { updateTransaction } from '@/state/pendingTransactions'; import { logger, RainbowError } from '@/logger'; -import { supportedFlashbotsChainIds } from '@/chains'; -import { ChainId } from '@/chains/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; +import { ChainId } from '@/state/backendNetworks/types'; import { ThemeContextProps, useTheme } from '@/theme'; import { BigNumberish } from '@ethersproject/bignumber'; import { RootStackParamList } from '@/navigation/types'; @@ -313,7 +313,7 @@ export default function SpeedUpAndCancelSheet() { if (currentChainId) { startPollingGasFees(currentChainId, tx.flashbots); let provider; - if (supportedFlashbotsChainIds.includes(tx.chainId || ChainId.mainnet) && tx.flashbots) { + if (useBackendNetworksStore.getState().getFlashbotsSupportedChainIds().includes(tx.chainId || ChainId.mainnet) && tx.flashbots) { logger.debug(`[SpeedUpAndCancelSheet]: using flashbots provider for chainId ${tx?.chainId}`); provider = getFlashbotsProvider(); } else { diff --git a/src/screens/WalletConnectApprovalSheet.tsx b/src/screens/WalletConnectApprovalSheet.tsx index 9c3ff6295cf..e979e6f3ed3 100644 --- a/src/screens/WalletConnectApprovalSheet.tsx +++ b/src/screens/WalletConnectApprovalSheet.tsx @@ -29,8 +29,8 @@ import { DAppStatus } from '@/graphql/__generated__/metadata'; import { InfoAlert } from '@/components/info-alert/info-alert'; import { EthCoinIcon } from '@/components/coin-icon/EthCoinIcon'; import { findWalletWithAccount } from '@/helpers/findWalletWithAccount'; -import { ChainId } from '@/chains/types'; -import { chainsLabel, chainsNativeAsset, defaultChains } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { ThemeContextProps, useTheme } from '@/theme'; import { noop } from 'lodash'; import { RootStackParamList } from '@/navigation/types'; @@ -132,7 +132,7 @@ const NetworkPill = ({ chainIds }: { chainIds: ChainId[] }) => { - {chainsLabel[availableNetworkChainIds[0]]} + {useBackendNetworksStore.getState().getChainsLabel()[availableNetworkChainIds[0]]} @@ -229,8 +229,8 @@ export function WalletConnectApprovalSheet() { * v2. */ const approvalNetworkInfo = useMemo(() => { - const chain = defaultChains[approvalChainId || ChainId.mainnet]; - const nativeAsset = chainsNativeAsset[chain.id]; + const chain = useBackendNetworksStore.getState().getDefaultChains()[approvalChainId || ChainId.mainnet]; + const nativeAsset = useBackendNetworksStore.getState().getChainsNativeAsset()[chain.id]; return { chainId: chain.id, color: isDarkMode ? nativeAsset.colors.primary : nativeAsset.colors.fallback || nativeAsset.colors.primary, @@ -365,7 +365,9 @@ export function WalletConnectApprovalSheet() { {`${ - type === WalletConnectApprovalSheetType.connect ? approvalNetworkInfo.name : chainsLabel[chainId] + type === WalletConnectApprovalSheetType.connect + ? approvalNetworkInfo.name + : useBackendNetworksStore.getState().getChainsLabel()[chainId] } ${type === WalletConnectApprovalSheetType.connect && menuItems.length > 1 ? '􀁰' : ''}`} @@ -406,7 +408,7 @@ export function WalletConnectApprovalSheet() { {type === WalletConnectApprovalSheetType.connect ? lang.t(lang.l.walletconnect.wants_to_connect) : lang.t(lang.l.walletconnect.wants_to_connect_to_network, { - network: chainsLabel[chainId], + network: useBackendNetworksStore.getState().getChainsLabel()[chainId], })} diff --git a/src/screens/claimables/ClaimingClaimableSharedUI.tsx b/src/screens/claimables/ClaimingClaimableSharedUI.tsx index c4911e0e573..6d3ef2290e8 100644 --- a/src/screens/claimables/ClaimingClaimableSharedUI.tsx +++ b/src/screens/claimables/ClaimingClaimableSharedUI.tsx @@ -10,7 +10,7 @@ import { SponsoredClaimable, TransactionClaimable } from '@/resources/addys/clai import RainbowCoinIcon from '@/components/coin-icon/RainbowCoinIcon'; import { useTheme } from '@/theme'; import { FasterImageView } from '@candlefinance/faster-image'; -import { chainsLabel } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { useNavigation } from '@/navigation'; import { TextColor } from '@/design-system/color/palettes'; import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated'; @@ -262,7 +262,7 @@ export const ClaimingClaimableSharedUI = ({ {i18n.t(i18n.l.claimables.panel.amount_to_claim_on_network, { amount: nativeCurrencyGasFeeDisplay, - network: chainsLabel[claimable.chainId], + network: useBackendNetworksStore.getState().getChainsLabel()[claimable.chainId], })} diff --git a/src/screens/claimables/ClaimingTransactionClaimable.tsx b/src/screens/claimables/ClaimingTransactionClaimable.tsx index cc3d5eaa85d..ac0adea0a73 100644 --- a/src/screens/claimables/ClaimingTransactionClaimable.tsx +++ b/src/screens/claimables/ClaimingTransactionClaimable.tsx @@ -5,7 +5,7 @@ import { Claimable, TransactionClaimable } from '@/resources/addys/claimables/ty import { estimateGasWithPadding, getProvider } from '@/handlers/web3'; import { parseGasParamsForTransaction } from '@/parsers'; import { getNextNonce } from '@/state/nonces'; -import { needsL1SecurityFeeChains } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { logger, RainbowError } from '@/logger'; import { ClaimingClaimableSharedUI, ClaimStatus } from './ClaimingClaimableSharedUI'; import { TransactionRequest } from '@ethersproject/providers'; @@ -108,7 +108,7 @@ export const ClaimingTransactionClaimable = ({ claimable }: { claimable: Transac return; } - if (needsL1SecurityFeeChains.includes(claimable.chainId)) { + if (useBackendNetworksStore.getState().getNeedsL1SecurityFeeChains().includes(claimable.chainId)) { const l1SecurityFee = await ethereumUtils.calculateL1FeeOptimism( { to: claimable.action.to, diff --git a/src/screens/discover/components/DiscoverSearch.tsx b/src/screens/discover/components/DiscoverSearch.tsx index 2e5880d7d35..1eacade9724 100644 --- a/src/screens/discover/components/DiscoverSearch.tsx +++ b/src/screens/discover/components/DiscoverSearch.tsx @@ -18,13 +18,13 @@ import { ethereumUtils, safeAreaInsetValues } from '@/utils'; import { getPoapAndOpenSheetWithQRHash, getPoapAndOpenSheetWithSecretWord } from '@/utils/poaps'; import { navigateToMintCollection } from '@/resources/reservoir/mints'; import { TAB_BAR_HEIGHT } from '@/navigation/SwipeNavigator'; -import { ChainId, Network } from '@/chains/types'; -import { chainsIdByName } from '@/chains'; import { navbarHeight } from '@/components/navbar/Navbar'; import { IS_TEST } from '@/env'; import { uniqBy } from 'lodash'; import { useTheme } from '@/theme'; import { EnrichedExchangeAsset } from '@/components/ExchangeAssetList'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; +import { ChainId, Network } from '@/state/backendNetworks/types'; export const SearchContainer = styled(Row)({ height: '100%', @@ -71,7 +71,7 @@ export default function DiscoverSearch() { const lastSearchQuery = usePrevious(searchQueryForSearch); const [ensResults, setEnsResults] = useState([]); - const { swapCurrencyList, swapCurrencyListLoading } = useSearchCurrencyList(searchQueryForSearch, ChainId.mainnet, true); + const { swapCurrencyList, swapCurrencyListLoading } = useSearchCurrencyList(searchQueryForSearch, ChainId.mainnet); const profilesEnabled = useExperimentalFlag(PROFILES); const marginBottom = TAB_BAR_HEIGHT + safeAreaInsetValues.bottom + 16; @@ -148,7 +148,7 @@ export default function DiscoverSearch() { const mintdotfunURL = seachQueryForMint.split('https://mint.fun/'); const query = mintdotfunURL[1]; const [networkName] = query.split('/'); - let chainId = chainsIdByName[networkName]; + let chainId = useBackendNetworksStore.getState().getChainsIdByName()[networkName]; if (!chainId) { switch (networkName) { case 'op': diff --git a/src/screens/discover/components/DiscoverSearchInput.tsx b/src/screens/discover/components/DiscoverSearchInput.tsx index e03716fa877..2d21419dbd5 100644 --- a/src/screens/discover/components/DiscoverSearchInput.tsx +++ b/src/screens/discover/components/DiscoverSearchInput.tsx @@ -12,10 +12,10 @@ import { ImgixImage } from '@/components/images'; import styled from '@/styled-thing'; import { margin, padding } from '@/styles'; import { deviceUtils } from '@/utils'; -import { chainsName } from '@/chains'; import { ThemeContextProps } from '@/theme'; -import { ChainId } from '@/chains/types'; import { useDiscoverScreenContext } from '@/screens/discover/DiscoverScreenContext'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; +import { ChainId } from '@/state/backendNetworks/types'; const SearchHeight = 40; const SearchWidth = deviceUtils.dimensions.width - 30; @@ -151,7 +151,7 @@ const DiscoverSearchInput = ({ const placeholder = useMemo(() => { if (!currentChainId) return placeholderText; return lang.t('button.exchange_search_placeholder_network', { - network: chainsName[currentChainId], + network: useBackendNetworksStore.getState().getChainsName()[currentChainId], }); }, [currentChainId, placeholderText]); diff --git a/src/screens/mints/MintSheet.tsx b/src/screens/mints/MintSheet.tsx index 5060821490e..d78217c93c8 100644 --- a/src/screens/mints/MintSheet.tsx +++ b/src/screens/mints/MintSheet.tsx @@ -52,11 +52,11 @@ import { IS_ANDROID, IS_IOS } from '@/env'; import { EthCoinIcon } from '@/components/coin-icon/EthCoinIcon'; import { addNewTransaction } from '@/state/pendingTransactions'; import { getUniqueId } from '@/utils/ethereumUtils'; -import { chainsName, defaultChains, getChainDefaultRpc } from '@/chains'; import { getNextNonce } from '@/state/nonces'; import { metadataPOSTClient } from '@/graphql'; import { Transaction } from '@/graphql/__generated__/metadataPOST'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; const NFT_IMAGE_HEIGHT = 250; // inset * 2 -> 28 *2 @@ -252,10 +252,11 @@ const MintSheet = () => { // estimate gas limit useEffect(() => { const estimateMintGas = async () => { + const defaultChains = useBackendNetworksStore.getState().getDefaultChains(); const signer = createWalletClient({ account: accountAddress, chain: defaultChains[chainId], - transport: http(getChainDefaultRpc(chainId)), + transport: http(useBackendNetworksStore.getState().getChainDefaultRpc(chainId)), }); try { await getClient()?.actions.mintToken({ @@ -360,11 +361,11 @@ const MintSheet = () => { const privateKey = await loadPrivateKey(accountAddress, false); // @ts-ignore const account = privateKeyToAccount(privateKey); - const chain = defaultChains[chainId]; + const chain = useBackendNetworksStore.getState().getDefaultChains()[chainId]; const signer = createWalletClient({ account, chain, - transport: http(getChainDefaultRpc(chainId)), + transport: http(useBackendNetworksStore.getState().getChainDefaultRpc(chainId)), }); const feeAddress = getRainbowFeeAddress(chainId); @@ -381,6 +382,7 @@ const MintSheet = () => { wallet: signer!, chainId, onProgress: (steps: Execute['steps']) => { + const chainsName = useBackendNetworksStore.getState().getChainsName(); steps.forEach(step => { if (step.error) { logger.error(new RainbowError(`[MintSheet]: Error minting NFT: ${step.error}`)); @@ -708,7 +710,7 @@ const MintSheet = () => { )} - {`${defaultChains[chainId].name}`} + {`${useBackendNetworksStore.getState().getDefaultChains()[chainId].name}`} diff --git a/src/screens/points/claim-flow/ClaimRewardsPanel.tsx b/src/screens/points/claim-flow/ClaimRewardsPanel.tsx index d39b3619b3c..3332490cd23 100644 --- a/src/screens/points/claim-flow/ClaimRewardsPanel.tsx +++ b/src/screens/points/claim-flow/ClaimRewardsPanel.tsx @@ -5,7 +5,7 @@ import { Bleed, Box, Text, TextShadow, globalColors, useBackgroundColor, useColo import * as i18n from '@/languages'; import { ListHeader, ListPanel, Panel, TapToDismiss, controlPanelStyles } from '@/components/SmoothPager/ListPanel'; import { ChainImage } from '@/components/coin-icon/ChainImage'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import ethereumUtils, { useNativeAsset } from '@/utils/ethereumUtils'; import { useAccountAccentColor, useAccountProfile, useAccountSettings } from '@/hooks'; import { safeAreaInsetValues } from '@/utils'; @@ -34,7 +34,7 @@ import { useMeteorologySuggestions } from '@/__swaps__/utils/meteorology'; import { AnimatedSpinner } from '@/components/animations/AnimatedSpinner'; import { RainbowError, logger } from '@/logger'; import { RewardsActionButton } from '../components/RewardsActionButton'; -import { chainsLabel, chainsName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; type ClaimStatus = 'idle' | 'claiming' | 'success' | PointsErrorType | 'error' | 'bridge-error'; type ClaimNetwork = '10' | '8453' | '7777777'; @@ -93,7 +93,7 @@ export const ClaimRewardsPanel = () => { const NETWORK_LIST_ITEMS = CLAIM_NETWORKS.map(chainId => { return { IconComponent: , - label: chainsLabel[chainId], + label: useBackendNetworksStore.getState().getChainsLabel()[chainId], uniqueId: chainId.toString(), selected: false, }; @@ -209,6 +209,7 @@ const ClaimingRewards = ({ nonce: number | null; }>({ mutationFn: async () => { + const chainsName = useBackendNetworksStore.getState().getChainsName(); // Fetch the native asset from the origin chain const opEth_ = await ethereumUtils.getNativeAssetForNetwork({ chainId: ChainId.optimism }); const opEth = { @@ -337,6 +338,7 @@ const ClaimingRewards = ({ }, [claimStatus]); const panelTitle = useMemo(() => { + const chainsLabel = useBackendNetworksStore.getState().getChainsLabel(); switch (claimStatus) { case 'idle': return i18n.t(i18n.l.points.points.claim_on_network, { @@ -494,7 +496,7 @@ const ClaimingRewards = ({ {i18n.t(i18n.l.points.points.bridge_error_explainer, { - network: chainId ? chainsLabel[chainId] : '', + network: chainId ? useBackendNetworksStore.getState().getChainsLabel()[chainId] : '', })} diff --git a/src/screens/points/components/LeaderboardRow.tsx b/src/screens/points/components/LeaderboardRow.tsx index 8d2d451ba3e..fff29344f13 100644 --- a/src/screens/points/components/LeaderboardRow.tsx +++ b/src/screens/points/components/LeaderboardRow.tsx @@ -18,7 +18,7 @@ import { useTheme } from '@/theme'; import LinearGradient from 'react-native-linear-gradient'; import { ButtonPressAnimation } from '@/components/animations'; import { noop } from 'lodash'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const ACTIONS = { ADD_CONTACT: 'add-contact', diff --git a/src/screens/points/content/PointsContent.tsx b/src/screens/points/content/PointsContent.tsx index 220ce06a933..83e9a84e2b1 100644 --- a/src/screens/points/content/PointsContent.tsx +++ b/src/screens/points/content/PointsContent.tsx @@ -62,7 +62,7 @@ import { format, intervalToDuration, isToday } from 'date-fns'; import { useRemoteConfig } from '@/model/remoteConfig'; import { ETH_REWARDS, useExperimentalFlag } from '@/config'; import { RewardsActionButton } from '../components/RewardsActionButton'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const InfoCards = ({ points }: { points: GetPointsDataForWalletQuery | undefined }) => { const labelSecondary = useForegroundColor('labelSecondary'); diff --git a/src/screens/points/contexts/PointsProfileContext.tsx b/src/screens/points/contexts/PointsProfileContext.tsx index d54395db617..543062caec5 100644 --- a/src/screens/points/contexts/PointsProfileContext.tsx +++ b/src/screens/points/contexts/PointsProfileContext.tsx @@ -16,7 +16,7 @@ import { useNavigation } from '@/navigation'; import { getProvider } from '@/handlers/web3'; import { analyticsV2 } from '@/analytics'; import { delay } from '@/utils/delay'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; type PointsProfileContext = { step: RainbowPointsFlowSteps; diff --git a/src/screens/positions/SubPositionListItem.tsx b/src/screens/positions/SubPositionListItem.tsx index d4708f43517..78c5527763d 100644 --- a/src/screens/positions/SubPositionListItem.tsx +++ b/src/screens/positions/SubPositionListItem.tsx @@ -10,7 +10,7 @@ import { NativeDisplay, PositionAsset } from '@/resources/defi/types'; import { useExternalToken } from '@/resources/assets/externalAssetsQuery'; import { useAccountSettings } from '@/hooks'; import RainbowCoinIcon from '@/components/coin-icon/RainbowCoinIcon'; -import { chainsIdByName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; type Props = { asset: PositionAsset; @@ -23,7 +23,7 @@ type Props = { export const SubPositionListItem: React.FC = ({ asset, apy, quantity, native, positionColor }) => { const theme = useTheme(); const { nativeCurrency } = useAccountSettings(); - const chainId = chainsIdByName[asset.network]; + const chainId = useBackendNetworksStore.getState().getChainsIdByName()[asset.network]; const { data: externalAsset } = useExternalToken({ address: asset.asset_code, chainId, currency: nativeCurrency }); const priceChangeColor = (asset.price?.relative_change_24h || 0) < 0 ? theme.colors.blueGreyDark60 : theme.colors.green; diff --git a/src/screens/transaction-details/components/TransactionDetailsValueAndFeeSection.tsx b/src/screens/transaction-details/components/TransactionDetailsValueAndFeeSection.tsx index c6993a28b6d..dfde595df20 100644 --- a/src/screens/transaction-details/components/TransactionDetailsValueAndFeeSection.tsx +++ b/src/screens/transaction-details/components/TransactionDetailsValueAndFeeSection.tsx @@ -15,7 +15,7 @@ import ImgixImage from '@/components/images/ImgixImage'; import { View } from 'react-native'; import ChainBadge from '@/components/coin-icon/ChainBadge'; import { checkForPendingSwap } from '@/helpers/checkForPendingSwap'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; type Props = { transaction: RainbowTransaction; diff --git a/src/screens/transaction-details/components/TransactionMasthead.tsx b/src/screens/transaction-details/components/TransactionMasthead.tsx index f431fd0e3ea..0de04d2616a 100644 --- a/src/screens/transaction-details/components/TransactionMasthead.tsx +++ b/src/screens/transaction-details/components/TransactionMasthead.tsx @@ -34,7 +34,7 @@ import ImageAvatar from '@/components/contacts/ImageAvatar'; import RainbowCoinIcon from '@/components/coin-icon/RainbowCoinIcon'; import * as lang from '@/languages'; import { checkForPendingSwap } from '@/helpers/checkForPendingSwap'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const TransactionMastheadHeight = android ? 153 : 135; diff --git a/src/state/appSessions/index.test.ts b/src/state/appSessions/index.test.ts index 71ca5d15697..2cfd0c8399a 100644 --- a/src/state/appSessions/index.test.ts +++ b/src/state/appSessions/index.test.ts @@ -1,4 +1,4 @@ -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { useAppSessionsStore } from '.'; const UNISWAP_HOST = 'uniswap.org'; diff --git a/src/state/appSessions/index.ts b/src/state/appSessions/index.ts index 02128c94c47..ee5400779ca 100644 --- a/src/state/appSessions/index.ts +++ b/src/state/appSessions/index.ts @@ -1,6 +1,6 @@ import { Address } from 'viem'; -import { Network, ChainId } from '@/chains/types'; +import { Network, ChainId } from '@/state/backendNetworks/types'; import { createRainbowStore } from '../internal/createRainbowStore'; const chainsIdByNetwork: Record = { diff --git a/src/state/assets/userAssets.ts b/src/state/assets/userAssets.ts index 35548509b29..2109601e25d 100644 --- a/src/state/assets/userAssets.ts +++ b/src/state/assets/userAssets.ts @@ -6,8 +6,8 @@ import { supportedNativeCurrencies } from '@/references'; import { createRainbowStore } from '@/state/internal/createRainbowStore'; import { useStore } from 'zustand'; import { swapsStore } from '@/state/swaps/swapsStore'; -import { ChainId } from '@/chains/types'; -import { SUPPORTED_CHAIN_IDS } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { useSelector } from 'react-redux'; const SEARCH_CACHE_MAX_ENTRIES = 50; @@ -19,7 +19,7 @@ const getDefaultCacheKeys = (): Set => { const queryKeysToPreserve = new Set(); queryKeysToPreserve.add('all'); - for (const chainId of SUPPORTED_CHAIN_IDS) { + for (const chainId of useBackendNetworksStore.getState().getSupportedChainIds()) { queryKeysToPreserve.add(`${chainId}`); } return queryKeysToPreserve; @@ -317,12 +317,15 @@ export const createUserAssetsStore = (address: Address | string) => }); // Ensure all supported chains are in the map with a fallback value of 0 - SUPPORTED_CHAIN_IDS.forEach(chainId => { - if (!unsortedChainBalances.has(chainId)) { - unsortedChainBalances.set(chainId, 0); - idsByChain.set(chainId, []); - } - }); + useBackendNetworksStore + .getState() + .getSupportedChainIds() + .forEach(chainId => { + if (!unsortedChainBalances.has(chainId)) { + unsortedChainBalances.set(chainId, 0); + idsByChain.set(chainId, []); + } + }); // Sort the existing map by balance in descending order const sortedEntries = Array.from(unsortedChainBalances.entries()).sort(([, balanceA], [, balanceB]) => balanceB - balanceA); diff --git a/src/state/backendNetworks/backendNetworks.ts b/src/state/backendNetworks/backendNetworks.ts new file mode 100644 index 00000000000..e656c780bd5 --- /dev/null +++ b/src/state/backendNetworks/backendNetworks.ts @@ -0,0 +1,623 @@ +import { makeMutable, SharedValue } from 'react-native-reanimated'; +import { queryClient } from '@/react-query'; +import buildTimeNetworks from '@/references/networks.json'; +import { backendNetworksQueryKey, BackendNetworksResponse } from '@/resources/metadata/backendNetworks'; +import { createRainbowStore } from '@/state/internal/createRainbowStore'; +import { Chain } from 'viem/chains'; +import { transformBackendNetworksToChains } from '@/state/backendNetworks/utils'; +import { IS_TEST } from '@/env'; +import { BackendNetwork, BackendNetworkServices, chainHardhat, chainHardhatOptimism, ChainId } from '@/state/backendNetworks/types'; +import { GasSpeed } from '@/__swaps__/types/gas'; +import { useConnectedToHardhatStore } from '@/state/connectedToHardhat'; + +const INITIAL_BACKEND_NETWORKS = queryClient.getQueryData(backendNetworksQueryKey()) ?? buildTimeNetworks; + +export interface BackendNetworksState { + backendNetworks: BackendNetworksResponse; + backendNetworksSharedValue: SharedValue; + + getBackendChains: () => Chain[]; + getSupportedChains: () => Chain[]; + + getDefaultChains: () => Record; + getSupportedChainIds: () => ChainId[]; + getSupportedMainnetChains: () => Chain[]; + getSupportedMainnetChainIds: () => ChainId[]; + getNeedsL1SecurityFeeChains: () => ChainId[]; + getChainsNativeAsset: () => Record; + getChainsLabel: () => Record; + getChainsName: () => Record; + getChainsIdByName: () => Record; + + defaultGasSpeeds: (chainId: ChainId) => GasSpeed[]; + + getChainsGasSpeeds: () => Record; + defaultPollingInterval: (chainId: ChainId) => number; + getChainsPollingInterval: () => Record; + + defaultSimplehashNetwork: (chainId: ChainId) => string; + getChainsSimplehashNetwork: () => Record; + filterChainIdsByService: (servicePath: (services: BackendNetworkServices) => boolean) => ChainId[]; + + getMeteorologySupportedChainIds: () => ChainId[]; + getSwapSupportedChainIds: () => ChainId[]; + getSwapExactOutputSupportedChainIds: () => ChainId[]; + getBridgeExactOutputSupportedChainIds: () => ChainId[]; + getNotificationsSupportedChainIds: () => ChainId[]; + getApprovalsSupportedChainIds: () => ChainId[]; + getTransactionsSupportedChainIds: () => ChainId[]; + getSupportedAssetsChainIds: () => ChainId[]; + getSupportedPositionsChainIds: () => ChainId[]; + getTokenSearchSupportedChainIds: () => ChainId[]; + getNftSupportedChainIds: () => ChainId[]; + getFlashbotsSupportedChainIds: () => ChainId[]; + getShouldDefaultToFastGasChainIds: () => ChainId[]; + + getChainGasUnits: (chainId?: ChainId) => BackendNetwork['gasUnits']; + getChainDefaultRpc: (chainId: ChainId) => string; + + setBackendNetworks: (backendNetworks: BackendNetworksResponse) => void; +} + +export const useBackendNetworksStore = createRainbowStore((set, get) => ({ + backendNetworks: INITIAL_BACKEND_NETWORKS, + backendNetworksSharedValue: makeMutable(INITIAL_BACKEND_NETWORKS), + + getBackendChains: () => { + const { backendNetworks } = get(); + return transformBackendNetworksToChains(backendNetworks.networks); + }, + + getSupportedChains: () => { + const backendChains = get().getBackendChains(); + return IS_TEST ? [...backendChains, chainHardhat, chainHardhatOptimism] : backendChains; + }, + + getDefaultChains: () => { + const supportedChains = get().getSupportedChains(); + return supportedChains.reduce( + (acc, chain) => { + acc[chain.id] = chain; + return acc; + }, + {} as Record + ); + }, + + getSupportedChainIds: () => { + const supportedChains = get().getSupportedChains(); + return supportedChains.map(chain => chain.id); + }, + + getSupportedMainnetChains: () => { + const supportedChains = get().getSupportedChains(); + return supportedChains.filter(chain => !chain.testnet); + }, + + getSupportedMainnetChainIds: () => { + const supportedMainnetChains = get().getSupportedMainnetChains(); + return supportedMainnetChains.map(chain => chain.id); + }, + + getNeedsL1SecurityFeeChains: () => { + const backendNetworks = get().backendNetworks; + return backendNetworks.networks + .filter((backendNetwork: BackendNetwork) => backendNetwork.opStack) + .map((backendNetwork: BackendNetwork) => parseInt(backendNetwork.id, 10)); + }, + + getChainsNativeAsset: () => { + const backendNetworks = get().backendNetworks; + return backendNetworks.networks.reduce( + (acc, backendNetwork) => { + acc[parseInt(backendNetwork.id, 10)] = backendNetwork.nativeAsset; + return acc; + }, + {} as Record + ); + }, + + getChainsLabel: () => { + const backendNetworks = get().backendNetworks; + return backendNetworks.networks.reduce( + (acc, backendNetwork) => { + acc[parseInt(backendNetwork.id, 10)] = backendNetwork.label; + return acc; + }, + {} as Record + ); + }, + + getChainsName: () => { + const backendNetworks = get().backendNetworks; + return backendNetworks.networks.reduce( + (acc, backendNetwork) => { + acc[parseInt(backendNetwork.id, 10)] = backendNetwork.name; + return acc; + }, + {} as Record + ); + }, + + getChainsIdByName: () => { + const backendNetworks = get().backendNetworks; + return backendNetworks.networks.reduce( + (acc, backendNetwork) => { + acc[backendNetwork.name] = parseInt(backendNetwork.id, 10); + return acc; + }, + {} as Record + ); + }, + + // TODO: This should come from the backend at some point + defaultGasSpeeds: chainId => { + switch (chainId) { + case ChainId.bsc: + case ChainId.goerli: + case ChainId.polygon: + return [GasSpeed.NORMAL, GasSpeed.FAST, GasSpeed.URGENT]; + case ChainId.gnosis: + return [GasSpeed.NORMAL]; + default: + return [GasSpeed.NORMAL, GasSpeed.FAST, GasSpeed.URGENT, GasSpeed.CUSTOM]; + } + }, + + getChainsGasSpeeds: () => { + const backendNetworks = get().backendNetworks; + return backendNetworks.networks.reduce( + (acc, backendNetwork) => { + acc[parseInt(backendNetwork.id, 10)] = get().defaultGasSpeeds(parseInt(backendNetwork.id, 10)); + return acc; + }, + {} as Record + ); + }, + + defaultPollingInterval: chainId => { + switch (chainId) { + case ChainId.polygon: + return 2_000; + case ChainId.arbitrum: + case ChainId.bsc: + return 3_000; + default: + return 5_000; + } + }, + + getChainsPollingInterval: () => { + const backendNetworks = get().backendNetworks; + return backendNetworks.networks.reduce( + (acc, backendNetwork) => { + acc[parseInt(backendNetwork.id, 10)] = get().defaultPollingInterval(parseInt(backendNetwork.id, 10)); + return acc; + }, + {} as Record + ); + }, + + // TODO: This should come from the backend at some point + defaultSimplehashNetwork: chainId => { + switch (chainId) { + case ChainId.apechain: + return 'apechain'; + case ChainId.arbitrum: + return 'arbitrum'; + case ChainId.avalanche: + return 'avalanche'; + case ChainId.base: + return 'base'; + case ChainId.blast: + return 'blast'; + case ChainId.bsc: + return 'bsc'; + case ChainId.degen: + return 'degen'; + case ChainId.gnosis: + return 'gnosis'; + case ChainId.goerli: + return 'ethereum-goerli'; + case ChainId.mainnet: + return 'ethereum'; + case ChainId.optimism: + return 'optimism'; + case ChainId.polygon: + return 'polygon'; + case ChainId.zora: + return 'zora'; + default: + return ''; + } + }, + + getChainsSimplehashNetwork: () => { + const backendNetworks = get().backendNetworks; + return backendNetworks.networks.reduce( + (acc, backendNetwork) => { + acc[parseInt(backendNetwork.id, 10)] = get().defaultSimplehashNetwork(parseInt(backendNetwork.id, 10)); + return acc; + }, + {} as Record + ); + }, + + filterChainIdsByService: servicePath => { + const backendNetworks = get().backendNetworks; + return backendNetworks.networks.filter(network => servicePath(network.enabledServices)).map(network => parseInt(network.id, 10)); + }, + + getMeteorologySupportedChainIds: () => { + return get().filterChainIdsByService(services => services.meteorology.enabled); + }, + + getSwapSupportedChainIds: () => { + return get().filterChainIdsByService(services => services.swap.enabled); + }, + + getSwapExactOutputSupportedChainIds: () => { + return get().filterChainIdsByService(services => services.swap.swapExactOutput); + }, + + getBridgeExactOutputSupportedChainIds: () => { + return get().filterChainIdsByService(services => services.swap.bridgeExactOutput); + }, + + getNotificationsSupportedChainIds: () => { + return get().filterChainIdsByService(services => services.notifications.enabled); + }, + + getApprovalsSupportedChainIds: () => { + return get().filterChainIdsByService(services => services.addys.approvals); + }, + + getTransactionsSupportedChainIds: () => { + return get().filterChainIdsByService(services => services.addys.transactions); + }, + + getSupportedAssetsChainIds: () => { + return get().filterChainIdsByService(services => services.addys.assets); + }, + + getSupportedPositionsChainIds: () => { + return get().filterChainIdsByService(services => services.addys.positions); + }, + + getTokenSearchSupportedChainIds: () => { + return get().filterChainIdsByService(services => services.tokenSearch.enabled); + }, + + getNftSupportedChainIds: () => { + return get().filterChainIdsByService(services => services.nftProxy.enabled); + }, + + getFlashbotsSupportedChainIds: () => { + return [ChainId.mainnet]; + }, + + getShouldDefaultToFastGasChainIds: () => { + return [ChainId.mainnet, ChainId.polygon, ChainId.goerli]; + }, + + getChainGasUnits: chainId => { + const backendNetworks = get().backendNetworks; + const chainsGasUnits = backendNetworks.networks.reduce( + (acc, backendNetwork: BackendNetwork) => { + acc[parseInt(backendNetwork.id, 10)] = backendNetwork.gasUnits; + return acc; + }, + {} as Record + ); + + return (chainId ? chainsGasUnits[chainId] : undefined) || chainsGasUnits[ChainId.mainnet]; + }, + + getChainDefaultRpc: chainId => { + const defaultChains = get().getDefaultChains(); + switch (chainId) { + case ChainId.mainnet: + return useConnectedToHardhatStore.getState().connectedToHardhat + ? 'http://127.0.0.1:8545' + : defaultChains[ChainId.mainnet].rpcUrls.default.http[0]; + default: + return defaultChains[chainId].rpcUrls.default.http[0]; + } + }, + + setBackendNetworks: backendNetworks => + set(state => { + state.backendNetworksSharedValue.value = backendNetworks; + return { + ...state, + backendNetworks: backendNetworks, + }; + }), +})); + +// ------ WORKLET FUNCTIONS ------ + +export const getBackendChainsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return transformBackendNetworksToChains(backendNetworks.value.networks); +}; + +export const getSupportedChainsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + const backendChains = getBackendChainsWorklet(backendNetworks); + return IS_TEST ? [...backendChains, chainHardhat, chainHardhatOptimism] : backendChains; +}; + +export const getDefaultChainsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + const supportedChains = getSupportedChainsWorklet(backendNetworks); + return supportedChains.reduce( + (acc, chain) => { + acc[chain.id] = chain; + return acc; + }, + {} as Record + ); +}; + +export const getSupportedChainIdsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + const supportedChains = getSupportedChainsWorklet(backendNetworks); + return supportedChains.map(chain => chain.id); +}; + +export const getSupportedMainnetChainsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + const supportedChains = getSupportedChainsWorklet(backendNetworks); + return supportedChains.filter(chain => !chain.testnet); +}; + +export const getSupportedMainnetChainIdsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + const supportedMainnetChains = getSupportedMainnetChainsWorklet(backendNetworks); + return supportedMainnetChains.map(chain => chain.id); +}; + +export const getNeedsL1SecurityFeeChainsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return backendNetworks.value.networks + .filter((backendNetwork: BackendNetwork) => backendNetwork.opStack) + .map((backendNetwork: BackendNetwork) => parseInt(backendNetwork.id, 10)); +}; + +export const getChainsNativeAssetWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return backendNetworks.value.networks.reduce( + (acc, backendNetwork) => { + acc[parseInt(backendNetwork.id, 10)] = backendNetwork.nativeAsset; + return acc; + }, + {} as Record + ); +}; + +export const getChainsLabelWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return backendNetworks.value.networks.reduce( + (acc, backendNetwork: BackendNetwork) => { + acc[parseInt(backendNetwork.id, 10)] = backendNetwork.label; + return acc; + }, + {} as Record + ); +}; + +export const getChainsNameWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return backendNetworks.value.networks.reduce( + (acc, backendNetwork: BackendNetwork) => { + acc[parseInt(backendNetwork.id, 10)] = backendNetwork.name; + return acc; + }, + {} as Record + ); +}; + +export const getChainsIdByNameWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return backendNetworks.value.networks.reduce( + (acc, backendNetwork) => { + acc[backendNetwork.name] = parseInt(backendNetwork.id, 10); + return acc; + }, + {} as Record + ); +}; + +export const defaultGasSpeedsWorklet = (chainId: ChainId) => { + 'worklet'; + switch (chainId) { + case ChainId.bsc: + case ChainId.goerli: + case ChainId.polygon: + return [GasSpeed.NORMAL, GasSpeed.FAST, GasSpeed.URGENT]; + case ChainId.gnosis: + return [GasSpeed.NORMAL]; + default: + return [GasSpeed.NORMAL, GasSpeed.FAST, GasSpeed.URGENT, GasSpeed.CUSTOM]; + } +}; + +export const getChainsGasSpeedsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return backendNetworks.value.networks.reduce( + (acc, backendNetwork) => { + acc[parseInt(backendNetwork.id, 10)] = defaultGasSpeedsWorklet(parseInt(backendNetwork.id, 10)); + return acc; + }, + {} as Record + ); +}; + +export const defaultPollingIntervalWorklet = (chainId: ChainId) => { + 'worklet'; + switch (chainId) { + case ChainId.polygon: + return 2_000; + case ChainId.arbitrum: + case ChainId.bsc: + return 3_000; + default: + return 5_000; + } +}; + +export const getChainsPollingIntervalWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return backendNetworks.value.networks.reduce( + (acc, backendNetwork) => { + acc[parseInt(backendNetwork.id, 10)] = defaultPollingIntervalWorklet(parseInt(backendNetwork.id, 10)); + return acc; + }, + {} as Record + ); +}; + +export const defaultSimplehashNetworkWorklet = (chainId: ChainId) => { + 'worklet'; + switch (chainId) { + case ChainId.apechain: + return 'apechain'; + case ChainId.arbitrum: + return 'arbitrum'; + case ChainId.avalanche: + return 'avalanche'; + case ChainId.base: + return 'base'; + case ChainId.blast: + return 'blast'; + case ChainId.bsc: + return 'bsc'; + case ChainId.degen: + return 'degen'; + case ChainId.gnosis: + return 'gnosis'; + case ChainId.goerli: + return 'ethereum-goerli'; + case ChainId.mainnet: + return 'ethereum'; + case ChainId.optimism: + return 'optimism'; + case ChainId.polygon: + return 'polygon'; + case ChainId.zora: + return 'zora'; + default: + return ''; + } +}; + +export const getChainsSimplehashNetworkWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return backendNetworks.value.networks.reduce( + (acc, backendNetwork) => { + acc[parseInt(backendNetwork.id, 10)] = defaultSimplehashNetworkWorklet(parseInt(backendNetwork.id, 10)); + return acc; + }, + {} as Record + ); +}; + +export const filterChainIdsByServiceWorklet = ( + backendNetworks: SharedValue, + servicePath: (services: BackendNetworkServices) => boolean +) => { + 'worklet'; + return backendNetworks.value.networks.filter(network => servicePath(network.enabledServices)).map(network => parseInt(network.id, 10)); +}; + +export const getMeteorologySupportedChainIdsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return filterChainIdsByServiceWorklet(backendNetworks, services => services.meteorology.enabled); +}; + +export const getSwapSupportedChainIdsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return filterChainIdsByServiceWorklet(backendNetworks, services => services.swap.enabled); +}; + +export const getSwapExactOutputSupportedChainIdsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return filterChainIdsByServiceWorklet(backendNetworks, services => services.swap.swapExactOutput); +}; + +export const getBridgeExactOutputSupportedChainIdsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return filterChainIdsByServiceWorklet(backendNetworks, services => services.swap.bridgeExactOutput); +}; + +export const getNotificationsSupportedChainIdsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return filterChainIdsByServiceWorklet(backendNetworks, services => services.notifications.enabled); +}; + +export const getApprovalsSupportedChainIdsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return filterChainIdsByServiceWorklet(backendNetworks, services => services.addys.approvals); +}; + +export const getTransactionsSupportedChainIdsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return filterChainIdsByServiceWorklet(backendNetworks, services => services.addys.transactions); +}; + +export const getSupportedAssetsChainIdsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return filterChainIdsByServiceWorklet(backendNetworks, services => services.addys.assets); +}; + +export const getSupportedPositionsChainIdsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return filterChainIdsByServiceWorklet(backendNetworks, services => services.addys.positions); +}; + +export const getTokenSearchSupportedChainIdsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return filterChainIdsByServiceWorklet(backendNetworks, services => services.tokenSearch.enabled); +}; + +export const getNftSupportedChainIdsWorklet = (backendNetworks: SharedValue) => { + 'worklet'; + return filterChainIdsByServiceWorklet(backendNetworks, services => services.nftProxy.enabled); +}; + +export const getFlashbotsSupportedChainIdsWorklet = (_?: SharedValue) => { + 'worklet'; + return [ChainId.mainnet]; +}; + +export const getShouldDefaultToFastGasChainIdsWorklet = (_?: SharedValue) => { + 'worklet'; + return [ChainId.mainnet, ChainId.polygon, ChainId.goerli]; +}; + +export const getChainGasUnitsWorklet = (backendNetworks: SharedValue, chainId?: ChainId) => { + 'worklet'; + const chainsGasUnits = backendNetworks.value.networks.reduce( + (acc, backendNetwork: BackendNetwork) => { + acc[parseInt(backendNetwork.id, 10)] = backendNetwork.gasUnits; + return acc; + }, + {} as Record + ); + + return (chainId ? chainsGasUnits[chainId] : undefined) || chainsGasUnits[ChainId.mainnet]; +}; + +export const getChainDefaultRpcWorklet = (backendNetworks: SharedValue, chainId: ChainId) => { + 'worklet'; + const defaultChains = getDefaultChainsWorklet(backendNetworks); + switch (chainId) { + case ChainId.mainnet: + return useConnectedToHardhatStore.getState().connectedToHardhat + ? 'http://127.0.0.1:8545' + : defaultChains[ChainId.mainnet].rpcUrls.default.http[0]; + default: + return defaultChains[chainId].rpcUrls.default.http[0]; + } +}; diff --git a/src/chains/types.ts b/src/state/backendNetworks/types.ts similarity index 100% rename from src/chains/types.ts rename to src/state/backendNetworks/types.ts diff --git a/src/chains/utils/backendNetworks.ts b/src/state/backendNetworks/utils.ts similarity index 96% rename from src/chains/utils/backendNetworks.ts rename to src/state/backendNetworks/utils.ts index 0082b40abd0..2242f3042c1 100644 --- a/src/chains/utils/backendNetworks.ts +++ b/src/state/backendNetworks/utils.ts @@ -2,7 +2,7 @@ import { Chain } from 'viem'; import { mainnet } from 'viem/chains'; import { IS_DEV, RPC_PROXY_API_KEY } from '@/env'; -import { BackendNetwork } from '../types'; +import { BackendNetwork } from './types'; const proxyBackendNetworkRpcEndpoint = (endpoint: string) => { return `${endpoint}${RPC_PROXY_API_KEY}`; diff --git a/src/state/nonces/index.ts b/src/state/nonces/index.ts index fa0ae319441..100a3659aea 100644 --- a/src/state/nonces/index.ts +++ b/src/state/nonces/index.ts @@ -1,8 +1,8 @@ import create from 'zustand'; import { createStore } from '../internal/createStore'; -import { Network, ChainId } from '@/chains/types'; +import { Network, ChainId } from '@/state/backendNetworks/types'; import { getProvider } from '@/handlers/web3'; -import { chainsIdByName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; type NonceData = { currentNonce?: number; @@ -75,6 +75,7 @@ export const nonceStore = createStore>( version: 1, migrate: (persistedState: unknown, version: number) => { if (version === 0) { + const chainsIdByName = useBackendNetworksStore.getState().getChainsIdByName(); const oldState = persistedState as CurrentNonceState; const newNonces: CurrentNonceState['nonces'] = {}; for (const [address, networkNonces] of Object.entries(oldState.nonces)) { diff --git a/src/state/pendingTransactions/index.ts b/src/state/pendingTransactions/index.ts index 34896c3d006..07ab62618e2 100644 --- a/src/state/pendingTransactions/index.ts +++ b/src/state/pendingTransactions/index.ts @@ -3,7 +3,7 @@ import { createStore } from '../internal/createStore'; import create from 'zustand'; import { convertNewTransactionToRainbowTransaction } from '@/parsers/transactions'; import { nonceStore } from '../nonces'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; export interface PendingTransactionsState { pendingTransactions: Record; diff --git a/src/state/staleBalances/index.test.ts b/src/state/staleBalances/index.test.ts index 8631c572bd7..7ac5bbaa270 100644 --- a/src/state/staleBalances/index.test.ts +++ b/src/state/staleBalances/index.test.ts @@ -3,7 +3,7 @@ import { Address } from 'viem'; import { staleBalancesStore } from '.'; import { DAI_ADDRESS } from '@/references'; import { ETH_ADDRESS } from '@rainbow-me/swaps'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; const TEST_ADDRESS_1 = '0xFOO'; const TEST_ADDRESS_2 = '0xBAR'; diff --git a/src/state/swaps/swapsStore.ts b/src/state/swaps/swapsStore.ts index a16be52941b..b74d961f507 100644 --- a/src/state/swaps/swapsStore.ts +++ b/src/state/swaps/swapsStore.ts @@ -2,7 +2,7 @@ import { MIN_FLASHBOTS_PRIORITY_FEE } from '@/__swaps__/screens/Swap/constants'; import { getCustomGasSettings, setCustomMaxPriorityFee } from '@/__swaps__/screens/Swap/hooks/useCustomGas'; import { getSelectedGasSpeed } from '@/__swaps__/screens/Swap/hooks/useSelectedGas'; import { ExtendedAnimatedAssetWithColors, ParsedSearchAsset } from '@/__swaps__/types/assets'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { GasSpeed } from '@/__swaps__/types/gas'; import { RecentSwap } from '@/__swaps__/types/swap'; import { getCachedGasSuggestions } from '@/__swaps__/utils/meteorology'; diff --git a/src/state/sync/UserAssetsSync.tsx b/src/state/sync/UserAssetsSync.tsx index 639d9cbc38a..e8722cddfce 100644 --- a/src/state/sync/UserAssetsSync.tsx +++ b/src/state/sync/UserAssetsSync.tsx @@ -4,7 +4,7 @@ import { useSwapsStore } from '@/state/swaps/swapsStore'; import { selectUserAssetsList, selectorFilterByUserChains } from '@/__swaps__/screens/Swap/resources/_selectors/assets'; import { ParsedSearchAsset } from '@/__swaps__/types/assets'; import { useUserAssets } from '@/__swaps__/screens/Swap/resources/assets'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; export const UserAssetsSync = function UserAssetsSync() { const { accountAddress, nativeCurrency: currentCurrency } = useAccountSettings(); diff --git a/src/storage/index.ts b/src/storage/index.ts index 1014ce03dbf..db4e2d88ca1 100644 --- a/src/storage/index.ts +++ b/src/storage/index.ts @@ -3,7 +3,7 @@ import { MMKV } from 'react-native-mmkv'; import { Account, Cards, Campaigns, Device, Review, WatchedWalletCohort } from '@/storage/schema'; import { EthereumAddress, RainbowTransaction } from '@/entities'; import { SecureStorage } from '@coinbase/mobile-wallet-protocol-host'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; /** * Generic storage class. DO NOT use this directly. Instead, use the exported diff --git a/src/styles/colors.ts b/src/styles/colors.ts index b1bfe39c376..0cdac9387af 100644 --- a/src/styles/colors.ts +++ b/src/styles/colors.ts @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { globalColors } from '@/design-system'; import currentColors from '../theme/currentColors'; import { memoFn } from '../utils/memoFn'; -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; export type Colors = ReturnType; diff --git a/src/utils/ethereumUtils.ts b/src/utils/ethereumUtils.ts index daf8cbb0d66..7c095eb3676 100644 --- a/src/utils/ethereumUtils.ts +++ b/src/utils/ethereumUtils.ts @@ -39,9 +39,9 @@ import { fetchExternalToken, useExternalToken, } from '@/resources/assets/externalAssetsQuery'; -import { ChainId, Network } from '@/chains/types'; +import { ChainId, Network } from '@/state/backendNetworks/types'; import { AddressOrEth } from '@/__swaps__/types/assets'; -import { chainsIdByName, chainsName, chainsNativeAsset, defaultChains, getChainGasUnits } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { useConnectedToHardhatStore } from '@/state/connectedToHardhat'; /** @@ -75,7 +75,7 @@ export const getAddressAndChainIdFromUniqueId = (uniqueId: string): { address: A const networkOrChainId = parts[1]; // if the second part is a string, it's probably a network if (isNaN(Number(networkOrChainId))) { - const chainId = chainsIdByName[networkOrChainId] || ChainId.mainnet; // Default to mainnet if unknown + const chainId = useBackendNetworksStore.getState().getChainsIdByName()[networkOrChainId] || ChainId.mainnet; // Default to mainnet if unknown return { address, chainId }; } @@ -83,7 +83,7 @@ export const getAddressAndChainIdFromUniqueId = (uniqueId: string): { address: A }; const getNetworkNativeAsset = ({ chainId }: { chainId: ChainId }) => { - const nativeAssetAddress = chainsNativeAsset[chainId].address; + const nativeAssetAddress = useBackendNetworksStore.getState().getChainsNativeAsset()[chainId].address; const nativeAssetUniqueId = getUniqueId(nativeAssetAddress, chainId); return getAccountAsset(nativeAssetUniqueId); }; @@ -102,7 +102,7 @@ export const getNativeAssetForNetwork = async ({ // If the asset is on a different wallet, or not available in this wallet if (differentWallet || !nativeAsset) { - const chainNativeAsset = chainsNativeAsset[chainId]; + const chainNativeAsset = useBackendNetworksStore.getState().getChainsNativeAsset()[chainId]; const mainnetAddress = chainNativeAsset?.address || ETH_ADDRESS; const nativeAssetAddress = chainNativeAsset.address as AddressOrEth; @@ -117,7 +117,7 @@ export const getNativeAssetForNetwork = async ({ // @ts-ignore nativeAsset = { ...externalAsset, - network: chainsName[chainId], + network: useBackendNetworksStore.getState().getChainsName()[chainId], uniqueId: getUniqueId(chainNativeAsset.address, chainId), address: chainNativeAsset.address, decimals: chainNativeAsset.decimals, @@ -211,7 +211,7 @@ const getAssetPrice = ( export const useNativeAsset = ({ chainId }: { chainId: ChainId }) => { const { nativeCurrency } = store.getState().settings; - const address = (chainsNativeAsset[chainId]?.address || ETH_ADDRESS) as AddressOrEth; + const address = (useBackendNetworksStore.getState().getChainsNativeAsset()[chainId]?.address || ETH_ADDRESS) as AddressOrEth; const { data: nativeAsset } = useExternalToken({ address, @@ -223,6 +223,7 @@ export const useNativeAsset = ({ chainId }: { chainId: ChainId }) => { }; const getPriceOfNativeAssetForNetwork = ({ chainId }: { chainId: ChainId }) => { + const chainsNativeAsset = useBackendNetworksStore.getState().getChainsNativeAsset(); const address = (chainsNativeAsset[chainId]?.address || ETH_ADDRESS) as AddressOrEth; return getAssetPrice({ address, chainId }); }; @@ -297,8 +298,8 @@ const getDataString = (func: string, arrVals: string[]) => { */ function getEtherscanHostForNetwork({ chainId }: { chainId: ChainId }): string { const base_host = 'etherscan.io'; - const blockExplorer = defaultChains[chainId]?.blockExplorers?.default?.url; - const network = chainsName[chainId]; + const blockExplorer = useBackendNetworksStore.getState().getDefaultChains()[chainId]?.blockExplorers?.default?.url; + const network = useBackendNetworksStore.getState().getChainsName()[chainId]; if (network && isTestnetChain({ chainId })) { return `${network}.${base_host}`; @@ -373,29 +374,29 @@ export const getFirstTransactionTimestamp = async (address: EthereumAddress): Pr }; function getBlockExplorer({ chainId }: { chainId: ChainId }) { - return defaultChains[chainId]?.blockExplorers?.default.name || 'etherscan'; + return useBackendNetworksStore.getState().getDefaultChains()[chainId]?.blockExplorers?.default.name || 'etherscan'; } function openAddressInBlockExplorer({ address, chainId }: { address: EthereumAddress; chainId: ChainId }) { - const explorer = defaultChains[chainId]?.blockExplorers?.default?.url; + const explorer = useBackendNetworksStore.getState().getDefaultChains()[chainId]?.blockExplorers?.default?.url; Linking.openURL(`${explorer}/address/${address}`); } function openTokenEtherscanURL({ address, chainId }: { address: EthereumAddress; chainId: ChainId }) { if (!isString(address)) return; - const explorer = defaultChains[chainId]?.blockExplorers?.default?.url; + const explorer = useBackendNetworksStore.getState().getDefaultChains()[chainId]?.blockExplorers?.default?.url; Linking.openURL(`${explorer}/token/${address}`); } function openNftInBlockExplorer({ contractAddress, tokenId, chainId }: { contractAddress: string; tokenId: string; chainId: ChainId }) { - const explorer = defaultChains[chainId]?.blockExplorers?.default?.url; + const explorer = useBackendNetworksStore.getState().getDefaultChains()[chainId]?.blockExplorers?.default?.url; Linking.openURL(`${explorer}/token/${contractAddress}?a=${tokenId}`); } function openTransactionInBlockExplorer({ hash, chainId }: { hash: string; chainId: ChainId }) { const normalizedHash = hash.replace(/-.*/g, ''); if (!isString(hash)) return; - const explorer = defaultChains[chainId]?.blockExplorers?.default?.url; + const explorer = useBackendNetworksStore.getState().getDefaultChains()[chainId]?.blockExplorers?.default?.url; Linking.openURL(`${explorer}/tx/${normalizedHash}`); } @@ -411,14 +412,14 @@ async function parseEthereumUrl(data: string) { const functionName = ethUrl.function_name; let asset = null; const chainId = (ethUrl.chain_id as ChainId) || ChainId.mainnet; - const network = chainsName[chainId]; + const network = useBackendNetworksStore.getState().getChainsName()[chainId]; let address: any = null; let nativeAmount: any = null; const { nativeCurrency } = store.getState().settings; if (!functionName) { // Send native asset - const chainId = chainsIdByName[network]; + const chainId = useBackendNetworksStore.getState().getChainsIdByName()[network]; asset = getNetworkNativeAsset({ chainId }); // @ts-ignore @@ -506,7 +507,7 @@ const calculateL1FeeOptimism = async ( }; const getBasicSwapGasLimit = (chainId: ChainId) => { - return Number(getChainGasUnits(chainId).basic.swap); + return Number(useBackendNetworksStore.getState().getChainGasUnits(chainId).basic.swap); }; export default { diff --git a/src/utils/getUrlForTrustIconFallback.ts b/src/utils/getUrlForTrustIconFallback.ts index c9757d3080d..53509e2b121 100644 --- a/src/utils/getUrlForTrustIconFallback.ts +++ b/src/utils/getUrlForTrustIconFallback.ts @@ -1,6 +1,6 @@ -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { EthereumAddress } from '@/entities'; -import { chainsName } from '@/chains'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; export default function getUrlForTrustIconFallback(address: EthereumAddress, chainId: ChainId): string | null { if (!address) return null; @@ -13,7 +13,7 @@ export default function getUrlForTrustIconFallback(address: EthereumAddress, cha networkPath = 'smartchain'; break; default: - networkPath = chainsName[chainId]; + networkPath = useBackendNetworksStore.getState().getChainsName()[chainId]; } return `https://rainbowme-res.cloudinary.com/image/upload/assets/${networkPath}/${address}.png`; } diff --git a/src/utils/requestNavigationHandlers.ts b/src/utils/requestNavigationHandlers.ts index 26d07de7559..0c3d1d21622 100644 --- a/src/utils/requestNavigationHandlers.ts +++ b/src/utils/requestNavigationHandlers.ts @@ -32,8 +32,8 @@ import { noop } from 'lodash'; import { toUtf8String } from '@ethersproject/strings'; import { BigNumber } from '@ethersproject/bignumber'; import { Address } from 'viem'; -import { ChainId } from '@/chains/types'; -import { chainsName, SUPPORTED_MAINNET_CHAIN_IDS } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { MobileWalletProtocolUserErrors } from '@/components/MobileWalletProtocolListener'; import { hideWalletConnectToast } from '@/components/toasts/WalletConnectToast'; import { removeWalletConnectRequest } from '@/state/walletConnectRequests'; @@ -122,7 +122,7 @@ export const handleMobileWalletProtocolRequest = async ({ const routeParams: WalletconnectApprovalSheetRouteParams = { receivedTimestamp, meta: { - chainIds: SUPPORTED_MAINNET_CHAIN_IDS, + chainIds: useBackendNetworksStore.getState().getSupportedMainnetChainIds(), dappName: dappMetadata?.appName || dappMetadata?.appUrl || action.appName || action.appIconUrl || action.appId || '', dappUrl: dappMetadata?.appUrl || action.appId || '', imageUrl: maybeSignUri(dappMetadata?.iconUrl || action.appIconUrl), @@ -168,7 +168,10 @@ export const handleMobileWalletProtocolRequest = async ({ } if (action.method === 'wallet_switchEthereumChain') { - const isSupportedChain = SUPPORTED_MAINNET_CHAIN_IDS.includes(BigNumber.from(action.params.chainId).toNumber()); + const isSupportedChain = useBackendNetworksStore + .getState() + .getSupportedMainnetChainIds() + .includes(BigNumber.from(action.params.chainId).toNumber()); if (!isSupportedChain) { await rejectAction(action, { message: 'Unsupported chain', @@ -300,7 +303,7 @@ export const handleDappBrowserConnectionPrompt = ( const routeParams: WalletconnectApprovalSheetRouteParams = { receivedTimestamp, meta: { - chainIds: SUPPORTED_MAINNET_CHAIN_IDS, + chainIds: useBackendNetworksStore.getState().getSupportedMainnetChainIds(), dappName: dappData?.dappName || dappData.dappUrl, dappUrl: dappData.dappUrl, imageUrl: maybeSignUri(dappData.imageUrl), @@ -400,7 +403,7 @@ export const handleDappBrowserRequest = async (request: Omit { const chainId = request?.walletConnectV2RequestValues?.chainId; if (!chainId) return; - const network = chainsName[chainId]; + const network = useBackendNetworksStore.getState().getChainsName()[chainId]; const address = request?.walletConnectV2RequestValues?.address; const onSuccess = async (result: string) => { diff --git a/src/walletConnect/index.tsx b/src/walletConnect/index.tsx index c5600cfb845..81894116634 100644 --- a/src/walletConnect/index.tsx +++ b/src/walletConnect/index.tsx @@ -47,8 +47,8 @@ import { DAppStatus } from '@/graphql/__generated__/metadata'; import { handleWalletConnectRequest } from '@/utils/requestNavigationHandlers'; import { PerformanceMetrics } from '@/performance/tracking/types/PerformanceMetrics'; import { PerformanceTracking } from '@/performance/tracking'; -import { ChainId } from '@/chains/types'; -import { SUPPORTED_CHAIN_IDS } from '@/chains'; +import { ChainId } from '@/state/backendNetworks/types'; +import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks'; import { hideWalletConnectToast } from '@/components/toasts/WalletConnectToast'; const SUPPORTED_SESSION_EVENTS = ['chainChanged', 'accountsChanged']; @@ -451,7 +451,8 @@ export async function onSessionProposal(proposal: WalletKitTypes.SessionProposal // we already checked for eip155 namespace above const chainIds = chains?.map(chain => parseInt(chain.split('eip155:')[1])); - const supportedChainIds = chainIds.filter(chainId => SUPPORTED_CHAIN_IDS.includes(chainId)); + const supportedChainIds = useBackendNetworksStore.getState().getSupportedChainIds(); + const chainIdsToUse = chainIds.filter(chainId => supportedChainIds.includes(chainId)); const peerMeta = proposer.metadata; const metadata = await fetchDappMetadata({ url: peerMeta.url, status: true }); @@ -462,7 +463,7 @@ export async function onSessionProposal(proposal: WalletKitTypes.SessionProposal const routeParams: WalletconnectApprovalSheetRouteParams = { receivedTimestamp, meta: { - chainIds: supportedChainIds, + chainIds: chainIdsToUse, dappName, dappScheme: 'unused in WC v2', // only used for deeplinks from WC v1 dappUrl: peerMeta.url || lang.t(lang.l.walletconnect.unknown_url), @@ -492,7 +493,7 @@ export async function onSessionProposal(proposal: WalletKitTypes.SessionProposal const supportedEvents = requiredNamespaces?.eip155?.events || SUPPORTED_SESSION_EVENTS; /** @see https://chainagnostic.org/CAIPs/caip-2 */ - const caip2ChainIds = SUPPORTED_CHAIN_IDS.map(id => `eip155:${id}`); + const caip2ChainIds = supportedChainIds.map(id => `eip155:${id}`); const namespaces = getApprovedNamespaces({ proposal: proposal.params, supportedNamespaces: { diff --git a/src/walletConnect/types.ts b/src/walletConnect/types.ts index 18a8a2a7237..239265a1220 100644 --- a/src/walletConnect/types.ts +++ b/src/walletConnect/types.ts @@ -1,4 +1,4 @@ -import { ChainId } from '@/chains/types'; +import { ChainId } from '@/state/backendNetworks/types'; import { Address } from 'viem'; import { SignClientTypes, Verify } from '@walletconnect/types'; import { RequestSource } from '@/utils/requestNavigationHandlers';