-
-
-
-
- Network is busy. Gas prices are high and estimates are less accurate.
-
-
-
@@ -398,12 +381,12 @@ exports[`ConfirmSendEther should render correct information for for confirm send
- 0.00021
+ 0.000021
@@ -416,12 +399,12 @@ exports[`ConfirmSendEther should render correct information for for confirm send
>
- 0.00021
+ 0.000021
+ Promise.resolve({
+ chainId: '0x5',
+ }),
+ ),
getGasFeeTimeEstimate: jest.fn(),
getGasFeeEstimatesAndStartPolling: jest.fn(),
promisifiedBackground: jest.fn(),
diff --git a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.test.js b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.test.js
index 55044842b445..89d44104ae06 100644
--- a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.test.js
+++ b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.test.js
@@ -32,6 +32,15 @@ import ConfirmTransactionBase from './confirm-transaction-base.container';
const middleware = [thunk];
setBackgroundConnection({
+ gasFeeStartPollingByNetworkClientId: jest
+ .fn()
+ .mockResolvedValue('pollingToken'),
+ gasFeeStopPollingByPollingToken: jest.fn(),
+ getNetworkConfigurationByNetworkClientId: jest.fn().mockImplementation(() =>
+ Promise.resolve({
+ chainId: '0x5',
+ }),
+ ),
getGasFeeTimeEstimate: jest.fn(),
getGasFeeEstimatesAndStartPolling: jest.fn(),
promisifiedBackground: jest.fn(),
@@ -200,43 +209,87 @@ const baseStore = {
},
};
-const mockedStore = jest.mocked(baseStore);
-
-const mockedStoreWithConfirmTxParams = (_mockTxParams = mockTxParams) => {
- mockedStore.metamask.transactions[0].txParams = { ..._mockTxParams };
- mockedStore.confirmTransaction.txData.txParams = { ..._mockTxParams };
+const mockedStoreWithConfirmTxParams = (
+ store,
+ _mockTxParams = mockTxParams,
+) => {
+ const [firstTx, ...restTxs] = store.metamask.transactions;
+
+ return {
+ ...store,
+ metamask: {
+ ...store.metamask,
+ transactions: [
+ {
+ ...firstTx,
+ txParams: {
+ ..._mockTxParams,
+ },
+ },
+ ...restTxs,
+ ],
+ },
+ confirmTransaction: {
+ ...store.confirmTransaction,
+ txData: {
+ ...store.confirmTransaction.txData,
+ txParams: {
+ ..._mockTxParams,
+ },
+ },
+ },
+ };
};
const sendToRecipientSelector =
'.sender-to-recipient__party--recipient .sender-to-recipient__name';
+const render = async ({ props, state } = {}) => {
+ const store = configureMockStore(middleware)({
+ ...baseStore,
+ ...state,
+ });
+
+ const componentProps = {
+ actionKey: 'confirm',
+ ...props,
+ };
+
+ let result;
+
+ await act(
+ async () =>
+ (result = renderWithProvider(
+ ,
+ store,
+ )),
+ );
+
+ return result;
+};
+
describe('Confirm Transaction Base', () => {
- it('should match snapshot', () => {
- const store = configureMockStore(middleware)(baseStore);
- const { container } = renderWithProvider(
- ,
- store,
- );
+ it('should match snapshot', async () => {
+ const { container } = await render();
expect(container).toMatchSnapshot();
});
- it('should not contain L1 L2 fee details for chains that are not optimism', () => {
- const store = configureMockStore(middleware)(baseStore);
- const { queryByText } = renderWithProvider(
- ,
- store,
- );
+ it('should not contain L1 L2 fee details for chains that are not optimism', async () => {
+ const { queryByText } = await render();
+
expect(queryByText('Layer 1 fees')).not.toBeInTheDocument();
expect(queryByText('Layer 2 gas fee')).not.toBeInTheDocument();
});
- it('should render only total fee details if simulation fails', () => {
- mockedStore.send.hasSimulationError = true;
- const store = configureMockStore(middleware)(mockedStore);
- const { queryByText } = renderWithProvider(
- ,
- store,
- );
+ it('should render only total fee details if simulation fails', async () => {
+ const state = {
+ send: {
+ ...baseStore.send,
+ hasSimulationError: true,
+ },
+ };
+
+ const { queryByText } = await render({ state });
expect(queryByText('Total')).toBeInTheDocument();
expect(queryByText('Amount + gas fee')).toBeInTheDocument();
@@ -244,19 +297,18 @@ describe('Confirm Transaction Base', () => {
expect(queryByText('Estimated fee')).not.toBeInTheDocument();
});
- it('renders blockaid security alert if recipient is a malicious address', () => {
- const newMockedStore = {
- ...mockedStore,
+ it('renders blockaid security alert if recipient is a malicious address', async () => {
+ const state = {
send: {
- ...mockedStore.send,
+ ...baseStore.send,
hasSimulationError: false,
},
confirmTransaction: {
- ...mockedStore.confirmTransaction,
+ ...baseStore.confirmTransaction,
txData: {
- ...mockedStore.confirmTransaction.txData,
+ ...baseStore.confirmTransaction.txData,
txParams: {
- ...mockedStore.confirmTransaction.txData.txParams,
+ ...baseStore.confirmTransaction.txData.txParams,
to: mockMaliciousToAddress,
},
securityAlertResponse: {
@@ -268,12 +320,7 @@ describe('Confirm Transaction Base', () => {
},
};
- const store = configureMockStore(middleware)(newMockedStore);
-
- const { getByTestId } = renderWithProvider(
- ,
- store,
- );
+ const { getByTestId } = await render({ state });
const securityProviderBanner = getByTestId(
'security-provider-banner-alert',
@@ -281,63 +328,74 @@ describe('Confirm Transaction Base', () => {
expect(securityProviderBanner).toBeInTheDocument();
});
- it('should contain L1 L2 fee details for optimism', () => {
- mockedStore.metamask.providerConfig.chainId = CHAIN_IDS.OPTIMISM;
- mockedStore.confirmTransaction.txData.chainId = CHAIN_IDS.OPTIMISM;
- const store = configureMockStore(middleware)(mockedStore);
- const { queryByText } = renderWithProvider(
- ,
- store,
- );
+ it('should contain L1 L2 fee details for optimism', async () => {
+ const state = {
+ metamask: {
+ ...baseStore.metamask,
+ providerConfig: {
+ ...baseStore.metamask.providerConfig,
+ chainId: CHAIN_IDS.OPTIMISM,
+ },
+ },
+ confirmTransaction: {
+ ...baseStore.confirmTransaction,
+ txData: {
+ ...baseStore.confirmTransaction.txData,
+ chainId: CHAIN_IDS.OPTIMISM,
+ },
+ },
+ };
+
+ const { queryByText } = await render({ state });
+
expect(queryByText('Layer 1 fees')).toBeInTheDocument();
expect(queryByText('Layer 2 gas fee')).toBeInTheDocument();
});
- it('should render NoteToTrader when isNoteToTraderSupported is true', () => {
- mockedStore.metamask.custodyAccountDetails = {
- [mockTxParamsFromAddress]: {
- address: mockTxParamsFromAddress,
- details: 'details',
- custodyType: 'testCustody - Saturn',
- custodianName: 'saturn-dev',
- },
- };
-
- mockedStore.metamask.mmiConfiguration = {
- custodians: [
- {
- envName: 'saturn-dev',
- displayName: 'Saturn Custody',
- isNoteToTraderSupported: true,
+ it('should render NoteToTrader when isNoteToTraderSupported is true', async () => {
+ const state = {
+ metamask: {
+ ...baseStore.metamask,
+ custodyAccountDetails: {
+ [mockTxParamsFromAddress]: {
+ address: mockTxParamsFromAddress,
+ details: 'details',
+ custodyType: 'testCustody - Saturn',
+ custodianName: 'saturn-dev',
+ },
},
- ],
+ mmiConfiguration: {
+ custodians: [
+ {
+ envName: 'saturn-dev',
+ displayName: 'Saturn Custody',
+ isNoteToTraderSupported: true,
+ },
+ ],
+ },
+ },
};
- const store = configureMockStore(middleware)(mockedStore);
- const { getByTestId } = renderWithProvider(
- ,
- store,
- );
+ const { getByTestId } = await render({ state });
expect(getByTestId('note-tab')).toBeInTheDocument();
});
it('handleMMISubmit calls sendTransaction correctly when isNoteToTraderSupported is false', async () => {
- const newMockedStore = {
- ...mockedStore,
+ const state = {
appState: {
- ...mockedStore.appState,
+ ...baseStore.appState,
gasLoadingAnimationIsShowing: false,
},
confirmTransaction: {
- ...mockedStore.confirmTransaction,
+ ...baseStore.confirmTransaction,
txData: {
- ...mockedStore.confirmTransaction.txData,
+ ...baseStore.confirmTransaction.txData,
custodyStatus: true,
},
},
metamask: {
- ...mockedStore.metamask,
+ ...baseStore.metamask,
accounts: {
[mockTxParamsFromAddress]: {
balance: '0x1000000000000000000',
@@ -347,7 +405,7 @@ describe('Confirm Transaction Base', () => {
gasEstimateType: GasEstimateTypes.feeMarket,
selectedNetworkClientId: NetworkType.mainnet,
networksMetadata: {
- ...mockedStore.metamask.networksMetadata,
+ ...baseStore.metamask.networksMetadata,
[NetworkType.mainnet]: {
EIPS: {
1559: true,
@@ -385,9 +443,9 @@ describe('Confirm Transaction Base', () => {
},
},
send: {
- ...mockedStore.send,
+ ...baseStore.send,
gas: {
- ...mockedStore.send.gas,
+ ...baseStore.send.gas,
gasEstimateType: GasEstimateTypes.legacy,
gasFeeEstimates: {
low: '0',
@@ -404,27 +462,24 @@ describe('Confirm Transaction Base', () => {
},
};
- const store = configureMockStore(middleware)(newMockedStore);
const sendTransaction = jest
.fn()
- .mockResolvedValue(newMockedStore.confirmTransaction.txData);
+ .mockResolvedValue(state.confirmTransaction.txData);
const updateTransaction = jest.fn().mockResolvedValue();
const showCustodianDeepLink = jest.fn();
const setWaitForConfirmDeepLinkDialog = jest.fn();
- const { getByTestId } = renderWithProvider(
- ,
- store,
- );
+ const props = {
+ sendTransaction,
+ updateTransaction,
+ showCustodianDeepLink,
+ setWaitForConfirmDeepLinkDialog,
+ toAddress: mockPropsToAddress,
+ toAccounts: [{ address: mockPropsToAddress }],
+ isMainBetaFlask: false,
+ };
+
+ const { getByTestId } = await render({ props, state });
const confirmButton = getByTestId('page-container-footer-next');
@@ -436,14 +491,13 @@ describe('Confirm Transaction Base', () => {
});
it('handleMainSubmit calls sendTransaction correctly', async () => {
- const newMockedStore = {
- ...mockedStore,
+ const state = {
appState: {
- ...mockedStore.appState,
+ ...baseStore.appState,
gasLoadingAnimationIsShowing: false,
},
metamask: {
- ...mockedStore.metamask,
+ ...baseStore.metamask,
accounts: {
[mockTxParamsFromAddress]: {
balance: '0x1000000000000000000',
@@ -453,7 +507,7 @@ describe('Confirm Transaction Base', () => {
gasEstimateType: GasEstimateTypes.feeMarket,
selectedNetworkClientId: NetworkType.mainnet,
networksMetadata: {
- ...mockedStore.metamask.networksMetadata,
+ ...baseStore.metamask.networksMetadata,
[NetworkType.mainnet]: {
EIPS: { 1559: true },
status: NetworkStatus.Available,
@@ -466,9 +520,9 @@ describe('Confirm Transaction Base', () => {
noGasPrice: false,
},
send: {
- ...mockedStore.send,
+ ...baseStore.send,
gas: {
- ...mockedStore.send.gas,
+ ...baseStore.send.gas,
gasEstimateType: GasEstimateTypes.legacy,
gasFeeEstimates: {
low: '0',
@@ -485,39 +539,38 @@ describe('Confirm Transaction Base', () => {
},
};
- const store = configureMockStore(middleware)(newMockedStore);
const sendTransaction = jest.fn().mockResolvedValue();
- const { getByTestId } = renderWithProvider(
- ,
- store,
- );
+ const props = {
+ sendTransaction,
+ toAddress: mockPropsToAddress,
+ toAccounts: [{ address: mockPropsToAddress }],
+ };
+
+ const { getByTestId } = await render({ props, state });
+
const confirmButton = getByTestId('page-container-footer-next');
- fireEvent.click(confirmButton);
+ await act(async () => {
+ fireEvent.click(confirmButton);
+ });
expect(sendTransaction).toHaveBeenCalled();
});
it('handleMMISubmit calls sendTransaction correctly and then showCustodianDeepLink', async () => {
- const newMockedStore = {
- ...mockedStore,
+ const state = {
appState: {
- ...mockedStore.appState,
+ ...baseStore.appState,
gasLoadingAnimationIsShowing: false,
},
confirmTransaction: {
- ...mockedStore.confirmTransaction,
+ ...baseStore.confirmTransaction,
txData: {
- ...mockedStore.confirmTransaction.txData,
+ ...baseStore.confirmTransaction.txData,
custodyStatus: true,
},
},
metamask: {
- ...mockedStore.metamask,
+ ...baseStore.metamask,
accounts: {
[mockTxParamsFromAddress]: {
balance: '0x1000000000000000000',
@@ -527,7 +580,7 @@ describe('Confirm Transaction Base', () => {
gasEstimateType: GasEstimateTypes.feeMarket,
selectedNetworkClientId: NetworkType.mainnet,
networksMetadata: {
- ...mockedStore.metamask.networksMetadata,
+ ...baseStore.metamask.networksMetadata,
[NetworkType.mainnet]: {
EIPS: {
1559: true,
@@ -542,9 +595,9 @@ describe('Confirm Transaction Base', () => {
noGasPrice: false,
},
send: {
- ...mockedStore.send,
+ ...baseStore.send,
gas: {
- ...mockedStore.send.gas,
+ ...baseStore.send.gas,
gasEstimateType: GasEstimateTypes.legacy,
gasFeeEstimates: {
low: '0',
@@ -561,27 +614,27 @@ describe('Confirm Transaction Base', () => {
},
};
- const store = configureMockStore(middleware)(newMockedStore);
const sendTransaction = jest
.fn()
- .mockResolvedValue(newMockedStore.confirmTransaction.txData);
+ .mockResolvedValue(state.confirmTransaction.txData);
const showCustodianDeepLink = jest.fn();
const setWaitForConfirmDeepLinkDialog = jest.fn();
- const { getByTestId } = renderWithProvider(
- ,
- store,
- );
+ const props = {
+ sendTransaction,
+ showCustodianDeepLink,
+ setWaitForConfirmDeepLinkDialog,
+ toAddress: mockPropsToAddress,
+ toAccounts: [{ address: mockPropsToAddress }],
+ isMainBetaFlask: false,
+ };
+
+ const { getByTestId } = await render({ props, state });
+
const confirmButton = getByTestId('page-container-footer-next');
- fireEvent.click(confirmButton);
+ await act(async () => {
+ fireEvent.click(confirmButton);
+ });
expect(setWaitForConfirmDeepLinkDialog).toHaveBeenCalled();
await expect(sendTransaction).toHaveBeenCalled();
expect(showCustodianDeepLink).toHaveBeenCalled();
@@ -589,27 +642,19 @@ describe('Confirm Transaction Base', () => {
describe('when rendering the recipient value', () => {
describe(`when the transaction is a ${TransactionType.simpleSend} type`, () => {
- it(`should use txParams.to address`, () => {
- const store = configureMockStore(middleware)(mockedStore);
- const { container } = renderWithProvider(
- ,
- store,
- );
+ it(`should use txParams.to address`, async () => {
+ const { container } = await render();
const recipientElem = container.querySelector(sendToRecipientSelector);
expect(recipientElem).toHaveTextContent(mockTxParamsToAddressConcat);
});
- it(`should use txParams.to address even if there is no amount sent`, () => {
- mockedStoreWithConfirmTxParams({
+ it(`should use txParams.to address even if there is no amount sent`, async () => {
+ const state = mockedStoreWithConfirmTxParams(baseStore, {
...mockTxParams,
value: '0x0',
});
- const store = configureMockStore(middleware)(mockedStore);
- const { container } = renderWithProvider(
- ,
- store,
- );
+ const { container } = await render({ state });
const recipientElem = container.querySelector(sendToRecipientSelector);
expect(recipientElem).toHaveTextContent(mockTxParamsToAddressConcat);
@@ -617,21 +662,22 @@ describe('Confirm Transaction Base', () => {
});
describe(`when the transaction is NOT a ${TransactionType.simpleSend} type`, () => {
beforeEach(() => {
- mockedStore.confirmTransaction.txData.type =
+ baseStore.confirmTransaction.txData.type =
TransactionType.contractInteraction;
});
describe('when there is an amount being sent (it should be treated as a general contract intereaction rather than custom one)', () => {
- it('should use txParams.to address (contract address)', () => {
- mockedStoreWithConfirmTxParams({
+ it('should use txParams.to address (contract address)', async () => {
+ const state = mockedStoreWithConfirmTxParams(baseStore, {
...mockTxParams,
value: '0x45666',
});
- const store = configureMockStore(middleware)(mockedStore);
- const { container } = renderWithProvider(
- ,
- store,
- );
+ state.confirmTransaction.txData = {
+ ...state.confirmTransaction.txData,
+ type: TransactionType.contractInteraction,
+ };
+
+ const { container } = await render({ state });
const recipientElem = container.querySelector(
sendToRecipientSelector,
@@ -641,23 +687,24 @@ describe('Confirm Transaction Base', () => {
});
describe(`when there is no amount being sent`, () => {
- it('should use propToAddress (toAddress passed as prop)', () => {
- mockedStoreWithConfirmTxParams({
+ it('should use propToAddress (toAddress passed as prop)', async () => {
+ const state = mockedStoreWithConfirmTxParams(baseStore, {
...mockTxParams,
value: '0x0',
});
- const store = configureMockStore(middleware)(mockedStore);
-
- const { container } = renderWithProvider(
- ,
- store,
- );
+ state.confirmTransaction.txData = {
+ ...state.confirmTransaction.txData,
+ type: TransactionType.contractInteraction,
+ };
+
+ const props = {
+ // we want to test toAddress provided by ownProps in mapStateToProps, but this
+ // currently overrides toAddress this should pan out fine when we refactor the
+ // component into a functional component and remove the container.js file
+ toAddress: mockPropsToAddress,
+ };
+
+ const { container } = await render({ props, state });
const recipientElem = container.querySelector(
sendToRecipientSelector,
@@ -665,16 +712,19 @@ describe('Confirm Transaction Base', () => {
expect(recipientElem).toHaveTextContent(mockPropsToAddressConcat);
});
- it('should use address parsed from transaction data if propToAddress is not provided', () => {
- mockedStoreWithConfirmTxParams({
+ it('should use address parsed from transaction data if propToAddress is not provided', async () => {
+ const state = mockedStoreWithConfirmTxParams(baseStore, {
...mockTxParams,
value: '0x0',
});
- const store = configureMockStore(middleware)(mockedStore);
- const { container } = renderWithProvider(
- ,
- store,
- );
+ state.confirmTransaction.txData = {
+ ...state.confirmTransaction.txData,
+ type: TransactionType.contractInteraction,
+ };
+
+ const props = {};
+
+ const { container } = await render({ props, state });
const recipientElem = container.querySelector(
sendToRecipientSelector,
@@ -682,17 +732,20 @@ describe('Confirm Transaction Base', () => {
expect(recipientElem).toHaveTextContent(mockParsedTxDataToAddress);
});
- it('should use txParams.to if neither propToAddress is not provided nor the transaction data to address were provided', () => {
- mockedStoreWithConfirmTxParams({
+ it('should use txParams.to if neither propToAddress is not provided nor the transaction data to address were provided', async () => {
+ const state = mockedStoreWithConfirmTxParams(baseStore, {
...mockTxParams,
data: '0x',
value: '0x0',
});
- const store = configureMockStore(middleware)(mockedStore);
- const { container } = renderWithProvider(
- ,
- store,
- );
+ state.confirmTransaction.txData = {
+ ...state.confirmTransaction.txData,
+ type: TransactionType.contractInteraction,
+ };
+
+ const props = {};
+
+ const { container } = await render({ props, state });
const recipientElem = container.querySelector(
sendToRecipientSelector,
@@ -703,19 +756,19 @@ describe('Confirm Transaction Base', () => {
});
});
describe('user op contract deploy attempt', () => {
- it('should show error and disable Confirm button', () => {
+ it('should show error and disable Confirm button', async () => {
const txParams = {
...mockTxParams,
to: undefined,
data: '0xa22cb46500000000000000',
};
- const newMockedStore = {
- ...mockedStore,
+ const state = {
+ ...baseStore,
metamask: {
- ...mockedStore.metamask,
+ ...baseStore.metamask,
transactions: [
{
- id: mockedStore.confirmTransaction.txData.id,
+ id: baseStore.confirmTransaction.txData.id,
chainId: '0x5',
status: 'unapproved',
txParams,
@@ -723,9 +776,9 @@ describe('Confirm Transaction Base', () => {
],
},
confirmTransaction: {
- ...mockedStore.confirmTransaction,
+ ...baseStore.confirmTransaction,
txData: {
- ...mockedStore.confirmTransaction.txData,
+ ...baseStore.confirmTransaction.txData,
type: TransactionType.deployContract,
value: '0x0',
isUserOperation: true,
@@ -734,11 +787,7 @@ describe('Confirm Transaction Base', () => {
},
};
- const store = configureMockStore(middleware)(newMockedStore);
- const { getByTestId } = renderWithProvider(
- ,
- store,
- );
+ const { getByTestId } = await render({ state });
const banner = getByTestId(
'confirm-page-container-content-error-banner-2',
diff --git a/ui/pages/confirmations/confirm-transaction/confirm-transaction.component.js b/ui/pages/confirmations/confirm-transaction/confirm-transaction.component.js
index f32867639b11..41f31a856301 100644
--- a/ui/pages/confirmations/confirm-transaction/confirm-transaction.component.js
+++ b/ui/pages/confirmations/confirm-transaction/confirm-transaction.component.js
@@ -37,19 +37,19 @@ import {
unconfirmedTransactionsListSelector,
unconfirmedTransactionsHashSelector,
use4ByteResolutionSelector,
+ getSelectedNetworkClientId,
} from '../../../selectors';
import {
- disconnectGasFeeEstimatePoller,
getContractMethodData,
- getGasFeeEstimatesAndStartPolling,
- addPollingTokenToAppState,
- removePollingTokenFromAppState,
setDefaultHomeActiveTabName,
+ gasFeeStartPollingByNetworkClientId,
+ gasFeeStopPollingByPollingToken,
} from '../../../store/actions';
import ConfirmSignatureRequest from '../confirm-signature-request';
///: BEGIN:ONLY_INCLUDE_IF(conf-redesign)
import Confirm from '../confirm/confirm';
///: END:ONLY_INCLUDE_IF
+import usePolling from '../../../hooks/usePolling';
import ConfirmTokenTransactionSwitch from './confirm-token-transaction-switch';
const ConfirmTransaction = () => {
@@ -57,14 +57,12 @@ const ConfirmTransaction = () => {
const history = useHistory();
const { id: paramsTransactionId } = useParams();
- const [isMounted, setIsMounted] = useState(false);
- const [pollingToken, setPollingToken] = useState();
-
const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage);
const sendTo = useSelector(getSendTo);
const unconfirmedTxsSorted = useSelector(unconfirmedTransactionsListSelector);
const unconfirmedTxs = useSelector(unconfirmedTransactionsHashSelector);
+ const networkClientId = useSelector(getSelectedNetworkClientId);
const totalUnapproved = unconfirmedTxsSorted.length || 0;
const getTransaction = useCallback(() => {
@@ -109,30 +107,13 @@ const ConfirmTransaction = () => {
const prevParamsTransactionId = usePrevious(paramsTransactionId);
const prevTransactionId = usePrevious(transactionId);
- const _beforeUnload = useCallback(() => {
- setIsMounted(false);
-
- if (pollingToken) {
- disconnectGasFeeEstimatePoller(pollingToken);
- removePollingTokenFromAppState(pollingToken);
- }
- }, [pollingToken]);
+ usePolling({
+ startPollingByNetworkClientId: gasFeeStartPollingByNetworkClientId,
+ stopPollingByPollingToken: gasFeeStopPollingByPollingToken,
+ networkClientId: transaction.networkClientId ?? networkClientId,
+ });
useEffect(() => {
- setIsMounted(true);
-
- getGasFeeEstimatesAndStartPolling().then((_pollingToken) => {
- if (isMounted) {
- setPollingToken(_pollingToken);
- addPollingTokenToAppState(_pollingToken);
- } else {
- disconnectGasFeeEstimatePoller(_pollingToken);
- removePollingTokenFromAppState(_pollingToken);
- }
- });
-
- window.addEventListener('beforeunload', _beforeUnload);
-
if (!totalUnapproved && !sendTo) {
history.replace(mostRecentOverviewPage);
} else {
@@ -148,10 +129,6 @@ const ConfirmTransaction = () => {
}
}
- return () => {
- _beforeUnload();
- window.removeEventListener('beforeunload', _beforeUnload);
- };
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
diff --git a/ui/pages/confirmations/confirm-transaction/confirm-transaction.test.js b/ui/pages/confirmations/confirm-transaction/confirm-transaction.test.js
index c374316f320a..69d6206aeb09 100644
--- a/ui/pages/confirmations/confirm-transaction/confirm-transaction.test.js
+++ b/ui/pages/confirmations/confirm-transaction/confirm-transaction.test.js
@@ -135,6 +135,11 @@ jest.mock('../confirm-transaction-switch', () => {
});
describe('Confirmation Transaction Page', () => {
+ beforeEach(() => {
+ jest
+ .spyOn(Actions, 'gasFeeStartPollingByNetworkClientId')
+ .mockResolvedValue(null);
+ });
it('should display the Loading component when the transaction is invalid', () => {
const mockStore = configureMockStore(middleware)({
...mockState,
@@ -216,10 +221,9 @@ describe('Confirmation Transaction Page', () => {
describe('initialization', () => {
it('should poll for gas estimates', () => {
const mockStore = configureMockStore(middleware)(mockState);
- const gasEstimationPollingSpy = jest.spyOn(
- Actions,
- 'getGasFeeEstimatesAndStartPolling',
- );
+ const gasEstimationPollingSpy = jest
+ .spyOn(Actions, 'gasFeeStartPollingByNetworkClientId')
+ .mockResolvedValue(null);
renderWithProvider(, mockStore);
diff --git a/ui/pages/confirmations/confirm-transaction/confirm-transaction.transaction.test.js b/ui/pages/confirmations/confirm-transaction/confirm-transaction.transaction.test.js
index 5be82bcb7588..4c3f9f20dc99 100644
--- a/ui/pages/confirmations/confirm-transaction/confirm-transaction.transaction.test.js
+++ b/ui/pages/confirmations/confirm-transaction/confirm-transaction.transaction.test.js
@@ -1,7 +1,7 @@
import React from 'react';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
-
+import * as Actions from '../../../store/actions';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import { setBackgroundConnection } from '../../../store/background-connection';
import mockState from '../../../../test/data/mock-state.json';
@@ -28,6 +28,9 @@ describe('Confirm Transaction', () => {
mockState.metamask.transactions,
)[0];
it('should render correct information for approve transaction with value', () => {
+ jest
+ .spyOn(Actions, 'gasFeeStartPollingByNetworkClientId')
+ .mockResolvedValue(null);
const store = configureMockStore(middleware)({
...mockState,
confirmTransaction: {
diff --git a/ui/pages/confirmations/hooks/test-utils.js b/ui/pages/confirmations/hooks/test-utils.js
index a0805096dbf6..5805c56c8f93 100644
--- a/ui/pages/confirmations/hooks/test-utils.js
+++ b/ui/pages/confirmations/hooks/test-utils.js
@@ -6,7 +6,6 @@ import {
getNativeCurrency,
} from '../../../ducks/metamask/metamask';
import {
- checkNetworkAndAccountSupports1559,
getCurrentCurrency,
getShouldShowFiat,
getPreferences,
@@ -132,7 +131,7 @@ export const generateUseSelectorRouter =
if (selector === getCustomMaxPriorityFeePerGas) {
return '0x5208';
}
- if (selector === checkNetworkAndAccountSupports1559) {
+ if (selector.toString().includes('checkNetworkAndAccountSupports1559')) {
return checkNetworkAndAccountSupports1559Response;
}
if (selector === getCurrentKeyring) {
diff --git a/ui/pages/confirmations/hooks/useGasEstimates.js b/ui/pages/confirmations/hooks/useGasEstimates.js
index a277bdff4d5d..083c084689a6 100644
--- a/ui/pages/confirmations/hooks/useGasEstimates.js
+++ b/ui/pages/confirmations/hooks/useGasEstimates.js
@@ -53,8 +53,9 @@ export function useGasEstimates({
transaction,
}) {
const supportsEIP1559 =
- useSelector(checkNetworkAndAccountSupports1559) &&
- !isLegacyTransaction(transaction?.txParams);
+ useSelector((state) =>
+ checkNetworkAndAccountSupports1559(state, transaction?.networkClientId),
+ ) && !isLegacyTransaction(transaction?.txParams);
const {
currency: primaryCurrency,
@@ -76,7 +77,7 @@ export function useGasEstimates({
maxPriorityFeePerGas: decGWEIToHexWEI(
maxPriorityFeePerGas || maxFeePerGas || gasPrice || '0',
),
- baseFeePerGas: decGWEIToHexWEI(gasFeeEstimates.estimatedBaseFee ?? '0'),
+ baseFeePerGas: decGWEIToHexWEI(gasFeeEstimates?.estimatedBaseFee ?? '0'),
};
} else {
gasSettings = {
diff --git a/ui/pages/confirmations/hooks/useGasFeeInputs.js b/ui/pages/confirmations/hooks/useGasFeeInputs.js
index 90913f8f86c3..27a60ad5f043 100644
--- a/ui/pages/confirmations/hooks/useGasFeeInputs.js
+++ b/ui/pages/confirmations/hooks/useGasFeeInputs.js
@@ -130,7 +130,7 @@ export function useGasFeeInputs(
gasFeeEstimates,
isGasEstimatesLoading,
isNetworkBusy,
- } = useGasFeeEstimates();
+ } = useGasFeeEstimates(transaction?.networkClientId);
const userPrefersAdvancedGas = useSelector(getAdvancedInlineGasShown);
diff --git a/ui/pages/confirmations/hooks/useIncrementedGasFees.js b/ui/pages/confirmations/hooks/useIncrementedGasFees.js
index 319312e1b421..68556c216f53 100644
--- a/ui/pages/confirmations/hooks/useIncrementedGasFees.js
+++ b/ui/pages/confirmations/hooks/useIncrementedGasFees.js
@@ -39,7 +39,9 @@ function getHighestIncrementedFee(originalFee, currentEstimate) {
* ).CustomGasSettings} Gas settings for cancellations/speed ups
*/
export function useIncrementedGasFees(transaction) {
- const { gasFeeEstimates = {} } = useGasFeeEstimates();
+ const { gasFeeEstimates = {} } = useGasFeeEstimates(
+ transaction.networkClientId,
+ );
// We memoize this value so that it can be relied upon in other hooks.
const customGasSettings = useMemo(() => {
diff --git a/ui/pages/confirmations/hooks/useTransactionFunctions.js b/ui/pages/confirmations/hooks/useTransactionFunctions.js
index db947e08f337..17b5165da94e 100644
--- a/ui/pages/confirmations/hooks/useTransactionFunctions.js
+++ b/ui/pages/confirmations/hooks/useTransactionFunctions.js
@@ -183,6 +183,9 @@ export const useTransactionFunctions = ({
? CUSTOM_GAS_ESTIMATE
: PriorityLevels.tenPercentIncreased;
+ if (!gasFeeEstimates) {
+ return;
+ }
updateTransaction({
estimateSuggested: initTransaction
? defaultEstimateToUse
diff --git a/ui/pages/confirmations/send/send-content/__snapshots__/send-content.component.test.js.snap b/ui/pages/confirmations/send/send-content/__snapshots__/send-content.component.test.js.snap
index cb4204841623..55fc897b62f5 100644
--- a/ui/pages/confirmations/send/send-content/__snapshots__/send-content.component.test.js.snap
+++ b/ui/pages/confirmations/send/send-content/__snapshots__/send-content.component.test.js.snap
@@ -287,5 +287,3 @@ exports[`SendContent Component render should match snapshot 1`] = `
`;
-
-exports[`SendContent Component render should match snapshot 2`] = `