From 667b1e03ddba1a2fac16488239f6bc977fa4cb6d Mon Sep 17 00:00:00 2001
From: Steve Klebanoff <steve.klebanoff@gmail.com>
Date: Fri, 26 Oct 2018 15:51:23 -0700
Subject: Validate enough ETH when user clicks buy

---
 packages/instant/src/components/buy_button.tsx | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

(limited to 'packages/instant/src/components/buy_button.tsx')

diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx
index 4780b80e7..8b2e0e1f6 100644
--- a/packages/instant/src/components/buy_button.tsx
+++ b/packages/instant/src/components/buy_button.tsx
@@ -5,6 +5,7 @@ import * as React from 'react';
 import { WEB_3_WRAPPER_TRANSACTION_FAILED_ERROR_MSG_PREFIX } from '../constants';
 import { ColorOption } from '../style/theme';
 import { getBestAddress } from '../util/address';
+import { balanceUtil } from '../util/balance';
 import { util } from '../util/util';
 import { web3Wrapper } from '../util/web3_wrapper';
 
@@ -18,6 +19,7 @@ export interface BuyButtonProps {
     onBuyProcessing: (buyQuote: BuyQuote, txHash: string) => void;
     onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void;
     onBuyFailure: (buyQuote: BuyQuote, txHash: string) => void;
+    validateWalletBeforeBuy: (buyQuote: BuyQuote, takerAddress: string | undefined) => Promise<boolean>;
 }
 
 export class BuyButton extends React.Component<BuyButtonProps> {
@@ -43,10 +45,15 @@ export class BuyButton extends React.Component<BuyButtonProps> {
             return;
         }
 
+        const takerAddress = await getBestAddress();
+        const validWallet = await this.props.validateWalletBeforeBuy(buyQuote, takerAddress);
+        if (!validWallet) {
+            return;
+        }
+
         let txHash: string | undefined;
         this.props.onAwaitingSignature(buyQuote);
         try {
-            const takerAddress = await getBestAddress();
             txHash = await assetBuyer.executeBuyQuoteAsync(buyQuote, { takerAddress });
         } catch (e) {
             if (e instanceof Error && e.message === AssetBuyerError.SignatureRequestDenied) {
-- 
cgit 

