-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force-toggle testnets visibility in network switcher #3793
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { createSlice, createSelector } from "@reduxjs/toolkit" | ||
import Emittery from "emittery" | ||
import { AddressOnNetwork } from "../accounts" | ||
import { ETHEREUM } from "../constants" | ||
import { ETHEREUM, TEST_NETWORK_BY_CHAIN_ID } from "../constants" | ||
import { AnalyticsEvent, OneTimeAnalyticsEvent } from "../lib/posthog" | ||
import { EVMNetwork } from "../networks" | ||
import { AnalyticsPreferences, DismissableItem } from "../services/preferences" | ||
|
@@ -11,11 +11,12 @@ import { AccountState, addAddressNetwork } from "./accounts" | |
import { createBackgroundAsyncThunk } from "./utils" | ||
import { UNIXTime } from "../types" | ||
import { DEFAULT_AUTOLOCK_INTERVAL } from "../services/preferences/defaults" | ||
import type { RootState } from "." | ||
|
||
export const defaultSettings = { | ||
hideDust: false, | ||
defaultWallet: false, | ||
showTestNetworks: false, | ||
showTestNetworks: true, | ||
showNotifications: undefined, | ||
collectAnalytics: false, | ||
showAnalyticsNotification: false, | ||
|
@@ -77,6 +78,7 @@ export type Events = { | |
updateAnalyticsPreferences: Partial<AnalyticsPreferences> | ||
addCustomNetworkResponse: [string, boolean] | ||
updateAutoLockInterval: number | ||
toggleShowTestNetworks: boolean | ||
} | ||
|
||
export const emitter = new Emittery<Events>() | ||
|
@@ -392,6 +394,22 @@ export const setSelectedNetwork = createBackgroundAsyncThunk( | |
}, | ||
) | ||
|
||
export const toggleShowTestNetworks = createBackgroundAsyncThunk( | ||
"ui/toggleShowTestNetworks", | ||
async (value: boolean, { dispatch, getState }) => { | ||
const state = getState() as RootState | ||
|
||
const currentNetwork = state.ui.selectedAccount.network | ||
|
||
// If user is on one of the built-in test networks, don't leave them stranded | ||
if (TEST_NETWORK_BY_CHAIN_ID.has(currentNetwork.chainID)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also guard on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I think this should also happen if the production build has the testnet as a built in network that's still under a feature flag. |
||
dispatch(setSelectedNetwork(ETHEREUM)) | ||
} | ||
|
||
await emitter.emit("toggleShowTestNetworks", value) | ||
}, | ||
) | ||
|
||
export const refreshBackgroundPage = createBackgroundAsyncThunk( | ||
"ui/refreshBackgroundPage", | ||
async () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,8 @@ import { | |
selectShowNotifications, | ||
setShouldShowNotifications, | ||
selectShowTestNetworks, | ||
toggleTestNetworks, | ||
toggleHideBanners, | ||
toggleShowTestNetworks, | ||
selectHideBanners, | ||
selectShowUnverifiedAssets, | ||
toggleShowUnverifiedAssets, | ||
|
@@ -186,8 +186,8 @@ export default function Settings(): ReactElement { | |
) | ||
} | ||
|
||
const toggleShowTestNetworks = (defaultWalletValue: boolean) => { | ||
dispatch(toggleTestNetworks(defaultWalletValue)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably kill this old action in the UI slice yeah? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait this old action is still used to update the "cached" store value 👀 (in the redux service) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhh I see. Ok, so we have moved from, “if you want to toggle test networks you update directly in redux” to “if you want to toggle test networks you thunk in redux, which updates the preference service, which then updates in redux”, and Ok well that's clear as mud as in other cases that we've done this heh, and we have the same problem in the whole slice. We should figure out a clearer way to name these IMO—something like This isn't a blocker though, just going to continue to be a pain point. The other option is abstracting preference settings a little more, but I remember I did a deep pass at that a couple of years ago and the typing is (or was) a near impossibility. |
||
const toggleShowTestnets = (defaultWalletValue: boolean) => { | ||
dispatch(toggleShowTestNetworks(defaultWalletValue)) | ||
} | ||
|
||
const toggleShowUnverified = (toggleValue: boolean) => { | ||
|
@@ -243,7 +243,7 @@ export default function Settings(): ReactElement { | |
title: t("settings.enableTestNetworks"), | ||
component: () => ( | ||
<SharedToggleButton | ||
onChange={(toggleValue) => toggleShowTestNetworks(toggleValue)} | ||
onChange={(toggleValue) => toggleShowTestnets(toggleValue)} | ||
value={showTestNetworks} | ||
/> | ||
), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps for clarity? Or even
updatedShowTestNetworksValue
or similar?