aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/components/asset_amount_input.tsx
blob: 9f4b5861a3fcb03ff24a00e1dd833a93b28624de (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
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import * as React from 'react';
import { oc } from 'ts-optchain';

import { ColorOption } from '../style/theme';
import { ERC20Asset } from '../types';
import { util } from '../util/util';

import { AmountInput, AmountInputProps } from './amount_input';
import { Container, Text } from './ui';

// Asset amounts only apply to ERC20 assets
export interface AssetAmountInputProps extends AmountInputProps {
    asset?: ERC20Asset;
    onChange: (value?: BigNumber, asset?: ERC20Asset) => void;
}

export class AssetAmountInput extends React.Component<AssetAmountInputProps> {
    public static defaultProps = {
        onChange: util.boundNoop,
    };
    public render(): React.ReactNode {
        const { asset, onChange, ...rest } = this.props;
        return (
            <Container>
                <AmountInput {...rest} onChange={this._handleChange} />
                <Container display="inline-block" marginLeft="10px">
                    <Text fontSize={rest.fontSize} fontColor={ColorOption.white} textTransform="uppercase">
                        {oc(asset).metaData.symbol()}
                    </Text>
                </Container>
            </Container>
        );
    }
    private readonly _handleChange = (value?: BigNumber): void => {
        this.props.onChange(value, this.props.asset);
    };
}