aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/components/buy_button.tsx
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-10-27 10:53:15 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-10-27 10:53:15 +0800
commitff295daa5c56b5c056a5faa5ca8875c317524070 (patch)
tree96e6ee707cf75e3272d90d44a8c8cf1b0567a5ce /packages/instant/src/components/buy_button.tsx
parentbb307a55d347c34ab51144c75721860e13659ecb (diff)
downloaddexon-0x-contracts-ff295daa5c56b5c056a5faa5ca8875c317524070.tar.gz
dexon-0x-contracts-ff295daa5c56b5c056a5faa5ca8875c317524070.tar.zst
dexon-0x-contracts-ff295daa5c56b5c056a5faa5ca8875c317524070.zip
Simpler way of validaitng has enough eth
Diffstat (limited to 'packages/instant/src/components/buy_button.tsx')
-rw-r--r--packages/instant/src/components/buy_button.tsx13
1 files changed, 8 insertions, 5 deletions
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<boolean>;
}
export class BuyButton extends React.Component<BuyButtonProps> {
@@ -45,14 +46,16 @@ export class BuyButton extends React.Component<BuyButtonProps> {
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) {