@@ -10,7 +10,17 @@ import { useTransactionMetadataRequest } from '../transactions/useTransactionMet
1010import { AlertKeys } from '../../constants/alerts' ;
1111import { RowAlertKey } from '../../components/UI/info-row/alert-row/constants' ;
1212import { 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
1525const 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
3652describe ( '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} ) ;
0 commit comments