aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/components/asset_button.tsx
blob: 84a27303d94dbdd771e4c87ce8b4a3e81c891393 (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
52
53
54
55
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';

interface AssetButtonProps {
    assetBuyer?: AssetBuyer;
    buyQuote?: BuyQuote;
    buyOrderState: AsyncProcessState;
    onBuyClick: (buyQuote: BuyQuote) => void;
    onBuySuccess: (buyQuote: BuyQuote) => void;
    onBuyFailure: (buyQuote: BuyQuote) => 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={() => {
                            console.log('try again');
                        }}
                    />
                );
            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'}
                    />
                );
        }
    }
}