import { colors, EtherscanLinkSuffixes, Styles, utils as sharedUtils } from '@0xproject/react-shared'; import * as _ from 'lodash'; import * as React from 'react'; import { TokenIcon } from 'ts/components/ui/token_icon'; import { WebsiteBackendTokenInfo } from 'ts/types'; export interface TopTokensProps { tokens: WebsiteBackendTokenInfo[]; networkId: number; } const styles: Styles = { tokenLabel: { textDecoration: 'none', color: colors.mediumBlue, }, followingTokenLabel: { paddingLeft: 16, }, }; export const TopTokens: React.StatelessComponent = (props: TopTokensProps) => { return (
{_.map(props.tokens, (tokenInfo: WebsiteBackendTokenInfo, index: number) => { const firstItemStyle = { ...styles.tokenLabel, ...styles.followingTokenLabel }; const style = index !== 0 ? firstItemStyle : styles.tokenLabel; return ; })}
); }; interface TokenLinkProps { tokenInfo: WebsiteBackendTokenInfo; style: React.CSSProperties; networkId: number; } interface TokenLinkState { isHovering: boolean; } class TokenLink extends React.Component { constructor(props: TokenLinkProps) { super(props); this.state = { isHovering: false, }; } public render(): React.ReactNode { const style = { ...this.props.style, cursor: 'pointer', opacity: this.state.isHovering ? 0.5 : 1, }; return ( {this.props.tokenInfo.symbol} ); } private _onToggleHover(isHovering: boolean): void { this.setState({ isHovering, }); } } function tokenLinkFromToken(tokenInfo: WebsiteBackendTokenInfo, networkId: number): string { return sharedUtils.getEtherScanLinkIfExists(tokenInfo.address, networkId, EtherscanLinkSuffixes.Address); }