aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util/etherscan.ts
blob: 4d62c4d9f02dbcfa5295d0238d4112a7bf20161e (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
import * as _ from 'lodash';

import { Network } from '../types';

const etherscanPrefix = (networkId: number): string | undefined => {
    switch (networkId) {
        case Network.Kovan:
            return 'kovan.';
        case Network.Mainnet:
            return '';
        default:
            return undefined;
    }
};

export const etherscanUtil = {
    getEtherScanTxnAddressIfExists: (txHash: string, networkId: number) => {
        const prefix = etherscanPrefix(networkId);
        if (_.isUndefined(prefix)) {
            return;
        }
        return `https://${prefix}etherscan.io/tx/${txHash}`;
    },
    getEtherScanEthAddressIfExists: (ethAddress: string, networkId: number) => {
        const prefix = etherscanPrefix(networkId);
        if (_.isUndefined(prefix)) {
            return;
        }
        return `https://${prefix}etherscan.io/address/${ethAddress}`;
    },
};