aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/containers
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-10-27 03:43:44 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-10-27 03:43:44 +0800
commit9512978de9aee1953930d4f16a105ec5ef7f048e (patch)
tree64758b2ed21ad734f23c8d764b17d2f48abcb716 /packages/instant/src/containers
parentffecba21f4e9dcda961a3e8432e70e6605174de5 (diff)
downloaddexon-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.ts14
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 });