aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/test/utils/token_utils.ts
blob: 9c20f52a141141442c3e99b9b15a64fd66c381a1 (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
import * as _ from 'lodash';

import {InternalZeroExError, Token} from '../../src/types';

const PROTOCOL_TOKEN_SYMBOL = 'ZRX';

export class TokenUtils {
    private tokens: Token[];
    constructor(tokens: Token[]) {
        this.tokens = tokens;
    }
    public getProtocolTokenOrThrow(): Token {
        const zrxToken = _.find(this.tokens, {symbol: PROTOCOL_TOKEN_SYMBOL});
        if (_.isUndefined(zrxToken)) {
            throw new Error(InternalZeroExError.ZrxNotInTokenRegistry);
        }
        return zrxToken;
    }
    public getNonProtocolTokens(): Token[] {
        const nonProtocolTokens = _.filter(this.tokens, token => {
            return token.symbol !== PROTOCOL_TOKEN_SYMBOL;
        });
        return nonProtocolTokens;
    }
}