mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-28 23:06:37 +01:00
2cd242252f
* Created new screen/page "Token details" * Change color in scss * Modify elements to the latest requirements and added unit tests * Review requested changes * Condensing files into one component * Added unit tests for token details page * Added redirection when switching networks, added image for a token and update unit tests * Requested review changes * Modify index.scss regarding of the requested review * Delete data-testid's from Typography and token-details-page.js * Requested review changes
99 lines
3.1 KiB
JavaScript
99 lines
3.1 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import { useHistory } from 'react-router-dom';
|
|
import { getTokenTrackerLink } from '@metamask/etherscan-link';
|
|
import TransactionList from '../../../components/app/transaction-list';
|
|
import { TokenOverview } from '../../../components/app/wallet-overview';
|
|
import {
|
|
getCurrentChainId,
|
|
getSelectedIdentity,
|
|
getRpcPrefsForCurrentProvider,
|
|
} from '../../../selectors/selectors';
|
|
import {
|
|
DEFAULT_ROUTE,
|
|
TOKEN_DETAILS,
|
|
} from '../../../helpers/constants/routes';
|
|
import { getURLHostName } from '../../../helpers/utils/util';
|
|
import { showModal } from '../../../store/actions';
|
|
import { useNewMetricEvent } from '../../../hooks/useMetricEvent';
|
|
import { ASSET_TYPES, updateSendAsset } from '../../../ducks/send';
|
|
|
|
import AssetNavigation from './asset-navigation';
|
|
import AssetOptions from './asset-options';
|
|
|
|
export default function TokenAsset({ token }) {
|
|
const dispatch = useDispatch();
|
|
const chainId = useSelector(getCurrentChainId);
|
|
const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider);
|
|
const selectedIdentity = useSelector(getSelectedIdentity);
|
|
const selectedAccountName = selectedIdentity.name;
|
|
const selectedAddress = selectedIdentity.address;
|
|
const history = useHistory();
|
|
const tokenTrackerLink = getTokenTrackerLink(
|
|
token.address,
|
|
chainId,
|
|
null,
|
|
selectedAddress,
|
|
rpcPrefs,
|
|
);
|
|
|
|
const blockExplorerLinkClickedEvent = useNewMetricEvent({
|
|
category: 'Navigation',
|
|
event: 'Clicked Block Explorer Link',
|
|
properties: {
|
|
link_type: 'Token Tracker',
|
|
action: 'Token Options',
|
|
block_explorer_domain: getURLHostName(tokenTrackerLink),
|
|
},
|
|
});
|
|
|
|
return (
|
|
<>
|
|
<AssetNavigation
|
|
accountName={selectedAccountName}
|
|
assetName={token.symbol}
|
|
onBack={() => history.push(DEFAULT_ROUTE)}
|
|
optionsButton={
|
|
<AssetOptions
|
|
onRemove={() =>
|
|
dispatch(
|
|
showModal({ name: 'HIDE_TOKEN_CONFIRMATION', token, history }),
|
|
)
|
|
}
|
|
isEthNetwork={!rpcPrefs.blockExplorerUrl}
|
|
onClickBlockExplorer={() => {
|
|
blockExplorerLinkClickedEvent();
|
|
global.platform.openTab({ url: tokenTrackerLink });
|
|
}}
|
|
onViewAccountDetails={() => {
|
|
dispatch(showModal({ name: 'ACCOUNT_DETAILS' }));
|
|
}}
|
|
onViewTokenDetails={() => {
|
|
dispatch(
|
|
updateSendAsset({
|
|
type: ASSET_TYPES.TOKEN,
|
|
details: { ...token },
|
|
}),
|
|
).then(() => {
|
|
history.push(TOKEN_DETAILS);
|
|
});
|
|
}}
|
|
tokenSymbol={token.symbol}
|
|
/>
|
|
}
|
|
/>
|
|
<TokenOverview className="asset__overview" token={token} />
|
|
<TransactionList tokenAddress={token.address} />
|
|
</>
|
|
);
|
|
}
|
|
|
|
TokenAsset.propTypes = {
|
|
token: PropTypes.shape({
|
|
address: PropTypes.string.isRequired,
|
|
decimals: PropTypes.number,
|
|
symbol: PropTypes.string,
|
|
}).isRequired,
|
|
};
|