diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-10-11 09:27:06 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-10-11 09:28:12 +0800 |
commit | 19f61906d3075391efb32c17c99c2cba1f7a3858 (patch) | |
tree | 5341adb545f8cbc883f3e569adf99b58a8b03de1 /packages/instant/src/containers/selected_asset_buy_button.ts | |
parent | a5a033c359a1a00a144ae0655080b4e6d0e43c88 (diff) | |
download | dexon-sol-tools-19f61906d3075391efb32c17c99c2cba1f7a3858.tar dexon-sol-tools-19f61906d3075391efb32c17c99c2cba1f7a3858.tar.gz dexon-sol-tools-19f61906d3075391efb32c17c99c2cba1f7a3858.tar.bz2 dexon-sol-tools-19f61906d3075391efb32c17c99c2cba1f7a3858.tar.lz dexon-sol-tools-19f61906d3075391efb32c17c99c2cba1f7a3858.tar.xz dexon-sol-tools-19f61906d3075391efb32c17c99c2cba1f7a3858.tar.zst dexon-sol-tools-19f61906d3075391efb32c17c99c2cba1f7a3858.zip |
feat: Move over features from zrx-buyer
Diffstat (limited to 'packages/instant/src/containers/selected_asset_buy_button.ts')
-rw-r--r-- | packages/instant/src/containers/selected_asset_buy_button.ts | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/packages/instant/src/containers/selected_asset_buy_button.ts b/packages/instant/src/containers/selected_asset_buy_button.ts new file mode 100644 index 000000000..f537294e4 --- /dev/null +++ b/packages/instant/src/containers/selected_asset_buy_button.ts @@ -0,0 +1,59 @@ +import { BuyQuote } from '@0xproject/asset-buyer'; +import * as _ from 'lodash'; +import * as React from 'react'; +import { connect } from 'react-redux'; +import { Dispatch } from 'redux'; + +import { State } from '../redux/reducer'; +import { Action, ActionTypes, AsyncProcessState } from '../types'; +import { assetBuyer } from '../util/asset_buyer'; +import { web3Wrapper } from '../util/web3_wrapper'; + +import { BuyButton } from '../components/buy_button'; + +export interface SelectedAssetBuyButtonProps {} + +interface ConnectedState { + text: string; + buyQuote?: BuyQuote; +} + +interface ConnectedDispatch { + onClick: (buyQuote: BuyQuote) => void; + onBuySuccess: (buyQuote: BuyQuote) => void; + onBuyFailure: (buyQuote: BuyQuote) => void; +} + +const textForState = (state: AsyncProcessState): string => { + switch (state) { + case AsyncProcessState.NONE: + return 'Buy'; + case AsyncProcessState.PENDING: + return '...Loading'; + case AsyncProcessState.SUCCESS: + return 'Success!'; + case AsyncProcessState.FAILURE: + return 'Failed'; + default: + return 'Buy'; + } +}; + +const mapStateToProps = (state: State, _ownProps: SelectedAssetBuyButtonProps): ConnectedState => ({ + text: textForState(state.selectedAssetBuyState), + buyQuote: state.latestBuyQuote, +}); + +const mapDispatchToProps = (dispatch: Dispatch<Action>, ownProps: SelectedAssetBuyButtonProps): ConnectedDispatch => ({ + onClick: buyQuote => + dispatch({ type: ActionTypes.UPDATE_SELECTED_ASSET_BUY_STATE, data: AsyncProcessState.PENDING }), + onBuySuccess: buyQuote => + dispatch({ type: ActionTypes.UPDATE_SELECTED_ASSET_BUY_STATE, data: AsyncProcessState.SUCCESS }), + onBuyFailure: buyQuote => + dispatch({ type: ActionTypes.UPDATE_SELECTED_ASSET_BUY_STATE, data: AsyncProcessState.FAILURE }), +}); + +export const SelectedAssetBuyButton: React.ComponentClass<SelectedAssetBuyButtonProps> = connect( + mapStateToProps, + mapDispatchToProps, +)(BuyButton); |