From ffecba21f4e9dcda961a3e8432e70e6605174de5 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Fri, 26 Oct 2018 12:43:08 -0700 Subject: ethDecimals -> ETH_DECIMALS --- packages/instant/src/components/buy_button.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (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 a70269dde..4780b80e7 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 { getBestAddress } from '../util/address'; import { util } from '../util/util'; import { web3Wrapper } from '../util/web3_wrapper'; @@ -45,7 +46,8 @@ export class BuyButton extends React.Component { let txHash: string | undefined; this.props.onAwaitingSignature(buyQuote); try { - txHash = await assetBuyer.executeBuyQuoteAsync(buyQuote); + const takerAddress = await getBestAddress(); + txHash = await assetBuyer.executeBuyQuoteAsync(buyQuote, { takerAddress }); } catch (e) { if (e instanceof Error && e.message === AssetBuyerError.SignatureRequestDenied) { this.props.onSignatureDenied(buyQuote, e); -- cgit From 667b1e03ddba1a2fac16488239f6bc977fa4cb6d Mon Sep 17 00:00:00 2001 From: Steve Klebanoff 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 ++++++++- packages/instant/src/components/buy_order_state_buttons.tsx | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) (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 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; } export class BuyButton extends React.Component { @@ -43,10 +45,15 @@ export class BuyButton extends React.Component { 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; } // TODO: rename to buttons @@ -58,6 +59,7 @@ export const BuyOrderStateButtons: React.StatelessComponent ); }; -- cgit From bb307a55d347c34ab51144c75721860e13659ecb Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Fri, 26 Oct 2018 19:23:42 -0700 Subject: questionmark syntax instead of '| undefined' --- packages/instant/src/components/buy_button.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 8b2e0e1f6..86c55dbf9 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -19,7 +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; + validateWalletBeforeBuy: (buyQuote: BuyQuote, takerAddress?: string) => Promise; } export class BuyButton extends React.Component { -- cgit 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 From 1bb7a28690662d682f865505b6c62fe655d57316 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 29 Oct 2018 08:56:49 -0700 Subject: onPendingValidation -> onValidationPending --- packages/instant/src/components/buy_button.tsx | 4 ++-- packages/instant/src/components/buy_order_state_buttons.tsx | 8 ++++---- 2 files changed, 6 insertions(+), 6 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 2f670d387..876edd396 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -15,7 +15,7 @@ import { Button, Text } from './ui'; export interface BuyButtonProps { buyQuote?: BuyQuote; assetBuyer?: AssetBuyer; - onPendingValidation: (buyQuote: BuyQuote) => void; + onValidationPending: (buyQuote: BuyQuote) => void; onValidationFail: (buyQuote: BuyQuote, error: ZeroExInstantError) => void; onSignatureDenied: (buyQuote: BuyQuote, preventedError: Error) => void; onBuyProcessing: (buyQuote: BuyQuote, txHash: string) => void; @@ -46,7 +46,7 @@ export class BuyButton extends React.Component { return; } - this.props.onPendingValidation(buyQuote); + this.props.onValidationPending(buyQuote); const takerAddress = await getBestAddress(); const hasSufficientFunds = await balanceUtil.hasSufficientFunds(takerAddress, buyQuote, web3Wrapper); diff --git a/packages/instant/src/components/buy_order_state_buttons.tsx b/packages/instant/src/components/buy_order_state_buttons.tsx index 8225441f7..f9d683be6 100644 --- a/packages/instant/src/components/buy_order_state_buttons.tsx +++ b/packages/instant/src/components/buy_order_state_buttons.tsx @@ -17,13 +17,13 @@ export interface BuyOrderStateButtonProps { buyOrderProcessingState: OrderProcessState; assetBuyer?: AssetBuyer; onViewTransaction: () => void; - onPendingValidation: (buyQuote: BuyQuote) => void; + onValidationPending: (buyQuote: BuyQuote) => void; + onValidationFail: (buyQuote: BuyQuote, error: ZeroExInstantError) => 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; - onValidationFail: (buyQuote: BuyQuote, error: ZeroExInstantError) => void; } // TODO: rename to buttons @@ -54,12 +54,12 @@ export const BuyOrderStateButtons: React.StatelessComponent ); }; -- cgit From 8288e8cce963bbd96c71b3adeb5d34bb96c30693 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 29 Oct 2018 09:03:39 -0700 Subject: When transaction too low, treat as validation error. also modify callback: errorMessage could be AssetBuyError as well --- packages/instant/src/components/buy_button.tsx | 13 +++++++++---- packages/instant/src/components/buy_order_state_buttons.tsx | 4 ++-- 2 files changed, 11 insertions(+), 6 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 876edd396..bceabbca3 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -16,7 +16,7 @@ export interface BuyButtonProps { buyQuote?: BuyQuote; assetBuyer?: AssetBuyer; onValidationPending: (buyQuote: BuyQuote) => void; - onValidationFail: (buyQuote: BuyQuote, error: ZeroExInstantError) => void; + onValidationFail: (buyQuote: BuyQuote, errorMessage: AssetBuyerError | ZeroExInstantError) => void; onSignatureDenied: (buyQuote: BuyQuote, preventedError: Error) => void; onBuyProcessing: (buyQuote: BuyQuote, txHash: string) => void; onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void; @@ -59,9 +59,14 @@ export class BuyButton extends React.Component { try { txHash = await assetBuyer.executeBuyQuoteAsync(buyQuote, { takerAddress }); } catch (e) { - if (e instanceof Error && e.message === AssetBuyerError.SignatureRequestDenied) { - this.props.onSignatureDenied(buyQuote, e); - return; + if (e instanceof Error) { + if (e.message === AssetBuyerError.SignatureRequestDenied) { + this.props.onSignatureDenied(buyQuote, e); + return; + } else if (e.message === AssetBuyerError.TransactionValueTooLow) { + this.props.onValidationFail(buyQuote, AssetBuyerError.TransactionValueTooLow); + return; + } } throw e; } diff --git a/packages/instant/src/components/buy_order_state_buttons.tsx b/packages/instant/src/components/buy_order_state_buttons.tsx index f9d683be6..7c06ff31b 100644 --- a/packages/instant/src/components/buy_order_state_buttons.tsx +++ b/packages/instant/src/components/buy_order_state_buttons.tsx @@ -1,4 +1,4 @@ -import { AssetBuyer, BuyQuote } from '@0x/asset-buyer'; +import { AssetBuyer, AssetBuyerError, BuyQuote } from '@0x/asset-buyer'; import * as React from 'react'; import { BuyButton } from '../components/buy_button'; @@ -18,7 +18,7 @@ export interface BuyOrderStateButtonProps { assetBuyer?: AssetBuyer; onViewTransaction: () => void; onValidationPending: (buyQuote: BuyQuote) => void; - onValidationFail: (buyQuote: BuyQuote, error: ZeroExInstantError) => void; + onValidationFail: (buyQuote: BuyQuote, errorMessage: AssetBuyerError | ZeroExInstantError) => void; onSignatureDenied: (buyQuote: BuyQuote, error: Error) => void; onBuyProcessing: (buyQuote: BuyQuote, txHash: string) => void; onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void; -- cgit From 7ed44f7b2f0224b4169f0a8f34bae09e8c6b986f Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 29 Oct 2018 09:07:40 -0700 Subject: Has Sufficient Funds/Balance -> Has Sufficient ETH --- packages/instant/src/components/buy_button.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 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 bceabbca3..bcd435250 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -49,9 +49,9 @@ export class BuyButton extends React.Component { this.props.onValidationPending(buyQuote); const takerAddress = await getBestAddress(); - const hasSufficientFunds = await balanceUtil.hasSufficientFunds(takerAddress, buyQuote, web3Wrapper); - if (!hasSufficientFunds) { - this.props.onValidationFail(buyQuote, ZeroExInstantError.InsufficientBalance); + const hasSufficentEth = await balanceUtil.hasSufficentEth(takerAddress, buyQuote, web3Wrapper); + if (!hasSufficentEth) { + this.props.onValidationFail(buyQuote, ZeroExInstantError.InsufficientETH); return; } -- cgit