diff --git a/.changeset/great-crabs-trade.md b/.changeset/great-crabs-trade.md new file mode 100644 index 0000000000..8bd42c337d --- /dev/null +++ b/.changeset/great-crabs-trade.md @@ -0,0 +1,6 @@ +--- +"@venusprotocol/chains": minor +"@venusprotocol/evm": minor +--- + +add auto-reload ui support for new hardforks config diff --git a/apps/evm/src/App/ChainUpgradeHandler/__tests__/index.spec.tsx b/apps/evm/src/App/ChainUpgradeHandler/__tests__/index.spec.tsx new file mode 100644 index 0000000000..107c881236 --- /dev/null +++ b/apps/evm/src/App/ChainUpgradeHandler/__tests__/index.spec.tsx @@ -0,0 +1,42 @@ +import { renderComponent } from 'testUtils/render'; + +import type { MockInstance } from 'vitest'; +import { ChainUpgradeHandler } from '../'; + +const runtimeTimestamp = new Date().getTime(); +const upgradeTimestamps = [new Date(runtimeTimestamp + 2000)]; +const fakeNowMs = runtimeTimestamp + 12000; + +describe('ChainUpgradeHandler', () => { + const original = window.location; + let reloadSpy: MockInstance; + + beforeEach(() => { + // 1. Redefine the 'reload' property on window.location to be configurable. + // This is necessary because it is non-configurable by default in jsdom. + Object.defineProperty(window, 'location', { + configurable: true, + value: () => {}, // Provide a dummy function initially + }); + + Object.defineProperty(window.location, 'reload', { + configurable: true, + value: () => {}, // Provide a dummy function initially + }); + + // 2. Create the spy on the now-configurable property. + reloadSpy = vi.spyOn(window.location, 'reload'); + }); + + afterAll(() => { + Object.defineProperty(window, 'location', { configurable: true, value: original }); + }); + + it('auto reload after passing hardforks', () => { + vi.useFakeTimers().setSystemTime(new Date(fakeNowMs)); + + renderComponent(); + + expect(reloadSpy).toHaveBeenCalled(); + }); +}); diff --git a/apps/evm/src/App/index.tsx b/apps/evm/src/App/index.tsx index 42b45181ee..720d772ed3 100644 --- a/apps/evm/src/App/index.tsx +++ b/apps/evm/src/App/index.tsx @@ -1,8 +1,7 @@ -import { opBnbTestnetFourierForkTimestamp } from '@venusprotocol/chains'; - import { QueryClientProvider } from '@tanstack/react-query'; import { queryClient } from 'clients/api'; import config from 'config'; +import { useChain } from 'hooks/useChain'; import { AnalyticProvider } from 'libs/analytics'; import { ErrorBoundary } from 'libs/errors'; import { SentryErrorInfo } from 'libs/errors/SentryErrorInfo'; @@ -22,61 +21,62 @@ const GaslessChecker = safeLazyLoad(() => import('containers/GaslessChecker')); const ResendPayingGasModal = safeLazyLoad(() => import('containers/ResendPayingGasModal')); const ImportPositionsModal = safeLazyLoad(() => import('containers/ImportPositionsModal')); -const App = () => ( - <> - { - // Only index production with search engines - config.environment !== 'production' && ( - - - - ) - } +const App = () => { + const { hardforks } = useChain(); + const upgradeTimestamps = (hardforks ?? []).map(hardfork => new Date(hardfork.startTimestamp)); + + return ( + <> + { + // Only index production with search engines + config.environment !== 'production' && ( + + + + ) + } - - - - - - - + + + + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - + - + - - - - - - - - -); + + + + + + + + + ); +}; export default App; diff --git a/packages/chains/src/chains/chainMetadata/index.ts b/packages/chains/src/chains/chainMetadata/index.ts index 84fb14457e..2686c80584 100644 --- a/packages/chains/src/chains/chainMetadata/index.ts +++ b/packages/chains/src/chains/chainMetadata/index.ts @@ -2,8 +2,6 @@ import { iconSrcs } from '../../generated/manifests/chainIcons'; import { bnb, eth } from '../../tokens/nativeTokens'; import { type Chain, ChainId } from '../../types'; -export const opBnbTestnetFourierForkTimestamp = new Date('2025-11-06T03:00:00Z'); - export const chains: Record = { [ChainId.BSC_MAINNET]: { name: 'BNB Chain',