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

Adding warnings for excessive custom gas input #10582

Merged
merged 1 commit into from Mar 5, 2021
Merged

Adding warnings for excessive custom gas input #10582

merged 1 commit into from Mar 5, 2021

Conversation

ryanml
Copy link
Contributor

@ryanml ryanml commented Mar 4, 2021

Fixes #9811

Screen Shot 2021-03-03 at 9 35 58 PM

Screen Shot 2021-03-03 at 9 35 36 PM

Manual testing steps:

  • Go to "Send"
  • Click on "Advanced Options"
  • Ensure that entering custom amounts lower than fast or slightly above it produces no warning
  • Enter an amount of GWEI exceeding 1.5 times the fast estimate.
  • Ensure that the excessive warning is shown beneath the input.
  • Click "Save"
  • Ensure the warning persists on the send content screen
  • Click "Reset" to wipe the custom gas entry
  • Ensure that the warning goes away.

@ryanml ryanml self-assigned this Mar 4, 2021
@ryanml ryanml requested a review from a team as a code owner March 4, 2021 05:27
@ryanml ryanml requested a review from shanejonas March 4, 2021 05:27
@@ -47,6 +47,7 @@ export default function reduceMetamask(state = {}, action) {
participateInMetaMetrics: null,
metaMetricsSendCount: 0,
nextNonce: null,
customGasIsExcessive: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After navigating away from the advanced gas options, hex value representations of the custom gas are wiped from memory, so we can't recalculate using isCustomPriceExcessive to display the warning on the Send screen. We can just cache it here for access.

Copy link
Member

Choose a reason for hiding this comment

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

We mostly use this Redux slice for holding background data. We've added UI-specific data here in the past, but we had plans to migrate all of that state elsewhere and reduce this to just the background state. In the meantime I think we should avoid adding more UI state here.

I'm not sure I follow the reason for caching this in the first place though 🤔 The full transaction state remains accessible throughout the send flow. It should be accessible while the user is on the Send screen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So from the send transaction screen, after navigating to "Advanced Options", and inputting 100 GWEI for the custom gas amount, the value of state.gas.customData is: {price: "0x174876e800", limit: "0x5208"}. The excessive calculation is then performed on that price hex value.

After clicking "Save" and the advanced options being closed, the value of state.gas.customData is: {price: null, limit: null}, so the Send component if it uses the isCustomPriceExcessive selector at that point will always see that to be false.

I'm not sure if there's a good reason that state.gas.customData.price is cleared after closing the advanced options, but maybe it should persist as long as the transaction screen is open at all?

Copy link
Member

Choose a reason for hiding this comment

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

A couple of things on this.

  1. I don't think we need to refer to this as a cache, it is just an application state entry. I understand that we're not doing the calculation again, which mimics a cache-like behavior, but that's a side effect of not having access.
  2. I think that this entry should likely be in the 'send' duck, vs metamask state. I believe this slice is used/cleared from the send page level.

Copy link
Member

Choose a reason for hiding this comment

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

Oops, refresh page before commenting brad, duh.

Copy link
Member

@Gudahtt Gudahtt Mar 4, 2021

Choose a reason for hiding this comment

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

After clicking "Save" and the advanced options being closed, the value of state.gas.customData is: {price: null, limit: null}, so the Send component if it uses the isCustomPriceExcessive selector at that point will always see that to be false.

At that point, the new gas data is saved on the actual transaction though, which is in state.metamask.send.gasPrice. The selector can use that value instead, without needing to cache anything.

The state.gas slice is used for state relating to the gas customization modal that is currently open (which, for the record, seems like a fundamentally poor use of Redux but 🤷 It is what it is). I'm guessing that the custom data is cleared when the modal closes, because then it's not meant to be used for anything.

The state for the Send flow is currently split between state.send and state.metamask.send, with state.send being the preferred place for all send state.

I'm not opposed to adding this to the send state, but using send.gasPrice directly seems safer to me. That way if it changes for any reason, this warning will always reflect the correct state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good to know! I think ideally nothing would be stored in the state for this, I can modify the isCustomPriceExcessive selector to check state.metamask.send.gasPrice when we are outside the customization modal 👍

Copy link
Member

Choose a reason for hiding this comment

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

I'm not opposed to adding this to the send state, but using send.gasPrice directly seems safer to me. That way if it changes for any reason, this warning will always reflect the correct state.

Yeah that looks like the winner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed! Now no modifications to the state, I added some additional selector tests to support the send.gasPrice check

@metamaskbot
Copy link
Collaborator

Builds ready [28591ea]
Page Load Metrics (604 ± 21 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint47765884
domContentLoaded4596546034521
load4616556044521
domInteractive4596536034521

Copy link
Member

@brad-decker brad-decker left a comment

Choose a reason for hiding this comment

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

With the exception of moving the state related to this excessive gas error into the send slide of state, this looks good to me. Ran locally to QA and did code review., prefer to use the gasPrice from the metamask.send.gasPrice and remove the need to have an additional state entry.

@metamaskbot
Copy link
Collaborator

Builds ready [1cf6846]
Page Load Metrics (572 ± 26 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint43805895
domContentLoaded3586295715426
load3606305725326
domInteractive3586295715426

brad-decker
brad-decker previously approved these changes Mar 4, 2021
Copy link
Member

@brad-decker brad-decker left a comment

Choose a reason for hiding this comment

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

LGTM

Gudahtt
Gudahtt previously approved these changes Mar 4, 2021
Copy link
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 suggested a few more improvements, but nothing major.

Copy link
Member

@brad-decker brad-decker 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
Collaborator

Builds ready [74dfbe8]
Page Load Metrics (566 ± 22 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint448458105
domContentLoaded3736015644622
load3756025664622
domInteractive3736005644622

@ryanml ryanml merged commit 45c076e into develop Mar 5, 2021
@ryanml ryanml deleted the fix-9811 branch March 5, 2021 17:32
@github-actions github-actions bot locked and limited conversation to collaborators Mar 5, 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.

Warn users when gas price being provided is wildly over estimate
4 participants