diff options
author | Jake Ellowitz <jake.ellowitz@gmail.com> | 2018-11-20 11:11:51 +0800 |
---|---|---|
committer | Alex Browne <stephenalexbrowne@gmail.com> | 2018-12-05 06:24:48 +0800 |
commit | dea89c4e221d5b22de97b27573719cd27ce250c7 (patch) | |
tree | 8bb98513d90e6759d57f20d2d458625d4b68dc80 /packages/pipeline/src/parsers/token_metadata | |
parent | c6af5131b0b06433d6294260274e187ad61f4ef7 (diff) | |
download | dexon-sol-tools-dea89c4e221d5b22de97b27573719cd27ce250c7.tar dexon-sol-tools-dea89c4e221d5b22de97b27573719cd27ce250c7.tar.gz dexon-sol-tools-dea89c4e221d5b22de97b27573719cd27ce250c7.tar.bz2 dexon-sol-tools-dea89c4e221d5b22de97b27573719cd27ce250c7.tar.lz dexon-sol-tools-dea89c4e221d5b22de97b27573719cd27ce250c7.tar.xz dexon-sol-tools-dea89c4e221d5b22de97b27573719cd27ce250c7.tar.zst dexon-sol-tools-dea89c4e221d5b22de97b27573719cd27ce250c7.zip |
metadata and trusted sources in same raw table
Diffstat (limited to 'packages/pipeline/src/parsers/token_metadata')
-rw-r--r-- | packages/pipeline/src/parsers/token_metadata/index.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/packages/pipeline/src/parsers/token_metadata/index.ts b/packages/pipeline/src/parsers/token_metadata/index.ts new file mode 100644 index 000000000..d09def0db --- /dev/null +++ b/packages/pipeline/src/parsers/token_metadata/index.ts @@ -0,0 +1,47 @@ +import * as R from 'ramda'; + +import { MetamaskTrustedTokenMeta, ZeroExTrustedTokenMeta } from '../../data_sources/trusted_tokens'; +import { TokenMetadata } from '../../entities'; + +/** + * 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 json 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 = 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; + trustedToken.symbol = resp.symbol; + trustedToken.name = resp.name; + trustedToken.authority = '0x'; + + return trustedToken; +} |