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

Replace useSafeGasEstimatePolling with usePolling #23010

Merged
merged 93 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
556a765
Added generic polling hook
shanejonas Feb 15, 2024
5706baa
Added fast stable stringify
shanejonas Feb 15, 2024
a9a2303
Removed fast stringify for normal json stringify to not deal with ESM
shanejonas Feb 16, 2024
591c934
Removed fast-json-stable-stringify
shanejonas Feb 16, 2024
d8bb41d
Fixed issue if usePollingOptions.options is not defined
shanejonas Feb 16, 2024
1c6d5ea
Merge branch 'develop' into sj/added-generic-polling-hook
jiexi Feb 16, 2024
cf501b9
Replace useSafeGasEstimatePolling with usePolling
jiexi Feb 16, 2024
57a0469
update specs
jiexi Feb 16, 2024
3d48452
update useGasFeeEstimates to use usePolling hook
jiexi Feb 16, 2024
cabd6db
fix undefined dereference estimatedBaseFee
jiexi Feb 16, 2024
3ec134e
Fix base-fee-input
jiexi Feb 16, 2024
9a641c9
jsdoc
jiexi Feb 16, 2024
cd086c4
remove .tool-versions
jiexi Feb 16, 2024
6398d06
fix advanced-gas-fee-gas-limit.test.js
jiexi Feb 20, 2024
c99ff3b
Fix priority fee
jiexi Feb 20, 2024
db00da5
fix base fee import act
jiexi Feb 20, 2024
40bf680
fix advanced fee
jiexi Feb 20, 2024
3173387
fix priority fee input
jiexi Feb 20, 2024
b2d3f31
fix gas fee popover
jiexi Feb 20, 2024
b3160b8
lint
jiexi Feb 20, 2024
1dc2688
WIP gas-details-item.test.js
jiexi Feb 20, 2024
af58cc9
WIP
jiexi Feb 20, 2024
2e7db99
Fix specs
jiexi Feb 20, 2024
be2afe8
lint
jiexi Feb 20, 2024
a9b0dc6
missed one
jiexi Feb 20, 2024
3d4d00d
Merge branch 'jl/fix-incorrect-gas-estimate-tests' into jl/added-gene…
jiexi Feb 20, 2024
aef9520
restore useGasFeeEstimates
jiexi Feb 20, 2024
c0339b8
fix gas-details-item act
jiexi Feb 20, 2024
93973ce
Merge branch 'develop' into sj/added-generic-polling-hook
shanejonas Feb 21, 2024
8c1d16a
Merge branch 'sj/added-generic-polling-hook' into jl/added-generic-po…
jiexi Feb 21, 2024
ffb7ab4
Fix useGasItemFeeDetails gasFeeEstimates undefined reference
jiexi Feb 21, 2024
c20fb28
Fix base-fee-input.test.js
jiexi Feb 21, 2024
18e5801
fix priority-fee-input.test.js
jiexi Feb 21, 2024
55a76ab
fix transaction-detail.component.test.js
jiexi Feb 21, 2024
35b7f78
Fix ui/pages/swaps test
jiexi Feb 21, 2024
2293f79
fix transaction-list-item-details.component.test.js
jiexi Feb 21, 2024
1123976
fix send-content.component.test.js
jiexi Feb 21, 2024
f565236
Get confirmation container container tests passing and remove act war…
shanejonas Feb 21, 2024
00f30a6
remove snapshot
jiexi Feb 21, 2024
f2c5a94
fix snapshot
jiexi Feb 21, 2024
1ed23fc
fix snapshot attempt 2
jiexi Feb 21, 2024
4919512
fix snapshot attempt 3
jiexi Feb 21, 2024
4cdaaa3
fix edit-gas-fee-button.test.js
jiexi Feb 21, 2024
f27318e
fix edit-gas-item.test.js
jiexi Feb 21, 2024
9f705f5
lint
jiexi Feb 21, 2024
f441ccf
fix fee-details-component.test.js
jiexi Feb 21, 2024
adf57bf
Fix routes.component.test.js
jiexi Feb 22, 2024
b4d3743
update mock-send-state to silence required props errors
jiexi Feb 22, 2024
e03e539
fix edit-gas-fee-icon.test.js
jiexi Feb 22, 2024
4c5a52d
fix edit-gas-tooltip.test.js
jiexi Feb 22, 2024
5b9f557
lint
jiexi Feb 22, 2024
aa0580d
Fixed token allowance tests
shanejonas Feb 22, 2024
eb38f68
Fixed action mocks
shanejonas Feb 22, 2024
b66fc18
fix confirm-gas-display.test
jiexi Feb 22, 2024
a2ac2ff
fix send.test.js
jiexi Feb 22, 2024
13d8eff
Updated snapshot for confirm-send-ether.test.js
shanejonas Feb 22, 2024
9892d45
Fixed action mocks for confirm-transaction-base.test.js
shanejonas Feb 22, 2024
cde5e7a
Fixed action mocks for advanced-gas-fee-input-subtext.test.js
shanejonas Feb 22, 2024
ad7e756
Fixed action mocks for cancel-speedup-popover.test.js
shanejonas Feb 22, 2024
013eebb
fix confirm-transaction-base.test.js
jiexi Feb 22, 2024
d97ddd9
fix advanced-gas-fee-input-subtext.test.js
jiexi Feb 22, 2024
5ed2636
fix edit-gas-fee-popover.test.js
jiexi Feb 23, 2024
86bf912
fix useGasFeeInputs.test.js via test-utils selectors
jiexi Feb 23, 2024
2e710c9
add mock state by chain id to speedup test
jiexi Feb 23, 2024
9422acb
wip
jiexi Feb 23, 2024
170fee4
exit early updateTransactionToTenPercentIncreasedGasFee
jiexi Feb 23, 2024
2142d98
Revert "wip"
jiexi Feb 23, 2024
54519ae
update updateTransactionToTenPercentIncreasedGasFee guard
jiexi Feb 23, 2024
82710b4
Merge branch 'develop' into jl/added-generic-polling-hook-replace-use…
jiexi Feb 23, 2024
47b8b1f
lint
jiexi Feb 23, 2024
98d3230
update blockaid-banner-alert snapshot?..
jiexi Feb 23, 2024
8ec1e7c
fix send-content.component.test.js snapshot
jiexi Feb 23, 2024
df77d8f
Merge branch 'develop' into jl/added-generic-polling-hook-replace-use…
jiexi Feb 26, 2024
a0ba91f
wait for confirm to be enabled before continuing to tx insights in te…
jiexi Feb 26, 2024
45f960e
Merge branch 'develop' into jl/added-generic-polling-hook-replace-use…
jiexi Feb 26, 2024
7d1eca7
Merge branch 'develop' into jl/added-generic-polling-hook-replace-use…
adonesky1 Feb 27, 2024
3f6f272
Merge branch 'develop' into jl/added-generic-polling-hook-replace-use…
jiexi Feb 28, 2024
d0d702f
Add isMounted guard to useGasFeeEstimates
jiexi Mar 4, 2024
97dc6db
Merge branch 'develop' into jl/added-generic-polling-hook-replace-use…
adonesky1 Mar 5, 2024
4f28da6
Merge branch 'develop' into jl/added-generic-polling-hook-replace-use…
adonesky1 Mar 5, 2024
75c91c1
fix test
adonesky1 Mar 5, 2024
1080c91
add isMounted guard to gas-timing-component effect
jiexi Mar 5, 2024
168fc81
Merge branch 'develop' into jl/added-generic-polling-hook-replace-use…
adonesky1 Mar 5, 2024
7cf4cc1
update confirm-send-ether.test.js snapshot
jiexi Mar 5, 2024
ec6c828
Merge branch 'develop' into jl/added-generic-polling-hook-replace-use…
jiexi Mar 5, 2024
c246019
Merge branch 'develop' into jl/added-generic-polling-hook-replace-use…
jiexi Mar 5, 2024
928c60b
Merge branch 'develop' into jl/added-generic-polling-hook-replace-use…
adonesky1 Mar 6, 2024
02a0c73
use renderHookWithProvider
adonesky1 Mar 6, 2024
37ef9ac
fix broken swaps flow
adonesky1 Mar 6, 2024
64c3fd5
Merge branch 'develop' into jl/added-generic-polling-hook-replace-use…
jiexi Mar 6, 2024
974acba
Merge branch 'develop' into jl/added-generic-polling-hook-replace-use…
adonesky1 Mar 6, 2024
56fedb4
Merge branch 'develop' into jl/added-generic-polling-hook-replace-use…
jiexi Mar 7, 2024
d7b1e5e
Merge branch 'develop' into jl/added-generic-polling-hook-replace-use…
adonesky1 Mar 8, 2024
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
10 changes: 10 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2941,6 +2941,10 @@ export default class MetamaskController extends EventEmitter {
this.networkController.getEIP1559Compatibility.bind(
this.networkController,
),
getNetworkConfigurationByNetworkClientId:
this.networkController.getNetworkConfigurationByNetworkClientId.bind(
this.networkController,
),
// PreferencesController
setSelectedAddress: (address) => {
const account = this.accountsController.getAccountByAddress(address);
Expand Down Expand Up @@ -3421,6 +3425,12 @@ export default class MetamaskController extends EventEmitter {
),

// GasFeeController
gasFeeStartPollingByNetworkClientId:
gasFeeController.startPollingByNetworkClientId.bind(gasFeeController),

gasFeeStopPollingByPollingToken:
gasFeeController.stopPollingByPollingToken.bind(gasFeeController),

getGasFeeEstimatesAndStartPolling:
gasFeeController.getGasFeeEstimatesAndStartPolling.bind(
gasFeeController,
Expand Down
1 change: 0 additions & 1 deletion development/ts-migration-dashboard/files-to-convert.json
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,6 @@
"ui/hooks/useIncrementedGasFees.js",
"ui/hooks/useOriginMetadata.js",
"ui/hooks/usePrevious.js",
"ui/hooks/useSafeGasEstimatePolling.js",
"ui/hooks/useSegmentContext.js",
"ui/hooks/useShouldAnimateGasEstimations.js",
"ui/hooks/useShouldShowSpeedUp.js",
Expand Down
37 changes: 37 additions & 0 deletions test/data/mock-send-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"importNftsModal": { "open": false },
"gasIsLoading": false,
"isLoading": false,
"importTokensModalOpen": false,
"modal": {
"open": false,
"modalState": {
Expand All @@ -24,6 +25,9 @@
"name": null
}
},
"showIpfsModalOpen": false,
"showKeyringRemovalSnapModal": false,
"showWhatsNewPopup": false,
adonesky1 marked this conversation as resolved.
Show resolved Hide resolved
"warning": null,
"alertOpen": false
},
Expand Down Expand Up @@ -90,13 +94,46 @@
"priorityFeeTrend": "down",
"networkCongestion": 0.90625
},
"gasFeeEstimatesByChainId": {
"0x5": {
"gasEstimateType": "fee-market",
"gasFeeEstimates": {
"low": {
"minWaitTimeEstimate": 180000,
"maxWaitTimeEstimate": 300000,
"suggestedMaxPriorityFeePerGas": "3",
"suggestedMaxFeePerGas": "53"
},
"medium": {
"minWaitTimeEstimate": 15000,
"maxWaitTimeEstimate": 60000,
"suggestedMaxPriorityFeePerGas": "7",
"suggestedMaxFeePerGas": "70"
},
"high": {
"minWaitTimeEstimate": 0,
"maxWaitTimeEstimate": 15000,
"suggestedMaxPriorityFeePerGas": "10",
"suggestedMaxFeePerGas": "100"
},
"estimatedBaseFee": "50",
"historicalBaseFeeRange": ["28.533098435", "70.351148354"],
"baseFeeTrend": "up",
"latestPriorityFeeRange": ["1", "40"],
"historicalPriorityFeeRange": ["0.1458417", "700.156384646"],
"priorityFeeTrend": "down",
"networkCongestion": 0.90625
}
}
},
"snaps": [{}],
"preferences": {
"hideZeroBalanceTokens": false,
"showFiatInTestnets": false,
"showTestNetworks": true,
"useNativeCurrencyAsPrimaryCurrency": true
},
"seedPhraseBackedUp": null,
"ensResolutionsByAddress": {},
"isAccountMenuOpen": false,
"isUnlocked": true,
Expand Down
32 changes: 32 additions & 0 deletions test/data/mock-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,38 @@
"participateInMetaMetrics": false,
"gasEstimateType": "fee-market",
"showBetaHeader": false,
"gasFeeEstimatesByChainId": {
"0x5": {
"gasEstimateType": "fee-market",
"gasFeeEstimates": {
"low": {
"minWaitTimeEstimate": 180000,
"maxWaitTimeEstimate": 300000,
"suggestedMaxPriorityFeePerGas": "3",
"suggestedMaxFeePerGas": "53"
},
"medium": {
"minWaitTimeEstimate": 15000,
"maxWaitTimeEstimate": 60000,
"suggestedMaxPriorityFeePerGas": "7",
"suggestedMaxFeePerGas": "70"
},
"high": {
"minWaitTimeEstimate": 0,
"maxWaitTimeEstimate": 15000,
"suggestedMaxPriorityFeePerGas": "10",
"suggestedMaxFeePerGas": "100"
},
"estimatedBaseFee": "50",
"historicalBaseFeeRange": ["28.533098435", "70.351148354"],
"baseFeeTrend": "up",
"latestPriorityFeeRange": ["1", "40"],
"historicalPriorityFeeRange": ["0.1458417", "700.156384646"],
"priorityFeeTrend": "down",
"networkCongestion": 0.90625
}
}
},
"permissionHistory": {},
"gasFeeEstimates": {
"low": {
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/snaps/test-snap-txinsights-v2.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ describe('Test Snap TxInsights-v2', function () {
WINDOW_TITLES.Dialog,
windowHandles,
);

await driver.findClickableElement({
text: 'Confirm',
tag: 'button',
});
adonesky1 marked this conversation as resolved.
Show resolved Hide resolved

await driver.waitForSelector({
text: 'Insights Example Snap',
tag: 'button',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ const MOCK_SUGGESTED_MEDIUM_MAXFEEPERGAS_HEX_WEI =
MOCK_SUGGESTED_MEDIUM_MAXFEEPERGAS_BN_WEI.toString(16);

jest.mock('../../../store/actions', () => ({
gasFeeStartPollingByNetworkClientId: jest
.fn()
.mockResolvedValue('pollingToken'),
gasFeeStopPollingByPollingToken: jest.fn(),
getNetworkConfigurationByNetworkClientId: jest.fn().mockImplementation(() =>
Promise.resolve({
chainId: '0x5',
}),
),
disconnectGasFeeEstimatePoller: jest.fn(),
getGasFeeTimeEstimate: jest.fn().mockImplementation(() => Promise.resolve()),
getGasFeeEstimatesAndStartPolling: jest
Expand Down Expand Up @@ -85,6 +94,14 @@ const render = (
featureFlags: { advancedInlineGas: true },
gasFeeEstimates:
mockEstimates[GasEstimateTypes.feeMarket].gasFeeEstimates,
gasFeeEstimatesByChainId: {
...mockState.metamask.gasFeeEstimatesByChainId,
'0x5': {
...mockState.metamask.gasFeeEstimatesByChainId['0x5'],
gasFeeEstimates:
mockEstimates[GasEstimateTypes.feeMarket].gasFeeEstimates,
},
},
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { waitFor } from '@testing-library/react';
import { act, waitFor } from '@testing-library/react';
import { TransactionStatus } from '@metamask/transaction-controller';
import { GAS_LIMITS } from '../../../../shared/constants/gas';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
Expand All @@ -10,8 +10,13 @@ import TransactionListItemDetails from '.';

jest.mock('../../../store/actions.ts', () => ({
tryReverseResolveAddress: () => jest.fn(),
getGasFeeEstimatesAndStartPolling: jest.fn().mockResolvedValue(),
addPollingTokenToAppState: jest.fn(),
gasFeeStartPollingByNetworkClientId: jest
.fn()
.mockResolvedValue('pollingToken'),
gasFeeStopPollingByPollingToken: jest.fn(),
getNetworkConfigurationByNetworkClientId: jest
.fn()
.mockResolvedValue({ chainId: '0x5' }),
}));

let mockGetCustodianTransactionDeepLink = jest.fn();
Expand All @@ -22,34 +27,34 @@ jest.mock('../../../store/institutional/institution-background', () => ({
}),
}));

describe('TransactionListItemDetails Component', () => {
const transaction = {
history: [],
id: 1,
status: TransactionStatus.confirmed,
txParams: {
from: '0x1',
gas: GAS_LIMITS.SIMPLE,
gasPrice: '0x3b9aca00',
nonce: '0xa4',
to: '0x2',
value: '0x2386f26fc10000',
},
metadata: {
note: 'some note',
},
custodyId: '1',
};

const transactionGroup = {
transactions: [transaction],
primaryTransaction: transaction,
initialTransaction: transaction,
const transaction = {
history: [],
id: 1,
status: TransactionStatus.confirmed,
txParams: {
from: '0x1',
gas: GAS_LIMITS.SIMPLE,
gasPrice: '0x3b9aca00',
nonce: '0xa4',
hasRetried: false,
hasCancelled: false,
};

to: '0x2',
value: '0x2386f26fc10000',
},
metadata: {
note: 'some note',
},
custodyId: '1',
};

const transactionGroup = {
transactions: [transaction],
primaryTransaction: transaction,
initialTransaction: transaction,
nonce: '0xa4',
hasRetried: false,
hasCancelled: false,
};

const render = async (overrideProps) => {
const rpcPrefs = {
blockExplorerUrl: 'https://customblockexplorer.com/',
};
Expand All @@ -69,70 +74,52 @@ describe('TransactionListItemDetails Component', () => {
transactionStatus: () => <div></div>,
blockExplorerLinkText,
rpcPrefs,
...overrideProps,
};

it('should render title with title prop', async () => {
const mockStore = configureMockStore([thunk])(mockState);
const mockStore = configureMockStore([thunk])(mockState);

let result;

const { queryByText } = renderWithProvider(
<TransactionListItemDetails {...props} />,
mockStore,
);
await act(
async () =>
(result = renderWithProvider(
<TransactionListItemDetails {...props} />,
mockStore,
)),
);

return result;
};

describe('TransactionListItemDetails Component', () => {
it('should render title with title prop', async () => {
const { queryByText } = await render();

await waitFor(() => {
expect(queryByText(props.title)).toBeInTheDocument();
expect(queryByText('Test Transaction Details')).toBeInTheDocument();
});
});

describe('Retry button', () => {
it('should render retry button with showRetry prop', () => {
const retryProps = {
...props,
showRetry: true,
};

const mockStore = configureMockStore([thunk])(mockState);

const { queryByTestId } = renderWithProvider(
<TransactionListItemDetails {...retryProps} />,
mockStore,
);
it('should render retry button with showRetry prop', async () => {
const { queryByTestId } = await render({ showRetry: true });

expect(queryByTestId('rety-button')).toBeInTheDocument();
});
});

describe('Cancel button', () => {
it('should render cancel button with showCancel prop', () => {
const retryProps = {
...props,
showCancel: true,
};

const mockStore = configureMockStore([thunk])(mockState);

const { queryByTestId } = renderWithProvider(
<TransactionListItemDetails {...retryProps} />,
mockStore,
);
it('should render cancel button with showCancel prop', async () => {
const { queryByTestId } = await render({ showCancel: true });

expect(queryByTestId('cancel-button')).toBeInTheDocument();
});
});

describe('Speedup button', () => {
it('should render speedup button with showSpeedUp prop', () => {
const retryProps = {
...props,
showSpeedUp: true,
};

const mockStore = configureMockStore([thunk])(mockState);

const { queryByTestId } = renderWithProvider(
<TransactionListItemDetails {...retryProps} />,
mockStore,
);
it('should render speedup button with showSpeedUp prop', async () => {
const { queryByTestId } = await render({ showSpeedUp: true });

expect(queryByTestId('speedup-button')).toBeInTheDocument();
});
Expand All @@ -144,9 +131,7 @@ describe('TransactionListItemDetails Component', () => {
.fn()
.mockReturnValue({ url: 'https://url.com' });

const mockStore = configureMockStore([thunk])(mockState);

renderWithProvider(<TransactionListItemDetails {...props} />, mockStore);
await render({ showCancel: true });

await waitFor(() => {
const custodianViewButton = document.querySelector(
Expand All @@ -173,15 +158,10 @@ describe('TransactionListItemDetails Component', () => {
primaryTransaction: newTransaction,
initialTransaction: newTransaction,
};
const mockStore = configureMockStore([thunk])(mockState);

const { queryByText } = renderWithProvider(
<TransactionListItemDetails
{...props}
transactionGroup={newTransactionGroup}
/>,
mockStore,
);
const { queryByText } = await render({
transactionGroup: newTransactionGroup,
});

await waitFor(() => {
expect(queryByText('some note')).toBeInTheDocument();
Expand Down
Loading
Loading