Skip to content

fix: hide balance alert if selected gas fee token #31497

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ describe('useInsufficientBalanceAlerts', () => {
).toEqual([]);
});

it('returns no alerts if account has balance less than gas fee plus value but gas fee token is selected', () => {
const alerts = runHook({
balance: 7,
currentConfirmation: TRANSACTION_MOCK,
transaction: { ...TRANSACTION_MOCK, selectedGasFeeToken: '0x123' },
});

expect(alerts).toEqual([]);
});

it('returns alert if account has balance less than gas fee plus value', () => {
const alerts = runHook({
balance: 7,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMemo } from 'react';
import { useSelector } from 'react-redux';

import { TransactionMeta } from '@metamask/transaction-controller';
import { Alert } from '../../../../../ducks/confirm-alerts/confirm-alerts';
import {
selectTransactionAvailableBalance,
Expand All @@ -19,8 +20,8 @@ import { useConfirmContext } from '../../../context/confirm';

export function useInsufficientBalanceAlerts(): Alert[] {
const t = useI18nContext();
const { currentConfirmation } = useConfirmContext();
const { id: transactionId } = currentConfirmation ?? {};
const { currentConfirmation } = useConfirmContext<TransactionMeta>();
const { id: transactionId, selectedGasFeeToken } = currentConfirmation ?? {};

const balance = useSelector((state) =>
selectTransactionAvailableBalance(state, transactionId),
Expand All @@ -42,8 +43,10 @@ export function useInsufficientBalanceAlerts(): Alert[] {
balance,
});

const showAlert = insufficientBalance && !selectedGasFeeToken;

return useMemo(() => {
if (!insufficientBalance) {
if (!showAlert) {
return [];
}

Expand All @@ -65,5 +68,5 @@ export function useInsufficientBalanceAlerts(): Alert[] {
severity: Severity.Danger,
},
];
}, [insufficientBalance]);
}, [nativeCurrency, showAlert, t]);
}
Loading