mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-01 13:47:06 +01:00
e2c4e93ab0
* When gas fees suggested by dapp is too high, show warning color and icon Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> tests Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> Fix tests Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> set a default for high gas fees Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> Fix test cases where transaction is undefined. Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> Fix locale error Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> Fix error where dappSuggestedGasFees is null Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> Fix icon for site suggested Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> Fix unit tests snapshot Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> * Fix QA Comments Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> * lint:fix Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> * Fix unit tests Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> * Fix PR comments Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> * Lint fix Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> * Fix PR comment. - call setEstimateUsed only once. Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> * use constants for Priority levels. Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com> --------- Signed-off-by: Olusegun Akintayo <akintayo.segun@gmail.com>
180 lines
5.2 KiB
JavaScript
180 lines
5.2 KiB
JavaScript
import React from 'react';
|
|
import { screen, waitFor } from '@testing-library/react';
|
|
|
|
import { GasEstimateTypes } from '../../../../shared/constants/gas';
|
|
import mockEstimates from '../../../../test/data/mock-estimates.json';
|
|
import mockState from '../../../../test/data/mock-state.json';
|
|
import { GasFeeContextProvider } from '../../../contexts/gasFee';
|
|
import { renderWithProvider } from '../../../../test/jest';
|
|
import configureStore from '../../../store/store';
|
|
|
|
import GasDetailsItem from './gas-details-item';
|
|
|
|
jest.mock('../../../store/actions', () => ({
|
|
disconnectGasFeeEstimatePoller: jest.fn(),
|
|
getGasFeeEstimatesAndStartPolling: jest
|
|
.fn()
|
|
.mockImplementation(() => Promise.resolve()),
|
|
addPollingTokenToAppState: jest.fn(),
|
|
getGasFeeTimeEstimate: jest.fn().mockImplementation(() => Promise.resolve()),
|
|
}));
|
|
|
|
const render = ({ contextProps } = {}) => {
|
|
const store = configureStore({
|
|
metamask: {
|
|
...mockState.metamask,
|
|
accounts: {
|
|
[mockState.metamask.selectedAddress]: {
|
|
address: mockState.metamask.selectedAddress,
|
|
balance: '0x1F4',
|
|
},
|
|
},
|
|
preferences: {
|
|
useNativeCurrencyAsPrimaryCurrency: true,
|
|
},
|
|
gasFeeEstimates: mockEstimates[GasEstimateTypes.feeMarket],
|
|
...contextProps,
|
|
},
|
|
});
|
|
|
|
return renderWithProvider(
|
|
<GasFeeContextProvider
|
|
transaction={{
|
|
txParams: {
|
|
gas: '0x5208',
|
|
maxFeePerGas: '0x59682f10',
|
|
maxPriorityFeePerGas: '0x59682f00',
|
|
},
|
|
userFeeLevel: 'medium',
|
|
}}
|
|
{...contextProps}
|
|
>
|
|
<GasDetailsItem userAcknowledgedGasMissing={false} />
|
|
</GasFeeContextProvider>,
|
|
store,
|
|
);
|
|
};
|
|
|
|
describe('GasDetailsItem', () => {
|
|
it('should render label', async () => {
|
|
render();
|
|
await waitFor(() => {
|
|
expect(screen.queryByText('Gas')).toBeInTheDocument();
|
|
expect(screen.queryByText('(estimated)')).toBeInTheDocument();
|
|
expect(screen.queryByText('Max fee:')).toBeInTheDocument();
|
|
expect(screen.queryAllByText('ETH').length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
it('should show warning icon if estimates are high', async () => {
|
|
render({
|
|
contextProps: { transaction: { txParams: {}, userFeeLevel: 'high' } },
|
|
});
|
|
await waitFor(() => {
|
|
expect(screen.queryByText('⚠ Max fee:')).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
it('should show warning icon if dapp estimates are high', async () => {
|
|
render({
|
|
contextProps: {
|
|
gasFeeEstimates: {
|
|
high: {
|
|
suggestedMaxPriorityFeePerGas: '1',
|
|
},
|
|
},
|
|
transaction: {
|
|
txParams: {
|
|
gas: '0x52081',
|
|
maxFeePerGas: '0x38D7EA4C68000',
|
|
},
|
|
userFeeLevel: 'medium',
|
|
dappSuggestedGasFees: {
|
|
maxPriorityFeePerGas: '0x38D7EA4C68000',
|
|
maxFeePerGas: '0x38D7EA4C68000',
|
|
},
|
|
},
|
|
},
|
|
});
|
|
await waitFor(() => {
|
|
expect(screen.queryByText('⚠ Max fee:')).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
it('should not show warning icon if estimates are not high', async () => {
|
|
render({
|
|
contextProps: { transaction: { txParams: {}, userFeeLevel: 'low' } },
|
|
});
|
|
await waitFor(() => {
|
|
expect(screen.queryByText('Max fee:')).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
it('should return null if there is simulationError and user has not acknowledged gasMissing warning', () => {
|
|
const { container } = render({
|
|
contextProps: {
|
|
transaction: {
|
|
txParams: {},
|
|
simulationFails: true,
|
|
userFeeLevel: 'low',
|
|
},
|
|
},
|
|
});
|
|
expect(container.innerHTML).toHaveLength(0);
|
|
});
|
|
|
|
it('should not return null even if there is simulationError if user acknowledged gasMissing warning', async () => {
|
|
render();
|
|
await waitFor(() => {
|
|
expect(screen.queryByText('Gas')).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
it('should render gas fee details', async () => {
|
|
render();
|
|
await waitFor(() => {
|
|
expect(screen.queryAllByTitle('0.0000315 ETH').length).toBeGreaterThan(0);
|
|
expect(screen.queryAllByText('ETH').length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
it('should render gas fee details if maxPriorityFeePerGas is 0', async () => {
|
|
render({
|
|
contextProps: {
|
|
transaction: {
|
|
txParams: {
|
|
gas: '0x5208',
|
|
maxFeePerGas: '0x59682f10',
|
|
maxPriorityFeePerGas: '0',
|
|
},
|
|
simulationFails: false,
|
|
userFeeLevel: 'low',
|
|
},
|
|
},
|
|
});
|
|
await waitFor(() => {
|
|
expect(screen.queryAllByTitle('0.0000315 ETH').length).toBeGreaterThan(0);
|
|
expect(screen.queryAllByText('ETH').length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
it('should render gas fee details if maxPriorityFeePerGas is undefined', async () => {
|
|
render({
|
|
contextProps: {
|
|
transaction: {
|
|
txParams: {
|
|
gas: '0x5208',
|
|
maxFeePerGas: '0x59682f10',
|
|
},
|
|
simulationFails: false,
|
|
userFeeLevel: 'low',
|
|
},
|
|
},
|
|
});
|
|
await waitFor(() => {
|
|
expect(screen.queryAllByTitle('0.0000315 ETH').length).toBeGreaterThan(0);
|
|
expect(screen.queryAllByText('ETH').length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
});
|