Skip to content

cancel unapproved confirmations on network change#10357

Merged
brad-decker merged 2 commits intodevelopfrom
clear-pending-confirmations
Feb 8, 2021
Merged

cancel unapproved confirmations on network change#10357
brad-decker merged 2 commits intodevelopfrom
clear-pending-confirmations

Conversation

@brad-decker
Copy link
Copy Markdown
Contributor

Rationale

We will soon be switching a user's actively selected network after they confirm an addEthereumChain request. This can confuse other unapproved confirmations that can be associated with specific chains. This change drops all unapproved confirmations when switching networks.

It also adds some new constants for event names, but only cleans up the ones that were touched as part of this work.

@brad-decker brad-decker force-pushed the clear-pending-confirmations branch from cfdc3da to 9a35be4 Compare February 3, 2021 18:27
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [9a35be4]
Page Load Metrics (574 ± 37 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint45725984
domContentLoaded3947165737837
load3957175747837
domInteractive3947165737837

@brad-decker brad-decker marked this pull request as ready for review February 3, 2021 19:41
@brad-decker brad-decker requested a review from a team as a code owner February 3, 2021 19:41
@brad-decker brad-decker force-pushed the clear-pending-confirmations branch 2 times, most recently from 4950061 to dc1b808 Compare February 4, 2021 22:09
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [dc1b808]
Page Load Metrics (563 ± 35 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint44755894
domContentLoaded3607395617335
load3627405637335
domInteractive3607395617335

// Fired when the actively selected network *will* change
NETWORK_WILL_CHANGE: 'networkWillChange',
// Fired after state changes that impact the extension badge (unapproved msg count)
UPDATE_BADGE: 'updateBadge',
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.

I'm not sure it makes sense to group these together 🤔 The first two are network controller events, but the third is a MetaMask controller event. They're emitted on entirely different things.

Or at the very least this difference should be more prominent in the comment descriptions.

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.

@Gudahtt do you have any preference for one of the following:

a. Controller specific event constants declared and exported in the controller file as EVENTS with events that are emitted by many controllers in the metamask-controller file
b. Group events in this event-names file by controller name. NETWORK.WILL_CHANGE and METAMASK_CONTROLLER.UPDATE_BADGE

Either option is good for me, and I agree with your feedback.

Copy link
Copy Markdown
Member

@Gudahtt Gudahtt Feb 8, 2021

Choose a reason for hiding this comment

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

I'd probably choose the first approach, but either one seems fine! These will likely be supplanted by the new controller messaging system in the future anyway I would imagine.

* Clears all unapproved messages from memory.
*/
clearUnapproved() {
this.memStore.updateState({
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.

For some ungodly reason we store signature requests in two different places in these message manager classes. They are communicated to the UI via this memStore but the primary list is in this.messages, which remains unchanged here. Take a look at getUnapprovedMsgs for example - that would still return messages "cleared" here.

I believe the same applies to the other message manager classes as well.

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.

Huh, I don't disagree, but I'm very curious how this was working in practice then. I'll dig into that to understand more and submit this fix in the meantime

@brad-decker brad-decker force-pushed the clear-pending-confirmations branch from dc1b808 to d4ef5bb Compare February 8, 2021 17:54
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [d4ef5bb]
Page Load Metrics (565 ± 36 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint44835894
domContentLoaded3596925637636
load3616935657536
domInteractive3596925637636

@brad-decker brad-decker requested a review from Gudahtt February 8, 2021 18:30
* Clears all unapproved messages from memory.
*/
clearUnapproved() {
this.messages = [];
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.

This seems to clear all messages 🤔 Not just unapproved messages.

Not sure I'm reading this right or not, but it looks like in prod right now we keep messages indefinitely, but they don't get persisted so they're lost upon restart.

Copy link
Copy Markdown
Member

@Gudahtt Gudahtt Feb 8, 2021

Choose a reason for hiding this comment

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

Since we never do anything with approved messages, and since they get cleared on restart, clearing them when switching networks seems fine 🤷‍♂️

I guess we should update the method name and description though.

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.

I decided to just filter out the unapproved messages here instead of resetting them completely. the function signature and description now align with the code.

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!

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [e13260f]
Page Load Metrics (654 ± 41 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint50735973
domContentLoaded4728316518541
load4738326548641
domInteractive4728306518541

@brad-decker brad-decker merged commit 19fa2f5 into develop Feb 8, 2021
@brad-decker brad-decker deleted the clear-pending-confirmations branch February 8, 2021 23:22
@github-actions github-actions bot locked and limited conversation to collaborators Feb 8, 2021
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