diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-11-03 05:38:18 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-11-03 05:38:18 +0800 |
commit | d5521ea5e09f5a42471335b856989751b90184dc (patch) | |
tree | c612141ef0b2101fdfe117d5944c143ae74e7c52 /packages/instant/src/containers/selected_erc20_asset_amount_input.ts | |
parent | cc4ccda6232af470b96950a37fa1d0f4b4ef7f3a (diff) | |
parent | 6a57a7b5be151114bb06c171560976b09a8c4aa1 (diff) | |
download | dexon-sol-tools-d5521ea5e09f5a42471335b856989751b90184dc.tar dexon-sol-tools-d5521ea5e09f5a42471335b856989751b90184dc.tar.gz dexon-sol-tools-d5521ea5e09f5a42471335b856989751b90184dc.tar.bz2 dexon-sol-tools-d5521ea5e09f5a42471335b856989751b90184dc.tar.lz dexon-sol-tools-d5521ea5e09f5a42471335b856989751b90184dc.tar.xz dexon-sol-tools-d5521ea5e09f5a42471335b856989751b90184dc.tar.zst dexon-sol-tools-d5521ea5e09f5a42471335b856989751b90184dc.zip |
Merge branch 'development' of https://github.com/0xProject/0x-monorepo into feature/instant/maker-asset-datas-interface
Diffstat (limited to 'packages/instant/src/containers/selected_erc20_asset_amount_input.ts')
-rw-r--r-- | packages/instant/src/containers/selected_erc20_asset_amount_input.ts | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/packages/instant/src/containers/selected_erc20_asset_amount_input.ts b/packages/instant/src/containers/selected_erc20_asset_amount_input.ts index 64b6f4b3b..99999ee14 100644 --- a/packages/instant/src/containers/selected_erc20_asset_amount_input.ts +++ b/packages/instant/src/containers/selected_erc20_asset_amount_input.ts @@ -6,12 +6,13 @@ import * as _ from 'lodash'; import * as React from 'react'; import { connect } from 'react-redux'; import { Dispatch } from 'redux'; +import { oc } from 'ts-optchain'; import { ERC20AssetAmountInput } from '../components/erc20_asset_amount_input'; import { Action, actions } from '../redux/actions'; import { State } from '../redux/reducer'; import { ColorOption } from '../style/theme'; -import { ERC20Asset, OrderProcessState } from '../types'; +import { AffiliateInfo, ERC20Asset, OrderProcessState } from '../types'; import { assetUtils } from '../util/asset'; import { BigNumberInput } from '../util/big_number_input'; import { errorFlasher } from '../util/error_flasher'; @@ -28,10 +29,16 @@ interface ConnectedState { asset?: ERC20Asset; isDisabled: boolean; numberOfAssetsAvailable?: number; + affiliateInfo?: AffiliateInfo; } interface ConnectedDispatch { - updateBuyQuote: (assetBuyer?: AssetBuyer, value?: BigNumberInput, asset?: ERC20Asset) => void; + updateBuyQuote: ( + assetBuyer?: AssetBuyer, + value?: BigNumberInput, + asset?: ERC20Asset, + affiliateInfo?: AffiliateInfo, + ) => void; } interface ConnectedProps { @@ -59,6 +66,7 @@ const mapStateToProps = (state: State, _ownProps: SelectedERC20AssetAmountInputP asset: selectedAsset, isDisabled, numberOfAssetsAvailable, + affiliateInfo: state.affiliateInfo, }; }; @@ -67,6 +75,7 @@ const updateBuyQuoteAsync = async ( dispatch: Dispatch<Action>, asset: ERC20Asset, assetAmount: BigNumber, + affiliateInfo?: AffiliateInfo, ): Promise<void> => { // get a new buy quote. const baseUnitValue = Web3Wrapper.toBaseUnitAmount(assetAmount, asset.metaData.decimals); @@ -74,9 +83,10 @@ const updateBuyQuoteAsync = async ( // mark quote as pending dispatch(actions.setQuoteRequestStatePending()); + const feePercentage = oc(affiliateInfo).feePercentage(); let newBuyQuote: BuyQuote | undefined; try { - newBuyQuote = await assetBuyer.getBuyQuoteAsync(asset.assetData, baseUnitValue); + newBuyQuote = await assetBuyer.getBuyQuoteAsync(asset.assetData, baseUnitValue, { feePercentage }); } catch (error) { dispatch(actions.setQuoteRequestStateFailure()); let errorMessage; @@ -92,7 +102,11 @@ const updateBuyQuoteAsync = async ( const assetName = assetUtils.bestNameForAsset(asset, 'This asset'); errorMessage = `${assetName} is currently unavailable`; } - errorFlasher.flashNewErrorMessage(dispatch, errorMessage); + if (!_.isUndefined(errorMessage)) { + errorFlasher.flashNewErrorMessage(dispatch, errorMessage); + } else { + throw error; + } return; } // We have a successful new buy quote @@ -107,19 +121,19 @@ const mapDispatchToProps = ( dispatch: Dispatch<Action>, _ownProps: SelectedERC20AssetAmountInputProps, ): ConnectedDispatch => ({ - updateBuyQuote: (assetBuyer, value, asset) => { + updateBuyQuote: (assetBuyer, value, asset, affiliateInfo) => { // Update the input dispatch(actions.updateSelectedAssetAmount(value)); // invalidate the last buy quote. dispatch(actions.updateLatestBuyQuote(undefined)); // reset our buy state - dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.NONE })); + dispatch(actions.setBuyOrderStateNone()); - if (!_.isUndefined(value) && !_.isUndefined(asset) && !_.isUndefined(assetBuyer)) { + if (!_.isUndefined(value) && value.greaterThan(0) && !_.isUndefined(asset) && !_.isUndefined(assetBuyer)) { // even if it's debounced, give them the illusion it's loading dispatch(actions.setQuoteRequestStatePending()); // tslint:disable-next-line:no-floating-promises - debouncedUpdateBuyQuoteAsync(assetBuyer, dispatch, asset, value); + debouncedUpdateBuyQuoteAsync(assetBuyer, dispatch, asset, value, affiliateInfo); } }, }); @@ -134,7 +148,7 @@ const mergeProps = ( asset: connectedState.asset, value: connectedState.value, onChange: (value, asset) => { - connectedDispatch.updateBuyQuote(connectedState.assetBuyer, value, asset); + connectedDispatch.updateBuyQuote(connectedState.assetBuyer, value, asset, connectedState.affiliateInfo); }, isDisabled: connectedState.isDisabled, numberOfAssetsAvailable: connectedState.numberOfAssetsAvailable, |