aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/utils/simple_erc20_balance_and_allowance_fetcher.ts
blob: 6eed9227a59d8bf876d81f025be2053581da919b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { AbstractBalanceAndProxyAllowanceFetcher } from '@0xproject/order-utils';
import { BigNumber } from '@0xproject/utils';

import { ERC20Wrapper } from './erc20_wrapper';

// TODO(fabio): Refactor this to also work for ERC721!
export class SimpleERC20BalanceAndProxyAllowanceFetcher implements AbstractBalanceAndProxyAllowanceFetcher {
    private _erc20TokenWrapper: ERC20Wrapper;
    constructor(erc20TokenWrapper: ERC20Wrapper) {
        this._erc20TokenWrapper = erc20TokenWrapper;
    }
    public async getBalanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber> {
        const balance = await this._erc20TokenWrapper.getBalanceAsync(userAddress, tokenAddress);
        return balance;
    }
    public async getProxyAllowanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber> {
        const proxyAllowance = await this._erc20TokenWrapper.getProxyAllowanceAsync(userAddress, tokenAddress);
        return proxyAllowance;
    }
}