diff options
author | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-10-27 03:43:44 +0800 |
---|---|---|
committer | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-10-27 03:43:44 +0800 |
commit | 9512978de9aee1953930d4f16a105ec5ef7f048e (patch) | |
tree | 64758b2ed21ad734f23c8d764b17d2f48abcb716 /packages/instant/src/containers | |
parent | ffecba21f4e9dcda961a3e8432e70e6605174de5 (diff) | |
download | dexon-0x-contracts-9512978de9aee1953930d4f16a105ec5ef7f048e.tar.gz dexon-0x-contracts-9512978de9aee1953930d4f16a105ec5ef7f048e.tar.zst dexon-0x-contracts-9512978de9aee1953930d4f16a105ec5ef7f048e.zip |
feat(instant): Show message if user doesn't have enough ETH
Diffstat (limited to 'packages/instant/src/containers')
-rw-r--r-- | packages/instant/src/containers/selected_asset_amount_input.ts | 14 |
1 files changed, 13 insertions, 1 deletions
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 }); |