From ff295daa5c56b5c056a5faa5ca8875c317524070 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Fri, 26 Oct 2018 19:53:15 -0700 Subject: Simpler way of validaitng has enough eth --- .../selected_asset_buy_order_state_buttons.ts | 20 +++++++++++--------- .../containers/selected_erc20_asset_amount_input.ts | 4 ---- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'packages/instant/src/containers') diff --git a/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts b/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts index 49b9cf209..dee724e15 100644 --- a/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts +++ b/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts @@ -6,12 +6,13 @@ import { Dispatch } from 'redux'; import { Action, actions } from '../redux/actions'; import { State } from '../redux/reducer'; -import { OrderProcessState, OrderState } from '../types'; +import { OrderProcessState, OrderState, ZeroExInstantError } from '../types'; import { balanceUtil } from '../util/balance'; import { etherscanUtil } from '../util/etherscan'; import { web3Wrapper } from '../util/web3_wrapper'; import { BuyOrderStateButtons } from '../components/buy_order_state_buttons'; +import { errorUtil } from '../util/error'; interface ConnectedState { buyQuote?: BuyQuote; @@ -21,13 +22,13 @@ interface ConnectedState { } interface ConnectedDispatch { - onAwaitingSignature: (buyQuote: BuyQuote) => void; + onPendingValidation: (buyQuote: BuyQuote) => void; onSignatureDenied: (buyQuote: BuyQuote, error: Error) => void; onBuyProcessing: (buyQuote: BuyQuote, txHash: string) => void; onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void; onBuyFailure: (buyQuote: BuyQuote, txHash: string) => void; onRetry: () => void; - validateWalletBeforeBuy: (buyQuote: BuyQuote, takerAddress: string | undefined) => Promise; + onValidationFail: (buyQuote: BuyQuote, error: ZeroExInstantError) => void; } export interface SelectedAssetBuyOrderStateButtons {} const mapStateToProps = (state: State, _ownProps: SelectedAssetBuyOrderStateButtons): ConnectedState => ({ @@ -57,8 +58,8 @@ const mapDispatchToProps = ( dispatch: Dispatch, ownProps: SelectedAssetBuyOrderStateButtons, ): ConnectedDispatch => ({ - onAwaitingSignature: (buyQuote: BuyQuote) => { - const newOrderState: OrderState = { processState: OrderProcessState.AWAITING_SIGNATURE }; + onPendingValidation: (buyQuote: BuyQuote) => { + const newOrderState: OrderState = { processState: OrderProcessState.VALIDATING }; dispatch(actions.updateBuyOrderState(newOrderState)); }, onBuyProcessing: (buyQuote: BuyQuote, txHash: string) => { @@ -71,14 +72,15 @@ const mapDispatchToProps = ( dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.FAILURE, txHash })), onSignatureDenied: (buyQuote, error) => { dispatch(actions.resetAmount()); - dispatch(actions.setError(error)); + errorUtil.errorFlasher.flashNewError(dispatch, error); + }, + onValidationFail: (buyQuote, error) => { + dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.NONE })); + errorUtil.errorFlasher.flashNewError(dispatch, new Error(error)); }, onRetry: () => { dispatch(actions.resetAmount()); }, - validateWalletBeforeBuy: async (buyQuote: BuyQuote, takerAddress: string | undefined) => { - return balanceUtil.checkInsufficientEthBalanceAndFlashError(takerAddress, buyQuote, web3Wrapper, dispatch); - }, }); export const SelectedAssetBuyOrderStateButtons: React.ComponentClass = connect( 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 325dc0ef2..a090ad8fb 100644 --- a/packages/instant/src/containers/selected_erc20_asset_amount_input.ts +++ b/packages/instant/src/containers/selected_erc20_asset_amount_input.ts @@ -79,10 +79,6 @@ 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(); - await balanceUtil.checkInsufficientEthBalanceAndFlashError(takerAddress, newBuyQuote, web3Wrapper, dispatch); }; const debouncedUpdateBuyQuoteAsync = _.debounce(updateBuyQuoteAsync, 200, { trailing: true }); -- cgit