Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/layouts/MobileMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -172,6 +173,7 @@ export const MobileMenu = ({ open, setOpen }: MobileMenuProps) => {
</ListItemText>
</ListItem>
<ShieldSwitcher />
{PROD_ENV && <TestNetModeSwitcher />}
<LanguageListItem onClick={() => setSubmenu('languages')} />
<ThemeListItem onClick={() => setSubmenu('themes')} />
</List>
Expand Down
3 changes: 3 additions & 0 deletions src/layouts/SettingsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -77,6 +79,7 @@ export function SettingsMenu() {

<Menu {...MENU_PROPS} anchorEl={anchorEl} open={view === 'settings'} onClose={handleClose}>
<ShieldSwitcher component={MenuItem} />
{PROD_ENV && <TestNetModeSwitcher component={MenuItem} />}
<LanguageListItem onClick={handleLanguageClick} component={MenuItem} />
<ThemeListItem onClick={() => setView('themes')} component={MenuItem} />

Expand Down
36 changes: 36 additions & 0 deletions src/layouts/components/TestNetModeSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<SettingSwitchRow
component={component}
label={<Trans>Test Mode</Trans>}
checked={testnetsEnabled}
onClick={toggleTestnetsEnabled}
onSwitchClick={() => trackEvent(SETTINGS.TESTNET_MODE)}
/>
);
};
1 change: 1 addition & 0 deletions src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions src/utils/marketsAndNetworksConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Loading