aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/components/asset_button.tsx
blob: 4ae7a27040ab8ac91e3ec6e0123e00669a2963ad (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
48
49
50
51
import { AssetBuyer, BuyQuote } from '@0x/asset-buyer';
import * as React from 'react';

import { AsyncProcessState } from '../types';

// TODO: better name?

import { BuyButton } from './buy_button';
import { RetryButton } from './retry_button';
import { Container } from './ui';

// TODO: split into sepearte components? getting really big..
interface AssetButtonProps {
    assetBuyer?: AssetBuyer;
    buyQuote?: BuyQuote;
    buyOrderState: AsyncProcessState;
    onBuyClick: (buyQuote: BuyQuote) => void;
    onBuySuccess: (buyQuote: BuyQuote) => void;
    onBuyFailure: (buyQuote: BuyQuote) => void;
    onRetryClick: () => void;
}

export class AssetButton extends React.Component<AssetButtonProps, {}> {
    public render(): React.ReactNode {
        return (
            <Container padding="20px" width="100%">
                {this._renderButton()}
            </Container>
        );
    }
    private _renderButton(): React.ReactNode {
        // TODO: figure out why buyOrderState is undefined in beginning, get rid of default
        switch (this.props.buyOrderState) {
            case AsyncProcessState.FAILURE:
                return <RetryButton onClick={this.props.onRetryClick} />;
            case AsyncProcessState.SUCCESS:
                return <div />;
            default:
                return (
                    <BuyButton
                        buyQuote={this.props.buyQuote}
                        assetBuyer={this.props.assetBuyer}
                        onClick={this.props.onBuyClick}
                        onBuySuccess={this.props.onBuySuccess}
                        onBuyFailure={this.props.onBuyFailure}
                        text={'Buy'}
                    />
                );
        }
    }
}