Skip to content
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

Merged
merged 3 commits into from
Mar 6, 2025

Conversation

hyphenized
Copy link
Collaborator

@hyphenized hyphenized commented Mar 3, 2025

This PR moves the testnet visibility setting to the preference service, and sets a migration to enable it on all existing and new installs.

Testing

  • On a new install, check testnets shows up by default on network switcher
  • On existing install, after update testnets should show up

Latest build: extension-builds-3793 (as of Tue, 04 Mar 2025 05:05:23 GMT).

Moves test network visibility user setting to preference service and sets force toggles it to display on all new and existing installs
@hyphenized hyphenized self-assigned this Mar 3, 2025
@hyphenized hyphenized marked this pull request as ready for review March 4, 2025 05:00
@hyphenized hyphenized requested a review from Shadowfiend March 4, 2025 05:00
@@ -186,8 +186,8 @@ export default function Settings(): ReactElement {
)
}

const toggleShowTestNetworks = (defaultWalletValue: boolean) => {
dispatch(toggleTestNetworks(defaultWalletValue))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably kill this old action in the UI slice yeah?

Copy link
Collaborator Author

@hyphenized hyphenized Mar 4, 2025

Choose a reason for hiding this comment

The 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)

Copy link
Contributor

Choose a reason for hiding this comment

The 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 toggleShowTestNetworks is the thunk and toggleTestNetworks is the direct state update.

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 setShow... and updateShow... or something—and we should clearly document at the top of the slice.

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.

Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty shocked this wasn't in the preferences service to begin with 😆

@@ -392,6 +394,22 @@ export const setSelectedNetwork = createBackgroundAsyncThunk(
},
)

export const toggleShowTestNetworks = createBackgroundAsyncThunk(
"ui/toggleShowTestNetworks",
async (value: boolean, { dispatch, getState }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async (value: boolean, { dispatch, getState }) => {
async (updatedValue: boolean, { dispatch, getState }) => {

Perhaps for clarity? Or even updatedShowTestNetworksValue or similar?

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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also guard on !value right? Like, if the user is toggling from off to on, we shouldn't push them into Ethereum—in theory they wouldn't be there anyway because they wouldn't be on a test network, but in fact they might be if they've added the testnet as a custom chain, for example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

@Shadowfiend Shadowfiend merged commit 4671a6e into campaign-1 Mar 6, 2025
6 checks passed
@Shadowfiend Shadowfiend deleted the test-network-visibility branch March 6, 2025 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants