import { colors, EtherscanLinkSuffixes, utils as sharedUtils } from '@0xproject/react-shared'; import * as _ from 'lodash'; import * as React from 'react'; import { Container } from 'ts/components/ui/container'; import { Text } from 'ts/components/ui/text'; import { WebsiteBackendTokenInfo } from 'ts/types'; import { analytics } from 'ts/utils/analytics'; import { utils } from 'ts/utils/utils'; export interface TopTokensProps { tokens: WebsiteBackendTokenInfo[]; networkId: number; } export const TopTokens: React.StatelessComponent = (props: TopTokensProps) => { return (
{_.map(props.tokens, (tokenInfo: WebsiteBackendTokenInfo) => { return ( ); })}
); }; interface TokenLinkProps { tokenInfo: WebsiteBackendTokenInfo; networkId: number; } interface TokenLinkState {} class TokenLink extends React.Component { constructor(props: TokenLinkProps) { super(props); this.state = { isHovering: false, }; } public render(): React.ReactNode { const onClick = (event: React.MouseEvent) => { event.stopPropagation(); analytics.track('Token Click', { tokenSymbol: this.props.tokenInfo.symbol, }); const tokenLink = this._tokenLinkFromToken(this.props.tokenInfo, this.props.networkId); utils.openUrl(tokenLink); }; return ( {this.props.tokenInfo.symbol} ); } private _tokenLinkFromToken(tokenInfo: WebsiteBackendTokenInfo, networkId: number): string { return sharedUtils.getEtherScanLinkIfExists(tokenInfo.address, networkId, EtherscanLinkSuffixes.Address); } }