Skip to content

set last provider when switching to a customRPC#10084

Merged
brad-decker merged 1 commit intodevelopfrom
fix-regressed-network-switch
Dec 16, 2020
Merged

set last provider when switching to a customRPC#10084
brad-decker merged 1 commit intodevelopfrom
fix-regressed-network-switch

Conversation

@brad-decker
Copy link
Copy Markdown
Contributor

Fixes: a regression in falling back to the last connected provider when attempting to connect to a custom rpc (localhost as an example). Previously the last successfully connected provider would be reconnected. Presently when attempting to connect to a custom RPC the currently connected provider is not set as the 'lastConnectedProvider', which means that the provider the UI falls back to in the case of an error or user exiting the loading screen is not the most recently connected provider. In some cases, such as if the user loads the extension and immediately chooses a custom RPC, the fallback provider is 'ropsten' which is hardcoded in the UI in case there is no lastConnectedProvider.

This PR resolves this by adding the call to setPreviousProvider to the custom RPC code. All other cases use the setProviderType which triggers the correct UI flow of first setting the lastConnectedProvider

@brad-decker brad-decker force-pushed the fix-regressed-network-switch branch from d3c042a to fecb664 Compare December 15, 2020 23:16
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [fecb664]
Page Load Metrics (576 ± 16 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint337150115
domContentLoaded5256265743316
load5266285763316
domInteractive5246265743316

@brad-decker brad-decker marked this pull request as ready for review December 15, 2020 23:37
@brad-decker brad-decker requested a review from a team as a code owner December 15, 2020 23:37
@brad-decker brad-decker requested a review from Gudahtt December 15, 2020 23:37
@Gudahtt
Copy link
Copy Markdown
Member

Gudahtt commented Dec 15, 2020

Great find! Any idea when this bug was introduced?

@brad-decker brad-decker changed the title fix regressed provider switch set last provider when switching to a customRPC Dec 15, 2020
@brad-decker
Copy link
Copy Markdown
Contributor Author

Actually after going another layer down, this wasn't a regression. I fixed a different issue before I joined MetaMask (#8197 my first merged PR) and I originally hunted this down because it felt like a regression of that fix. I think, though, this has existed for a while -- at least I don't see where lastConnectedProvider was set ever in this flow as I go back through the history

closeMenu={() => this.props.hideNetworkDropdown()}
onClick={() => {
if (isPrefixedFormattedHexString(chainId)) {
setPreviousProvider(providerType)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does this do when providerType is rpc 🤔

Maybe this is a separate bug that is out of scope here, but I think it would blow up in that case, as setProviderType in the network controller asserts that type isn't rpc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, good point. I'll address this in a follow-up.

Copy link
Copy Markdown
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM! I suspect this behavior is still broken in the case where it tries to switch back to a custom RPC endpoint, but that is independent of what you're addressing here.

@brad-decker brad-decker merged commit ce70c86 into develop Dec 16, 2020
@brad-decker brad-decker deleted the fix-regressed-network-switch branch December 16, 2020 15:48
@github-actions github-actions bot locked and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants