2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-05-18 19:23:54 +02:00
|
|
|
import { getTokenTrackerLink } from '@metamask/etherscan-link';
|
2022-02-01 16:30:15 +01:00
|
|
|
import ZENDESK_URLS from '../../helpers/constants/zendesk-url';
|
2021-08-25 00:28:16 +02:00
|
|
|
import {
|
|
|
|
checkExistingAddresses,
|
|
|
|
getURLHostName,
|
|
|
|
} from '../../helpers/utils/util';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { tokenInfoGetter } from '../../helpers/utils/token-util';
|
2021-09-20 21:42:58 +02:00
|
|
|
import {
|
|
|
|
CONFIRM_IMPORT_TOKEN_ROUTE,
|
2022-12-19 18:46:36 +01:00
|
|
|
SECURITY_ROUTE,
|
2021-09-20 21:42:58 +02:00
|
|
|
} from '../../helpers/constants/routes';
|
2021-02-04 19:15:23 +01:00
|
|
|
import TextField from '../../components/ui/text-field';
|
|
|
|
import PageContainer from '../../components/ui/page-container';
|
|
|
|
import { Tabs, Tab } from '../../components/ui/tabs';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { addHexPrefix } from '../../../app/scripts/lib/util';
|
2021-05-17 21:00:59 +02:00
|
|
|
import { isValidHexAddress } from '../../../shared/modules/hexstring-utils';
|
2021-07-02 21:07:56 +02:00
|
|
|
import ActionableMessage from '../../components/ui/actionable-message/actionable-message';
|
2021-05-18 19:23:54 +02:00
|
|
|
import Typography from '../../components/ui/typography';
|
2023-02-02 21:15:26 +01:00
|
|
|
import {
|
|
|
|
TypographyVariant,
|
|
|
|
FONT_WEIGHT,
|
|
|
|
} from '../../helpers/constants/design-system';
|
2021-05-18 19:23:54 +02:00
|
|
|
import Button from '../../components/ui/button';
|
2023-01-18 15:47:29 +01:00
|
|
|
import { TokenStandard } from '../../../shared/constants/transaction';
|
2022-08-10 03:26:25 +02:00
|
|
|
import { STATIC_MAINNET_TOKEN_LIST } from '../../../shared/constants/tokens';
|
2021-02-04 19:15:23 +01:00
|
|
|
import TokenSearch from './token-search';
|
2021-05-18 19:23:54 +02:00
|
|
|
import TokenList from './token-list';
|
2021-02-04 19:15:23 +01:00
|
|
|
|
|
|
|
const emptyAddr = '0x0000000000000000000000000000000000000000';
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2021-03-16 17:24:56 +01:00
|
|
|
const MIN_DECIMAL_VALUE = 0;
|
|
|
|
const MAX_DECIMAL_VALUE = 36;
|
|
|
|
|
2021-09-10 22:21:04 +02:00
|
|
|
class ImportToken extends Component {
|
2018-05-20 08:04:19 +02:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-05-20 08:04:19 +02:00
|
|
|
|
|
|
|
static propTypes = {
|
2022-03-30 00:20:19 +02:00
|
|
|
/**
|
|
|
|
* History object of the router.
|
|
|
|
*/
|
2018-05-20 08:04:19 +02:00
|
|
|
history: PropTypes.object,
|
2022-03-30 00:20:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the state of `pendingTokens`, called when adding a token.
|
|
|
|
*/
|
2018-05-20 08:04:19 +02:00
|
|
|
setPendingTokens: PropTypes.func,
|
2022-03-30 00:20:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The current list of pending tokens to be added.
|
|
|
|
*/
|
2018-05-20 08:04:19 +02:00
|
|
|
pendingTokens: PropTypes.object,
|
2022-03-30 00:20:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the list of pending tokens. Called when closing the modal.
|
|
|
|
*/
|
2018-05-20 08:04:19 +02:00
|
|
|
clearPendingTokens: PropTypes.func,
|
2022-03-30 00:20:19 +02:00
|
|
|
|
2023-07-14 18:18:41 +02:00
|
|
|
/**
|
|
|
|
* Clear the list of pending tokens. Called when closing the modal.
|
|
|
|
*/
|
|
|
|
showImportNftsModal: PropTypes.func,
|
|
|
|
|
2022-03-30 00:20:19 +02:00
|
|
|
/**
|
|
|
|
* The list of already added tokens.
|
|
|
|
*/
|
2018-05-20 08:04:19 +02:00
|
|
|
tokens: PropTypes.array,
|
2022-03-30 00:20:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The identities/accounts that are currently added to the wallet.
|
|
|
|
*/
|
2018-05-20 08:04:19 +02:00
|
|
|
identities: PropTypes.object,
|
2022-03-30 00:20:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Boolean flag that shows/hides the search tab.
|
|
|
|
*/
|
2021-03-25 20:25:22 +01:00
|
|
|
showSearchTab: PropTypes.bool.isRequired,
|
2022-03-30 00:20:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The most recent overview page route, which is 'navigated' to when closing the modal.
|
|
|
|
*/
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
2022-03-30 00:20:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The active chainId in use.
|
|
|
|
*/
|
2021-05-18 19:23:54 +02:00
|
|
|
chainId: PropTypes.string,
|
2022-03-30 00:20:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The rpc preferences to use for the current provider.
|
|
|
|
*/
|
2021-05-18 19:23:54 +02:00
|
|
|
rpcPrefs: PropTypes.object,
|
2022-03-30 00:20:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The list of tokens available for search.
|
|
|
|
*/
|
2021-09-09 22:56:27 +02:00
|
|
|
tokenList: PropTypes.object,
|
2022-03-30 00:20:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Boolean flag indicating whether token detection is enabled or not.
|
|
|
|
* When disabled, shows an information alert in the search tab informing the
|
|
|
|
* user of the availability of this feature.
|
|
|
|
*/
|
2021-11-29 19:28:35 +01:00
|
|
|
useTokenDetection: PropTypes.bool,
|
2022-03-30 00:20:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function called to fetch information about the token standard and
|
|
|
|
* details, see `actions.js`.
|
|
|
|
*/
|
2022-01-19 15:38:33 +01:00
|
|
|
getTokenStandardAndDetails: PropTypes.func,
|
2022-03-30 00:20:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The currently selected active address.
|
|
|
|
*/
|
2022-01-19 15:38:33 +01:00
|
|
|
selectedAddress: PropTypes.string,
|
2022-08-10 03:26:25 +02:00
|
|
|
isDynamicTokenListAvailable: PropTypes.bool.isRequired,
|
|
|
|
tokenDetectionInactiveOnNonMainnetSupportedNetwork:
|
|
|
|
PropTypes.bool.isRequired,
|
2022-03-31 15:48:05 +02:00
|
|
|
networkName: PropTypes.string.isRequired,
|
2021-09-09 22:56:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
tokenList: {},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2019-12-19 23:00:22 +01:00
|
|
|
state = {
|
|
|
|
customAddress: '',
|
|
|
|
customSymbol: '',
|
|
|
|
customDecimals: 0,
|
|
|
|
searchResults: [],
|
|
|
|
selectedTokens: {},
|
2023-01-18 15:47:29 +01:00
|
|
|
standard: TokenStandard.NONE,
|
2019-12-19 23:00:22 +01:00
|
|
|
tokenSelectorError: null,
|
|
|
|
customAddressError: null,
|
|
|
|
customSymbolError: null,
|
|
|
|
customDecimalsError: null,
|
2023-02-16 20:23:29 +01:00
|
|
|
nftAddressError: null,
|
2019-12-19 23:00:22 +01:00
|
|
|
forceEditSymbol: false,
|
2021-05-18 19:23:54 +02:00
|
|
|
symbolAutoFilled: false,
|
|
|
|
decimalAutoFilled: false,
|
2022-01-05 19:19:28 +01:00
|
|
|
mainnetTokenWarning: null,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
componentDidMount() {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.tokenInfoGetter = tokenInfoGetter();
|
|
|
|
const { pendingTokens = {} } = this.props;
|
|
|
|
const pendingTokenKeys = Object.keys(pendingTokens);
|
2018-05-20 08:04:19 +02:00
|
|
|
|
|
|
|
if (pendingTokenKeys.length > 0) {
|
2021-02-04 19:15:23 +01:00
|
|
|
let selectedTokens = {};
|
|
|
|
let customToken = {};
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
pendingTokenKeys.forEach((tokenAddress) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const token = pendingTokens[tokenAddress];
|
|
|
|
const { isCustom } = token;
|
2018-05-20 08:04:19 +02:00
|
|
|
|
|
|
|
if (isCustom) {
|
2021-02-04 19:15:23 +01:00
|
|
|
customToken = { ...token };
|
2018-05-20 08:04:19 +02:00
|
|
|
} else {
|
2021-02-04 19:15:23 +01:00
|
|
|
selectedTokens = { ...selectedTokens, [tokenAddress]: { ...token } };
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-20 08:04:19 +02:00
|
|
|
|
|
|
|
const {
|
|
|
|
address: customAddress = '',
|
|
|
|
symbol: customSymbol = '',
|
|
|
|
decimals: customDecimals = 0,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = customToken;
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
this.setState({
|
|
|
|
selectedTokens,
|
|
|
|
customAddress,
|
|
|
|
customSymbol,
|
|
|
|
customDecimals,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
handleToggleToken(token) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { address } = token;
|
|
|
|
const { selectedTokens = {} } = this.state;
|
|
|
|
const selectedTokensCopy = { ...selectedTokens };
|
2018-05-20 08:04:19 +02:00
|
|
|
|
|
|
|
if (address in selectedTokensCopy) {
|
2021-02-04 19:15:23 +01:00
|
|
|
delete selectedTokensCopy[address];
|
2018-05-20 08:04:19 +02:00
|
|
|
} else {
|
2021-02-04 19:15:23 +01:00
|
|
|
selectedTokensCopy[address] = token;
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
selectedTokens: selectedTokensCopy,
|
|
|
|
tokenSelectorError: null,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
hasError() {
|
2018-05-20 08:04:19 +02:00
|
|
|
const {
|
|
|
|
tokenSelectorError,
|
|
|
|
customAddressError,
|
|
|
|
customSymbolError,
|
|
|
|
customDecimalsError,
|
2023-02-16 20:23:29 +01:00
|
|
|
nftAddressError,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.state;
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
return (
|
|
|
|
tokenSelectorError ||
|
|
|
|
customAddressError ||
|
|
|
|
customSymbolError ||
|
2022-01-19 15:38:33 +01:00
|
|
|
customDecimalsError ||
|
2023-02-16 20:23:29 +01:00
|
|
|
nftAddressError
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
hasSelected() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { customAddress = '', selectedTokens = {} } = this.state;
|
|
|
|
return customAddress || Object.keys(selectedTokens).length > 0;
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
handleNext() {
|
2018-05-20 08:04:19 +02:00
|
|
|
if (this.hasError()) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return;
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.hasSelected()) {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ tokenSelectorError: this.context.t('mustSelectOne') });
|
|
|
|
return;
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
|
2021-09-09 22:56:27 +02:00
|
|
|
const { setPendingTokens, history, tokenList } = this.props;
|
2022-08-10 03:26:25 +02:00
|
|
|
const tokenAddressList = Object.keys(tokenList);
|
2018-05-20 08:04:19 +02:00
|
|
|
const {
|
|
|
|
customAddress: address,
|
|
|
|
customSymbol: symbol,
|
|
|
|
customDecimals: decimals,
|
|
|
|
selectedTokens,
|
2022-04-26 21:08:14 +02:00
|
|
|
standard,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.state;
|
2018-05-20 08:04:19 +02:00
|
|
|
|
|
|
|
const customToken = {
|
|
|
|
address,
|
|
|
|
symbol,
|
|
|
|
decimals,
|
2022-04-26 21:08:14 +02:00
|
|
|
standard,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2021-09-09 22:56:27 +02:00
|
|
|
setPendingTokens({ customToken, selectedTokens, tokenAddressList });
|
2021-09-10 22:21:04 +02:00
|
|
|
history.push(CONFIRM_IMPORT_TOKEN_ROUTE);
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
async attemptToAutoFillTokenParams(address) {
|
2021-09-09 22:56:27 +02:00
|
|
|
const { tokenList } = this.props;
|
|
|
|
const { symbol = '', decimals } = await this.tokenInfoGetter(
|
|
|
|
address,
|
|
|
|
tokenList,
|
|
|
|
);
|
2018-05-20 23:08:45 +02:00
|
|
|
|
2021-05-18 19:23:54 +02:00
|
|
|
const symbolAutoFilled = Boolean(symbol);
|
|
|
|
const decimalAutoFilled = Boolean(decimals);
|
|
|
|
this.setState({ symbolAutoFilled, decimalAutoFilled });
|
2021-02-04 19:15:23 +01:00
|
|
|
this.handleCustomSymbolChange(symbol || '');
|
|
|
|
this.handleCustomDecimalsChange(decimals);
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
|
2022-01-19 15:38:33 +01:00
|
|
|
async handleCustomAddressChange(value) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const customAddress = value.trim();
|
2018-05-20 08:04:19 +02:00
|
|
|
this.setState({
|
|
|
|
customAddress,
|
|
|
|
customAddressError: null,
|
2023-02-16 20:23:29 +01:00
|
|
|
nftAddressError: null,
|
2018-05-20 08:04:19 +02:00
|
|
|
tokenSelectorError: null,
|
2021-05-18 19:23:54 +02:00
|
|
|
symbolAutoFilled: false,
|
|
|
|
decimalAutoFilled: false,
|
2022-01-05 19:19:28 +01:00
|
|
|
mainnetTokenWarning: null,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2021-05-17 21:00:59 +02:00
|
|
|
const addressIsValid = isValidHexAddress(customAddress, {
|
|
|
|
allowNonPrefixed: false,
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
const standardAddress = addHexPrefix(customAddress).toLowerCase();
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2022-08-10 03:26:25 +02:00
|
|
|
const isMainnetToken = Object.keys(STATIC_MAINNET_TOKEN_LIST).some(
|
2022-01-05 19:19:28 +01:00
|
|
|
(key) => key.toLowerCase() === customAddress.toLowerCase(),
|
|
|
|
);
|
|
|
|
|
|
|
|
const isMainnetNetwork = this.props.chainId === '0x1';
|
|
|
|
|
2022-01-19 15:38:33 +01:00
|
|
|
let standard;
|
2022-04-26 21:08:14 +02:00
|
|
|
if (addressIsValid) {
|
2022-01-19 15:38:33 +01:00
|
|
|
try {
|
|
|
|
({ standard } = await this.props.getTokenStandardAndDetails(
|
|
|
|
standardAddress,
|
|
|
|
this.props.selectedAddress,
|
|
|
|
));
|
|
|
|
} catch (error) {
|
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const addressIsEmpty =
|
|
|
|
customAddress.length === 0 || customAddress === emptyAddr;
|
|
|
|
|
2018-05-20 08:04:19 +02:00
|
|
|
switch (true) {
|
2022-01-19 15:38:33 +01:00
|
|
|
case !addressIsValid && !addressIsEmpty:
|
2018-05-20 08:04:19 +02:00
|
|
|
this.setState({
|
|
|
|
customAddressError: this.context.t('invalidAddress'),
|
|
|
|
customSymbol: '',
|
|
|
|
customDecimals: 0,
|
|
|
|
customSymbolError: null,
|
|
|
|
customDecimalsError: null,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2022-01-19 15:38:33 +01:00
|
|
|
break;
|
2023-03-13 20:29:37 +01:00
|
|
|
case standard === 'ERC1155' || standard === 'ERC721':
|
2022-01-19 15:38:33 +01:00
|
|
|
this.setState({
|
2023-02-16 20:23:29 +01:00
|
|
|
nftAddressError: this.context.t('nftAddressError', [
|
2022-01-19 15:38:33 +01:00
|
|
|
<a
|
2023-02-16 20:23:29 +01:00
|
|
|
className="import-token__nft-address-error-link"
|
2023-07-14 18:18:41 +02:00
|
|
|
onClick={() => {
|
|
|
|
this.props.showImportNftsModal();
|
|
|
|
}}
|
2023-02-16 20:23:29 +01:00
|
|
|
key="nftAddressError"
|
2022-01-19 15:38:33 +01:00
|
|
|
>
|
|
|
|
{this.context.t('importNFTPage')}
|
|
|
|
</a>,
|
|
|
|
]),
|
|
|
|
});
|
2022-01-05 19:19:28 +01:00
|
|
|
break;
|
|
|
|
case isMainnetToken && !isMainnetNetwork:
|
|
|
|
this.setState({
|
|
|
|
mainnetTokenWarning: this.context.t('mainnetToken'),
|
|
|
|
customSymbol: '',
|
|
|
|
customDecimals: 0,
|
|
|
|
customSymbolError: null,
|
|
|
|
customDecimalsError: null,
|
|
|
|
});
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
break;
|
2018-05-20 08:04:19 +02:00
|
|
|
case Boolean(this.props.identities[standardAddress]):
|
|
|
|
this.setState({
|
|
|
|
customAddressError: this.context.t('personalAddressDetected'),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
break;
|
2018-05-20 08:04:19 +02:00
|
|
|
case checkExistingAddresses(customAddress, this.props.tokens):
|
|
|
|
this.setState({
|
|
|
|
customAddressError: this.context.t('tokenAlreadyAdded'),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
break;
|
2018-05-20 08:04:19 +02:00
|
|
|
default:
|
2022-01-19 15:38:33 +01:00
|
|
|
if (!addressIsEmpty) {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.attemptToAutoFillTokenParams(customAddress);
|
2022-04-26 21:08:14 +02:00
|
|
|
if (standard) {
|
|
|
|
this.setState({ standard });
|
|
|
|
}
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
handleCustomSymbolChange(value) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const customSymbol = value.trim();
|
|
|
|
const symbolLength = customSymbol.length;
|
|
|
|
let customSymbolError = null;
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2018-11-22 19:39:59 +01:00
|
|
|
if (symbolLength <= 0 || symbolLength >= 12) {
|
2021-02-04 19:15:23 +01:00
|
|
|
customSymbolError = this.context.t('symbolBetweenZeroTwelve');
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ customSymbol, customSymbolError });
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
handleCustomDecimalsChange(value) {
|
2021-05-18 19:23:54 +02:00
|
|
|
let customDecimals;
|
2021-02-04 19:15:23 +01:00
|
|
|
let customDecimalsError = null;
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2021-05-18 19:23:54 +02:00
|
|
|
if (value) {
|
|
|
|
customDecimals = Number(value.trim());
|
|
|
|
customDecimalsError =
|
|
|
|
value < MIN_DECIMAL_VALUE || value > MAX_DECIMAL_VALUE
|
|
|
|
? this.context.t('decimalsMustZerotoTen')
|
|
|
|
: null;
|
|
|
|
} else {
|
|
|
|
customDecimals = '';
|
|
|
|
customDecimalsError = this.context.t('tokenDecimalFetchFailed');
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ customDecimals, customDecimalsError });
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderCustomTokenForm() {
|
2022-03-31 15:48:05 +02:00
|
|
|
const { t } = this.context;
|
2018-05-20 08:04:19 +02:00
|
|
|
const {
|
|
|
|
customAddress,
|
|
|
|
customSymbol,
|
|
|
|
customDecimals,
|
|
|
|
customAddressError,
|
|
|
|
customSymbolError,
|
|
|
|
customDecimalsError,
|
2019-02-13 15:00:22 +01:00
|
|
|
forceEditSymbol,
|
2021-05-18 19:23:54 +02:00
|
|
|
symbolAutoFilled,
|
|
|
|
decimalAutoFilled,
|
2022-01-05 19:19:28 +01:00
|
|
|
mainnetTokenWarning,
|
2023-02-16 20:23:29 +01:00
|
|
|
nftAddressError,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.state;
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2022-08-10 03:26:25 +02:00
|
|
|
const {
|
|
|
|
chainId,
|
|
|
|
rpcPrefs,
|
|
|
|
isDynamicTokenListAvailable,
|
|
|
|
tokenDetectionInactiveOnNonMainnetSupportedNetwork,
|
|
|
|
history,
|
|
|
|
} = this.props;
|
2021-05-18 19:23:54 +02:00
|
|
|
const blockExplorerTokenLink = getTokenTrackerLink(
|
|
|
|
customAddress,
|
|
|
|
chainId,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
{ blockExplorerUrl: rpcPrefs?.blockExplorerUrl ?? null },
|
|
|
|
);
|
|
|
|
const blockExplorerLabel = rpcPrefs?.blockExplorerUrl
|
2021-08-25 00:28:16 +02:00
|
|
|
? getURLHostName(blockExplorerTokenLink)
|
2022-03-31 15:48:05 +02:00
|
|
|
: t('etherscan');
|
2021-05-18 19:23:54 +02:00
|
|
|
|
2018-05-20 08:04:19 +02:00
|
|
|
return (
|
2021-09-10 22:21:04 +02:00
|
|
|
<div className="import-token__custom-token-form">
|
2022-08-10 03:26:25 +02:00
|
|
|
{tokenDetectionInactiveOnNonMainnetSupportedNetwork ? (
|
|
|
|
<ActionableMessage
|
|
|
|
type="warning"
|
|
|
|
message={t('customTokenWarningInTokenDetectionNetworkWithTDOFF', [
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
key="import-token-security-risk"
|
|
|
|
className="import-token__link"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
target="_blank"
|
|
|
|
href={ZENDESK_URLS.TOKEN_SAFETY_PRACTICES}
|
|
|
|
>
|
|
|
|
{t('tokenScamSecurityRisk')}
|
|
|
|
</Button>,
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
key="import-token-token-detection-announcement"
|
|
|
|
className="import-token__link"
|
|
|
|
onClick={() =>
|
2022-12-19 18:46:36 +01:00
|
|
|
history.push(`${SECURITY_ROUTE}#token-description`)
|
2022-08-10 03:26:25 +02:00
|
|
|
}
|
|
|
|
>
|
|
|
|
{t('inYourSettings')}
|
|
|
|
</Button>,
|
|
|
|
])}
|
|
|
|
withRightButton
|
|
|
|
useIcon
|
|
|
|
iconFillColor="var(--color-warning-default)"
|
|
|
|
/>
|
|
|
|
) : (
|
2022-03-31 15:48:05 +02:00
|
|
|
<ActionableMessage
|
2022-08-10 03:26:25 +02:00
|
|
|
type={isDynamicTokenListAvailable ? 'warning' : 'default'}
|
2022-03-31 15:48:05 +02:00
|
|
|
message={t(
|
2022-08-10 03:26:25 +02:00
|
|
|
isDynamicTokenListAvailable
|
2022-03-31 15:48:05 +02:00
|
|
|
? 'customTokenWarningInTokenDetectionNetwork'
|
|
|
|
: 'customTokenWarningInNonTokenDetectionNetwork',
|
|
|
|
[
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
key="import-token-fake-token-warning"
|
|
|
|
className="import-token__link"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
target="_blank"
|
|
|
|
href={ZENDESK_URLS.TOKEN_SAFETY_PRACTICES}
|
|
|
|
>
|
|
|
|
{t('learnScamRisk')}
|
|
|
|
</Button>,
|
|
|
|
],
|
|
|
|
)}
|
|
|
|
withRightButton
|
|
|
|
useIcon
|
|
|
|
iconFillColor={
|
2022-08-10 03:26:25 +02:00
|
|
|
isDynamicTokenListAvailable
|
2022-03-31 15:48:05 +02:00
|
|
|
? 'var(--color-warning-default)'
|
|
|
|
: 'var(--color-info-default)'
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
2018-05-20 08:04:19 +02:00
|
|
|
<TextField
|
|
|
|
id="custom-address"
|
2022-03-31 15:48:05 +02:00
|
|
|
label={t('tokenContractAddress')}
|
2018-05-20 08:04:19 +02:00
|
|
|
type="text"
|
|
|
|
value={customAddress}
|
2020-02-15 21:34:12 +01:00
|
|
|
onChange={(e) => this.handleCustomAddressChange(e.target.value)}
|
2023-02-16 20:23:29 +01:00
|
|
|
error={customAddressError || mainnetTokenWarning || nftAddressError}
|
2018-05-20 08:04:19 +02:00
|
|
|
fullWidth
|
2020-10-12 23:10:51 +02:00
|
|
|
autoFocus
|
2018-05-20 08:04:19 +02:00
|
|
|
margin="normal"
|
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
id="custom-symbol"
|
2020-11-03 00:41:28 +01:00
|
|
|
label={
|
2021-09-10 22:21:04 +02:00
|
|
|
<div className="import-token__custom-symbol__label-wrapper">
|
|
|
|
<span className="import-token__custom-symbol__label">
|
2022-03-31 15:48:05 +02:00
|
|
|
{t('tokenSymbol')}
|
2019-02-13 15:00:22 +01:00
|
|
|
</span>
|
2021-05-18 19:23:54 +02:00
|
|
|
{symbolAutoFilled && !forceEditSymbol && (
|
2019-02-13 15:00:22 +01:00
|
|
|
<div
|
2021-09-10 22:21:04 +02:00
|
|
|
className="import-token__custom-symbol__edit"
|
2019-02-13 15:00:22 +01:00
|
|
|
onClick={() => this.setState({ forceEditSymbol: true })}
|
|
|
|
>
|
2022-03-31 15:48:05 +02:00
|
|
|
{t('edit')}
|
2019-02-13 15:00:22 +01:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
2018-05-20 08:04:19 +02:00
|
|
|
type="text"
|
|
|
|
value={customSymbol}
|
2020-02-15 21:34:12 +01:00
|
|
|
onChange={(e) => this.handleCustomSymbolChange(e.target.value)}
|
2018-05-20 08:04:19 +02:00
|
|
|
error={customSymbolError}
|
|
|
|
fullWidth
|
|
|
|
margin="normal"
|
2021-05-18 19:23:54 +02:00
|
|
|
disabled={symbolAutoFilled && !forceEditSymbol}
|
2018-05-20 08:04:19 +02:00
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
id="custom-decimals"
|
2022-03-31 15:48:05 +02:00
|
|
|
label={t('decimal')}
|
2018-05-20 08:04:19 +02:00
|
|
|
type="number"
|
|
|
|
value={customDecimals}
|
2020-02-15 21:34:12 +01:00
|
|
|
onChange={(e) => this.handleCustomDecimalsChange(e.target.value)}
|
2021-05-18 19:23:54 +02:00
|
|
|
error={customDecimals ? customDecimalsError : null}
|
2018-05-20 08:04:19 +02:00
|
|
|
fullWidth
|
|
|
|
margin="normal"
|
2021-05-18 19:23:54 +02:00
|
|
|
disabled={decimalAutoFilled}
|
2021-03-16 17:24:56 +01:00
|
|
|
min={MIN_DECIMAL_VALUE}
|
|
|
|
max={MAX_DECIMAL_VALUE}
|
2018-05-20 08:04:19 +02:00
|
|
|
/>
|
2021-05-18 19:23:54 +02:00
|
|
|
{customDecimals === '' && (
|
|
|
|
<ActionableMessage
|
|
|
|
message={
|
|
|
|
<>
|
|
|
|
<Typography
|
2023-02-02 21:15:26 +01:00
|
|
|
variant={TypographyVariant.H7}
|
2021-05-18 19:23:54 +02:00
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
>
|
2022-03-31 15:48:05 +02:00
|
|
|
{t('tokenDecimalFetchFailed')}
|
2021-05-18 19:23:54 +02:00
|
|
|
</Typography>
|
|
|
|
<Typography
|
2023-02-02 21:15:26 +01:00
|
|
|
variant={TypographyVariant.H7}
|
2021-05-18 19:23:54 +02:00
|
|
|
fontWeight={FONT_WEIGHT.NORMAL}
|
|
|
|
>
|
2022-03-31 15:48:05 +02:00
|
|
|
{t('verifyThisTokenDecimalOn', [
|
2021-05-18 19:23:54 +02:00
|
|
|
<Button
|
|
|
|
type="link"
|
2021-09-10 22:21:04 +02:00
|
|
|
key="import-token-verify-token-decimal"
|
|
|
|
className="import-token__link"
|
2021-05-18 19:23:54 +02:00
|
|
|
rel="noopener noreferrer"
|
|
|
|
target="_blank"
|
|
|
|
href={blockExplorerTokenLink}
|
|
|
|
>
|
|
|
|
{blockExplorerLabel}
|
|
|
|
</Button>,
|
|
|
|
])}
|
|
|
|
</Typography>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
type="warning"
|
|
|
|
withRightButton
|
2021-09-10 22:21:04 +02:00
|
|
|
className="import-token__decimal-warning"
|
2021-05-18 19:23:54 +02:00
|
|
|
/>
|
|
|
|
)}
|
2018-05-20 08:04:19 +02:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderSearchToken() {
|
2022-03-31 15:48:05 +02:00
|
|
|
const { t } = this.context;
|
|
|
|
const { tokenList, history, useTokenDetection, networkName } = this.props;
|
2021-02-04 19:15:23 +01:00
|
|
|
const { tokenSelectorError, selectedTokens, searchResults } = this.state;
|
2018-05-20 08:04:19 +02:00
|
|
|
return (
|
2021-09-10 22:21:04 +02:00
|
|
|
<div className="import-token__search-token">
|
2021-11-29 19:28:35 +01:00
|
|
|
{!useTokenDetection && (
|
|
|
|
<ActionableMessage
|
2022-09-19 22:23:21 +02:00
|
|
|
message={t('enhancedTokenDetectionAlertMessage', [
|
2022-08-10 03:26:25 +02:00
|
|
|
networkName,
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
key="token-detection-announcement"
|
|
|
|
className="import-token__link"
|
|
|
|
onClick={() =>
|
2022-12-19 18:46:36 +01:00
|
|
|
history.push(`${SECURITY_ROUTE}#token-description`)
|
2022-08-10 03:26:25 +02:00
|
|
|
}
|
|
|
|
>
|
|
|
|
{t('enableFromSettings')}
|
|
|
|
</Button>,
|
|
|
|
])}
|
2021-11-29 19:28:35 +01:00
|
|
|
withRightButton
|
|
|
|
useIcon
|
2022-03-25 23:15:31 +01:00
|
|
|
iconFillColor="var(--color-primary-default)"
|
2021-11-29 19:28:35 +01:00
|
|
|
className="import-token__token-detection-announcement"
|
|
|
|
/>
|
|
|
|
)}
|
2018-05-20 08:04:19 +02:00
|
|
|
<TokenSearch
|
2020-11-03 00:41:28 +01:00
|
|
|
onSearch={({ results = [] }) =>
|
|
|
|
this.setState({ searchResults: results })
|
|
|
|
}
|
2018-05-20 08:04:19 +02:00
|
|
|
error={tokenSelectorError}
|
2021-09-09 22:56:27 +02:00
|
|
|
tokenList={tokenList}
|
2018-05-20 08:04:19 +02:00
|
|
|
/>
|
2021-09-10 22:21:04 +02:00
|
|
|
<div className="import-token__token-list">
|
2018-05-20 08:04:19 +02:00
|
|
|
<TokenList
|
|
|
|
results={searchResults}
|
|
|
|
selectedTokens={selectedTokens}
|
2020-02-15 21:34:12 +01:00
|
|
|
onToggleToken={(token) => this.handleToggleToken(token)}
|
2018-05-20 08:04:19 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderTabs() {
|
2022-03-31 15:48:05 +02:00
|
|
|
const { t } = this.context;
|
2021-03-25 20:25:22 +01:00
|
|
|
const { showSearchTab } = this.props;
|
|
|
|
const tabs = [];
|
|
|
|
|
|
|
|
if (showSearchTab) {
|
|
|
|
tabs.push(
|
2023-01-19 16:05:42 +01:00
|
|
|
<Tab name={t('search')} key="search-tab" tabKey="search">
|
2021-03-25 20:25:22 +01:00
|
|
|
{this.renderSearchToken()}
|
|
|
|
</Tab>,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
tabs.push(
|
2023-01-19 16:05:42 +01:00
|
|
|
<Tab name={t('customToken')} key="custom-tab" tabKey="customToken">
|
2021-03-25 20:25:22 +01:00
|
|
|
{this.renderCustomTokenForm()}
|
|
|
|
</Tab>,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-03-25 20:25:22 +01:00
|
|
|
|
|
|
|
return <Tabs>{tabs}</Tabs>;
|
2018-07-19 02:47:01 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { history, clearPendingTokens, mostRecentOverviewPage } = this.props;
|
2018-05-20 08:04:19 +02:00
|
|
|
|
|
|
|
return (
|
2018-07-19 02:47:01 +02:00
|
|
|
<PageContainer
|
2021-09-10 22:21:04 +02:00
|
|
|
title={this.context.t('importTokensCamelCase')}
|
2018-07-19 02:47:01 +02:00
|
|
|
tabsComponent={this.renderTabs()}
|
|
|
|
onSubmit={() => this.handleNext()}
|
2021-09-10 22:21:04 +02:00
|
|
|
hideCancel
|
2020-06-02 23:47:43 +02:00
|
|
|
disabled={Boolean(this.hasError()) || !this.hasSelected()}
|
2021-09-10 22:21:04 +02:00
|
|
|
onClose={() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
clearPendingTokens();
|
|
|
|
history.push(mostRecentOverviewPage);
|
2018-07-19 02:47:01 +02:00
|
|
|
}}
|
|
|
|
/>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 22:21:04 +02:00
|
|
|
export default ImportToken;
|