-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Replace useSafeGasEstimatePolling with usePolling #23010
Replace useSafeGasEstimatePolling with usePolling #23010
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #23010 +/- ##
===========================================
+ Coverage 68.70% 68.77% +0.07%
===========================================
Files 1120 1120
Lines 43509 43527 +18
Branches 11636 11654 +18
===========================================
+ Hits 29891 29933 +42
+ Misses 13618 13594 -24 ☔ View full report in Codecov by Sentry. |
...components/advanced-gas-fee-popover/advanced-gas-fee-inputs/base-fee-input/base-fee-input.js
Show resolved
Hide resolved
ui/hooks/useGasFeeEstimates.js
Outdated
useEffect(() => { | ||
getNetworkConfigurationByNetworkClientId(networkClientId).then( | ||
(networkConfig) => { | ||
if (networkConfig) { |
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.
could this be undefined?
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.
doesn't seem like we have any plan in the case that it is... should we throw an error since this would be unexpected?
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.
yeah, i suppose we should throw an error, but i think that's tricky to do from inside an effect
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.
If its undefined
we could set some error state that we could return from the hook. The reason I think we probably need to do something like this is because it won't be apparent what's wrong and why polling isn't working if this failed... Though I admit I don't see why it would fail
96dee07
to
b91d6f9
Compare
b91d6f9
to
6398d06
Compare
I agree this is should be addressed separately but I'm confused why I'm not seeing the errors you describe. I followed the steps above and this is what I'm seeing: Screen.Recording.2024-03-05.at.12.37.45.PM.mov |
@@ -65,6 +65,7 @@ export default function GasTiming({ | |||
const previousIsUnknownLow = usePrevious(isUnknownLow); |
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.
Looks like we're not reading gasFeeEstimates
and gasEstimateType
from the gasFeeEstimatesByChainId
state yet on this component. Is that intentional?
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.
i believe values derived from gasFeeEstimatesByChainId are used here
JSON.stringify( | ||
usePollingOptions.options, | ||
Object.keys(usePollingOptions.options).sort(), | ||
), |
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.
Wondering if its possible to simplify above conditional.
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.
This logic is to ensure that if the usePollingOptions.options
is present we can guarantee the order of the keys in the option object so that the hook doesn't rerun unnecessarily. I'm not sure if there is a better way to express that conditional.
const [priorityFee, setPriorityFee] = useState(defaultPriorityFee); | ||
useEffect(() => { | ||
setPriorityFee(defaultPriorityFee); | ||
}, [defaultPriorityFee, setPriorityFee]); |
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.
Here we did calculation in useState
as this should be done only once. defaultPriorityFee
should not change.
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.
I believe this is necessary because with the new polling hook some of the values from useGasFeeContext
used to derive defaultPriorityFee
will be undefined on first render. @jiexi can maybe add some color here
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.
But we need to check scenario if user has set a custom value for priority fee, can this override that ?
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.
User set Max Base Fee and Priority Fee are not reset/changed by this. I have verified by delaying the gas estimate state update in the hook and seeing that the Max Fee does not change and that of course the Max Base Fee and Priority Fee inputs do not change either
b627c45
to
37ef9ac
Compare
Builds ready [37ef9ac]
Page Load Metrics (857 ± 451 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [974acba]
Page Load Metrics (1093 ± 393 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [d7b1e5e]
Page Load Metrics (1058 ± 431 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
…tworkClientId (#24065) <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** #23010 made initial changes to replace the GasFeeController's legacy gas fee polling in favor of polling via networkClientId. It was discovered that there are still lingering instances of the legacy gas fee polling which were causing double polling to occur since the legacy and networkClientId based polling run on separate loops. This PR fixes this by replacing those remaining legacy gas fee polling usages. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24065?quickstart=1) ## **Related issues** Fixes: #23010 ## **Manual testing steps** 1. Open background console -> Network tab 2. Open Extension Popup -> send -> enter address and amount -> next 3. Background console network tab should now start showing one single network request every 10s to the gas api endpoint ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: Alex <adonesky@gmail.com>
Description
Added
usePolling
hook and used it withinuseSafeGasEstimatePolling
hook.This replaces where gas estimates are coming from for the confirmation flow.
Related issues
Fixes: https://github.com/MetaMask/MetaMask-planning/issues/2014
Manual testing steps
Pre-merge author checklist
Pre-merge reviewer checklist