-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Alert users when the network is busy #12268
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. |
@@ -91,7 +91,7 @@ export default function EditGasDisplay({ | |||
|
|||
useLayoutEffect(() => { | |||
if (showAdvancedForm && scrollRef.current) { | |||
scrollRef.current.scrollIntoView(); | |||
scrollRef.current.scrollIntoView?.(); |
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.
Added because the unit test I wrote for EditGasPopover choked on this. My guess is that this works differently in a jsdom environment than in a real environment.
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 is still applicable, only I ended up writing a test for EditGasDisplay instead.
...ts/app/gas-customization/gas-modal-page-container/gas-modal-page-container-component.test.js
Outdated
Show resolved
Hide resolved
...ponents/app/gas-customization/gas-modal-page-container/gas-modal-page-container.component.js
Outdated
Show resolved
Hide resolved
ui/pages/confirm-transaction-base/confirm-transaction-base.component.js
Outdated
Show resolved
Hide resolved
...ts/app/gas-customization/gas-modal-page-container/gas-modal-page-container-component.test.js
Outdated
Show resolved
Hide resolved
...ts/app/gas-customization/gas-modal-page-container/gas-modal-page-container-component.test.js
Outdated
Show resolved
Hide resolved
Great work @mcmire , esp with test coverage. |
1e8bc62
to
8d0a9bc
Compare
d8aa3f2
to
a039c0e
Compare
a039c0e
to
9a511a6
Compare
Builds ready [9a511a6]
Page Load Metrics (488 ± 52 ms)
highlights:storybook
|
9a511a6
to
596317b
Compare
Builds ready [596317b]Page Load Metrics (1162 ± 76 ms)
highlights:storybook
|
When a lot of transactions are occurring on the network, such as during an NFT drop, it drives gas fees up. When this happens, we want to not only inform the user about this, but also dissuade them from using a higher gas fee (as we have proved in testing that high gas fees can cause bidding wars and exacerbate the situation). The method for determining whether the network is "busy" is already handled by GasFeeController, which exposes a `networkCongestion` property within the gas fee estimate data. If this number exceeds 0.66 — meaning that the current base fee is above the 66th percentile among the base fees over the last several days — then we determine that the network is "busy".
596317b
to
0651d8b
Compare
@@ -133,14 +133,6 @@ export default function EditGasDisplay({ | |||
return ( | |||
<div className="edit-gas-display"> | |||
<div className="edit-gas-display__content"> | |||
{warning && !isGasEstimatesLoading && ( |
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 opted to take off the warning
prop because I didn't see it getting used. We can very easily just add a warning ourselves to this component.
@@ -24,24 +25,24 @@ const determineStatusInfo = (givenNetworkCongestion) => { | |||
const color = GRADIENT_COLORS[colorIndex]; | |||
const sliderTickValue = colorIndex * 10; | |||
|
|||
if (networkCongestion <= 0.33) { |
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 changed this slightly so that instead of:
- not busy: <= 0.33
- stable: > 0.33, <= 0.66
- busy: > 0.66
It is now:
- not busy: 0 up to 0.33
- stable: 0.33 up to 0.66
- busy: 0.66-
This is not strictly necessary to change, but given that I need to just test that the network is busy elsewhere, it made more sense in my head to say that the status changes to busy as soon as networkCongestion
crosses 0.66 instead of as soon as it exceeds it. Happy to change this back though.
@@ -20,31 +20,31 @@ const renderComponent = ({ networkCongestion }) => { | |||
|
|||
describe('StatusSlider', () => { | |||
it('should show "Not busy" when networkCongestion is less than 0.33', () => { | |||
const { queryByText } = renderComponent({ networkCongestion: 0.32 }); |
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.
Apparently I forgot the difference between query*
and get*
😆
At the same time all of these tests changed because the logic behind the slider changed.
export function getIsNetworkBusy(state) { | ||
const gasFeeEstimates = getGasFeeEstimates(state); | ||
return ( | ||
gasFeeEstimates?.networkCongestion >= NETWORK_CONGESTION_THRESHOLDS.BUSY |
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's the corresponding busy check that I referenced here #12268 (comment)
@@ -105,6 +106,13 @@ const TransactionAlerts = ({ | |||
type="warning" | |||
/> | |||
)} | |||
{isNetworkBusy ? ( |
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 warning applies to the EIP-1559 V2 UI and will appear on the confirm transaction screen. It will NOT appear within the edit gas modal because we already have the status slider which indicates the status of the network.
@@ -1,172 +1,307 @@ | |||
import React from 'react'; |
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 opted to refactor these tests so that they're simpler and don't require us to recreate the Redux state so much. I can put these changes in another PR if necessary, but I will point out the additional check for isNetworkBusy
regardless.
}); | ||
}); | ||
|
||
describe('if isNetworkBusy from useGasFeeContext is truthy', () => { |
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 are the new tests for the isNetworkBusy warning.
@@ -10,8 +10,11 @@ import { | |||
TRANSACTION_TYPES, | |||
} from '../../shared/constants/transaction'; | |||
import { transactionMatchesNetwork } from '../../shared/modules/transaction.utils'; | |||
import { getCurrentChainId, deprecatedGetCurrentNetworkId } from './selectors'; |
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.
The main change here is to have getSelectedAddress
come from ui/selectors/selectors
and not from ui/selectors
. The previous change created a circular dependency between ui/selectors
and ui/selectors/transactions
, which prevented us from jest.mock
'ing ui/selectors
correctly in component tests.
import configureStore from '../../../store/store'; | ||
import EditGasDisplay from '.'; | ||
|
||
jest.mock('../../../selectors'); |
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 might have been the simplest component test file I've ever written 😆
@@ -156,6 +148,16 @@ export default function EditGasDisplay({ | |||
/> | |||
</div> | |||
)} | |||
{isNetworkBusy ? ( |
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 warning applies to the EIP-1559 V1 UI. Note that this warning appears within the edit gas modal, NOT the confirm transaction screen, unlike EIP-1559 V2. I could have added it to the confirm transaction screen, but it would be more work. Given that we are soon transitioning to the V2 UI I feel like this is an okay compromise for now, but happy to change if not.
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 good, in V@ as I understand we are showing network busy only on edit gas fee modal.
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.
In V2 it's slightly different — we are showing the network busy message on the confirm transaction screen, but not in the edit gas fee modal.
Builds ready [0651d8b]Page Load Metrics (1108 ± 40 ms)
highlights:storybook
|
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.
LGTM
When a lot of transactions are occurring on the network, such as during
an NFT drop, it drives gas fees up. When this happens, we want to not
only inform the user about this, but also dissuade them from using a
higher gas fee (as we have proved in testing that high gas fees can
cause bidding wars and exacerbate the situation).
The method for determining whether the network is "busy" is already
handled by GasFeeController, which exposes a
networkCongestion
property within the gas fee estimate data. If this number exceeds 0.66 —
meaning that the current base fee is above the 66th percentile among the
base fees over the last several days — then we determine that the
network is "busy".
References
Fixes: #11307
Manual testing steps
There are two versions of this message: one for the "EIP-1559 V1" designs and one for the "EIP-1559 V2" designs. These designs impact the appearance of the confirm transaction screen and modal that appears when you edit the gas fee. You can switch from V1 to V2 locally by going into
.metamaskrc
and adding the following line:Then re-running
yarn start
oryarn start:dev
.Once you've done this, attempt to send a transaction. Under the V1 design, you should see a message if the network is busy when you go to edit the gas fee. Under the V2 design, you should see a message if the network is busy right away on the confirm transaction screen.
What does it mean for the network to be busy? There isn't really a great way to see this because it depends on the base fee of the latest block (and the base fee of the last 20,000 blocks). That said, I made a dashboard that you can use to monitor current gas fees in realtime. It re-uses the same logic that the extension is using to determine network busyness, which is defined as when the current base fee ranks in the top third of all base fees over the last 20,000 blocks. I've provided this threshold on the dashboard. So, to test, you would wait until the current base fee is greater than this threshold. Once this happens and the base fee turns orange, try sending a transaction through the extension and you should see the "network busy" message. (Note: Based on recent base fees, this is likely to happen more often than not.)
Screencaps
eip_1559_v1_network_busy.mov
eip_1559_v2_network_busy.mov