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

Replace useSafeGasEstimatePolling with usePolling #23010

Merged
merged 93 commits into from
Mar 8, 2024

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Feb 16, 2024

Description

Added usePolling hook and used it within useSafeGasEstimatePolling 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

  1. Hit send button
  2. get to confirmation screen
  3. see that gas estimation updates

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

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.

Copy link
Contributor

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.

Copy link

codecov bot commented Feb 16, 2024

Codecov Report

Attention: Patch coverage is 94.78261% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 68.77%. Comparing base (6c810aa) to head (d7b1e5e).

Files Patch % Lines
ui/ducks/metamask/metamask.js 90.48% 2 Missing ⚠️
ui/store/actions.ts 77.78% 2 Missing ⚠️
app/scripts/metamask-controller.js 0.00% 1 Missing ⚠️
ui/pages/swaps/prepare-swap-page/review-quote.js 0.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

shanejonas
shanejonas previously approved these changes Feb 16, 2024
useEffect(() => {
getNetworkConfigurationByNetworkClientId(networkClientId).then(
(networkConfig) => {
if (networkConfig) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could this be undefined?

Copy link
Contributor

@adonesky1 adonesky1 Feb 20, 2024

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?

Copy link
Contributor Author

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

Copy link
Contributor

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

@jiexi jiexi force-pushed the jl/added-generic-polling-hook-replace-useSafe branch from 96dee07 to b91d6f9 Compare February 20, 2024 18:03
@jiexi jiexi force-pushed the jl/added-generic-polling-hook-replace-useSafe branch from b91d6f9 to 6398d06 Compare February 20, 2024 18:06
@adonesky1
Copy link
Contributor

I am able to repro, I see errors both from StaticIntervalPollingController and PolliognBlockTracker after I switch networks.

Steps:

Add ganache (server is on)
Perform a tx
Switch to sepolia

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

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?

Copy link
Contributor Author

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

adonesky1
adonesky1 previously approved these changes Mar 5, 2024
ui/hooks/usePolling.test.js Outdated Show resolved Hide resolved
JSON.stringify(
usePollingOptions.options,
Object.keys(usePollingOptions.options).sort(),
),
Copy link
Contributor

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.

Copy link
Contributor

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

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.

Copy link
Contributor

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

Copy link
Contributor

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 ?

Copy link
Contributor Author

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

@adonesky1 adonesky1 force-pushed the jl/added-generic-polling-hook-replace-useSafe branch from b627c45 to 37ef9ac Compare March 6, 2024 17:01
@metamaskbot
Copy link
Collaborator

Builds ready [37ef9ac]
Page Load Metrics (857 ± 451 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint862381364320
domContentLoaded158634199
load772761857939451
domInteractive158534199
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 278 Bytes (0.01%)
  • ui: 2.14 KiB (0.03%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [974acba]
Page Load Metrics (1093 ± 393 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint842111333316
domContentLoaded107132168
load8020071093818393
domInteractive97132168
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 278 Bytes (0.01%)
  • ui: 2.14 KiB (0.03%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [d7b1e5e]
Page Load Metrics (1058 ± 431 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint752931385627
domContentLoaded107427157
load5824081058897431
domInteractive107427157
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 278 Bytes (0.01%)
  • ui: 2.14 KiB (0.03%)
  • common: 0 Bytes (0.00%)

@adonesky1 adonesky1 merged commit 1f89a65 into develop Mar 8, 2024
76 checks passed
@adonesky1 adonesky1 deleted the jl/added-generic-polling-hook-replace-useSafe branch March 8, 2024 15:00
@github-actions github-actions bot locked and limited conversation to collaborators Mar 8, 2024
@metamaskbot metamaskbot added the release-11.14.0 Issue or pull request that will be included in release 11.14.0 label Mar 8, 2024
adonesky1 added a commit that referenced this pull request Apr 17, 2024
…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>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
INVALID-PR-TEMPLATE PR's body doesn't match template release-11.14.0 Issue or pull request that will be included in release 11.14.0 team-wallet-api-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants