2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
2021-03-09 22:37:19 +01:00
|
|
|
import { createTokenTrackerLinkForChain } from '@metamask/etherscan-link';
|
2020-06-12 19:04:40 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import TransactionList from '../../../components/app/transaction-list';
|
|
|
|
import { TokenOverview } from '../../../components/app/wallet-overview';
|
2020-11-19 05:29:42 +01:00
|
|
|
import {
|
2021-03-09 22:37:19 +01:00
|
|
|
getCurrentChainId,
|
2020-11-19 05:29:42 +01:00
|
|
|
getSelectedIdentity,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../selectors/selectors';
|
|
|
|
import { DEFAULT_ROUTE } from '../../../helpers/constants/routes';
|
|
|
|
import { showModal } from '../../../store/actions';
|
2020-06-12 19:04:40 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import AssetNavigation from './asset-navigation';
|
|
|
|
import TokenOptions from './token-options';
|
2020-06-12 19:04:40 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function TokenAsset({ token }) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const dispatch = useDispatch();
|
2021-03-09 22:37:19 +01:00
|
|
|
const chainId = useSelector(getCurrentChainId);
|
2021-02-04 19:15:23 +01:00
|
|
|
const selectedIdentity = useSelector(getSelectedIdentity);
|
|
|
|
const selectedAccountName = selectedIdentity.name;
|
|
|
|
const selectedAddress = selectedIdentity.address;
|
|
|
|
const history = useHistory();
|
2020-06-12 19:04:40 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<AssetNavigation
|
|
|
|
accountName={selectedAccountName}
|
|
|
|
assetName={token.symbol}
|
|
|
|
onBack={() => history.push(DEFAULT_ROUTE)}
|
2020-11-03 00:41:28 +01:00
|
|
|
optionsButton={
|
2020-06-12 19:04:40 +02:00
|
|
|
<TokenOptions
|
2020-11-03 00:41:28 +01:00
|
|
|
onRemove={() =>
|
|
|
|
dispatch(showModal({ name: 'HIDE_TOKEN_CONFIRMATION', token }))
|
|
|
|
}
|
2020-06-12 19:04:40 +02:00
|
|
|
onViewEtherscan={() => {
|
2021-03-09 22:37:19 +01:00
|
|
|
const url = createTokenTrackerLinkForChain(
|
2020-11-19 05:29:42 +01:00
|
|
|
token.address,
|
2021-03-09 22:37:19 +01:00
|
|
|
chainId,
|
2020-11-19 05:29:42 +01:00
|
|
|
selectedAddress,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
global.platform.openTab({ url });
|
2020-06-12 19:04:40 +02:00
|
|
|
}}
|
2021-04-27 00:07:33 +02:00
|
|
|
onViewAccountDetails={() => {
|
|
|
|
dispatch(showModal({ name: 'ACCOUNT_DETAILS' }));
|
|
|
|
}}
|
2020-06-12 19:04:40 +02:00
|
|
|
tokenSymbol={token.symbol}
|
|
|
|
/>
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
2020-06-12 19:04:40 +02:00
|
|
|
/>
|
|
|
|
<TokenOverview className="asset__overview" token={token} />
|
|
|
|
<TransactionList tokenAddress={token.address} />
|
|
|
|
</>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-06-12 19:04:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TokenAsset.propTypes = {
|
|
|
|
token: PropTypes.shape({
|
|
|
|
address: PropTypes.string.isRequired,
|
|
|
|
decimals: PropTypes.number,
|
|
|
|
symbol: PropTypes.string,
|
|
|
|
}).isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|