aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/components/relayer_index/relayer_top_tokens.tsx
blob: f3787bd272c3c0fffa255187f9218a28f7ac727c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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<TopTokensProps> = (props: TopTokensProps) => {
    return (
        <div className="flex">
            {_.map(props.tokens, (tokenInfo: WebsiteBackendTokenInfo) => {
                return (
                    <Container key={tokenInfo.address} marginRight="16px">
                        <TokenLink tokenInfo={tokenInfo} networkId={props.networkId} />
                    </Container>
                );
            })}
        </div>
    );
};

interface TokenLinkProps {
    tokenInfo: WebsiteBackendTokenInfo;
    networkId: number;
}
interface TokenLinkState {}

class TokenLink extends React.Component<TokenLinkProps, TokenLinkState> {
    constructor(props: TokenLinkProps) {
        super(props);
        this.state = {
            isHovering: false,
        };
    }
    public render(): React.ReactNode {
        const onClick = (event: React.MouseEvent<HTMLElement>) => {
            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 (
            <Text fontSize="14px" fontColor={colors.mediumBlue} onClick={onClick}>
                {this.props.tokenInfo.symbol}
            </Text>
        );
    }
    private _tokenLinkFromToken(tokenInfo: WebsiteBackendTokenInfo, networkId: number): string {
        return sharedUtils.getEtherScanLinkIfExists(tokenInfo.address, networkId, EtherscanLinkSuffixes.Address);
    }
}