-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Fix gas calculation checking wrong account balance #21174
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. |
@@ -122,7 +121,7 @@ export const generateUseSelectorRouter = | |||
}, | |||
}; | |||
} | |||
if (selector === getSelectedAccount) { | |||
if (selector.toString().includes('getTargetAccount')) { |
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.
Hack because the selector is actually a lambda, to allow getTargetAccount
to accept a second parameter. Therefore it can't use function equality like the others.
A better approach to this kind of mocking, would keep the selectors from the product code and mock the state instead. Better to mock the lowest level thing, so that the product selectors are tested too if they change.
// Balance check is only relevant for outgoing + pending transactions | ||
const balanceError = | ||
account !== undefined && | ||
transaction?.type !== TransactionType.incoming && | ||
transaction?.status in PENDING_STATUS_HASH |
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 found that this balance check was being called in cases it should not. Like for incoming transactions, and transactions that have already confirmed. Because we won't have the from
account in our state for incoming transactions, this guard is needed.
A better fix may be to further split these gas operations, so that callers can request only the necessary gas information for their contexts.
Builds ready [25a9129]
Page Load Metrics (1118 ± 355 ms)
Bundle size diffs
|
… brian/gas-check-wrong-account
506f20a
Builds ready [506f20a]
Page Load Metrics (640 ± 356 ms)
Bundle size diffs
|
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #21174 +/- ##
========================================
Coverage 68.61% 68.61%
========================================
Files 1020 1020
Lines 40929 40934 +5
Branches 10920 10925 +5
========================================
+ Hits 28080 28085 +5
Misses 12849 12849
☔ View full report in Codecov by Sentry. |
Description
Dapps can connect to / prompt transactions from a different account than the one currently selected within the wallet itself.
When this occurs,
useGasFeeErrors
was doing a balance check against the wrong account. It was using the current account within the wallet, instead of the account issuing the transaction. This can cause balance errors even when the account has sufficient funds.This shows in 2 places in the UI, which are the only places checking
balanceError
:Solution: Check balance of the account issuing the transaction.
Manual testing steps
Screenshots/Recordings
Before
gas-check-wrong-account.mov
Related issues
Fixes: #20770
Pre-merge author checklist
Pre-merge reviewer checklist