diff options
author | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-10-27 06:51:23 +0800 |
---|---|---|
committer | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-10-27 06:51:23 +0800 |
commit | 667b1e03ddba1a2fac16488239f6bc977fa4cb6d (patch) | |
tree | c26e672ea99e3b19ec53a2465abc5e7059730e70 /packages/instant/src/components | |
parent | 6ad8ac6a4836bf926666f2d05e91d2d4b31c6b19 (diff) | |
download | dexon-sol-tools-667b1e03ddba1a2fac16488239f6bc977fa4cb6d.tar dexon-sol-tools-667b1e03ddba1a2fac16488239f6bc977fa4cb6d.tar.gz dexon-sol-tools-667b1e03ddba1a2fac16488239f6bc977fa4cb6d.tar.bz2 dexon-sol-tools-667b1e03ddba1a2fac16488239f6bc977fa4cb6d.tar.lz dexon-sol-tools-667b1e03ddba1a2fac16488239f6bc977fa4cb6d.tar.xz dexon-sol-tools-667b1e03ddba1a2fac16488239f6bc977fa4cb6d.tar.zst dexon-sol-tools-667b1e03ddba1a2fac16488239f6bc977fa4cb6d.zip |
Validate enough ETH when user clicks buy
Diffstat (limited to 'packages/instant/src/components')
-rw-r--r-- | packages/instant/src/components/buy_button.tsx | 9 | ||||
-rw-r--r-- | packages/instant/src/components/buy_order_state_buttons.tsx | 2 |
2 files changed, 10 insertions, 1 deletions
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) { diff --git a/packages/instant/src/components/buy_order_state_buttons.tsx b/packages/instant/src/components/buy_order_state_buttons.tsx index b9e92e763..cb5654424 100644 --- a/packages/instant/src/components/buy_order_state_buttons.tsx +++ b/packages/instant/src/components/buy_order_state_buttons.tsx @@ -23,6 +23,7 @@ export interface BuyOrderStateButtonProps { onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void; onBuyFailure: (buyQuote: BuyQuote, txHash: string) => void; onRetry: () => void; + validateWalletBeforeBuy: (buyQuote: BuyQuote, takerAddress: string | undefined) => Promise<boolean>; } // TODO: rename to buttons @@ -58,6 +59,7 @@ export const BuyOrderStateButtons: React.StatelessComponent<BuyOrderStateButtonP onBuyProcessing={props.onBuyProcessing} onBuySuccess={props.onBuySuccess} onBuyFailure={props.onBuyFailure} + validateWalletBeforeBuy={props.validateWalletBeforeBuy} /> ); }; |