diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-11-09 08:09:38 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-11-09 08:09:38 +0800 |
commit | 211163b3724090347dba736cbcdcb2b1ec252bd0 (patch) | |
tree | 80f3b8e23daba4a12e4afc55d7a345678ca04795 /packages/instant/src/containers | |
parent | c84e163edb329b478749cad09f222cc12e3698fe (diff) | |
parent | 117e2f583ff44bdb63340a2134edea0f3ecb77b3 (diff) | |
download | dexon-sol-tools-211163b3724090347dba736cbcdcb2b1ec252bd0.tar dexon-sol-tools-211163b3724090347dba736cbcdcb2b1ec252bd0.tar.gz dexon-sol-tools-211163b3724090347dba736cbcdcb2b1ec252bd0.tar.bz2 dexon-sol-tools-211163b3724090347dba736cbcdcb2b1ec252bd0.tar.lz dexon-sol-tools-211163b3724090347dba736cbcdcb2b1ec252bd0.tar.xz dexon-sol-tools-211163b3724090347dba736cbcdcb2b1ec252bd0.tar.zst dexon-sol-tools-211163b3724090347dba736cbcdcb2b1ec252bd0.zip |
Merge branch 'development' into feature/instant/account-state-change
* development:
[instant] Viewport specific errors (#1228)
Added more comments
Include wholeNumberSchema in sra-spec schemas
chore(instant): fix linter
Fix isNode
fix(instant): update buy quote at start up in the case of default amount
fix: apply css reset to overlay as well
fix(website): turn off production flag when building locally
chore: linter
fix: progress bar
fix: use fontSize prop in button
feat: make instant resistant to external styles
feat: add faux externall css file
Add upstream issue
Use const require instead of import
Fix tslint issues
Use detect-node
Set curstom inspect printer in BigNumber
Diffstat (limited to 'packages/instant/src/containers')
-rw-r--r-- | packages/instant/src/containers/selected_erc20_asset_amount_input.ts | 56 |
1 files changed, 5 insertions, 51 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 784eb4bd0..c550aef04 100644 --- a/packages/instant/src/containers/selected_erc20_asset_amount_input.ts +++ b/packages/instant/src/containers/selected_erc20_asset_amount_input.ts @@ -1,20 +1,17 @@ -import { AssetBuyer, AssetBuyerError, BuyQuote } from '@0x/asset-buyer'; +import { AssetBuyer } from '@0x/asset-buyer'; import { AssetProxyId } from '@0x/types'; import { BigNumber } from '@0x/utils'; -import { Web3Wrapper } from '@0x/web3-wrapper'; 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 { AffiliateInfo, ERC20Asset, OrderProcessState } from '../types'; -import { assetUtils } from '../util/asset'; -import { errorFlasher } from '../util/error_flasher'; +import { buyQuoteUpdater } from '../util/buy_quote_updater'; export interface SelectedERC20AssetAmountInputProps { fontColor?: ColorOption; @@ -70,52 +67,9 @@ const mapStateToProps = (state: State, _ownProps: SelectedERC20AssetAmountInputP }; }; -const updateBuyQuoteAsync = async ( - assetBuyer: AssetBuyer, - dispatch: Dispatch<Action>, - asset: ERC20Asset, - assetAmount: BigNumber, - affiliateInfo?: AffiliateInfo, -): Promise<void> => { - // get a new buy quote. - const baseUnitValue = Web3Wrapper.toBaseUnitAmount(assetAmount, asset.metaData.decimals); - - // mark quote as pending - dispatch(actions.setQuoteRequestStatePending()); - - const feePercentage = oc(affiliateInfo).feePercentage(); - let newBuyQuote: BuyQuote | undefined; - try { - newBuyQuote = await assetBuyer.getBuyQuoteAsync(asset.assetData, baseUnitValue, { feePercentage }); - } catch (error) { - dispatch(actions.setQuoteRequestStateFailure()); - let errorMessage; - if (error.message === AssetBuyerError.InsufficientAssetLiquidity) { - const assetName = assetUtils.bestNameForAsset(asset, 'of this asset'); - errorMessage = `Not enough ${assetName} available`; - } else if (error.message === AssetBuyerError.InsufficientZrxLiquidity) { - errorMessage = 'Not enough ZRX available'; - } else if ( - error.message === AssetBuyerError.StandardRelayerApiError || - error.message.startsWith(AssetBuyerError.AssetUnavailable) - ) { - const assetName = assetUtils.bestNameForAsset(asset, 'This asset'); - errorMessage = `${assetName} is currently unavailable`; - } - if (!_.isUndefined(errorMessage)) { - errorFlasher.flashNewErrorMessage(dispatch, errorMessage); - } else { - throw error; - } - return; - } - // We have a successful new buy quote - errorFlasher.clearError(dispatch); - // invalidate the last buy quote. - dispatch(actions.updateLatestBuyQuote(newBuyQuote)); -}; - -const debouncedUpdateBuyQuoteAsync = _.debounce(updateBuyQuoteAsync, 200, { trailing: true }); +const debouncedUpdateBuyQuoteAsync = _.debounce(buyQuoteUpdater.updateBuyQuoteAsync.bind(buyQuoteUpdater), 200, { + trailing: true, +}); const mapDispatchToProps = ( dispatch: Dispatch<Action>, |