From 9512978de9aee1953930d4f16a105ec5ef7f048e Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Fri, 26 Oct 2018 12:43:44 -0700 Subject: feat(instant): Show message if user doesn't have enough ETH --- .../instant/src/containers/selected_asset_amount_input.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'packages/instant/src/containers') diff --git a/packages/instant/src/containers/selected_asset_amount_input.ts b/packages/instant/src/containers/selected_asset_amount_input.ts index e9dbc61ce..504f51535 100644 --- a/packages/instant/src/containers/selected_asset_amount_input.ts +++ b/packages/instant/src/containers/selected_asset_amount_input.ts @@ -10,11 +10,15 @@ import { Dispatch } from 'redux'; import { Action, actions } from '../redux/actions'; import { State } from '../redux/reducer'; import { ColorOption } from '../style/theme'; -import { ERC20Asset, OrderProcessState } from '../types'; +import { ERC20Asset, OrderProcessState, ZeroExInstantError } from '../types'; +import { getBestAddress } from '../util/address'; import { errorUtil } from '../util/error'; +import { web3Wrapper } from '../util/web3_wrapper'; import { AssetAmountInput } from '../components/asset_amount_input'; +import { ETH_DECIMALS } from '../constants'; + export interface SelectedAssetAmountInputProps { fontColor?: ColorOption; fontSize?: string; @@ -76,6 +80,14 @@ const updateBuyQuoteAsync = async ( errorUtil.errorFlasher.clearError(dispatch); // invalidate the last buy quote. dispatch(actions.updateLatestBuyQuote(newBuyQuote)); + + // set error if user doesn't have appropriate balance + const takerAddress = await getBestAddress(); + const balanceWei = await web3Wrapper.getBalanceInWeiAsync(takerAddress); + if (balanceWei < newBuyQuote.worstCaseQuoteInfo.totalEthAmount) { + const balanceError = new Error(ZeroExInstantError.InsufficientBalance); + errorUtil.errorFlasher.flashNewError(dispatch, balanceError); + } }; const debouncedUpdateBuyQuoteAsync = _.debounce(updateBuyQuoteAsync, 200, { trailing: true }); -- cgit v1.2.3