You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
556 lines
18 KiB
556 lines
18 KiB
4 years ago
|
import React, { useContext, useEffect, useState, useCallback } from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import { useDispatch, useSelector } from 'react-redux';
|
||
|
import classnames from 'classnames';
|
||
4 years ago
|
import { uniqBy, isEqual } from 'lodash';
|
||
4 years ago
|
import { useHistory } from 'react-router-dom';
|
||
4 years ago
|
import {
|
||
|
createCustomTokenTrackerLink,
|
||
|
createTokenTrackerLinkForChain,
|
||
|
} from '@metamask/etherscan-link';
|
||
4 years ago
|
import { MetaMetricsContext } from '../../../contexts/metametrics.new';
|
||
4 years ago
|
import {
|
||
|
useTokensToSearch,
|
||
|
getRenderableTokenData,
|
||
|
} from '../../../hooks/useTokensToSearch';
|
||
4 years ago
|
import { useEqualityCheck } from '../../../hooks/useEqualityCheck';
|
||
|
import { I18nContext } from '../../../contexts/i18n';
|
||
|
import DropdownInputPair from '../dropdown-input-pair';
|
||
|
import DropdownSearchList from '../dropdown-search-list';
|
||
|
import SlippageButtons from '../slippage-buttons';
|
||
|
import { getTokens } from '../../../ducks/metamask/metamask';
|
||
|
import InfoTooltip from '../../../components/ui/info-tooltip';
|
||
4 years ago
|
import ActionableMessage from '../actionable-message';
|
||
4 years ago
|
|
||
|
import {
|
||
|
fetchQuotesAndSetQuoteState,
|
||
|
setSwapsFromToken,
|
||
|
setSwapToToken,
|
||
|
getFromToken,
|
||
|
getToToken,
|
||
|
getBalanceError,
|
||
|
getTopAssets,
|
||
|
getFetchParams,
|
||
4 years ago
|
} from '../../../ducks/swaps/swaps';
|
||
4 years ago
|
import {
|
||
4 years ago
|
getSwapsDefaultToken,
|
||
4 years ago
|
getTokenExchangeRates,
|
||
|
getConversionRate,
|
||
|
getCurrentCurrency,
|
||
4 years ago
|
getCurrentChainId,
|
||
4 years ago
|
getRpcPrefsForCurrentProvider,
|
||
4 years ago
|
} from '../../../selectors';
|
||
4 years ago
|
import {
|
||
|
getValueFromWeiHex,
|
||
|
hexToDecimal,
|
||
4 years ago
|
} from '../../../helpers/utils/conversions.util';
|
||
|
import { calcTokenAmount } from '../../../helpers/utils/token-util';
|
||
|
import { usePrevious } from '../../../hooks/usePrevious';
|
||
|
import { useTokenTracker } from '../../../hooks/useTokenTracker';
|
||
|
import { useTokenFiatAmount } from '../../../hooks/useTokenFiatAmount';
|
||
|
import { useEthFiatAmount } from '../../../hooks/useEthFiatAmount';
|
||
4 years ago
|
|
||
4 years ago
|
import {
|
||
|
isSwapsDefaultTokenAddress,
|
||
|
isSwapsDefaultTokenSymbol,
|
||
4 years ago
|
} from '../../../../shared/modules/swaps.utils';
|
||
|
import { SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP } from '../../../../shared/constants/swaps';
|
||
4 years ago
|
|
||
4 years ago
|
import { resetSwapsPostFetchState, removeToken } from '../../../store/actions';
|
||
|
import { fetchTokenPrice, fetchTokenBalance } from '../swaps.util';
|
||
|
import SwapsFooter from '../swaps-footer';
|
||
4 years ago
|
|
||
4 years ago
|
const fuseSearchKeys = [
|
||
|
{ name: 'name', weight: 0.499 },
|
||
|
{ name: 'symbol', weight: 0.499 },
|
||
|
{ name: 'address', weight: 0.002 },
|
||
4 years ago
|
];
|
||
4 years ago
|
|
||
4 years ago
|
const MAX_ALLOWED_SLIPPAGE = 15;
|
||
4 years ago
|
|
||
4 years ago
|
export default function BuildQuote({
|
||
4 years ago
|
inputValue,
|
||
|
onInputChange,
|
||
|
ethBalance,
|
||
|
setMaxSlippage,
|
||
|
maxSlippage,
|
||
|
selectedAccountAddress,
|
||
4 years ago
|
isFeatureFlagLoaded,
|
||
4 years ago
|
}) {
|
||
4 years ago
|
const t = useContext(I18nContext);
|
||
|
const dispatch = useDispatch();
|
||
|
const history = useHistory();
|
||
|
const metaMetricsEvent = useContext(MetaMetricsContext);
|
||
4 years ago
|
|
||
4 years ago
|
const [fetchedTokenExchangeRate, setFetchedTokenExchangeRate] = useState(
|
||
|
undefined,
|
||
4 years ago
|
);
|
||
4 years ago
|
const [verificationClicked, setVerificationClicked] = useState(false);
|
||
4 years ago
|
|
||
4 years ago
|
const balanceError = useSelector(getBalanceError);
|
||
|
const fetchParams = useSelector(getFetchParams);
|
||
4 years ago
|
const { sourceTokenInfo = {}, destinationTokenInfo = {} } =
|
||
4 years ago
|
fetchParams?.metaData || {};
|
||
|
const tokens = useSelector(getTokens);
|
||
|
const topAssets = useSelector(getTopAssets);
|
||
|
const fromToken = useSelector(getFromToken);
|
||
|
const toToken = useSelector(getToToken) || destinationTokenInfo;
|
||
4 years ago
|
const defaultSwapsToken = useSelector(getSwapsDefaultToken);
|
||
|
const chainId = useSelector(getCurrentChainId);
|
||
4 years ago
|
const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider);
|
||
4 years ago
|
|
||
4 years ago
|
const tokenConversionRates = useSelector(getTokenExchangeRates, isEqual);
|
||
|
const conversionRate = useSelector(getConversionRate);
|
||
|
const currentCurrency = useSelector(getCurrentCurrency);
|
||
|
|
||
4 years ago
|
const fetchParamsFromToken = isSwapsDefaultTokenSymbol(
|
||
|
sourceTokenInfo?.symbol,
|
||
|
chainId,
|
||
|
)
|
||
|
? defaultSwapsToken
|
||
|
: sourceTokenInfo;
|
||
|
|
||
4 years ago
|
const { loading, tokensWithBalances } = useTokenTracker(tokens);
|
||
4 years ago
|
|
||
|
// If the fromToken was set in a call to `onFromSelect` (see below), and that from token has a balance
|
||
|
// but is not in tokensWithBalances or tokens, then we want to add it to the usersTokens array so that
|
||
|
// the balance of the token can appear in the from token selection dropdown
|
||
4 years ago
|
const fromTokenArray =
|
||
4 years ago
|
!isSwapsDefaultTokenSymbol(fromToken?.symbol, chainId) && fromToken?.balance
|
||
|
? [fromToken]
|
||
|
: [];
|
||
4 years ago
|
const usersTokens = uniqBy(
|
||
|
[...tokensWithBalances, ...tokens, ...fromTokenArray],
|
||
|
'address',
|
||
4 years ago
|
);
|
||
|
const memoizedUsersTokens = useEqualityCheck(usersTokens);
|
||
4 years ago
|
|
||
4 years ago
|
const selectedFromToken = getRenderableTokenData(
|
||
|
fromToken || fetchParamsFromToken,
|
||
|
tokenConversionRates,
|
||
|
conversionRate,
|
||
|
currentCurrency,
|
||
4 years ago
|
chainId,
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
|
const tokensToSearch = useTokensToSearch({
|
||
|
usersTokens: memoizedUsersTokens,
|
||
|
topTokens: topAssets,
|
||
4 years ago
|
});
|
||
4 years ago
|
const selectedToToken =
|
||
|
tokensToSearch.find(({ address }) => address === toToken?.address) ||
|
||
4 years ago
|
toToken;
|
||
4 years ago
|
const toTokenIsNotDefault =
|
||
4 years ago
|
selectedToToken?.address &&
|
||
4 years ago
|
!isSwapsDefaultTokenAddress(selectedToToken?.address, chainId);
|
||
4 years ago
|
const occurances = Number(selectedToToken?.occurances || 0);
|
||
4 years ago
|
const {
|
||
|
address: fromTokenAddress,
|
||
|
symbol: fromTokenSymbol,
|
||
|
string: fromTokenString,
|
||
|
decimals: fromTokenDecimals,
|
||
4 years ago
|
balance: rawFromTokenBalance,
|
||
4 years ago
|
} = selectedFromToken || {};
|
||
4 years ago
|
|
||
4 years ago
|
const fromTokenBalance =
|
||
|
rawFromTokenBalance &&
|
||
4 years ago
|
calcTokenAmount(rawFromTokenBalance, fromTokenDecimals).toString(10);
|
||
4 years ago
|
|
||
4 years ago
|
const prevFromTokenBalance = usePrevious(fromTokenBalance);
|
||
4 years ago
|
|
||
|
const swapFromTokenFiatValue = useTokenFiatAmount(
|
||
|
fromTokenAddress,
|
||
|
inputValue || 0,
|
||
|
fromTokenSymbol,
|
||
|
{
|
||
|
showFiat: true,
|
||
|
},
|
||
|
true,
|
||
4 years ago
|
);
|
||
4 years ago
|
const swapFromEthFiatValue = useEthFiatAmount(
|
||
|
inputValue || 0,
|
||
|
{ showFiat: true },
|
||
|
true,
|
||
4 years ago
|
);
|
||
4 years ago
|
const swapFromFiatValue = isSwapsDefaultTokenSymbol(fromTokenSymbol, chainId)
|
||
|
? swapFromEthFiatValue
|
||
|
: swapFromTokenFiatValue;
|
||
4 years ago
|
|
||
|
const onFromSelect = (token) => {
|
||
4 years ago
|
if (
|
||
|
token?.address &&
|
||
|
!swapFromFiatValue &&
|
||
|
fetchedTokenExchangeRate !== null
|
||
|
) {
|
||
|
fetchTokenPrice(token.address).then((rate) => {
|
||
|
if (rate !== null && rate !== undefined) {
|
||
4 years ago
|
setFetchedTokenExchangeRate(rate);
|
||
4 years ago
|
}
|
||
4 years ago
|
});
|
||
4 years ago
|
} else {
|
||
4 years ago
|
setFetchedTokenExchangeRate(null);
|
||
4 years ago
|
}
|
||
4 years ago
|
if (
|
||
|
token?.address &&
|
||
|
!memoizedUsersTokens.find(
|
||
|
(usersToken) => usersToken.address === token.address,
|
||
|
)
|
||
|
) {
|
||
|
fetchTokenBalance(token.address, selectedAccountAddress).then(
|
||
|
(fetchedBalance) => {
|
||
4 years ago
|
if (fetchedBalance?.balance) {
|
||
4 years ago
|
const balanceAsDecString = fetchedBalance.balance.toString(10);
|
||
4 years ago
|
const userTokenBalance = calcTokenAmount(
|
||
|
balanceAsDecString,
|
||
|
token.decimals,
|
||
4 years ago
|
);
|
||
4 years ago
|
dispatch(
|
||
|
setSwapsFromToken({
|
||
|
...token,
|
||
|
string: userTokenBalance.toString(10),
|
||
|
balance: balanceAsDecString,
|
||
|
}),
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
4 years ago
|
},
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
4 years ago
|
dispatch(setSwapsFromToken(token));
|
||
4 years ago
|
onInputChange(
|
||
|
token?.address ? inputValue : '',
|
||
|
token.string,
|
||
|
token.decimals,
|
||
4 years ago
|
);
|
||
|
};
|
||
4 years ago
|
|
||
4 years ago
|
let blockExplorerTokenLink;
|
||
|
let blockExplorerLabel;
|
||
|
if (rpcPrefs.blockExplorerUrl) {
|
||
|
blockExplorerTokenLink = createCustomTokenTrackerLink(
|
||
|
selectedToToken.address,
|
||
|
rpcPrefs.blockExplorerUrl,
|
||
|
);
|
||
|
blockExplorerLabel = new URL(rpcPrefs.blockExplorerUrl).hostname;
|
||
|
} else if (SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId]) {
|
||
|
blockExplorerTokenLink = createCustomTokenTrackerLink(
|
||
|
selectedToToken.address,
|
||
|
SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId],
|
||
|
);
|
||
|
blockExplorerLabel = new URL(
|
||
|
SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP[chainId],
|
||
|
).hostname;
|
||
|
} else {
|
||
|
blockExplorerTokenLink = createTokenTrackerLinkForChain(
|
||
|
selectedToToken.address,
|
||
|
chainId,
|
||
|
);
|
||
|
blockExplorerLabel = t('etherscan');
|
||
|
}
|
||
|
|
||
4 years ago
|
const { destinationTokenAddedForSwap } = fetchParams || {};
|
||
|
const { address: toAddress } = toToken || {};
|
||
4 years ago
|
const onToSelect = useCallback(
|
||
|
(token) => {
|
||
|
if (destinationTokenAddedForSwap && token.address !== toAddress) {
|
||
4 years ago
|
dispatch(removeToken(toAddress));
|
||
4 years ago
|
}
|
||
4 years ago
|
dispatch(setSwapToToken(token));
|
||
4 years ago
|
setVerificationClicked(false);
|
||
4 years ago
|
},
|
||
|
[dispatch, destinationTokenAddedForSwap, toAddress],
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
4 years ago
|
const hideDropdownItemIf = useCallback(
|
||
|
(item) => item.address === fromTokenAddress,
|
||
|
[fromTokenAddress],
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
4 years ago
|
const tokensWithBalancesFromToken = tokensWithBalances.find(
|
||
|
(token) => token.address === fromToken?.address,
|
||
4 years ago
|
);
|
||
4 years ago
|
const previousTokensWithBalancesFromToken = usePrevious(
|
||
|
tokensWithBalancesFromToken,
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
|
useEffect(() => {
|
||
4 years ago
|
const notDefault = !isSwapsDefaultTokenAddress(
|
||
|
tokensWithBalancesFromToken?.address,
|
||
|
chainId,
|
||
|
);
|
||
4 years ago
|
const addressesAreTheSame =
|
||
|
tokensWithBalancesFromToken?.address ===
|
||
4 years ago
|
previousTokensWithBalancesFromToken?.address;
|
||
4 years ago
|
const balanceHasChanged =
|
||
|
tokensWithBalancesFromToken?.balance !==
|
||
4 years ago
|
previousTokensWithBalancesFromToken?.balance;
|
||
4 years ago
|
if (notDefault && addressesAreTheSame && balanceHasChanged) {
|
||
4 years ago
|
dispatch(
|
||
|
setSwapsFromToken({
|
||
|
...fromToken,
|
||
|
balance: tokensWithBalancesFromToken?.balance,
|
||
|
string: tokensWithBalancesFromToken?.string,
|
||
|
}),
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
4 years ago
|
}, [
|
||
|
dispatch,
|
||
|
tokensWithBalancesFromToken,
|
||
|
previousTokensWithBalancesFromToken,
|
||
|
fromToken,
|
||
4 years ago
|
chainId,
|
||
4 years ago
|
]);
|
||
4 years ago
|
|
||
4 years ago
|
// If the eth balance changes while on build quote, we update the selected from token
|
||
4 years ago
|
useEffect(() => {
|
||
4 years ago
|
if (
|
||
4 years ago
|
isSwapsDefaultTokenAddress(fromToken?.address, chainId) &&
|
||
4 years ago
|
fromToken?.balance !== hexToDecimal(ethBalance)
|
||
|
) {
|
||
|
dispatch(
|
||
|
setSwapsFromToken({
|
||
|
...fromToken,
|
||
|
balance: hexToDecimal(ethBalance),
|
||
|
string: getValueFromWeiHex({
|
||
|
value: ethBalance,
|
||
|
numberOfDecimals: 4,
|
||
|
toDenomination: 'ETH',
|
||
|
}),
|
||
|
}),
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
4 years ago
|
}, [dispatch, fromToken, ethBalance, chainId]);
|
||
4 years ago
|
|
||
|
useEffect(() => {
|
||
4 years ago
|
if (prevFromTokenBalance !== fromTokenBalance) {
|
||
4 years ago
|
onInputChange(inputValue, fromTokenBalance);
|
||
4 years ago
|
}
|
||
4 years ago
|
}, [onInputChange, prevFromTokenBalance, inputValue, fromTokenBalance]);
|
||
4 years ago
|
|
||
|
useEffect(() => {
|
||
4 years ago
|
dispatch(resetSwapsPostFetchState());
|
||
|
}, [dispatch]);
|
||
4 years ago
|
|
||
|
return (
|
||
|
<div className="build-quote">
|
||
|
<div className="build-quote__content">
|
||
|
<div className="build-quote__dropdown-input-pair-header">
|
||
|
<div className="build-quote__input-label">{t('swapSwapFrom')}</div>
|
||
4 years ago
|
{!isSwapsDefaultTokenSymbol(fromTokenSymbol, chainId) && (
|
||
4 years ago
|
<div
|
||
|
className="build-quote__max-button"
|
||
4 years ago
|
onClick={() =>
|
||
|
onInputChange(fromTokenBalance || '0', fromTokenBalance)
|
||
|
}
|
||
|
>
|
||
|
{t('max')}
|
||
4 years ago
|
</div>
|
||
|
)}
|
||
4 years ago
|
</div>
|
||
|
<DropdownInputPair
|
||
|
onSelect={onFromSelect}
|
||
|
itemsToSearch={tokensToSearch}
|
||
|
onInputChange={(value) => {
|
||
4 years ago
|
onInputChange(value, fromTokenBalance);
|
||
4 years ago
|
}}
|
||
|
inputValue={inputValue}
|
||
|
leftValue={inputValue && swapFromFiatValue}
|
||
|
selectedItem={selectedFromToken}
|
||
|
maxListItems={30}
|
||
4 years ago
|
loading={
|
||
|
loading &&
|
||
|
(!tokensToSearch?.length ||
|
||
|
!topAssets ||
|
||
|
!Object.keys(topAssets).length)
|
||
|
}
|
||
4 years ago
|
selectPlaceHolderText={t('swapSelect')}
|
||
4 years ago
|
hideItemIf={(item) => item.address === selectedToToken?.address}
|
||
|
listContainerClassName="build-quote__open-dropdown"
|
||
4 years ago
|
autoFocus
|
||
4 years ago
|
/>
|
||
|
<div
|
||
|
className={classnames('build-quote__balance-message', {
|
||
|
'build-quote__balance-message--error': balanceError,
|
||
|
})}
|
||
|
>
|
||
4 years ago
|
{!balanceError &&
|
||
|
fromTokenSymbol &&
|
||
|
t('swapYourTokenBalance', [
|
||
|
fromTokenString || '0',
|
||
|
fromTokenSymbol,
|
||
|
])}
|
||
4 years ago
|
{balanceError && fromTokenSymbol && (
|
||
|
<div className="build-quite__insufficient-funds">
|
||
4 years ago
|
<div className="build-quite__insufficient-funds-first">
|
||
|
{t('swapsNotEnoughForTx', [fromTokenSymbol])}
|
||
|
</div>
|
||
|
<div className="build-quite__insufficient-funds-second">
|
||
|
{t('swapYourTokenBalance', [
|
||
|
fromTokenString || '0',
|
||
|
fromTokenSymbol,
|
||
|
])}
|
||
|
</div>
|
||
4 years ago
|
</div>
|
||
|
)}
|
||
|
</div>
|
||
4 years ago
|
<div className="build-quote__swap-arrows-row">
|
||
4 years ago
|
<button
|
||
4 years ago
|
className="build-quote__swap-arrows"
|
||
|
onClick={() => {
|
||
4 years ago
|
onToSelect(selectedFromToken);
|
||
|
onFromSelect(selectedToToken);
|
||
4 years ago
|
}}
|
||
4 years ago
|
>
|
||
|
<img
|
||
|
src="/images/icons/swap2.svg"
|
||
|
alt={t('swapSwapSwitch')}
|
||
|
width="12"
|
||
|
height="16"
|
||
|
/>
|
||
4 years ago
|
</button>
|
||
4 years ago
|
</div>
|
||
|
<div className="build-quote__dropdown-swap-to-header">
|
||
|
<div className="build-quote__input-label">{t('swapSwapTo')}</div>
|
||
|
</div>
|
||
4 years ago
|
<div className="dropdown-input-pair dropdown-input-pair__to">
|
||
|
<DropdownSearchList
|
||
|
startingItem={selectedToToken}
|
||
|
itemsToSearch={tokensToSearch}
|
||
|
searchPlaceholderText={t('swapSearchForAToken')}
|
||
|
fuseSearchKeys={fuseSearchKeys}
|
||
|
selectPlaceHolderText={t('swapSelectAToken')}
|
||
|
maxListItems={30}
|
||
|
onSelect={onToSelect}
|
||
4 years ago
|
loading={
|
||
|
loading &&
|
||
|
(!tokensToSearch?.length ||
|
||
|
!topAssets ||
|
||
|
!Object.keys(topAssets).length)
|
||
|
}
|
||
4 years ago
|
externallySelectedItem={selectedToToken}
|
||
|
hideItemIf={hideDropdownItemIf}
|
||
|
listContainerClassName="build-quote__open-to-dropdown"
|
||
|
hideRightLabels
|
||
|
defaultToAll
|
||
|
/>
|
||
|
</div>
|
||
4 years ago
|
{toTokenIsNotDefault &&
|
||
4 years ago
|
(occurances < 2 ? (
|
||
4 years ago
|
<ActionableMessage
|
||
|
message={
|
||
|
<div className="build-quote__token-verification-warning-message">
|
||
|
<div className="build-quote__bold">
|
||
4 years ago
|
{occurances === 1
|
||
|
? t('swapTokenVerificationOnlyOneSource')
|
||
|
: t('swapTokenVerificationNoSource')}
|
||
4 years ago
|
</div>
|
||
|
<div>
|
||
4 years ago
|
{blockExplorerTokenLink &&
|
||
|
t('verifyThisTokenOn', [
|
||
|
<a
|
||
|
className="build-quote__token-etherscan-link build-quote__underline"
|
||
|
key="build-quote-etherscan-link"
|
||
|
href={blockExplorerTokenLink}
|
||
|
target="_blank"
|
||
|
rel="noopener noreferrer"
|
||
|
>
|
||
|
{blockExplorerLabel}
|
||
|
</a>,
|
||
|
])}
|
||
4 years ago
|
</div>
|
||
|
</div>
|
||
|
}
|
||
|
primaryAction={
|
||
|
verificationClicked
|
||
|
? null
|
||
|
: {
|
||
|
label: t('continue'),
|
||
|
onClick: () => setVerificationClicked(true),
|
||
|
}
|
||
|
}
|
||
|
type="warning"
|
||
|
withRightButton
|
||
4 years ago
|
infoTooltipText={
|
||
|
blockExplorerTokenLink &&
|
||
|
t('swapVerifyTokenExplanation', [blockExplorerLabel])
|
||
|
}
|
||
4 years ago
|
/>
|
||
|
) : (
|
||
4 years ago
|
<div className="build-quote__token-message">
|
||
4 years ago
|
<span
|
||
|
className="build-quote__bold"
|
||
|
key="token-verification-bold-text"
|
||
|
>
|
||
4 years ago
|
{t('swapTokenVerificationSources', [occurances])}
|
||
4 years ago
|
</span>
|
||
4 years ago
|
{blockExplorerTokenLink && (
|
||
|
<>
|
||
|
{t('swapTokenVerificationMessage', [
|
||
|
<a
|
||
|
className="build-quote__token-etherscan-link"
|
||
|
key="build-quote-etherscan-link"
|
||
|
href={blockExplorerTokenLink}
|
||
|
target="_blank"
|
||
|
rel="noopener noreferrer"
|
||
|
>
|
||
|
{blockExplorerLabel}
|
||
|
</a>,
|
||
|
])}
|
||
|
<InfoTooltip
|
||
|
position="top"
|
||
|
contentText={t('swapVerifyTokenExplanation', [
|
||
|
blockExplorerLabel,
|
||
|
])}
|
||
|
containerClassName="build-quote__token-tooltip-container"
|
||
|
key="token-verification-info-tooltip"
|
||
|
/>
|
||
|
</>
|
||
|
)}
|
||
4 years ago
|
</div>
|
||
4 years ago
|
))}
|
||
4 years ago
|
<div className="build-quote__slippage-buttons-container">
|
||
|
<SlippageButtons
|
||
|
onSelect={(newSlippage) => {
|
||
4 years ago
|
setMaxSlippage(newSlippage);
|
||
4 years ago
|
}}
|
||
4 years ago
|
maxAllowedSlippage={MAX_ALLOWED_SLIPPAGE}
|
||
4 years ago
|
currentSlippage={maxSlippage}
|
||
4 years ago
|
/>
|
||
|
</div>
|
||
|
</div>
|
||
|
<SwapsFooter
|
||
|
onSubmit={() => {
|
||
4 years ago
|
dispatch(
|
||
|
fetchQuotesAndSetQuoteState(
|
||
|
history,
|
||
|
inputValue,
|
||
|
maxSlippage,
|
||
|
metaMetricsEvent,
|
||
|
),
|
||
4 years ago
|
);
|
||
4 years ago
|
}}
|
||
4 years ago
|
submitText={t('swapReviewSwap')}
|
||
4 years ago
|
disabled={
|
||
4 years ago
|
!isFeatureFlagLoaded ||
|
||
4 years ago
|
!Number(inputValue) ||
|
||
|
!selectedToToken?.address ||
|
||
4 years ago
|
Number(maxSlippage) === 0 ||
|
||
4 years ago
|
Number(maxSlippage) > MAX_ALLOWED_SLIPPAGE ||
|
||
4 years ago
|
(toTokenIsNotDefault && occurances < 2 && !verificationClicked)
|
||
4 years ago
|
}
|
||
4 years ago
|
hideCancel
|
||
4 years ago
|
showTermsOfService
|
||
4 years ago
|
/>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
|
|
||
|
BuildQuote.propTypes = {
|
||
|
maxSlippage: PropTypes.number,
|
||
|
inputValue: PropTypes.string,
|
||
|
onInputChange: PropTypes.func,
|
||
|
ethBalance: PropTypes.string,
|
||
|
setMaxSlippage: PropTypes.func,
|
||
|
selectedAccountAddress: PropTypes.string,
|
||
4 years ago
|
isFeatureFlagLoaded: PropTypes.bool.isRequired,
|
||
4 years ago
|
};
|