Skip to content
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

fix: fix network client ID used on the useGasFeeInputs hook #28391

Merged
merged 6 commits into from
Nov 12, 2024
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
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
10 changes: 9 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,13 @@ export function useGasFeeInputs(
? retryTxMeta
: _transaction;

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

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

const supportsEIP1559 =
useSelector(checkNetworkAndAccountSupports1559) &&
!isLegacyTransaction(transaction?.txParams);
Expand All @@ -130,7 +138,7 @@ export function useGasFeeInputs(
gasFeeEstimates,
isGasEstimatesLoading,
isNetworkBusy,
} = useGasFeeEstimates(transaction?.networkClientId);
salimtb marked this conversation as resolved.
Show resolved Hide resolved
} = useGasFeeEstimates(networkClientId);

const userPrefersAdvancedGas = useSelector(getAdvancedInlineGasShown);

Expand Down
12 changes: 12 additions & 0 deletions ui/pages/confirmations/hooks/useGasFeeInputs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jest.mock('../../../hooks/useMultichainSelector', () => ({
const mockTransaction = {
status: TransactionStatus.unapproved,
type: TransactionType.simpleSend,
networkClientId: '2',
txParams: {
from: '0x000000000000000000000000000000000000dead',
type: '0x2',
Expand Down Expand Up @@ -94,6 +95,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 @@ -187,9 +189,19 @@ describe('useGasFeeInputs', () => {
);
expect(result.current.balanceError).toBe(true);
});

it('should call useGasFeeEstimates with correct networkClientId', () => {
renderHook(() => useGasFeeInputs(null, mockTransaction));
expect(useGasFeeEstimates).not.toHaveBeenCalledWith('2');
});
});

describe('editGasMode', () => {
beforeEach(() => {
salimtb marked this conversation as resolved.
Show resolved Hide resolved
useGasFeeEstimates.mockImplementation(
() => HIGH_FEE_MARKET_ESTIMATE_RETURN_VALUE,
);
});
it('should return editGasMode passed', () => {
const { result } = renderHook(() =>
useGasFeeInputs(undefined, undefined, undefined, EditGasModes.swaps),
Expand Down