Skip to content

Commit 08c4b6f

Browse files
committed
fix: release-blocker restore gas estimate alerts
1 parent 825cbe0 commit 08c4b6f

2 files changed

Lines changed: 63 additions & 34 deletions

File tree

app/components/Views/confirmations/hooks/alerts/useGasEstimateFailedAlert.test.ts

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ import { useTransactionMetadataRequest } from '../transactions/useTransactionMet
1010
import { AlertKeys } from '../../constants/alerts';
1111
import { RowAlertKey } from '../../components/UI/info-row/alert-row/constants';
1212
import { Severity } from '../../types/alerts';
13-
import { useIsGaslessSupported } from '../gas/useIsGaslessSupported';
13+
import { getGasFeesSponsoredNetworkEnabled } from '../../../../../selectors/featureFlagController/gasFeesSponsored';
14+
import { isHardwareAccount } from '../../../../../util/address';
15+
import { selectSelectedInternalAccountFormattedAddress } from '../../../../../selectors/accountsController';
16+
17+
jest.mock('../../../../../selectors/featureFlagController/gasFeesSponsored');
18+
jest.mock('../transactions/useTransactionMetadataRequest');
19+
jest.mock('../../../../../selectors/accountsController');
20+
jest.mock('../../../../../util/address', () => ({
21+
...jest.requireActual('../../../../../util/address'),
22+
isHardwareAccount: jest.fn(),
23+
}));
1424

1525
const MOCK_TRANSACTION_META = {
1626
id: '1',
@@ -30,21 +40,31 @@ const MOCK_TRANSACTION_META_WITH_SIMULATION_FAILS = {
3040
},
3141
} as unknown as TransactionMeta;
3242

33-
jest.mock('../transactions/useTransactionMetadataRequest');
34-
jest.mock('../gas/useIsGaslessSupported');
43+
const mockGetGasFeesSponsoredNetworkEnabled = jest.mocked(
44+
getGasFeesSponsoredNetworkEnabled,
45+
);
46+
47+
const mockIsHardwareAccount = jest.mocked(isHardwareAccount);
48+
const mockSelectSelectedInternalAccountFormattedAddress = jest.mocked(
49+
selectSelectedInternalAccountFormattedAddress,
50+
);
3551

3652
describe('useGasEstimateFailedAlert', () => {
3753
const mockUseTransactionMetadataRequest = jest.mocked(
3854
useTransactionMetadataRequest,
3955
);
40-
const useIsGaslessSupportedMock = jest.mocked(useIsGaslessSupported);
56+
4157
beforeEach(() => {
4258
jest.clearAllMocks();
43-
useIsGaslessSupportedMock.mockReturnValue({
44-
isSmartTransaction: false,
45-
isSupported: false,
46-
pending: false,
47-
});
59+
mockGetGasFeesSponsoredNetworkEnabled.mockReturnValue(() => false);
60+
mockIsHardwareAccount.mockReturnValue(false);
61+
mockSelectSelectedInternalAccountFormattedAddress.mockReturnValue(
62+
'0x13b7e6EBcd40777099E4c45d407745aB2de1D1F8',
63+
);
64+
});
65+
66+
afterEach(() => {
67+
jest.clearAllMocks();
4868
});
4969

5070
it('returns alert when simulationFails is truthy', () => {
@@ -113,35 +133,32 @@ describe('useGasEstimateFailedAlert', () => {
113133
expect(result.current).toEqual([]);
114134
});
115135

116-
it('returns no alerts if simulation fails but transaction is gasless or sponsored', () => {
136+
it('returns no alerts if simulation fails but network is sponsored', () => {
117137
mockUseTransactionMetadataRequest.mockReturnValue(
118138
MOCK_TRANSACTION_META_WITH_SIMULATION_FAILS,
119139
);
120-
useIsGaslessSupportedMock.mockReturnValue({
121-
isSmartTransaction: false,
122-
isSupported: true,
123-
pending: false,
124-
});
140+
mockGetGasFeesSponsoredNetworkEnabled.mockReturnValue(() => true);
125141
const { result } = renderHookWithProvider(() =>
126142
useGasEstimateFailedAlert(),
127143
);
128144

129-
expect(result.current[0]).toBe(undefined);
145+
expect(result.current).toEqual([]);
130146
});
131147

132-
it('returns no alerts when gasless support check is pending', () => {
148+
it('returns alert with correct message content if network is sponsored but user is hardware wallet', () => {
133149
mockUseTransactionMetadataRequest.mockReturnValue(
134150
MOCK_TRANSACTION_META_WITH_SIMULATION_FAILS,
135151
);
136-
useIsGaslessSupportedMock.mockReturnValue({
137-
isSmartTransaction: false,
138-
isSupported: false,
139-
pending: true,
140-
});
152+
mockIsHardwareAccount.mockReturnValue(true);
153+
mockGetGasFeesSponsoredNetworkEnabled.mockReturnValue(() => true);
154+
141155
const { result } = renderHookWithProvider(() =>
142156
useGasEstimateFailedAlert(),
143157
);
144158

145-
expect(result.current[0]).toBe(undefined);
159+
expect(result.current.length).toBe(1);
160+
expect(result.current[0].message).toBe(
161+
"We're unable to provide an accurate fee and this estimate might be high. We suggest you to input a custom gas limit, but there's a risk the transaction will still fail.",
162+
);
146163
});
147164
});

app/components/Views/confirmations/hooks/alerts/useGasEstimateFailedAlert.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,33 @@ import { RowAlertKey } from '../../components/UI/info-row/alert-row/constants';
55
import { AlertKeys } from '../../constants/alerts';
66
import { Alert, Severity } from '../../types/alerts';
77
import { useEstimationFailed } from '../gas/useEstimationFailed';
8-
import { useIsGaslessSupported } from '../gas/useIsGaslessSupported';
8+
import { useSelector } from 'react-redux';
9+
import { getGasFeesSponsoredNetworkEnabled } from '../../../../../selectors/featureFlagController/gasFeesSponsored';
10+
import { isHardwareAccount } from '../../../../../util/address';
11+
import { selectSelectedInternalAccountFormattedAddress } from '../../../../../selectors/accountsController';
12+
import { useTransactionMetadataRequest } from '../transactions/useTransactionMetadataRequest';
913

1014
export const useGasEstimateFailedAlert = (): Alert[] => {
1115
const estimationFailed = useEstimationFailed();
12-
const {
13-
isSupported: isGaslessSupported,
14-
pending: isGaslessSupportCheckPending,
15-
} = useIsGaslessSupported();
16+
17+
const transactionMeta = useTransactionMetadataRequest();
18+
19+
const isGasFeesSponsoredNetworkEnabled = useSelector(
20+
getGasFeesSponsoredNetworkEnabled,
21+
);
22+
const selectedAddress = useSelector(
23+
selectSelectedInternalAccountFormattedAddress,
24+
);
25+
const isHardwareWallet = Boolean(
26+
selectedAddress && isHardwareAccount(selectedAddress),
27+
);
28+
const isGasSponsored =
29+
transactionMeta?.chainId &&
30+
!isHardwareWallet &&
31+
isGasFeesSponsoredNetworkEnabled(transactionMeta?.chainId);
1632

1733
return useMemo(() => {
18-
if (
19-
!estimationFailed ||
20-
isGaslessSupportCheckPending ||
21-
isGaslessSupported
22-
) {
34+
if (!estimationFailed || isGasSponsored) {
2335
return [];
2436
}
2537

@@ -33,5 +45,5 @@ export const useGasEstimateFailedAlert = (): Alert[] => {
3345
severity: Severity.Warning,
3446
},
3547
];
36-
}, [estimationFailed, isGaslessSupportCheckPending, isGaslessSupported]);
48+
}, [estimationFailed, isGasSponsored]);
3749
};

0 commit comments

Comments
 (0)