diff --git a/src/components/common/GasStation/index.tsx b/src/components/common/GasStation/index.tsx index 2422f3fff4..f7887160f2 100644 --- a/src/components/common/GasStation/index.tsx +++ b/src/components/common/GasStation/index.tsx @@ -9,8 +9,10 @@ const GasStation = () => { const gasGwei = maxFeePerGas ? formatVisualAmount(maxFeePerGas, 'gwei', 0) : '' return ( - - {gasGwei} + + + {gasGwei} + ) diff --git a/src/hooks/__tests__/useGasPrice.test.ts b/src/hooks/__tests__/useGasPrice.test.ts index d34ead9250..10dfe13d0c 100644 --- a/src/hooks/__tests__/useGasPrice.test.ts +++ b/src/hooks/__tests__/useGasPrice.test.ts @@ -1,6 +1,6 @@ import { BigNumber } from 'ethers' import { act, renderHook } from '@/tests/test-utils' -import useGasPrice from '@/hooks/useGasPrice' +import { useGasPriceAsync as useGasPrice } from '@/hooks/useGasPrice' import { useCurrentChain } from '../useChains' // mock useWeb3Readonly diff --git a/src/hooks/useGasPrice.ts b/src/hooks/useGasPrice.ts index 01ee5a4f28..384a4bed74 100644 --- a/src/hooks/useGasPrice.ts +++ b/src/hooks/useGasPrice.ts @@ -1,3 +1,4 @@ +import { useContext, createContext } from 'react' import { BigNumber } from 'ethers' import type { FeeData } from '@ethersproject/abstract-provider' import type { @@ -124,7 +125,12 @@ const getGasParameters = ( maxPriorityFeePerGas: undefined, } } -const useGasPrice = (): AsyncResult => { + +type AsyncGasPrice = AsyncResult + +export const GasContext = createContext([undefined, undefined, true]) + +export const useGasPriceAsync = (): AsyncGasPrice => { const chain = useCurrentChain() const gasPriceConfigs = chain?.gasPrice const [counter] = useIntervalCounter(REFRESH_DELAY) @@ -154,4 +160,8 @@ const useGasPrice = (): AsyncResult => { return [gasPrice, gasPriceError, isLoading] } +const useGasPrice = (): AsyncResult => { + return useContext(GasContext) +} + export default useGasPrice diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index d6612c4179..4a4246ba29 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -37,6 +37,7 @@ import useSafeMessageNotifications from '@/hooks/messages/useSafeMessageNotifica import useSafeMessagePendingStatuses from '@/hooks/messages/useSafeMessagePendingStatuses' import useChangedValue from '@/hooks/useChangedValue' import { TxModalProvider } from '@/components/tx-flow' +import { GasContext, useGasPriceAsync } from '@/hooks/useGasPrice' const GATEWAY_URL = IS_PRODUCTION || cgwDebugStorage.get() ? GATEWAY_URL_PRODUCTION : GATEWAY_URL_STAGING @@ -67,13 +68,16 @@ const clientSideEmotionCache = createEmotionCache() export const AppProviders = ({ children }: { children: ReactNode | ReactNode[] }) => { const isDarkMode = useDarkMode() const themeMode = isDarkMode ? 'dark' : 'light' + const gasPrice = useGasPriceAsync() return ( {(safeTheme: Theme) => ( - {children} + + {children} + )}