mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Hide basic tab in advanced gas modal for speedup and cancel when on testnets (#11115)
This commit is contained in:
parent
5f538f7ab2
commit
6a73b7c998
@ -30,12 +30,16 @@ export default class Sidebar extends Component {
|
|||||||
|
|
||||||
renderSidebarContent() {
|
renderSidebarContent() {
|
||||||
const { type, sidebarProps = {} } = this.props;
|
const { type, sidebarProps = {} } = this.props;
|
||||||
const { transaction = {}, onSubmit } = sidebarProps;
|
const { transaction = {}, onSubmit, hideBasic } = sidebarProps;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'customize-gas':
|
case 'customize-gas':
|
||||||
return (
|
return (
|
||||||
<div className="sidebar-left">
|
<div className="sidebar-left">
|
||||||
<CustomizeGas transaction={transaction} onSubmit={onSubmit} />
|
<CustomizeGas
|
||||||
|
transaction={transaction}
|
||||||
|
onSubmit={onSubmit}
|
||||||
|
hideBasic={hideBasic}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
|
@ -7,7 +7,11 @@ import {
|
|||||||
getHexGasTotal,
|
getHexGasTotal,
|
||||||
increaseLastGasPrice,
|
increaseLastGasPrice,
|
||||||
} from '../helpers/utils/confirm-tx.util';
|
} from '../helpers/utils/confirm-tx.util';
|
||||||
import { getConversionRate, getSelectedAccount } from '../selectors';
|
import {
|
||||||
|
getConversionRate,
|
||||||
|
getSelectedAccount,
|
||||||
|
getIsMainnet,
|
||||||
|
} from '../selectors';
|
||||||
import {
|
import {
|
||||||
setCustomGasLimit,
|
setCustomGasLimit,
|
||||||
setCustomGasPriceForRetry,
|
setCustomGasPriceForRetry,
|
||||||
@ -43,7 +47,8 @@ export function useCancelTransaction(transactionGroup) {
|
|||||||
multiplierBase: 10,
|
multiplierBase: 10,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
const isMainnet = useSelector(getIsMainnet);
|
||||||
|
const hideBasic = !(isMainnet || process.env.IN_TEST);
|
||||||
const cancelTransaction = useCallback(
|
const cancelTransaction = useCallback(
|
||||||
(event) => {
|
(event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
@ -62,6 +67,7 @@ export function useCancelTransaction(transactionGroup) {
|
|||||||
transitionName: 'sidebar-left',
|
transitionName: 'sidebar-left',
|
||||||
type: 'customize-gas',
|
type: 'customize-gas',
|
||||||
props: {
|
props: {
|
||||||
|
hideBasic,
|
||||||
transaction: tx,
|
transaction: tx,
|
||||||
onSubmit: (newGasLimit, newGasPrice) => {
|
onSubmit: (newGasLimit, newGasPrice) => {
|
||||||
const userCustomizedGasTotal = getHexGasTotal({
|
const userCustomizedGasTotal = getHexGasTotal({
|
||||||
@ -82,7 +88,7 @@ export function useCancelTransaction(transactionGroup) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[dispatch, transaction, defaultNewGasPrice],
|
[dispatch, transaction, defaultNewGasPrice, hideBasic],
|
||||||
);
|
);
|
||||||
|
|
||||||
const hasEnoughCancelGas =
|
const hasEnoughCancelGas =
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
|
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { showSidebar } from '../store/actions';
|
import { showSidebar } from '../store/actions';
|
||||||
import {
|
import {
|
||||||
@ -7,8 +8,8 @@ import {
|
|||||||
setCustomGasLimit,
|
setCustomGasLimit,
|
||||||
} from '../ducks/gas/gas.duck';
|
} from '../ducks/gas/gas.duck';
|
||||||
import { increaseLastGasPrice } from '../helpers/utils/confirm-tx.util';
|
import { increaseLastGasPrice } from '../helpers/utils/confirm-tx.util';
|
||||||
|
import { getIsMainnet } from '../selectors';
|
||||||
import { useMetricEvent } from './useMetricEvent';
|
import { useMetricEvent } from './useMetricEvent';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a reusable hook that, given a transactionGroup, will return
|
* Provides a reusable hook that, given a transactionGroup, will return
|
||||||
* a method for beginning the retry process
|
* a method for beginning the retry process
|
||||||
@ -17,6 +18,8 @@ import { useMetricEvent } from './useMetricEvent';
|
|||||||
*/
|
*/
|
||||||
export function useRetryTransaction(transactionGroup) {
|
export function useRetryTransaction(transactionGroup) {
|
||||||
const { primaryTransaction } = transactionGroup;
|
const { primaryTransaction } = transactionGroup;
|
||||||
|
const isMainnet = useSelector(getIsMainnet);
|
||||||
|
const hideBasic = !(isMainnet || process.env.IN_TEST);
|
||||||
// Signature requests do not have a txParams, but this hook is called indiscriminately
|
// Signature requests do not have a txParams, but this hook is called indiscriminately
|
||||||
const gasPrice = primaryTransaction.txParams?.gasPrice;
|
const gasPrice = primaryTransaction.txParams?.gasPrice;
|
||||||
const trackMetricsEvent = useMetricEvent({
|
const trackMetricsEvent = useMetricEvent({
|
||||||
@ -46,11 +49,11 @@ export function useRetryTransaction(transactionGroup) {
|
|||||||
showSidebar({
|
showSidebar({
|
||||||
transitionName: 'sidebar-left',
|
transitionName: 'sidebar-left',
|
||||||
type: 'customize-gas',
|
type: 'customize-gas',
|
||||||
props: { transaction },
|
props: { transaction, hideBasic },
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[dispatch, trackMetricsEvent, gasPrice, primaryTransaction],
|
[dispatch, trackMetricsEvent, gasPrice, primaryTransaction, hideBasic],
|
||||||
);
|
);
|
||||||
|
|
||||||
return retryTransaction;
|
return retryTransaction;
|
||||||
|
@ -3,23 +3,31 @@ import { renderHook } from '@testing-library/react-hooks';
|
|||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import transactions from '../../test/data/transaction-data.json';
|
import transactions from '../../test/data/transaction-data.json';
|
||||||
import { showSidebar } from '../store/actions';
|
import { showSidebar } from '../store/actions';
|
||||||
|
import { getIsMainnet } from '../selectors';
|
||||||
import * as methodDataHook from './useMethodData';
|
import * as methodDataHook from './useMethodData';
|
||||||
import * as metricEventHook from './useMetricEvent';
|
import * as metricEventHook from './useMetricEvent';
|
||||||
import { useRetryTransaction } from './useRetryTransaction';
|
import { useRetryTransaction } from './useRetryTransaction';
|
||||||
|
|
||||||
describe('useRetryTransaction', () => {
|
describe('useRetryTransaction', () => {
|
||||||
describe('when transaction meets retry enabled criteria', () => {
|
describe('when transaction meets retry enabled criteria', () => {
|
||||||
|
let useSelector;
|
||||||
const dispatch = sinon.spy(() => Promise.resolve({ blockTime: 0 }));
|
const dispatch = sinon.spy(() => Promise.resolve({ blockTime: 0 }));
|
||||||
const trackEvent = sinon.spy();
|
const trackEvent = sinon.spy();
|
||||||
const event = {
|
const event = {
|
||||||
preventDefault: () => undefined,
|
preventDefault: () => undefined,
|
||||||
stopPropagation: () => undefined,
|
stopPropagation: () => undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
sinon.stub(reactRedux, 'useDispatch').returns(dispatch);
|
sinon.stub(reactRedux, 'useDispatch').returns(dispatch);
|
||||||
sinon.stub(methodDataHook, 'useMethodData').returns({});
|
sinon.stub(methodDataHook, 'useMethodData').returns({});
|
||||||
sinon.stub(metricEventHook, 'useMetricEvent').returns(trackEvent);
|
sinon.stub(metricEventHook, 'useMetricEvent').returns(trackEvent);
|
||||||
|
useSelector = sinon.stub(reactRedux, 'useSelector');
|
||||||
|
useSelector.callsFake((selector) => {
|
||||||
|
if (selector === getIsMainnet) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -61,7 +69,10 @@ describe('useRetryTransaction', () => {
|
|||||||
showSidebar({
|
showSidebar({
|
||||||
transitionName: 'sidebar-left',
|
transitionName: 'sidebar-left',
|
||||||
type: 'customize-gas',
|
type: 'customize-gas',
|
||||||
props: { transaction: retryEnabledTransaction.initialTransaction },
|
props: {
|
||||||
|
transaction: retryEnabledTransaction.initialTransaction,
|
||||||
|
hideBasic: false,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
).toStrictEqual(true);
|
).toStrictEqual(true);
|
||||||
@ -104,7 +115,10 @@ describe('useRetryTransaction', () => {
|
|||||||
showSidebar({
|
showSidebar({
|
||||||
transitionName: 'sidebar-left',
|
transitionName: 'sidebar-left',
|
||||||
type: 'customize-gas',
|
type: 'customize-gas',
|
||||||
props: { transaction: cancelledTransaction.primaryTransaction },
|
props: {
|
||||||
|
transaction: cancelledTransaction.primaryTransaction,
|
||||||
|
hideBasic: false,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
).toStrictEqual(true);
|
).toStrictEqual(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user