aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant
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
parentffecba21f4e9dcda961a3e8432e70e6605174de5 (diff)
downloaddexon-sol-tools-9512978de9aee1953930d4f16a105ec5ef7f048e.tar
dexon-sol-tools-9512978de9aee1953930d4f16a105ec5ef7f048e.tar.gz
dexon-sol-tools-9512978de9aee1953930d4f16a105ec5ef7f048e.tar.bz2
dexon-sol-tools-9512978de9aee1953930d4f16a105ec5ef7f048e.tar.lz
dexon-sol-tools-9512978de9aee1953930d4f16a105ec5ef7f048e.tar.xz
dexon-sol-tools-9512978de9aee1953930d4f16a105ec5ef7f048e.tar.zst
dexon-sol-tools-9512978de9aee1953930d4f16a105ec5ef7f048e.zip
feat(instant): Show message if user doesn't have enough ETH
Diffstat (limited to 'packages/instant')
-rw-r--r--packages/instant/src/containers/selected_asset_amount_input.ts14
-rw-r--r--packages/instant/src/types.ts1
-rw-r--r--packages/instant/src/util/address.ts6
-rw-r--r--packages/instant/src/util/error.ts5
4 files changed, 24 insertions, 2 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 });
diff --git a/packages/instant/src/types.ts b/packages/instant/src/types.ts
index c63371fb4..174ad86e6 100644
--- a/packages/instant/src/types.ts
+++ b/packages/instant/src/types.ts
@@ -72,4 +72,5 @@ export enum Network {
export enum ZeroExInstantError {
AssetMetaDataNotAvailable = 'ASSET_META_DATA_NOT_AVAILABLE',
+ InsufficientBalance = 'INSUFFICIENT_BALANCE',
}
diff --git a/packages/instant/src/util/address.ts b/packages/instant/src/util/address.ts
new file mode 100644
index 000000000..97ed30a00
--- /dev/null
+++ b/packages/instant/src/util/address.ts
@@ -0,0 +1,6 @@
+import { web3Wrapper } from '../util/web3_wrapper';
+
+export const getBestAddress = async (): Promise<string> => {
+ const addresses = await web3Wrapper.getAvailableAddressesAsync();
+ return addresses[0];
+};
diff --git a/packages/instant/src/util/error.ts b/packages/instant/src/util/error.ts
index 64c1f4885..5db0c66d2 100644
--- a/packages/instant/src/util/error.ts
+++ b/packages/instant/src/util/error.ts
@@ -2,7 +2,7 @@ import { AssetBuyerError } from '@0x/asset-buyer';
import { Dispatch } from 'redux';
import { Action, actions } from '../redux/actions';
-import { Asset } from '../types';
+import { Asset, ZeroExInstantError } from '../types';
import { assetUtils } from './asset';
@@ -49,6 +49,9 @@ const humanReadableMessageForError = (error: Error, asset?: Asset): string | und
if (error.message === AssetBuyerError.SignatureRequestDenied) {
return 'You denied this transaction';
}
+ if (error.message === ZeroExInstantError.InsufficientBalance) {
+ return "You don't have enough ETH";
+ }
return undefined;
};