aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline/src/parsers/token_metadata/index.ts
blob: f258af06358ccd5e1c6d8b115a7f728802889d25 (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
import { BigNumber } from '@0x/utils';
import * as R from 'ramda';

import { MetamaskTrustedTokenMeta, ZeroExTrustedTokenMeta } from '../../data_sources/trusted_tokens';
import { TokenMetadata } from '../../entities';
import {} from '../../utils';

/**
 * Parses Metamask's trusted tokens list.
 * @param rawResp raw response from the metamask json file.
 */
export function parseMetamaskTrustedTokens(rawResp: Map<string, MetamaskTrustedTokenMeta>): TokenMetadata[] {
    const parsedAsObject = R.mapObjIndexed(parseMetamaskTrustedToken, rawResp);
    return R.values(parsedAsObject);
}

/**
 * Parses 0x's trusted tokens list.
 * @param rawResp raw response from the 0x trusted tokens file.
 */
export function parseZeroExTrustedTokens(rawResp: ZeroExTrustedTokenMeta[]): TokenMetadata[] {
    return R.map(parseZeroExTrustedToken, rawResp);
}

function parseMetamaskTrustedToken(resp: MetamaskTrustedTokenMeta, address: string): TokenMetadata {
    const trustedToken = new TokenMetadata();

    trustedToken.address = address;
    trustedToken.decimals = new BigNumber(resp.decimals);
    trustedToken.symbol = resp.symbol;
    trustedToken.name = resp.name;
    trustedToken.authority = 'metamask';

    return trustedToken;
}

function parseZeroExTrustedToken(resp: ZeroExTrustedTokenMeta): TokenMetadata {
    const trustedToken = new TokenMetadata();

    trustedToken.address = resp.address;
    trustedToken.decimals = resp.decimals ? new BigNumber(resp.decimals) : null;
    trustedToken.symbol = resp.symbol;
    trustedToken.name = resp.name;
    trustedToken.authority = '0x';

    return trustedToken;
}