diff --git a/src/layouts/MobileMenu.tsx b/src/layouts/MobileMenu.tsx index 3d46c86f59..ad7c7af499 100644 --- a/src/layouts/MobileMenu.tsx +++ b/src/layouts/MobileMenu.tsx @@ -9,12 +9,13 @@ import { useConnectGate } from 'src/hooks/useConnectGate'; import { useModalContext } from 'src/hooks/useModal'; import { useRootStore } from 'src/store/root'; import { figVars } from 'src/utils/figmaColors'; -import { isFeatureEnabled } from 'src/utils/marketsAndNetworksConfig'; +import { isFeatureEnabled, PROD_ENV } from 'src/utils/marketsAndNetworksConfig'; import { DrawerWrapper } from './components/DrawerWrapper'; import { LanguageListItem, LanguagesList } from './components/LanguageSwitcher'; import { NavItems } from './components/NavItems'; import { ShieldSwitcher } from './components/ShieldSwitcher'; +import { TestNetModeSwitcher } from './components/TestNetModeSwitcher'; import { ThemeListItem, ThemesList } from './components/ThemeSwitcher'; // The drill-in lists the options view can be replaced by. Keys are the submenu state. @@ -172,6 +173,7 @@ export const MobileMenu = ({ open, setOpen }: MobileMenuProps) => { + {PROD_ENV && } setSubmenu('languages')} /> setSubmenu('themes')} /> diff --git a/src/layouts/SettingsMenu.tsx b/src/layouts/SettingsMenu.tsx index 54a6d6997f..0f89286dac 100644 --- a/src/layouts/SettingsMenu.tsx +++ b/src/layouts/SettingsMenu.tsx @@ -6,9 +6,11 @@ import { useModalContext } from 'src/hooks/useModal'; import { DEFAULT_LOCALE } from 'src/libs/LanguageProvider'; import { useRootStore } from 'src/store/root'; import { SETTINGS } from 'src/utils/events'; +import { PROD_ENV } from 'src/utils/marketsAndNetworksConfig'; import { LanguageListItem, LanguagesList } from './components/LanguageSwitcher'; import { ShieldSwitcher } from './components/ShieldSwitcher'; +import { TestNetModeSwitcher } from './components/TestNetModeSwitcher'; import { ThemeListItem, ThemesList } from './components/ThemeSwitcher'; export const LANG_MAP = { @@ -77,6 +79,7 @@ export function SettingsMenu() { + {PROD_ENV && } setView('themes')} component={MenuItem} /> diff --git a/src/layouts/components/TestNetModeSwitcher.tsx b/src/layouts/components/TestNetModeSwitcher.tsx new file mode 100644 index 0000000000..5a72201a3f --- /dev/null +++ b/src/layouts/components/TestNetModeSwitcher.tsx @@ -0,0 +1,36 @@ +import { Trans } from '@lingui/macro'; +import { ListItem, MenuItem } from '@mui/material'; +import { useState } from 'react'; +import { useRootStore } from 'src/store/root'; +import { SETTINGS } from 'src/utils/events'; + +import { SettingSwitchRow } from './SettingSwitchRow'; + +interface TestNetModeSwitcherProps { + component?: typeof MenuItem | typeof ListItem; +} + +export const TestNetModeSwitcher = ({ component = ListItem }: TestNetModeSwitcherProps) => { + const testnetsEnabledId = 'testnetsEnabled'; + const testnetsEnabledLocalstorage = localStorage.getItem(testnetsEnabledId) === 'true' || false; + const [testnetsEnabled, setTestnetsMode] = useState(testnetsEnabledLocalstorage); + const trackEvent = useRootStore((store) => store.trackEvent); + + const toggleTestnetsEnabled = () => { + const newState = !testnetsEnabled; + setTestnetsMode(!testnetsEnabled); + localStorage.setItem(testnetsEnabledId, newState ? 'true' : 'false'); + // Set window.location to trigger a page reload when navigating to the the dashboard + window.location.href = '/'; + }; + + return ( + Test Mode} + checked={testnetsEnabled} + onClick={toggleTestnetsEnabled} + onSwitchClick={() => trackEvent(SETTINGS.TESTNET_MODE)} + /> + ); +}; diff --git a/src/locales/en/messages.po b/src/locales/en/messages.po index 321e99e511..6d58e9a8e8 100644 --- a/src/locales/en/messages.po +++ b/src/locales/en/messages.po @@ -61,6 +61,7 @@ msgid "Estimated time" msgstr "Estimated time" #: src/layouts/AppHeader.tsx +#: src/layouts/components/TestNetModeSwitcher.tsx msgid "Test Mode" msgstr "Test Mode" diff --git a/src/utils/marketsAndNetworksConfig.ts b/src/utils/marketsAndNetworksConfig.ts index 53850e80c0..37a977ca2f 100644 --- a/src/utils/marketsAndNetworksConfig.ts +++ b/src/utils/marketsAndNetworksConfig.ts @@ -23,8 +23,8 @@ export type Pool = { export const STAGING_ENV = process.env.NEXT_PUBLIC_ENV === 'staging'; export const PROD_ENV = !process.env.NEXT_PUBLIC_ENV || process.env.NEXT_PUBLIC_ENV === 'prod'; -// Test mode has been removed from the UI; testnets are always disabled. -export const ENABLE_TESTNET = false; +export const ENABLE_TESTNET = + PROD_ENV && global?.window?.localStorage.getItem('testnetsEnabled') === 'true'; // determines if forks should be shown export const FORK_ENABLED =