diff --git a/src/__swaps__/screens/Swap/providers/SyncSwapStateAndSharedValues.tsx b/src/__swaps__/screens/Swap/providers/SyncSwapStateAndSharedValues.tsx index 40a337051b8..474f44943a7 100644 --- a/src/__swaps__/screens/Swap/providers/SyncSwapStateAndSharedValues.tsx +++ b/src/__swaps__/screens/Swap/providers/SyncSwapStateAndSharedValues.tsx @@ -24,7 +24,6 @@ import { calculateGasFee } from '../hooks/useEstimatedGasFee'; import { useSelectedGas } from '../hooks/useSelectedGas'; import { useSwapEstimatedGasLimit } from '../hooks/useSwapEstimatedGasLimit'; import { useSwapContext } from './swap-provider'; -import { lessThan } from '@/helpers/utilities'; const BUFFER_RATIO = 0.5; @@ -93,7 +92,7 @@ export function SyncGasStateToSharedValues() { const { assetToSell, chainId = ChainId.mainnet, quote } = useSyncedSwapQuoteStore(); const gasSettings = useSelectedGas(chainId); - const { data: userNativeNetworkAsset } = useUserNativeNetworkAsset(chainId); + const { data: userNativeNetworkAsset, isLoading: isLoadingNativeNetworkAsset } = useUserNativeNetworkAsset(chainId); const { data: estimatedGasLimit } = useSwapEstimatedGasLimit({ chainId, assetToSell, quote }); const gasFeeRange = useSharedValue<[string, string] | null>(null); @@ -128,7 +127,12 @@ export function SyncGasStateToSharedValues() { useEffect(() => { hasEnoughFundsForGas.value = undefined; - if (!gasSettings || !estimatedGasLimit || !quote || 'error' in quote || !userNativeNetworkAsset) return; + if (!gasSettings || !estimatedGasLimit || !quote || 'error' in quote || isLoadingNativeNetworkAsset) return; + + if (!userNativeNetworkAsset) { + hasEnoughFundsForGas.value = false; + return; + } const gasFee = calculateGasFee(gasSettings, estimatedGasLimit); @@ -151,7 +155,16 @@ export function SyncGasStateToSharedValues() { return () => { hasEnoughFundsForGas.value = undefined; }; - }, [estimatedGasLimit, gasFeeRange, gasSettings, hasEnoughFundsForGas, quote, userNativeNetworkAsset]); + }, [ + estimatedGasLimit, + gasFeeRange, + gasSettings, + hasEnoughFundsForGas, + quote, + userNativeNetworkAsset, + isLoadingNativeNetworkAsset, + chainId, + ]); return null; } diff --git a/src/__swaps__/screens/Swap/providers/swap-provider.tsx b/src/__swaps__/screens/Swap/providers/swap-provider.tsx index f192af5819d..e907b5ea4e1 100644 --- a/src/__swaps__/screens/Swap/providers/swap-provider.tsx +++ b/src/__swaps__/screens/Swap/providers/swap-provider.tsx @@ -37,7 +37,7 @@ import { RainbowError, logger } from '@/logger'; import { loadWallet } from '@/model/wallet'; import { Navigation } from '@/navigation'; import Routes from '@/navigation/routesNames'; -import { getNetworkObj } from '@/networks'; +import { RainbowNetworkByChainId, getNetworkObj } from '@/networks'; import { walletExecuteRap } from '@/raps/execute'; import { QuoteTypeMap, RapSwapActionParameters } from '@/raps/references'; import { queryClient } from '@/react-query'; @@ -47,12 +47,12 @@ import { swapsStore } from '@/state/swaps/swapsStore'; import { ethereumUtils, haptics } from '@/utils'; import { CrosschainQuote, Quote, QuoteError } from '@rainbow-me/swaps'; +import { IS_IOS } from '@/env'; import { Address } from 'viem'; import { clearCustomGasSettings } from '../hooks/useCustomGas'; import { getGasSettingsBySpeed, getSelectedGas, getSelectedGasSpeed } from '../hooks/useSelectedGas'; import { useSwapOutputQuotesDisabled } from '../hooks/useSwapOutputQuotesDisabled'; import { SyncGasStateToSharedValues, SyncQuoteSharedValuesToState } from './SyncSwapStateAndSharedValues'; -import { IS_IOS } from '@/env'; const swapping = i18n.t(i18n.l.swap.actions.swapping); const tapToSwap = i18n.t(i18n.l.swap.actions.tap_to_swap); @@ -62,6 +62,7 @@ const review = i18n.t(i18n.l.swap.actions.review); const fetchingPrices = i18n.t(i18n.l.swap.actions.fetching_prices); const selectToken = i18n.t(i18n.l.swap.actions.select_token); const insufficientFunds = i18n.t(i18n.l.swap.actions.insufficient_funds); +const insufficient = i18n.t(i18n.l.swap.actions.insufficient); const quoteError = i18n.t(i18n.l.swap.actions.quote_error); interface SwapContextType { @@ -667,7 +668,11 @@ export const SwapProvider = ({ children }: SwapProviderProps) => { } if (!hasEnoughFundsForGas.value) { - return { label: insufficientFunds, disabled: true }; + const nativeCurrency = RainbowNetworkByChainId[sellAsset?.chainId || ChainId.mainnet].nativeCurrency; + return { + label: `${insufficient} ${nativeCurrency.symbol}`, + disabled: true, + }; } if (isReviewSheetOpen) { diff --git a/src/languages/en_US.json b/src/languages/en_US.json index cdf347d9caf..3462977d995 100644 --- a/src/languages/en_US.json +++ b/src/languages/en_US.json @@ -1978,6 +1978,7 @@ "swapping": "Swapping", "select_token": "Select Token", "insufficient_funds": "Insufficient Funds", + "insufficient": "Insufficient", "quote_error": "Quote Error" }, "aggregators": { diff --git a/src/networks/index.ts b/src/networks/index.ts index 949a70ef828..e5cb731e66d 100644 --- a/src/networks/index.ts +++ b/src/networks/index.ts @@ -1,18 +1,19 @@ +import { ChainId } from '@/__swaps__/types/chains'; +import store from '@/redux/store'; +import * as ls from '@/storage'; import { getArbitrumNetworkObject } from './arbitrum'; +import { getAvalancheNetworkObject } from './avalanche'; +import { getBaseNetworkObject } from './base'; +import { getBlastNetworkObject } from './blast'; import { getBSCNetworkObject } from './bsc'; -import { getMainnetNetworkObject } from './mainnet'; +import { getDegenNetworkObject } from './degen'; +import { getGnosisNetworkObject } from './gnosis'; import { getGoerliNetworkObject } from './goerli'; +import { getMainnetNetworkObject } from './mainnet'; import { getOptimismNetworkObject } from './optimism'; import { getPolygonNetworkObject } from './polygon'; import { Network, NetworkProperties } from './types'; import { getZoraNetworkObject } from './zora'; -import { getGnosisNetworkObject } from './gnosis'; -import { getBaseNetworkObject } from './base'; -import { getAvalancheNetworkObject } from './avalanche'; -import { getBlastNetworkObject } from './blast'; -import { getDegenNetworkObject } from './degen'; -import store from '@/redux/store'; -import * as ls from '@/storage'; /** * Array of all Rainbow Networks @@ -93,3 +94,11 @@ export function sortNetworks(): NetworkProperties[] { export function getSwappableNetworks(): NetworkProperties[] { return RainbowNetworks.filter(network => network.features.swaps); } + +export const RainbowNetworkByChainId = RainbowNetworks.reduce( + (acc, network) => { + acc[network.id] = network; + return acc; + }, + {} as Record +);