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 --- packages/instant/src/components/buy_button.tsx | 13 ++++++++----- packages/instant/src/components/buy_order_state_buttons.tsx | 12 ++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'packages/instant/src/components') diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx index 86c55dbf9..2f670d387 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -4,6 +4,7 @@ import * as React from 'react'; import { WEB_3_WRAPPER_TRANSACTION_FAILED_ERROR_MSG_PREFIX } from '../constants'; import { ColorOption } from '../style/theme'; +import { ZeroExInstantError } from '../types'; import { getBestAddress } from '../util/address'; import { balanceUtil } from '../util/balance'; import { util } from '../util/util'; @@ -14,12 +15,12 @@ import { Button, Text } from './ui'; export interface BuyButtonProps { buyQuote?: BuyQuote; assetBuyer?: AssetBuyer; - onAwaitingSignature: (buyQuote: BuyQuote) => void; + onPendingValidation: (buyQuote: BuyQuote) => void; + onValidationFail: (buyQuote: BuyQuote, error: ZeroExInstantError) => void; onSignatureDenied: (buyQuote: BuyQuote, preventedError: Error) => void; onBuyProcessing: (buyQuote: BuyQuote, txHash: string) => void; onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void; onBuyFailure: (buyQuote: BuyQuote, txHash: string) => void; - validateWalletBeforeBuy: (buyQuote: BuyQuote, takerAddress?: string) => Promise; } export class BuyButton extends React.Component { @@ -45,14 +46,16 @@ export class BuyButton extends React.Component { return; } + this.props.onPendingValidation(buyQuote); const takerAddress = await getBestAddress(); - const validWallet = await this.props.validateWalletBeforeBuy(buyQuote, takerAddress); - if (!validWallet) { + + const hasSufficientFunds = await balanceUtil.hasSufficientFunds(takerAddress, buyQuote, web3Wrapper); + if (!hasSufficientFunds) { + this.props.onValidationFail(buyQuote, ZeroExInstantError.InsufficientBalance); return; } let txHash: string | undefined; - this.props.onAwaitingSignature(buyQuote); try { txHash = await assetBuyer.executeBuyQuoteAsync(buyQuote, { takerAddress }); } catch (e) { diff --git a/packages/instant/src/components/buy_order_state_buttons.tsx b/packages/instant/src/components/buy_order_state_buttons.tsx index cb5654424..8225441f7 100644 --- a/packages/instant/src/components/buy_order_state_buttons.tsx +++ b/packages/instant/src/components/buy_order_state_buttons.tsx @@ -7,7 +7,7 @@ import { Flex } from '../components/ui/flex'; import { PlacingOrderButton } from '../components/placing_order_button'; import { ColorOption } from '../style/theme'; -import { OrderProcessState } from '../types'; +import { OrderProcessState, ZeroExInstantError } from '../types'; import { Button } from './ui/button'; import { Text } from './ui/text'; @@ -17,13 +17,13 @@ export interface BuyOrderStateButtonProps { buyOrderProcessingState: OrderProcessState; assetBuyer?: AssetBuyer; onViewTransaction: () => void; - 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; } // TODO: rename to buttons @@ -46,7 +46,7 @@ export const BuyOrderStateButtons: React.StatelessComponentView Transaction; - } else if (props.buyOrderProcessingState === OrderProcessState.AWAITING_SIGNATURE) { + } else if (props.buyOrderProcessingState === OrderProcessState.VALIDATING) { return ; } @@ -54,12 +54,12 @@ export const BuyOrderStateButtons: React.StatelessComponent ); }; -- cgit