-
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,14 @@ import { shallowEqual, useSelector } from 'react-redux'; | |
import { GasEstimateTypes, GAS_LIMITS } from '../../../shared/constants/gas'; | ||
import { | ||
checkNetworkAndAccountSupports1559, | ||
getSelectedAccount, | ||
getTargetAccount, | ||
} from '../../selectors'; | ||
import { isLegacyTransaction } from '../../helpers/utils/transactions.util'; | ||
import { bnGreaterThan, bnLessThan } from '../../helpers/utils/util'; | ||
import { GAS_FORM_ERRORS } from '../../helpers/constants/gas'; | ||
import { Numeric } from '../../../shared/modules/Numeric'; | ||
import { PENDING_STATUS_HASH } from '../../helpers/constants/transactions'; | ||
import { TransactionType } from '../../../shared/constants/transaction'; | ||
|
||
const HIGH_FEE_WARNING_MULTIPLIER = 1.5; | ||
|
||
|
@@ -267,13 +269,19 @@ export function useGasFeeErrors({ | |
[gasErrors, gasWarnings], | ||
); | ||
|
||
const { balance: ethBalance } = useSelector(getSelectedAccount, shallowEqual); | ||
const balanceError = hasBalanceError( | ||
minimumCostInHexWei, | ||
transaction, | ||
ethBalance, | ||
const account = useSelector( | ||
(state) => getTargetAccount(state, transaction?.txParams?.from), | ||
shallowEqual, | ||
); | ||
|
||
// Balance check is only relevant for outgoing + pending transactions | ||
const balanceError = | ||
account !== undefined && | ||
transaction?.type !== TransactionType.incoming && | ||
transaction?.status in PENDING_STATUS_HASH | ||
Comment on lines
+277
to
+281
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 A better fix may be to further split these gas operations, so that callers can request only the necessary gas information for their contexts. |
||
? hasBalanceError(minimumCostInHexWei, transaction, account.balance) | ||
: false; | ||
|
||
return { | ||
gasErrors: errorsAndWarnings, | ||
hasGasErrors, | ||
|
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.