mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
parent
81f274303e
commit
38ff2c937f
@ -792,13 +792,12 @@ describe('MetaMask', function () {
|
|||||||
await driver.clickElement('.confirm-approve-content__small-blue-text');
|
await driver.clickElement('.confirm-approve-content__small-blue-text');
|
||||||
await driver.delay(regularDelayMs);
|
await driver.delay(regularDelayMs);
|
||||||
|
|
||||||
// wait for gas modal to be visible
|
await driver.clickElement(
|
||||||
const gasModal = await driver.findVisibleElement('span .modal');
|
'.edit-gas-display__dapp-acknowledgement-button',
|
||||||
await driver.clickElement('.page-container__tab:nth-of-type(2)');
|
);
|
||||||
await driver.delay(regularDelayMs);
|
|
||||||
|
|
||||||
const [gasPriceInput, gasLimitInput] = await driver.findElements(
|
const [gasLimitInput, gasPriceInput] = await driver.findElements(
|
||||||
'.advanced-gas-inputs__gas-edit-row__input',
|
'.advanced-gas-controls input[type="number"]',
|
||||||
);
|
);
|
||||||
|
|
||||||
await gasPriceInput.fill('10');
|
await gasPriceInput.fill('10');
|
||||||
@ -808,10 +807,7 @@ describe('MetaMask', function () {
|
|||||||
|
|
||||||
await driver.delay(1000);
|
await driver.delay(1000);
|
||||||
|
|
||||||
await driver.clickElement('.page-container__footer-button');
|
await driver.clickElement({ text: 'Save', tag: 'button' }, 10000);
|
||||||
|
|
||||||
// wait for gas modal to be removed from DOM.
|
|
||||||
await gasModal.waitForElementState('hidden');
|
|
||||||
|
|
||||||
const gasFeeInEth = await driver.findElement(
|
const gasFeeInEth = await driver.findElement(
|
||||||
'.confirm-approve-content__transaction-details-content__secondary-fee',
|
'.confirm-approve-content__transaction-details-content__secondary-fee',
|
||||||
|
@ -11,7 +11,6 @@ import { ENVIRONMENT_TYPE_POPUP } from '../../../../shared/constants/app';
|
|||||||
// Modal Components
|
// Modal Components
|
||||||
import ConfirmCustomizeGasModal from '../gas-customization/gas-modal-page-container';
|
import ConfirmCustomizeGasModal from '../gas-customization/gas-modal-page-container';
|
||||||
import SwapsGasCustomizationModal from '../../../pages/swaps/swaps-gas-customization-modal';
|
import SwapsGasCustomizationModal from '../../../pages/swaps/swaps-gas-customization-modal';
|
||||||
import EditGasPopover from '../edit-gas-popover/edit-gas-popover.component';
|
|
||||||
import DepositEtherModal from './deposit-ether-modal';
|
import DepositEtherModal from './deposit-ether-modal';
|
||||||
import AccountDetailsModal from './account-details-modal';
|
import AccountDetailsModal from './account-details-modal';
|
||||||
import ExportPrivateKeyModal from './export-private-key-modal';
|
import ExportPrivateKeyModal from './export-private-key-modal';
|
||||||
@ -246,35 +245,6 @@ const MODALS = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
CUSTOMIZE_GAS: {
|
|
||||||
contents: <EditGasPopover />,
|
|
||||||
mobileModalStyle: {
|
|
||||||
width: '100vw',
|
|
||||||
height: '100vh',
|
|
||||||
top: '0',
|
|
||||||
transform: 'none',
|
|
||||||
left: '0',
|
|
||||||
right: '0',
|
|
||||||
margin: '0 auto',
|
|
||||||
},
|
|
||||||
laptopModalStyle: {
|
|
||||||
width: 'auto',
|
|
||||||
height: '0px',
|
|
||||||
top: '80px',
|
|
||||||
left: '0px',
|
|
||||||
transform: 'none',
|
|
||||||
margin: '0 auto',
|
|
||||||
position: 'relative',
|
|
||||||
},
|
|
||||||
contentStyle: {
|
|
||||||
borderRadius: '8px',
|
|
||||||
},
|
|
||||||
customOnHideOpts: {
|
|
||||||
action: resetCustomGasData,
|
|
||||||
args: [],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
LEGACY_CUSTOMIZE_GAS: {
|
LEGACY_CUSTOMIZE_GAS: {
|
||||||
contents: <ConfirmCustomizeGasModal />,
|
contents: <ConfirmCustomizeGasModal />,
|
||||||
mobileModalStyle: {
|
mobileModalStyle: {
|
||||||
|
26
ui/hooks/useApproveTransaction.js
Normal file
26
ui/hooks/useApproveTransaction.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { useCallback, useState } from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether a transaction can be approved and provide a method to
|
||||||
|
* kick off the approval process.
|
||||||
|
*
|
||||||
|
* Provides a reusable hook that, given a transactionGroup, will manage
|
||||||
|
* the process of editing gas for approvals
|
||||||
|
* @param {Object} transactionGroup
|
||||||
|
* @return {[boolean, Function]}
|
||||||
|
*/
|
||||||
|
export function useApproveTransaction() {
|
||||||
|
const [showCustomizeGasPopover, setShowCustomizeGasPopover] = useState(false);
|
||||||
|
|
||||||
|
const closeCustomizeGasPopover = () => setShowCustomizeGasPopover(false);
|
||||||
|
|
||||||
|
const approveTransaction = useCallback(() => {
|
||||||
|
return setShowCustomizeGasPopover(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return {
|
||||||
|
approveTransaction,
|
||||||
|
showCustomizeGasPopover,
|
||||||
|
closeCustomizeGasPopover,
|
||||||
|
};
|
||||||
|
}
|
@ -2,6 +2,7 @@ import React, { useEffect, useRef, useState } from 'react';
|
|||||||
import { useDispatch, useSelector } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import ConfirmTransactionBase from '../confirm-transaction-base';
|
import ConfirmTransactionBase from '../confirm-transaction-base';
|
||||||
|
import { EDIT_GAS_MODES } from '../../../shared/constants/gas';
|
||||||
import {
|
import {
|
||||||
showModal,
|
showModal,
|
||||||
updateCustomNonce,
|
updateCustomNonce,
|
||||||
@ -14,11 +15,7 @@ import {
|
|||||||
getTokenValueParam,
|
getTokenValueParam,
|
||||||
} from '../../helpers/utils/token-util';
|
} from '../../helpers/utils/token-util';
|
||||||
import { useTokenTracker } from '../../hooks/useTokenTracker';
|
import { useTokenTracker } from '../../hooks/useTokenTracker';
|
||||||
import {
|
import { getTokens, getNativeCurrency } from '../../ducks/metamask/metamask';
|
||||||
getTokens,
|
|
||||||
getNativeCurrency,
|
|
||||||
isEIP1559Network,
|
|
||||||
} from '../../ducks/metamask/metamask';
|
|
||||||
import {
|
import {
|
||||||
transactionFeeSelector,
|
transactionFeeSelector,
|
||||||
txDataSelector,
|
txDataSelector,
|
||||||
@ -27,13 +24,13 @@ import {
|
|||||||
getUseNonceField,
|
getUseNonceField,
|
||||||
getCustomNonceValue,
|
getCustomNonceValue,
|
||||||
getNextSuggestedNonce,
|
getNextSuggestedNonce,
|
||||||
getNoGasPriceFetched,
|
|
||||||
getIsEthGasPriceFetched,
|
|
||||||
getIsMainnet,
|
|
||||||
} from '../../selectors';
|
} from '../../selectors';
|
||||||
|
|
||||||
|
import { useApproveTransaction } from '../../hooks/useApproveTransaction';
|
||||||
|
|
||||||
import { currentNetworkTxListSelector } from '../../selectors/transactions';
|
import { currentNetworkTxListSelector } from '../../selectors/transactions';
|
||||||
import Loading from '../../components/ui/loading-screen';
|
import Loading from '../../components/ui/loading-screen';
|
||||||
|
import EditGasPopover from '../../components/app/edit-gas-popover/edit-gas-popover.component';
|
||||||
import { getCustomTxParamsData } from './confirm-approve.util';
|
import { getCustomTxParamsData } from './confirm-approve.util';
|
||||||
import ConfirmApproveContent from './confirm-approve-content';
|
import ConfirmApproveContent from './confirm-approve-content';
|
||||||
|
|
||||||
@ -53,7 +50,6 @@ export default function ConfirmApprove() {
|
|||||||
const useNonceField = useSelector(getUseNonceField);
|
const useNonceField = useSelector(getUseNonceField);
|
||||||
const nextNonce = useSelector(getNextSuggestedNonce);
|
const nextNonce = useSelector(getNextSuggestedNonce);
|
||||||
const customNonceValue = useSelector(getCustomNonceValue);
|
const customNonceValue = useSelector(getCustomNonceValue);
|
||||||
const onEIP1559Network = useSelector(isEIP1559Network);
|
|
||||||
|
|
||||||
const transaction =
|
const transaction =
|
||||||
currentNetworkTxList.find(
|
currentNetworkTxList.find(
|
||||||
@ -83,6 +79,12 @@ export default function ConfirmApprove() {
|
|||||||
|
|
||||||
const previousTokenAmount = useRef(tokenAmount);
|
const previousTokenAmount = useRef(tokenAmount);
|
||||||
|
|
||||||
|
const {
|
||||||
|
approveTransaction,
|
||||||
|
showCustomizeGasPopover,
|
||||||
|
closeCustomizeGasPopover,
|
||||||
|
} = useApproveTransaction();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (customPermissionAmount && previousTokenAmount.current !== tokenAmount) {
|
if (customPermissionAmount && previousTokenAmount.current !== tokenAmount) {
|
||||||
setCustomPermissionAmount(tokenAmount);
|
setCustomPermissionAmount(tokenAmount);
|
||||||
@ -113,7 +115,6 @@ export default function ConfirmApprove() {
|
|||||||
const formattedOrigin = origin
|
const formattedOrigin = origin
|
||||||
? origin[0].toUpperCase() + origin.slice(1)
|
? origin[0].toUpperCase() + origin.slice(1)
|
||||||
: '';
|
: '';
|
||||||
const txData = transaction;
|
|
||||||
|
|
||||||
const { icon: siteImage = '' } = domainMetadata[origin] || {};
|
const { icon: siteImage = '' } = domainMetadata[origin] || {};
|
||||||
|
|
||||||
@ -124,11 +125,7 @@ export default function ConfirmApprove() {
|
|||||||
const customData = customPermissionAmount
|
const customData = customPermissionAmount
|
||||||
? getCustomTxParamsData(data, { customPermissionAmount, decimals })
|
? getCustomTxParamsData(data, { customPermissionAmount, decimals })
|
||||||
: null;
|
: null;
|
||||||
const isEthGasPrice = useSelector(getIsEthGasPriceFetched);
|
|
||||||
const noGasPrice = useSelector(getNoGasPriceFetched);
|
|
||||||
const isMainnet = useSelector(getIsMainnet);
|
|
||||||
const hideBasic =
|
|
||||||
isEthGasPrice || noGasPrice || !(isMainnet || process.env.IN_TEST);
|
|
||||||
return tokenSymbol === undefined ? (
|
return tokenSymbol === undefined ? (
|
||||||
<Loading />
|
<Loading />
|
||||||
) : (
|
) : (
|
||||||
@ -138,6 +135,7 @@ export default function ConfirmApprove() {
|
|||||||
showAccountInHeader
|
showAccountInHeader
|
||||||
title={tokensText}
|
title={tokensText}
|
||||||
contentComponent={
|
contentComponent={
|
||||||
|
<>
|
||||||
<ConfirmApproveContent
|
<ConfirmApproveContent
|
||||||
decimals={decimals}
|
decimals={decimals}
|
||||||
siteImage={siteImage}
|
siteImage={siteImage}
|
||||||
@ -147,17 +145,7 @@ export default function ConfirmApprove() {
|
|||||||
origin={formattedOrigin}
|
origin={formattedOrigin}
|
||||||
tokenSymbol={tokenSymbol}
|
tokenSymbol={tokenSymbol}
|
||||||
tokenBalance={tokenBalance}
|
tokenBalance={tokenBalance}
|
||||||
showCustomizeGasModal={() =>
|
showCustomizeGasModal={approveTransaction}
|
||||||
dispatch(
|
|
||||||
showModal({
|
|
||||||
name: onEIP1559Network
|
|
||||||
? 'CUSTOMIZE_GAS'
|
|
||||||
: 'LEGACY_CUSTOMIZE_GAS',
|
|
||||||
txData,
|
|
||||||
hideBasic,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
showEditApprovalPermissionModal={({
|
showEditApprovalPermissionModal={({
|
||||||
/* eslint-disable no-shadow */
|
/* eslint-disable no-shadow */
|
||||||
customTokenAmount,
|
customTokenAmount,
|
||||||
@ -217,6 +205,14 @@ export default function ConfirmApprove() {
|
|||||||
}
|
}
|
||||||
warning={submitWarning}
|
warning={submitWarning}
|
||||||
/>
|
/>
|
||||||
|
{showCustomizeGasPopover && (
|
||||||
|
<EditGasPopover
|
||||||
|
onClose={closeCustomizeGasPopover}
|
||||||
|
mode={EDIT_GAS_MODES.MODIFY_IN_PLACE}
|
||||||
|
transaction={transaction}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
}
|
}
|
||||||
hideSenderToRecipient
|
hideSenderToRecipient
|
||||||
customTxParamsData={customData}
|
customTxParamsData={customData}
|
||||||
|
@ -14,14 +14,7 @@ import {
|
|||||||
tryReverseResolveAddress,
|
tryReverseResolveAddress,
|
||||||
setDefaultHomeActiveTabName,
|
setDefaultHomeActiveTabName,
|
||||||
} from '../../store/actions';
|
} from '../../store/actions';
|
||||||
import {
|
|
||||||
INSUFFICIENT_FUNDS_ERROR_KEY,
|
|
||||||
GAS_LIMIT_TOO_LOW_ERROR_KEY,
|
|
||||||
} from '../../helpers/constants/error-keys';
|
|
||||||
import { getHexGasTotal } from '../../helpers/utils/confirm-tx.util';
|
|
||||||
import { isBalanceSufficient, calcGasTotal } from '../send/send.utils';
|
import { isBalanceSufficient, calcGasTotal } from '../send/send.utils';
|
||||||
import { conversionGreaterThan } from '../../../shared/modules/conversion.utils';
|
|
||||||
import { MIN_GAS_LIMIT_DEC } from '../send/send.constants';
|
|
||||||
import { shortenAddress, valuesFor } from '../../helpers/utils/util';
|
import { shortenAddress, valuesFor } from '../../helpers/utils/util';
|
||||||
import {
|
import {
|
||||||
getAdvancedInlineGasShown,
|
getAdvancedInlineGasShown,
|
||||||
@ -210,16 +203,6 @@ export const mapDispatchToProps = (dispatch) => {
|
|||||||
showTransactionConfirmedModal: ({ onSubmit }) => {
|
showTransactionConfirmedModal: ({ onSubmit }) => {
|
||||||
return dispatch(showModal({ name: 'TRANSACTION_CONFIRMED', onSubmit }));
|
return dispatch(showModal({ name: 'TRANSACTION_CONFIRMED', onSubmit }));
|
||||||
},
|
},
|
||||||
showCustomizeGasModal: ({ txData, onSubmit, validate }) => {
|
|
||||||
return dispatch(
|
|
||||||
showModal({
|
|
||||||
name: 'CUSTOMIZE_GAS',
|
|
||||||
txData,
|
|
||||||
onSubmit,
|
|
||||||
validate,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
showRejectTransactionsConfirmationModal: ({
|
showRejectTransactionsConfirmationModal: ({
|
||||||
onSubmit,
|
onSubmit,
|
||||||
unapprovedTxCount,
|
unapprovedTxCount,
|
||||||
@ -241,78 +224,19 @@ export const mapDispatchToProps = (dispatch) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getValidateEditGas = ({ balance, conversionRate, txData }) => {
|
|
||||||
const { txParams: { value: amount } = {} } = txData;
|
|
||||||
|
|
||||||
return ({ gasLimit, gasPrice }) => {
|
|
||||||
const gasTotal = getHexGasTotal({ gasLimit, gasPrice });
|
|
||||||
const hasSufficientBalance = isBalanceSufficient({
|
|
||||||
amount,
|
|
||||||
gasTotal,
|
|
||||||
balance,
|
|
||||||
conversionRate,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!hasSufficientBalance) {
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
errorKey: INSUFFICIENT_FUNDS_ERROR_KEY,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const gasLimitTooLow =
|
|
||||||
gasLimit &&
|
|
||||||
conversionGreaterThan(
|
|
||||||
{
|
|
||||||
value: MIN_GAS_LIMIT_DEC,
|
|
||||||
fromNumericBase: 'dec',
|
|
||||||
conversionRate,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: gasLimit,
|
|
||||||
fromNumericBase: 'hex',
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (gasLimitTooLow) {
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
errorKey: GAS_LIMIT_TOO_LOW_ERROR_KEY,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
valid: true,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
||||||
const { balance, conversionRate, txData, unapprovedTxs } = stateProps;
|
const { txData, unapprovedTxs } = stateProps;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
cancelAllTransactions: dispatchCancelAllTransactions,
|
cancelAllTransactions: dispatchCancelAllTransactions,
|
||||||
showCustomizeGasModal: dispatchShowCustomizeGasModal,
|
|
||||||
updateTransactionGasFees: dispatchUpdateTransactionGasFees,
|
updateTransactionGasFees: dispatchUpdateTransactionGasFees,
|
||||||
...otherDispatchProps
|
...otherDispatchProps
|
||||||
} = dispatchProps;
|
} = dispatchProps;
|
||||||
|
|
||||||
const validateEditGas = getValidateEditGas({
|
|
||||||
balance,
|
|
||||||
conversionRate,
|
|
||||||
txData,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...stateProps,
|
...stateProps,
|
||||||
...otherDispatchProps,
|
...otherDispatchProps,
|
||||||
...ownProps,
|
...ownProps,
|
||||||
showCustomizeGasModal: () =>
|
|
||||||
dispatchShowCustomizeGasModal({
|
|
||||||
txData,
|
|
||||||
onSubmit: (customGas) => dispatchUpdateTransactionGasFees(customGas),
|
|
||||||
validate: validateEditGas,
|
|
||||||
}),
|
|
||||||
cancelAllTransactions: () =>
|
cancelAllTransactions: () =>
|
||||||
dispatchCancelAllTransactions(valuesFor(unapprovedTxs)),
|
dispatchCancelAllTransactions(valuesFor(unapprovedTxs)),
|
||||||
updateGasAndCalculate: ({ gasLimit, gasPrice }) => {
|
updateGasAndCalculate: ({ gasLimit, gasPrice }) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user