aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/components/buy_button.tsx
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-11-08 15:36:00 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-11-08 15:41:25 +0800
commitcde192df0d48bb45f57c319179dbd9f64abd13e9 (patch)
tree010893e4f4e993e668d26bf049a446a27e4a48fc /packages/instant/src/components/buy_button.tsx
parentd0c009adff53d94414cf51028eff490e0452a3c9 (diff)
downloaddexon-sol-tools-cde192df0d48bb45f57c319179dbd9f64abd13e9.tar
dexon-sol-tools-cde192df0d48bb45f57c319179dbd9f64abd13e9.tar.gz
dexon-sol-tools-cde192df0d48bb45f57c319179dbd9f64abd13e9.tar.bz2
dexon-sol-tools-cde192df0d48bb45f57c319179dbd9f64abd13e9.tar.lz
dexon-sol-tools-cde192df0d48bb45f57c319179dbd9f64abd13e9.tar.xz
dexon-sol-tools-cde192df0d48bb45f57c319179dbd9f64abd13e9.tar.zst
dexon-sol-tools-cde192df0d48bb45f57c319179dbd9f64abd13e9.zip
feat(instant): fetch balance at startup
Diffstat (limited to 'packages/instant/src/components/buy_button.tsx')
-rw-r--r--packages/instant/src/components/buy_button.tsx13
1 files changed, 7 insertions, 6 deletions
diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx
index f24bb57ee..9a6e22ea9 100644
--- a/packages/instant/src/components/buy_button.tsx
+++ b/packages/instant/src/components/buy_button.tsx
@@ -1,4 +1,5 @@
import { AssetBuyer, AssetBuyerError, BuyQuote } from '@0x/asset-buyer';
+import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as _ from 'lodash';
import * as React from 'react';
@@ -7,8 +8,6 @@ import { oc } from 'ts-optchain';
import { WEB_3_WRAPPER_TRANSACTION_FAILED_ERROR_MSG_PREFIX } from '../constants';
import { ColorOption } from '../style/theme';
import { AffiliateInfo, ZeroExInstantError } from '../types';
-import { getBestAddress } from '../util/address';
-import { balanceUtil } from '../util/balance';
import { gasPriceEstimator } from '../util/gas_price_estimator';
import { util } from '../util/util';
@@ -17,8 +16,10 @@ import { Text } from './ui/text';
export interface BuyButtonProps {
accountAddress?: string;
+ accountEthBalanceInWei?: BigNumber;
buyQuote?: BuyQuote;
assetBuyer: AssetBuyer;
+ web3Wrapper: Web3Wrapper;
affiliateInfo?: AffiliateInfo;
onValidationPending: (buyQuote: BuyQuote) => void;
onValidationFail: (buyQuote: BuyQuote, errorMessage: AssetBuyerError | ZeroExInstantError) => void;
@@ -47,14 +48,14 @@ export class BuyButton extends React.Component<BuyButtonProps> {
}
private readonly _handleClick = async () => {
// The button is disabled when there is no buy quote anyway.
- const { buyQuote, assetBuyer, affiliateInfo, accountAddress } = this.props;
+ const { buyQuote, assetBuyer, affiliateInfo, accountAddress, accountEthBalanceInWei, web3Wrapper } = this.props;
if (_.isUndefined(buyQuote) || _.isUndefined(accountAddress)) {
return;
}
this.props.onValidationPending(buyQuote);
- // TODO(bmillman): move balance fetching to the async state and get rid of web3 wrapper here
- const web3Wrapper = new Web3Wrapper(assetBuyer.provider);
- const hasSufficientEth = await balanceUtil.hasSufficientEth(accountAddress, buyQuote, web3Wrapper);
+ const ethNeededForBuy = buyQuote.worstCaseQuoteInfo.totalEthAmount;
+ // if we don't have a balance for the user, let the transaction through, it will be handled by the wallet
+ const hasSufficientEth = _.isUndefined(accountEthBalanceInWei) || accountEthBalanceInWei.gte(ethNeededForBuy);
if (!hasSufficientEth) {
this.props.onValidationFail(buyQuote, ZeroExInstantError.InsufficientETH);
return;