2022-10-05 21:48:35 +02:00
|
|
|
import React, { useState, useContext } from 'react';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import PropTypes from 'prop-types';
|
2023-01-05 15:58:16 +01:00
|
|
|
import BigNumber from 'bignumber.js';
|
2022-10-05 21:48:35 +02:00
|
|
|
import Box from '../../components/ui/box/box';
|
|
|
|
import NetworkAccountBalanceHeader from '../../components/app/network-account-balance-header/network-account-balance-header';
|
|
|
|
import UrlIcon from '../../components/ui/url-icon/url-icon';
|
|
|
|
import {
|
2023-02-02 21:15:26 +01:00
|
|
|
AlignItems,
|
|
|
|
BorderStyle,
|
|
|
|
Color,
|
2022-10-05 21:48:35 +02:00
|
|
|
DISPLAY,
|
|
|
|
FLEX_DIRECTION,
|
2023-05-04 18:38:43 +02:00
|
|
|
FontWeight,
|
2023-02-02 21:15:26 +01:00
|
|
|
JustifyContent,
|
2023-05-04 18:38:43 +02:00
|
|
|
TextAlign,
|
2023-02-02 21:15:26 +01:00
|
|
|
TextColor,
|
2023-05-04 18:38:43 +02:00
|
|
|
TextVariant,
|
2022-10-05 21:48:35 +02:00
|
|
|
} from '../../helpers/constants/design-system';
|
|
|
|
import { I18nContext } from '../../contexts/i18n';
|
|
|
|
import ContractTokenValues from '../../components/ui/contract-token-values/contract-token-values';
|
|
|
|
import Button from '../../components/ui/button';
|
|
|
|
import ReviewSpendingCap from '../../components/ui/review-spending-cap/review-spending-cap';
|
|
|
|
import { PageContainerFooter } from '../../components/ui/page-container';
|
|
|
|
import ContractDetailsModal from '../../components/app/modals/contract-details-modal/contract-details-modal';
|
|
|
|
import {
|
|
|
|
getNetworkIdentifier,
|
|
|
|
transactionFeeSelector,
|
|
|
|
getKnownMethodData,
|
|
|
|
getRpcPrefsForCurrentProvider,
|
2022-11-07 19:21:38 +01:00
|
|
|
getCustomTokenAmount,
|
2022-12-13 13:33:35 +01:00
|
|
|
getUnapprovedTxCount,
|
|
|
|
getUnapprovedTransactions,
|
2023-02-03 18:13:19 +01:00
|
|
|
getUseCurrencyRateCheck,
|
2023-04-28 09:59:53 +02:00
|
|
|
getTargetAccountWithSendEtherInfo,
|
2022-10-05 21:48:35 +02:00
|
|
|
} from '../../selectors';
|
|
|
|
import { NETWORK_TO_NAME_MAP } from '../../../shared/constants/network';
|
|
|
|
import {
|
|
|
|
cancelTx,
|
2022-12-13 13:33:35 +01:00
|
|
|
cancelTxs,
|
|
|
|
showModal,
|
2022-10-05 21:48:35 +02:00
|
|
|
updateAndApproveTx,
|
|
|
|
updateCustomNonce,
|
|
|
|
} from '../../store/actions';
|
|
|
|
import { clearConfirmTransaction } from '../../ducks/confirm-transaction/confirm-transaction.duck';
|
|
|
|
import { getMostRecentOverviewPage } from '../../ducks/history/history';
|
|
|
|
import ApproveContentCard from '../../components/app/approve-content-card/approve-content-card';
|
2022-11-07 19:21:38 +01:00
|
|
|
import CustomSpendingCap from '../../components/app/custom-spending-cap/custom-spending-cap';
|
|
|
|
import Dialog from '../../components/ui/dialog';
|
|
|
|
import { useGasFeeContext } from '../../contexts/gasFee';
|
|
|
|
import { getCustomTxParamsData } from '../confirm-approve/confirm-approve.util';
|
2022-11-24 20:14:41 +01:00
|
|
|
import { setCustomTokenAmount } from '../../ducks/app/app';
|
2022-12-13 13:33:35 +01:00
|
|
|
import { valuesFor } from '../../helpers/utils/util';
|
2023-01-05 15:58:16 +01:00
|
|
|
import { calcTokenAmount } from '../../../shared/lib/transactions-controller-utils';
|
2023-01-18 10:53:10 +01:00
|
|
|
import {
|
|
|
|
MAX_TOKEN_ALLOWANCE_AMOUNT,
|
|
|
|
NUM_W_OPT_DECIMAL_COMMA_OR_DOT_REGEX,
|
|
|
|
} from '../../../shared/constants/tokens';
|
2023-06-23 20:08:22 +02:00
|
|
|
import { isSuspiciousResponse } from '../../../shared/modules/security-provider.utils';
|
2023-01-11 16:01:50 +01:00
|
|
|
import { ConfirmPageContainerNavigation } from '../../components/app/confirm-page-container';
|
2023-02-02 00:14:09 +01:00
|
|
|
import { useSimulationFailureWarning } from '../../hooks/useSimulationFailureWarning';
|
|
|
|
import SimulationErrorMessage from '../../components/ui/simulation-error-message';
|
2023-03-14 18:29:31 +01:00
|
|
|
import LedgerInstructionField from '../../components/app/ledger-instruction-field/ledger-instruction-field';
|
2023-04-13 19:24:33 +02:00
|
|
|
import SecurityProviderBannerMessage from '../../components/app/security-provider-banner-message/security-provider-banner-message';
|
2023-05-04 18:38:43 +02:00
|
|
|
import { Text, Icon, IconName } from '../../components/component-library';
|
2022-10-05 21:48:35 +02:00
|
|
|
|
2023-03-31 16:04:55 +02:00
|
|
|
const ALLOWED_HOSTS = ['portfolio.metamask.io'];
|
|
|
|
|
2022-10-05 21:48:35 +02:00
|
|
|
export default function TokenAllowance({
|
|
|
|
origin,
|
|
|
|
siteImage,
|
|
|
|
showCustomizeGasModal,
|
|
|
|
useNonceField,
|
|
|
|
currentCurrency,
|
|
|
|
nativeCurrency,
|
|
|
|
ethTransactionTotal,
|
|
|
|
fiatTransactionTotal,
|
|
|
|
hexTransactionTotal,
|
2023-04-26 02:13:38 +02:00
|
|
|
hexMinimumTransactionFee,
|
2022-10-05 21:48:35 +02:00
|
|
|
txData,
|
|
|
|
isMultiLayerFeeNetwork,
|
2022-12-08 19:37:06 +01:00
|
|
|
supportsEIP1559,
|
2022-10-05 21:48:35 +02:00
|
|
|
userAddress,
|
|
|
|
tokenAddress,
|
|
|
|
data,
|
|
|
|
isSetApproveForAll,
|
|
|
|
isApprovalOrRejection,
|
2022-11-07 19:21:38 +01:00
|
|
|
decimals,
|
2022-10-05 21:48:35 +02:00
|
|
|
dappProposedTokenAmount,
|
|
|
|
currentTokenBalance,
|
|
|
|
toAddress,
|
|
|
|
tokenSymbol,
|
2023-04-18 21:49:49 +02:00
|
|
|
fromAddressIsLedger,
|
2022-10-05 21:48:35 +02:00
|
|
|
}) {
|
|
|
|
const t = useContext(I18nContext);
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const history = useHistory();
|
|
|
|
const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage);
|
|
|
|
|
2023-03-31 16:04:55 +02:00
|
|
|
const { hostname } = new URL(origin);
|
|
|
|
const thisOriginIsAllowedToSkipFirstPage = ALLOWED_HOSTS.includes(hostname);
|
|
|
|
|
2022-10-05 21:48:35 +02:00
|
|
|
const [showContractDetails, setShowContractDetails] = useState(false);
|
2023-04-19 01:23:45 +02:00
|
|
|
const [inputChangeInProgress, setInputChangeInProgress] = useState(false);
|
2022-10-05 21:48:35 +02:00
|
|
|
const [showFullTxDetails, setShowFullTxDetails] = useState(false);
|
2022-11-17 15:12:44 +01:00
|
|
|
const [isFirstPage, setIsFirstPage] = useState(
|
2023-03-31 16:04:55 +02:00
|
|
|
dappProposedTokenAmount !== '0' && !thisOriginIsAllowedToSkipFirstPage,
|
2022-11-17 15:12:44 +01:00
|
|
|
);
|
2022-11-07 19:21:38 +01:00
|
|
|
const [errorText, setErrorText] = useState('');
|
2023-02-02 00:14:09 +01:00
|
|
|
const [userAcknowledgedGasMissing, setUserAcknowledgedGasMissing] =
|
|
|
|
useState(false);
|
2022-10-05 21:48:35 +02:00
|
|
|
|
2023-02-02 00:14:09 +01:00
|
|
|
const renderSimulationFailureWarning = useSimulationFailureWarning(
|
|
|
|
userAcknowledgedGasMissing,
|
|
|
|
);
|
2023-04-28 09:59:53 +02:00
|
|
|
const fromAccount = useSelector((state) =>
|
|
|
|
getTargetAccountWithSendEtherInfo(state, userAddress),
|
|
|
|
);
|
2022-10-05 21:48:35 +02:00
|
|
|
const networkIdentifier = useSelector(getNetworkIdentifier);
|
|
|
|
const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider);
|
2022-12-13 13:33:35 +01:00
|
|
|
const unapprovedTxCount = useSelector(getUnapprovedTxCount);
|
|
|
|
const unapprovedTxs = useSelector(getUnapprovedTransactions);
|
2023-02-03 18:13:19 +01:00
|
|
|
const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck);
|
2023-03-31 16:04:55 +02:00
|
|
|
let customTokenAmount = useSelector(getCustomTokenAmount);
|
|
|
|
if (thisOriginIsAllowedToSkipFirstPage && dappProposedTokenAmount) {
|
|
|
|
customTokenAmount = dappProposedTokenAmount;
|
|
|
|
}
|
2022-11-07 19:21:38 +01:00
|
|
|
|
2023-01-05 15:58:16 +01:00
|
|
|
const replaceCommaToDot = (inputValue) => {
|
|
|
|
return inputValue.replace(/,/gu, '.');
|
|
|
|
};
|
|
|
|
|
2023-01-18 10:53:10 +01:00
|
|
|
let customPermissionAmount = NUM_W_OPT_DECIMAL_COMMA_OR_DOT_REGEX.test(
|
|
|
|
customTokenAmount,
|
|
|
|
)
|
|
|
|
? replaceCommaToDot(customTokenAmount).toString()
|
|
|
|
: '0';
|
2023-01-05 15:58:16 +01:00
|
|
|
|
|
|
|
const maxTokenAmount = calcTokenAmount(MAX_TOKEN_ALLOWANCE_AMOUNT, decimals);
|
|
|
|
if (customTokenAmount.length > 1 && Number(customTokenAmount)) {
|
|
|
|
const customSpendLimitNumber = new BigNumber(customTokenAmount);
|
|
|
|
if (customSpendLimitNumber.greaterThan(maxTokenAmount)) {
|
|
|
|
customPermissionAmount = 0;
|
|
|
|
}
|
|
|
|
}
|
2022-11-07 19:21:38 +01:00
|
|
|
|
2023-01-05 15:58:16 +01:00
|
|
|
const customTxParamsData = customPermissionAmount
|
2022-11-07 19:21:38 +01:00
|
|
|
? getCustomTxParamsData(data, {
|
|
|
|
customPermissionAmount,
|
|
|
|
decimals,
|
|
|
|
})
|
|
|
|
: null;
|
2022-10-05 21:48:35 +02:00
|
|
|
|
|
|
|
let fullTxData = { ...txData };
|
|
|
|
|
|
|
|
if (customTxParamsData) {
|
|
|
|
fullTxData = {
|
|
|
|
...fullTxData,
|
|
|
|
txParams: {
|
|
|
|
...fullTxData.txParams,
|
|
|
|
data: customTxParamsData,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const fee = useSelector((state) => transactionFeeSelector(state, fullTxData));
|
|
|
|
const methodData = useSelector((state) => getKnownMethodData(state, data));
|
|
|
|
|
2022-11-07 19:21:38 +01:00
|
|
|
const { balanceError } = useGasFeeContext();
|
|
|
|
|
|
|
|
const disableNextButton =
|
|
|
|
isFirstPage && (customTokenAmount === '' || errorText !== '');
|
|
|
|
|
|
|
|
const disableApproveButton = !isFirstPage && balanceError;
|
|
|
|
|
2022-10-05 21:48:35 +02:00
|
|
|
const networkName =
|
|
|
|
NETWORK_TO_NAME_MAP[fullTxData.chainId] || networkIdentifier;
|
|
|
|
|
|
|
|
const customNonceValue = '';
|
|
|
|
const customNonceMerge = (transactionData) =>
|
|
|
|
customNonceValue
|
|
|
|
? {
|
|
|
|
...transactionData,
|
|
|
|
customNonceValue,
|
|
|
|
}
|
|
|
|
: transactionData;
|
|
|
|
|
|
|
|
const handleReject = () => {
|
2022-11-07 19:21:38 +01:00
|
|
|
dispatch(updateCustomNonce(''));
|
2022-11-24 20:14:41 +01:00
|
|
|
dispatch(setCustomTokenAmount(''));
|
2022-11-07 19:21:38 +01:00
|
|
|
|
2022-10-05 21:48:35 +02:00
|
|
|
dispatch(cancelTx(fullTxData)).then(() => {
|
|
|
|
dispatch(clearConfirmTransaction());
|
|
|
|
history.push(mostRecentOverviewPage);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleApprove = () => {
|
|
|
|
const { name } = methodData;
|
|
|
|
|
|
|
|
if (fee.gasEstimationObject.baseFeePerGas) {
|
|
|
|
fullTxData.estimatedBaseFee = fee.gasEstimationObject.baseFeePerGas;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
fullTxData.contractMethodName = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dappProposedTokenAmount) {
|
|
|
|
fullTxData.dappProposedTokenAmount = dappProposedTokenAmount;
|
|
|
|
fullTxData.originalApprovalAmount = dappProposedTokenAmount;
|
|
|
|
}
|
|
|
|
|
2022-11-07 19:21:38 +01:00
|
|
|
if (customTokenAmount) {
|
|
|
|
fullTxData.customTokenAmount = customTokenAmount;
|
|
|
|
fullTxData.finalApprovalAmount = customTokenAmount;
|
|
|
|
} else if (dappProposedTokenAmount !== undefined) {
|
|
|
|
fullTxData.finalApprovalAmount = dappProposedTokenAmount;
|
|
|
|
}
|
|
|
|
|
2022-10-05 21:48:35 +02:00
|
|
|
if (currentTokenBalance) {
|
|
|
|
fullTxData.currentTokenBalance = currentTokenBalance;
|
|
|
|
}
|
|
|
|
|
2022-11-07 19:21:38 +01:00
|
|
|
dispatch(updateCustomNonce(''));
|
|
|
|
|
2022-10-05 21:48:35 +02:00
|
|
|
dispatch(updateAndApproveTx(customNonceMerge(fullTxData))).then(() => {
|
|
|
|
dispatch(clearConfirmTransaction());
|
|
|
|
history.push(mostRecentOverviewPage);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-11-07 19:21:38 +01:00
|
|
|
const handleNextClick = () => {
|
|
|
|
setShowFullTxDetails(false);
|
|
|
|
setIsFirstPage(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleBackClick = () => {
|
|
|
|
setShowFullTxDetails(false);
|
|
|
|
setIsFirstPage(true);
|
|
|
|
};
|
|
|
|
|
2022-12-13 13:33:35 +01:00
|
|
|
const handleCancelAll = () => {
|
|
|
|
dispatch(
|
|
|
|
showModal({
|
|
|
|
name: 'REJECT_TRANSACTIONS',
|
|
|
|
unapprovedTxCount,
|
|
|
|
onSubmit: async () => {
|
|
|
|
await dispatch(cancelTxs(valuesFor(unapprovedTxs)));
|
|
|
|
dispatch(clearConfirmTransaction());
|
|
|
|
history.push(mostRecentOverviewPage);
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-11-17 15:12:44 +01:00
|
|
|
const isEmpty = customTokenAmount === '';
|
|
|
|
|
2022-11-25 11:26:29 +01:00
|
|
|
const renderContractTokenValues = (
|
|
|
|
<Box marginTop={4} key={tokenAddress}>
|
|
|
|
<ContractTokenValues
|
|
|
|
tokenName={tokenSymbol}
|
|
|
|
address={tokenAddress}
|
|
|
|
chainId={fullTxData.chainId}
|
|
|
|
rpcPrefs={rpcPrefs}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
|
2022-10-05 21:48:35 +02:00
|
|
|
return (
|
|
|
|
<Box className="token-allowance-container page-container">
|
2023-01-11 16:01:50 +01:00
|
|
|
<Box>
|
|
|
|
<ConfirmPageContainerNavigation />
|
|
|
|
</Box>
|
2023-06-23 20:08:22 +02:00
|
|
|
{isSuspiciousResponse(txData?.securityProviderResponse) && (
|
2023-04-13 19:24:33 +02:00
|
|
|
<SecurityProviderBannerMessage
|
|
|
|
securityProviderResponse={txData.securityProviderResponse}
|
|
|
|
/>
|
2023-06-23 20:08:22 +02:00
|
|
|
)}
|
2022-10-05 21:48:35 +02:00
|
|
|
<Box
|
|
|
|
paddingLeft={4}
|
|
|
|
paddingRight={4}
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={AlignItems.center}
|
2022-10-05 21:48:35 +02:00
|
|
|
display={DISPLAY.FLEX}
|
|
|
|
flexDirection={FLEX_DIRECTION.ROW}
|
2023-02-02 21:15:26 +01:00
|
|
|
justifyContent={JustifyContent.spaceBetween}
|
2022-10-05 21:48:35 +02:00
|
|
|
>
|
|
|
|
<Box>
|
|
|
|
{!isFirstPage && (
|
2022-11-07 19:21:38 +01:00
|
|
|
<Button type="inline" onClick={() => handleBackClick()}>
|
2023-05-04 18:38:43 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textMuted}
|
2023-05-04 18:38:43 +02:00
|
|
|
fontWeight={FontWeight.Bold}
|
2022-10-05 21:48:35 +02:00
|
|
|
>
|
|
|
|
{'<'} {t('back')}
|
2023-05-04 18:38:43 +02:00
|
|
|
</Text>
|
2022-10-05 21:48:35 +02:00
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</Box>
|
2023-05-04 18:38:43 +02:00
|
|
|
<Box textAlign={TextAlign.End}>
|
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textMuted}
|
2023-05-04 18:38:43 +02:00
|
|
|
fontWeight={FontWeight.Bold}
|
2022-10-05 21:48:35 +02:00
|
|
|
>
|
|
|
|
{isFirstPage ? 1 : 2} {t('ofTextNofM')} 2
|
2023-05-04 18:38:43 +02:00
|
|
|
</Text>
|
2022-10-05 21:48:35 +02:00
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
<NetworkAccountBalanceHeader
|
|
|
|
networkName={networkName}
|
2023-04-28 09:59:53 +02:00
|
|
|
accountName={fromAccount.name}
|
2022-10-05 21:48:35 +02:00
|
|
|
accountBalance={currentTokenBalance}
|
|
|
|
tokenName={tokenSymbol}
|
|
|
|
accountAddress={userAddress}
|
2022-10-25 17:03:45 +02:00
|
|
|
chainId={fullTxData.chainId}
|
2022-10-05 21:48:35 +02:00
|
|
|
/>
|
|
|
|
<Box
|
|
|
|
display={DISPLAY.FLEX}
|
|
|
|
flexDirection={FLEX_DIRECTION.ROW}
|
2023-02-02 21:15:26 +01:00
|
|
|
justifyContent={JustifyContent.center}
|
2022-10-05 21:48:35 +02:00
|
|
|
>
|
|
|
|
<Box
|
|
|
|
display={DISPLAY.FLEX}
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={AlignItems.center}
|
2022-10-05 21:48:35 +02:00
|
|
|
marginTop={6}
|
|
|
|
marginRight={12}
|
|
|
|
marginBottom={8}
|
|
|
|
marginLeft={12}
|
|
|
|
paddingTop={2}
|
|
|
|
paddingRight={4}
|
|
|
|
paddingBottom={2}
|
|
|
|
paddingLeft={2}
|
2023-02-02 21:15:26 +01:00
|
|
|
borderColor={Color.borderMuted}
|
|
|
|
borderStyle={BorderStyle.solid}
|
2022-10-05 21:48:35 +02:00
|
|
|
borderWidth={1}
|
|
|
|
className="token-allowance-container__icon-display-content"
|
|
|
|
>
|
|
|
|
<UrlIcon
|
|
|
|
className="token-allowance-container__icon-display-content__siteimage-identicon"
|
|
|
|
fallbackClassName="token-allowance-container__icon-display-content__siteimage-identicon"
|
|
|
|
name={origin}
|
|
|
|
url={siteImage}
|
|
|
|
/>
|
2023-05-04 18:38:43 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
2023-05-04 18:38:43 +02:00
|
|
|
marginLeft={1}
|
2022-10-05 21:48:35 +02:00
|
|
|
>
|
|
|
|
{origin}
|
2023-05-04 18:38:43 +02:00
|
|
|
</Text>
|
2022-10-05 21:48:35 +02:00
|
|
|
</Box>
|
|
|
|
</Box>
|
2022-11-25 11:26:29 +01:00
|
|
|
<Box marginLeft={4} marginRight={4}>
|
2023-05-04 18:38:43 +02:00
|
|
|
<Text variant={TextVariant.headingMd} align={TextAlign.Center}>
|
2022-11-25 11:26:29 +01:00
|
|
|
{isFirstPage ? (
|
|
|
|
t('setSpendingCap', [renderContractTokenValues])
|
|
|
|
) : (
|
|
|
|
<Box>
|
|
|
|
{customTokenAmount === '0' || isEmpty ? (
|
|
|
|
t('revokeSpendingCap', [renderContractTokenValues])
|
|
|
|
) : (
|
|
|
|
<Box>
|
|
|
|
{t('reviewSpendingCap')}
|
|
|
|
{renderContractTokenValues}
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
)}
|
2023-05-04 18:38:43 +02:00
|
|
|
</Text>
|
2022-10-05 21:48:35 +02:00
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
marginTop={1}
|
|
|
|
display={DISPLAY.FLEX}
|
|
|
|
flexDirection={FLEX_DIRECTION.ROW}
|
2023-02-02 21:15:26 +01:00
|
|
|
justifyContent={JustifyContent.center}
|
2022-10-05 21:48:35 +02:00
|
|
|
>
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
onClick={() => setShowContractDetails(true)}
|
|
|
|
className="token-allowance-container__verify-link"
|
|
|
|
>
|
2023-05-04 18:38:43 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={Color.primaryDefault}
|
|
|
|
>
|
2022-10-05 21:48:35 +02:00
|
|
|
{t('verifyContractDetails')}
|
2023-05-04 18:38:43 +02:00
|
|
|
</Text>
|
2022-10-05 21:48:35 +02:00
|
|
|
</Button>
|
|
|
|
</Box>
|
|
|
|
<Box margin={[4, 4, 3, 4]}>
|
2022-11-07 19:21:38 +01:00
|
|
|
{isFirstPage ? (
|
|
|
|
<CustomSpendingCap
|
2023-04-19 01:23:45 +02:00
|
|
|
txParams={txData?.txParams}
|
2022-11-07 19:21:38 +01:00
|
|
|
tokenName={tokenSymbol}
|
2023-01-05 15:58:16 +01:00
|
|
|
currentTokenBalance={currentTokenBalance}
|
|
|
|
dappProposedValue={dappProposedTokenAmount}
|
2022-11-07 19:21:38 +01:00
|
|
|
siteOrigin={origin}
|
|
|
|
passTheErrorText={(value) => setErrorText(value)}
|
2023-01-05 15:58:16 +01:00
|
|
|
decimals={decimals}
|
2023-04-19 01:23:45 +02:00
|
|
|
setInputChangeInProgress={setInputChangeInProgress}
|
2022-11-07 19:21:38 +01:00
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<ReviewSpendingCap
|
|
|
|
tokenName={tokenSymbol}
|
2023-01-05 15:58:16 +01:00
|
|
|
currentTokenBalance={currentTokenBalance}
|
2022-11-17 15:12:44 +01:00
|
|
|
tokenValue={
|
|
|
|
isNaN(parseFloat(customTokenAmount))
|
2023-01-05 15:58:16 +01:00
|
|
|
? dappProposedTokenAmount
|
|
|
|
: replaceCommaToDot(customTokenAmount)
|
2022-11-17 15:12:44 +01:00
|
|
|
}
|
2022-11-07 19:21:38 +01:00
|
|
|
onEdit={() => handleBackClick()}
|
|
|
|
/>
|
|
|
|
)}
|
2022-10-05 21:48:35 +02:00
|
|
|
</Box>
|
2022-11-07 19:21:38 +01:00
|
|
|
{!isFirstPage && balanceError && (
|
|
|
|
<Dialog type="error" className="send__error-dialog">
|
|
|
|
{t('insufficientFundsForGas')}
|
|
|
|
</Dialog>
|
|
|
|
)}
|
2022-10-05 21:48:35 +02:00
|
|
|
{!isFirstPage && (
|
|
|
|
<Box className="token-allowance-container__card-wrapper">
|
2023-02-02 00:14:09 +01:00
|
|
|
{renderSimulationFailureWarning && (
|
|
|
|
<Box
|
|
|
|
paddingTop={0}
|
|
|
|
paddingRight={4}
|
|
|
|
paddingBottom={4}
|
|
|
|
paddingLeft={4}
|
|
|
|
>
|
|
|
|
<SimulationErrorMessage
|
|
|
|
userAcknowledgedGasMissing={userAcknowledgedGasMissing}
|
|
|
|
setUserAcknowledgedGasMissing={() =>
|
|
|
|
setUserAcknowledgedGasMissing(true)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
)}
|
2022-10-05 21:48:35 +02:00
|
|
|
<ApproveContentCard
|
2023-04-24 16:19:19 +02:00
|
|
|
symbol={<Icon name={IconName.Tag} />}
|
2022-10-05 21:48:35 +02:00
|
|
|
title={t('transactionFee')}
|
|
|
|
showEdit
|
|
|
|
showAdvanceGasFeeOptions
|
|
|
|
onEditClick={showCustomizeGasModal}
|
|
|
|
renderTransactionDetailsContent
|
|
|
|
noBorder={useNonceField || !showFullTxDetails}
|
2022-12-08 19:37:06 +01:00
|
|
|
supportsEIP1559={supportsEIP1559}
|
2022-10-05 21:48:35 +02:00
|
|
|
isMultiLayerFeeNetwork={isMultiLayerFeeNetwork}
|
|
|
|
ethTransactionTotal={ethTransactionTotal}
|
|
|
|
nativeCurrency={nativeCurrency}
|
|
|
|
fullTxData={fullTxData}
|
2023-02-02 00:14:09 +01:00
|
|
|
userAcknowledgedGasMissing={userAcknowledgedGasMissing}
|
|
|
|
renderSimulationFailureWarning={renderSimulationFailureWarning}
|
2022-10-05 21:48:35 +02:00
|
|
|
hexTransactionTotal={hexTransactionTotal}
|
2023-04-26 02:13:38 +02:00
|
|
|
hexMinimumTransactionFee={hexMinimumTransactionFee}
|
2022-10-05 21:48:35 +02:00
|
|
|
fiatTransactionTotal={fiatTransactionTotal}
|
|
|
|
currentCurrency={currentCurrency}
|
2023-02-03 18:13:19 +01:00
|
|
|
useCurrencyRateCheck={useCurrencyRateCheck}
|
2022-10-05 21:48:35 +02:00
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
<Box
|
|
|
|
display={DISPLAY.FLEX}
|
|
|
|
flexDirection={FLEX_DIRECTION.ROW}
|
2023-02-02 21:15:26 +01:00
|
|
|
justifyContent={JustifyContent.center}
|
2022-10-05 21:48:35 +02:00
|
|
|
>
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
onClick={() => setShowFullTxDetails(!showFullTxDetails)}
|
|
|
|
className="token-allowance-container__view-details"
|
|
|
|
>
|
2023-05-04 18:38:43 +02:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
as="h6"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.primaryDefault}
|
2022-10-05 21:48:35 +02:00
|
|
|
marginRight={1}
|
|
|
|
>
|
|
|
|
{t('viewDetails')}
|
2023-05-04 18:38:43 +02:00
|
|
|
</Text>
|
2022-10-05 21:48:35 +02:00
|
|
|
{showFullTxDetails ? (
|
|
|
|
<i className="fa fa-sm fa-angle-up" />
|
|
|
|
) : (
|
|
|
|
<i className="fa fa-sm fa-angle-down" />
|
|
|
|
)}
|
|
|
|
</Button>
|
|
|
|
</Box>
|
|
|
|
{showFullTxDetails ? (
|
|
|
|
<Box
|
|
|
|
display={DISPLAY.FLEX}
|
|
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={AlignItems.center}
|
2022-10-05 21:48:35 +02:00
|
|
|
className="token-allowance-container__full-tx-content"
|
|
|
|
>
|
|
|
|
<Box className="token-allowance-container__data">
|
|
|
|
<ApproveContentCard
|
|
|
|
symbol={<i className="fa fa-file" />}
|
|
|
|
title={t('data')}
|
|
|
|
renderDataContent
|
|
|
|
noBorder
|
2022-12-08 19:37:06 +01:00
|
|
|
supportsEIP1559={supportsEIP1559}
|
2022-10-05 21:48:35 +02:00
|
|
|
isSetApproveForAll={isSetApproveForAll}
|
2023-02-02 00:14:09 +01:00
|
|
|
fullTxData={fullTxData}
|
|
|
|
userAcknowledgedGasMissing={userAcknowledgedGasMissing}
|
|
|
|
renderSimulationFailureWarning={renderSimulationFailureWarning}
|
2022-10-05 21:48:35 +02:00
|
|
|
isApprovalOrRejection={isApprovalOrRejection}
|
2022-11-07 19:21:38 +01:00
|
|
|
data={customTxParamsData || data}
|
2023-02-03 18:13:19 +01:00
|
|
|
useCurrencyRateCheck={useCurrencyRateCheck}
|
2023-04-26 02:13:38 +02:00
|
|
|
hexMinimumTransactionFee={hexMinimumTransactionFee}
|
2022-10-05 21:48:35 +02:00
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
) : null}
|
2023-04-18 21:49:49 +02:00
|
|
|
{!isFirstPage && fromAddressIsLedger && (
|
2023-03-14 18:29:31 +01:00
|
|
|
<Box paddingLeft={2} paddingRight={2}>
|
|
|
|
<LedgerInstructionField showDataInstruction />
|
|
|
|
</Box>
|
|
|
|
)}
|
2022-10-05 21:48:35 +02:00
|
|
|
<PageContainerFooter
|
|
|
|
cancelText={t('reject')}
|
|
|
|
submitText={isFirstPage ? t('next') : t('approveButtonText')}
|
|
|
|
onCancel={() => handleReject()}
|
2022-11-07 19:21:38 +01:00
|
|
|
onSubmit={() => (isFirstPage ? handleNextClick() : handleApprove())}
|
2023-04-19 01:23:45 +02:00
|
|
|
disabled={
|
|
|
|
inputChangeInProgress || disableNextButton || disableApproveButton
|
|
|
|
}
|
2022-12-13 13:33:35 +01:00
|
|
|
>
|
|
|
|
{unapprovedTxCount > 1 && (
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
handleCancelAll();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t('rejectTxsN', [unapprovedTxCount])}
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</PageContainerFooter>
|
2022-10-05 21:48:35 +02:00
|
|
|
{showContractDetails && (
|
|
|
|
<ContractDetailsModal
|
|
|
|
tokenName={tokenSymbol}
|
|
|
|
onClose={() => setShowContractDetails(false)}
|
|
|
|
tokenAddress={tokenAddress}
|
|
|
|
toAddress={toAddress}
|
|
|
|
chainId={fullTxData.chainId}
|
|
|
|
rpcPrefs={rpcPrefs}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
TokenAllowance.propTypes = {
|
|
|
|
/**
|
|
|
|
* Dapp URL
|
|
|
|
*/
|
|
|
|
origin: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Dapp image
|
|
|
|
*/
|
|
|
|
siteImage: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Function that is supposed to open the customized gas modal
|
|
|
|
*/
|
|
|
|
showCustomizeGasModal: PropTypes.func,
|
|
|
|
/**
|
|
|
|
* Whether nonce field should be used or not
|
|
|
|
*/
|
|
|
|
useNonceField: PropTypes.bool,
|
|
|
|
/**
|
|
|
|
* Current fiat currency (e.g. USD)
|
|
|
|
*/
|
|
|
|
currentCurrency: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Current native currency (e.g. RopstenETH)
|
|
|
|
*/
|
|
|
|
nativeCurrency: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Total sum of the transaction in native currency
|
|
|
|
*/
|
|
|
|
ethTransactionTotal: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Total sum of the transaction in fiat currency
|
|
|
|
*/
|
|
|
|
fiatTransactionTotal: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Total sum of the transaction converted to hex value
|
|
|
|
*/
|
|
|
|
hexTransactionTotal: PropTypes.string,
|
2023-04-26 02:13:38 +02:00
|
|
|
/**
|
|
|
|
* Minimum transaction fee converted to hex value
|
|
|
|
*/
|
|
|
|
hexMinimumTransactionFee: PropTypes.string,
|
2022-10-05 21:48:35 +02:00
|
|
|
/**
|
|
|
|
* Current transaction
|
|
|
|
*/
|
|
|
|
txData: PropTypes.object,
|
|
|
|
/**
|
|
|
|
* Is multi-layer fee network or not
|
|
|
|
*/
|
|
|
|
isMultiLayerFeeNetwork: PropTypes.bool,
|
|
|
|
/**
|
|
|
|
* Is the enhanced gas fee enabled or not
|
|
|
|
*/
|
2022-12-08 19:37:06 +01:00
|
|
|
supportsEIP1559: PropTypes.bool,
|
2022-10-05 21:48:35 +02:00
|
|
|
/**
|
|
|
|
* User's address
|
|
|
|
*/
|
|
|
|
userAddress: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Address of the token that is waiting to be allowed
|
|
|
|
*/
|
|
|
|
tokenAddress: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Current transaction data
|
|
|
|
*/
|
|
|
|
data: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Is set approve for all or not
|
|
|
|
*/
|
|
|
|
isSetApproveForAll: PropTypes.bool,
|
|
|
|
/**
|
|
|
|
* Whether a current set approval for all transaction will approve or revoke access
|
|
|
|
*/
|
|
|
|
isApprovalOrRejection: PropTypes.bool,
|
|
|
|
/**
|
2022-11-07 19:21:38 +01:00
|
|
|
* Number of decimals
|
2022-10-05 21:48:35 +02:00
|
|
|
*/
|
2022-11-07 19:21:38 +01:00
|
|
|
decimals: PropTypes.string,
|
2022-10-05 21:48:35 +02:00
|
|
|
/**
|
|
|
|
* Token amount proposed by the Dapp
|
|
|
|
*/
|
|
|
|
dappProposedTokenAmount: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Token balance of the current account
|
|
|
|
*/
|
|
|
|
currentTokenBalance: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Contract address requesting spending cap
|
|
|
|
*/
|
|
|
|
toAddress: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* Symbol of the token that is waiting to be allowed
|
|
|
|
*/
|
|
|
|
tokenSymbol: PropTypes.string,
|
2023-04-18 21:49:49 +02:00
|
|
|
/**
|
|
|
|
* Whether the address sending the transaction is a ledger address
|
|
|
|
*/
|
|
|
|
fromAddressIsLedger: PropTypes.bool,
|
2022-10-05 21:48:35 +02:00
|
|
|
};
|