@@ -4,13 +4,12 @@ import { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';
44import { isNonEvmChainId , isSolanaChainId } from '@metamask/bridge-controller' ;
55import { Hex , CaipChainId } from '@metamask/utils' ;
66import { BigNumber } from 'bignumber.js' ;
7- import BN from 'bnjs4' ;
87import Engine from '../../../../core/Engine' ;
98import { useAccountNativeBalance } from '../../../Views/confirmations/hooks/useAccountNativeBalance' ;
109import { selectMinSolBalance } from '../../../../selectors/bridgeController' ;
1110import { selectSelectedInternalAccountFormattedAddress } from '../../../../selectors/accountsController' ;
1211import { decGWEIToHexWEI } from '../../../../util/conversions' ;
13- import { hexToBN } from '../../../../util/number' ;
12+ import { hexToBigInt } from '../../../../util/number/bigint ' ;
1413import { safeFormatChainIdToHex } from '../util/safeFormatChainIdToHex' ;
1514import { CardFundingToken } from '../types' ;
1615import { useLatestBalance } from '../../Bridge/hooks/useLatestBalance' ;
@@ -93,7 +92,7 @@ export const useNeedsGasFaucet = (
9392 /**
9493 * Estimate gas fee for EVM chains
9594 */
96- const estimateEvmGasFee = useCallback ( async ( ) : Promise < BN > => {
95+ const estimateEvmGasFee = useCallback ( async ( ) : Promise < bigint > => {
9796 try {
9897 const { GasFeeController } = Engine . context ;
9998 const result = await GasFeeController . fetchGasFeeEstimates ( ) ;
@@ -120,16 +119,16 @@ export const useNeedsGasFaucet = (
120119 break ;
121120 }
122121
123- const weiGasPrice = hexToBN ( decGWEIToHexWEI ( gasPrice ) ) ;
124- return weiGasPrice . muln ( gasLimitWithBuffer ) ;
122+ const weiGasPrice = hexToBigInt ( decGWEIToHexWEI ( gasPrice ) as string ) ;
123+ return weiGasPrice * BigInt ( gasLimitWithBuffer ) ;
125124 } catch ( err ) {
126125 // Return a conservative fallback estimate if gas estimation fails
127126 // Assume ~20 Gwei gas price as fallback
128- const fallbackGasPrice = new BN ( '20000000000' ) ; // 20 Gwei in Wei
127+ const fallbackGasPrice = 20000000000n ; // 20 Gwei in Wei
129128 const gasLimitWithBuffer = Math . ceil (
130129 ERC20_APPROVE_GAS_LIMIT * GAS_LIMIT_BUFFER ,
131130 ) ;
132- return fallbackGasPrice . muln ( gasLimitWithBuffer ) ;
131+ return fallbackGasPrice * BigInt ( gasLimitWithBuffer ) ;
133132 }
134133 } , [ ] ) ;
135134
@@ -144,10 +143,10 @@ export const useNeedsGasFaucet = (
144143
145144 try {
146145 const estimatedGasFee = await estimateEvmGasFee ( ) ;
147- const balanceBN = new BN ( balanceWeiInHex . replace ( '0x' , '' ) , 'hex' ) ;
146+ const balance = hexToBigInt ( balanceWeiInHex ) ;
148147
149148 // User needs faucet if balance is less than estimated gas fee
150- return balanceBN . lt ( estimatedGasFee ) ;
149+ return balance < estimatedGasFee ;
151150 } catch ( err ) {
152151 console . error ( 'Error checking EVM faucet need:' , err ) ;
153152 // Assume needs faucet on error
0 commit comments