Skip to content

Commit

Permalink
fix: fix network client ID used on the useGasFeeInputs hook
Browse files Browse the repository at this point in the history
  • Loading branch information
salimtb committed Nov 8, 2024
1 parent ab8df12 commit dbd2e9d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ui/pages/confirmations/hooks/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getTokenExchangeRates,
getPreferences,
selectConversionRateByChainId,
selectNetworkConfigurationByChainId,
} from '../../../selectors';

import {
Expand Down Expand Up @@ -121,6 +122,9 @@ export const generateUseSelectorRouter =
) {
return 'USD';
}
if (selector === selectNetworkConfigurationByChainId) {
return '2';
}
if (
selector === getMultichainShouldShowFiat ||
selector === getShouldShowFiat
Expand Down
11 changes: 10 additions & 1 deletion ui/pages/confirmations/hooks/useGasFeeInputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { GAS_FORM_ERRORS } from '../../../helpers/constants/gas';
import {
checkNetworkAndAccountSupports1559,
getAdvancedInlineGasShown,
selectNetworkConfigurationByChainId,
} from '../../../selectors';
import { isLegacyTransaction } from '../../../helpers/utils/transactions.util';
import { useGasFeeEstimates } from '../../../hooks/useGasFeeEstimates';
Expand Down Expand Up @@ -118,6 +119,14 @@ export function useGasFeeInputs(
? retryTxMeta
: _transaction;

const network = useSelector((state) =>
selectNetworkConfigurationByChainId(state, transaction?.chainId),
);

const networkClientId =
network?.rpcEndpoints?.[network?.defaultRpcEndpointIndex].networkClientId ??
transaction?.networkClientId;

const supportsEIP1559 =
useSelector(checkNetworkAndAccountSupports1559) &&
!isLegacyTransaction(transaction?.txParams);
Expand All @@ -130,7 +139,7 @@ export function useGasFeeInputs(
gasFeeEstimates,
isGasEstimatesLoading,
isNetworkBusy,
} = useGasFeeEstimates(transaction?.networkClientId);
} = useGasFeeEstimates(networkClientId);

const userPrefersAdvancedGas = useSelector(getAdvancedInlineGasShown);

Expand Down
14 changes: 14 additions & 0 deletions ui/pages/confirmations/hooks/useGasFeeInputs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ETH, PRIMARY } from '../../../helpers/constants/common';

import { useGasFeeEstimates } from '../../../hooks/useGasFeeEstimates';
import { useUserPreferencedCurrency } from '../../../hooks/useUserPreferencedCurrency';
import { selectNetworkConfigurationByChainId } from '../../../selectors';
import { useGasFeeInputs } from './useGasFeeInputs';

import {
Expand Down Expand Up @@ -50,6 +51,7 @@ jest.mock('../../../hooks/useMultichainSelector', () => ({
const mockTransaction = {
status: TransactionStatus.unapproved,
type: TransactionType.simpleSend,
networkClientId: '1',
txParams: {
from: '0x000000000000000000000000000000000000dead',
type: '0x2',
Expand Down Expand Up @@ -94,6 +96,7 @@ describe('useGasFeeInputs', () => {
checkNetworkAndAccountSupports1559Response: false,
}),
);

const { result } = renderHook(() => useGasFeeInputs());
expect(result.current.gasPrice).toBe(
LEGACY_GAS_ESTIMATE_RETURN_VALUE.gasFeeEstimates.medium,
Expand Down Expand Up @@ -190,6 +193,17 @@ describe('useGasFeeInputs', () => {
});

describe('editGasMode', () => {
beforeEach(() => {
useSelector.mockImplementation((selector) => {
if (selector === selectNetworkConfigurationByChainId) {
return '2';
}
return undefined;
});
useGasFeeEstimates.mockImplementation(
() => HIGH_FEE_MARKET_ESTIMATE_RETURN_VALUE,
);
});
it('should return editGasMode passed', () => {
const { result } = renderHook(() =>
useGasFeeInputs(undefined, undefined, undefined, EditGasModes.swaps),
Expand Down

0 comments on commit dbd2e9d

Please sign in to comment.