From ce5bc3c1c945b12997e3030301bf25f982c55365 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 24 Oct 2018 10:38:56 -0700 Subject: Message when signature denied --- packages/instant/src/components/buy_button.tsx | 9 +++++++-- packages/instant/src/containers/selected_asset_buy_button.ts | 5 +++++ packages/instant/src/util/error.ts | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) (limited to 'packages/instant') diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx index 9c42f3d87..0d35d36ca 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -1,4 +1,4 @@ -import { AssetBuyer, BuyQuote } from '@0x/asset-buyer'; +import { AssetBuyer, AssetBuyerError, BuyQuote } from '@0x/asset-buyer'; import * as _ from 'lodash'; import * as React from 'react'; @@ -14,6 +14,7 @@ export interface BuyButtonProps { onClick: (buyQuote: BuyQuote) => void; onBuySuccess: (buyQuote: BuyQuote, txnHash: string) => void; onBuyFailure: (buyQuote: BuyQuote, tnxHash?: string) => void; + onBuyPrevented: (buyQuote: BuyQuote, preventedError: Error) => void; } export class BuyButton extends React.Component { @@ -43,7 +44,11 @@ export class BuyButton extends React.Component { txnHash = await this.props.assetBuyer.executeBuyQuoteAsync(this.props.buyQuote); const txnReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txnHash); this.props.onBuySuccess(this.props.buyQuote, txnReceipt.transactionHash); - } catch { + } catch (e) { + if (e instanceof Error && e.message === AssetBuyerError.SignatureRequestDenied) { + this.props.onBuyPrevented(this.props.buyQuote, e); + return; + } this.props.onBuyFailure(this.props.buyQuote, txnHash); } }; diff --git a/packages/instant/src/containers/selected_asset_buy_button.ts b/packages/instant/src/containers/selected_asset_buy_button.ts index 71d2b8cf0..428939e79 100644 --- a/packages/instant/src/containers/selected_asset_buy_button.ts +++ b/packages/instant/src/containers/selected_asset_buy_button.ts @@ -21,6 +21,7 @@ interface ConnectedDispatch { onClick: (buyQuote: BuyQuote) => void; onBuySuccess: (buyQuote: BuyQuote, txnHash: string) => void; onBuyFailure: (buyQuote: BuyQuote) => void; + onBuyPrevented: (buyQuote: BuyQuote, error: Error) => void; } const mapStateToProps = (state: State, _ownProps: SelectedAssetBuyButtonProps): ConnectedState => ({ @@ -33,6 +34,10 @@ const mapDispatchToProps = (dispatch: Dispatch, ownProps: SelectedAssetB onBuySuccess: (buyQuote: BuyQuote, txnHash: string) => dispatch(actions.updateBuyOrderState({ processState: AsyncProcessState.SUCCESS, txnHash })), onBuyFailure: buyQuote => dispatch(actions.updateBuyOrderState({ processState: AsyncProcessState.FAILURE })), + onBuyPrevented: (buyQuote, error) => { + dispatch(actions.resetAmount()); + dispatch(actions.setError(error)); + }, }); export const SelectedAssetBuyButton: React.ComponentClass = connect( diff --git a/packages/instant/src/util/error.ts b/packages/instant/src/util/error.ts index 40fd24c7e..873ba52ee 100644 --- a/packages/instant/src/util/error.ts +++ b/packages/instant/src/util/error.ts @@ -46,6 +46,10 @@ const humanReadableMessageForError = (error: Error, asset?: Asset): string | und return `${assetName} is currently unavailable`; } + if (error.message === AssetBuyerError.SignatureRequestDenied) { + return 'You denied this transaction.'; + } + return undefined; }; -- cgit v1.2.3 From 05ce8aa124ae4d912ef43a9cf70a30ac2704867a Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 24 Oct 2018 10:42:52 -0700 Subject: feat: Message when denying signing transaction --- packages/instant/src/util/error.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/instant') diff --git a/packages/instant/src/util/error.ts b/packages/instant/src/util/error.ts index 873ba52ee..64c1f4885 100644 --- a/packages/instant/src/util/error.ts +++ b/packages/instant/src/util/error.ts @@ -47,7 +47,7 @@ const humanReadableMessageForError = (error: Error, asset?: Asset): string | und } if (error.message === AssetBuyerError.SignatureRequestDenied) { - return 'You denied this transaction.'; + return 'You denied this transaction'; } return undefined; -- cgit v1.2.3 From db3ad83ebca88e0faf2529ec468044e6ce4d5746 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 24 Oct 2018 13:16:28 -0700 Subject: Introduce new OrderProcessState --- packages/instant/src/components/buy_order_state_button.tsx | 13 ++++++++----- packages/instant/src/components/instant_heading.tsx | 10 +++++----- .../instant/src/containers/selected_asset_amount_input.ts | 4 ++-- .../instant/src/containers/selected_asset_buy_button.ts | 8 ++++---- .../containers/selected_asset_buy_order_state_button.tsx | 4 ++-- .../containers/selected_asset_view_transaction_button.tsx | 4 ++-- packages/instant/src/redux/reducer.ts | 14 +++++++++++--- packages/instant/src/types.ts | 14 +++++++++++--- 8 files changed, 45 insertions(+), 26 deletions(-) (limited to 'packages/instant') diff --git a/packages/instant/src/components/buy_order_state_button.tsx b/packages/instant/src/components/buy_order_state_button.tsx index 5bc965c7d..b5b21fd1e 100644 --- a/packages/instant/src/components/buy_order_state_button.tsx +++ b/packages/instant/src/components/buy_order_state_button.tsx @@ -4,18 +4,21 @@ import { PlacingOrderButton } from '../components/placing_order_button'; import { SelectedAssetBuyButton } from '../containers/selected_asset_buy_button'; import { SelectedAssetRetryButton } from '../containers/selected_asset_retry_button'; import { SelectedAssetViewTransactionButton } from '../containers/selected_asset_view_transaction_button'; -import { AsyncProcessState } from '../types'; +import { OrderProcessState } from '../types'; export interface BuyOrderStateButtonProps { - buyOrderProcessingState: AsyncProcessState; + buyOrderProcessingState: OrderProcessState; } export const BuyOrderStateButton: React.StatelessComponent = props => { - if (props.buyOrderProcessingState === AsyncProcessState.FAILURE) { + if (props.buyOrderProcessingState === OrderProcessState.FAILURE) { return ; - } else if (props.buyOrderProcessingState === AsyncProcessState.SUCCESS) { + } else if (props.buyOrderProcessingState === OrderProcessState.SUCCESS) { return ; - } else if (props.buyOrderProcessingState === AsyncProcessState.PENDING) { + } else if ( + props.buyOrderProcessingState === OrderProcessState.AWAITING_SIGNATURE || + props.buyOrderProcessingState === OrderProcessState.PROCESSING + ) { return ; } diff --git a/packages/instant/src/components/instant_heading.tsx b/packages/instant/src/components/instant_heading.tsx index ed753a3bd..37d87580d 100644 --- a/packages/instant/src/components/instant_heading.tsx +++ b/packages/instant/src/components/instant_heading.tsx @@ -4,7 +4,7 @@ import * as React from 'react'; import { SelectedAssetAmountInput } from '../containers/selected_asset_amount_input'; import { ColorOption } from '../style/theme'; -import { AsyncProcessState, OrderState } from '../types'; +import { AsyncProcessState, OrderProcessState, OrderState } from '../types'; import { format } from '../util/format'; import { AmountPlaceholder } from './amount_placeholder'; @@ -68,9 +68,9 @@ export class InstantHeading extends React.Component { private _renderIcon(): React.ReactNode { const processState = this.props.buyOrderState.processState; - if (processState === AsyncProcessState.FAILURE) { + if (processState === OrderProcessState.FAILURE) { return ; - } else if (processState === AsyncProcessState.SUCCESS) { + } else if (processState === OrderProcessState.SUCCESS) { return ; } return undefined; @@ -78,9 +78,9 @@ export class InstantHeading extends React.Component { private _renderTopText(): React.ReactNode { const processState = this.props.buyOrderState.processState; - if (processState === AsyncProcessState.FAILURE) { + if (processState === OrderProcessState.FAILURE) { return 'Order failed'; - } else if (processState === AsyncProcessState.SUCCESS) { + } else if (processState === OrderProcessState.SUCCESS) { return 'Tokens received!'; } diff --git a/packages/instant/src/containers/selected_asset_amount_input.ts b/packages/instant/src/containers/selected_asset_amount_input.ts index f23b2010e..e9dbc61ce 100644 --- a/packages/instant/src/containers/selected_asset_amount_input.ts +++ b/packages/instant/src/containers/selected_asset_amount_input.ts @@ -10,7 +10,7 @@ import { Dispatch } from 'redux'; import { Action, actions } from '../redux/actions'; import { State } from '../redux/reducer'; import { ColorOption } from '../style/theme'; -import { AsyncProcessState, ERC20Asset } from '../types'; +import { ERC20Asset, OrderProcessState } from '../types'; import { errorUtil } from '../util/error'; import { AssetAmountInput } from '../components/asset_amount_input'; @@ -90,7 +90,7 @@ const mapDispatchToProps = ( // invalidate the last buy quote. dispatch(actions.updateLatestBuyQuote(undefined)); // reset our buy state - dispatch(actions.updateBuyOrderState({ processState: AsyncProcessState.NONE })); + dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.NONE })); if (!_.isUndefined(value) && !_.isUndefined(asset) && !_.isUndefined(assetBuyer)) { // even if it's debounced, give them the illusion it's loading diff --git a/packages/instant/src/containers/selected_asset_buy_button.ts b/packages/instant/src/containers/selected_asset_buy_button.ts index 428939e79..1d8b3b4bd 100644 --- a/packages/instant/src/containers/selected_asset_buy_button.ts +++ b/packages/instant/src/containers/selected_asset_buy_button.ts @@ -6,7 +6,7 @@ import { Dispatch } from 'redux'; import { Action, actions } from '../redux/actions'; import { State } from '../redux/reducer'; -import { AsyncProcessState } from '../types'; +import { AsyncProcessState, OrderProcessState } from '../types'; import { BuyButton } from '../components/buy_button'; @@ -30,10 +30,10 @@ const mapStateToProps = (state: State, _ownProps: SelectedAssetBuyButtonProps): }); const mapDispatchToProps = (dispatch: Dispatch, ownProps: SelectedAssetBuyButtonProps): ConnectedDispatch => ({ - onClick: buyQuote => dispatch(actions.updateBuyOrderState({ processState: AsyncProcessState.PENDING })), + onClick: buyQuote => dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.AWAITING_SIGNATURE })), onBuySuccess: (buyQuote: BuyQuote, txnHash: string) => - dispatch(actions.updateBuyOrderState({ processState: AsyncProcessState.SUCCESS, txnHash })), - onBuyFailure: buyQuote => dispatch(actions.updateBuyOrderState({ processState: AsyncProcessState.FAILURE })), + dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.SUCCESS, txnHash })), + onBuyFailure: buyQuote => dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.FAILURE })), onBuyPrevented: (buyQuote, error) => { dispatch(actions.resetAmount()); dispatch(actions.setError(error)); diff --git a/packages/instant/src/containers/selected_asset_buy_order_state_button.tsx b/packages/instant/src/containers/selected_asset_buy_order_state_button.tsx index f3efbb5d2..c02228d76 100644 --- a/packages/instant/src/containers/selected_asset_buy_order_state_button.tsx +++ b/packages/instant/src/containers/selected_asset_buy_order_state_button.tsx @@ -3,12 +3,12 @@ import * as React from 'react'; import { connect } from 'react-redux'; import { State } from '../redux/reducer'; -import { AsyncProcessState } from '../types'; +import { AsyncProcessState, OrderProcessState } from '../types'; import { BuyOrderStateButton } from '../components/buy_order_state_button'; interface ConnectedState { - buyOrderProcessingState: AsyncProcessState; + buyOrderProcessingState: OrderProcessState; } export interface SelectedAssetButtonProps {} const mapStateToProps = (state: State, _ownProps: SelectedAssetButtonProps): ConnectedState => ({ diff --git a/packages/instant/src/containers/selected_asset_view_transaction_button.tsx b/packages/instant/src/containers/selected_asset_view_transaction_button.tsx index 6f42b9f85..1f9bfd7a6 100644 --- a/packages/instant/src/containers/selected_asset_view_transaction_button.tsx +++ b/packages/instant/src/containers/selected_asset_view_transaction_button.tsx @@ -5,7 +5,7 @@ import { connect } from 'react-redux'; import { State } from '../redux/reducer'; import { ViewTransactionButton } from '../components/view_transaction_button'; -import { AsyncProcessState } from '../types'; +import { AsyncProcessState, OrderProcessState } from '../types'; import { etherscanUtil } from '../util/etherscan'; export interface SelectedAssetViewTransactionButtonProps {} @@ -16,7 +16,7 @@ interface ConnectedState { const mapStateToProps = (state: State, _ownProps: {}): ConnectedState => ({ onClick: () => { - if (state.assetBuyer && state.buyOrderState.processState === AsyncProcessState.SUCCESS) { + if (state.assetBuyer && state.buyOrderState.processState === OrderProcessState.SUCCESS) { const etherscanUrl = etherscanUtil.getEtherScanTxnAddressIfExists( state.buyOrderState.txnHash, state.assetBuyer.networkId, diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index c6a05ac52..25d0092b2 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -4,7 +4,15 @@ import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; import { assetMetaDataMap } from '../data/asset_meta_data_map'; -import { Asset, AssetMetaData, AsyncProcessState, DisplayStatus, Network, OrderState } from '../types'; +import { + Asset, + AssetMetaData, + AsyncProcessState, + DisplayStatus, + Network, + OrderProcessState, + OrderState, +} from '../types'; import { assetUtils } from '../util/asset'; import { Action, ActionTypes } from './actions'; @@ -27,7 +35,7 @@ export const INITIAL_STATE: State = { network: Network.Mainnet, selectedAssetAmount: undefined, assetMetaDataMap, - buyOrderState: { processState: AsyncProcessState.NONE }, + buyOrderState: { processState: OrderProcessState.NONE }, ethUsdPrice: undefined, latestBuyQuote: undefined, latestError: undefined, @@ -106,7 +114,7 @@ export const reducer = (state: State = INITIAL_STATE, action: Action): State => ...state, latestBuyQuote: undefined, quoteRequestState: AsyncProcessState.NONE, - buyOrderState: { processState: AsyncProcessState.NONE }, + buyOrderState: { processState: OrderProcessState.NONE }, selectedAssetAmount: undefined, }; default: diff --git a/packages/instant/src/types.ts b/packages/instant/src/types.ts index c5521c63c..91453eac8 100644 --- a/packages/instant/src/types.ts +++ b/packages/instant/src/types.ts @@ -8,15 +8,23 @@ export enum AsyncProcessState { FAILURE = 'Failure', } +export enum OrderProcessState { + NONE = 'None', + AWAITING_SIGNATURE = 'Awaiting Signature', + PROCESSING = 'Processing', + SUCCESS = 'Success', + FAILURE = 'Failure', +} + interface RegularOrderState { - processState: AsyncProcessState.NONE | AsyncProcessState.PENDING; + processState: OrderProcessState.NONE | OrderProcessState.AWAITING_SIGNATURE; } interface SuccessfulOrderState { - processState: AsyncProcessState.SUCCESS; + processState: OrderProcessState.SUCCESS; txnHash: string; } interface FailureOrderState { - processState: AsyncProcessState.FAILURE; + processState: OrderProcessState.FAILURE; txnHash?: string; } export type OrderState = RegularOrderState | SuccessfulOrderState | FailureOrderState; -- cgit v1.2.3 From 73f5ea2906502e89fa9bca275e229a1485d2f974 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 24 Oct 2018 16:04:09 -0700 Subject: Associate txnhash with processing state --- packages/instant/src/components/buy_button.tsx | 19 +++++++++++-------- .../src/containers/selected_asset_buy_button.ts | 14 +++++++++++--- packages/instant/src/types.ts | 7 ++++++- 3 files changed, 28 insertions(+), 12 deletions(-) (limited to 'packages/instant') diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx index 0d35d36ca..f70f2f5be 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -11,7 +11,8 @@ import { Button, Text } from './ui'; export interface BuyButtonProps { buyQuote?: BuyQuote; assetBuyer?: AssetBuyer; - onClick: (buyQuote: BuyQuote) => void; + onAwaitingSignature: (buyQuote: BuyQuote) => void; + onProcessingTransaction: (buyQuote: BuyQuote, txnHash: string) => void; onBuySuccess: (buyQuote: BuyQuote, txnHash: string) => void; onBuyFailure: (buyQuote: BuyQuote, tnxHash?: string) => void; onBuyPrevented: (buyQuote: BuyQuote, preventedError: Error) => void; @@ -35,21 +36,23 @@ export class BuyButton extends React.Component { } private readonly _handleClick = async () => { // The button is disabled when there is no buy quote anyway. - if (_.isUndefined(this.props.buyQuote) || _.isUndefined(this.props.assetBuyer)) { + const { buyQuote, assetBuyer } = this.props; + if (_.isUndefined(buyQuote) || _.isUndefined(assetBuyer)) { return; } - this.props.onClick(this.props.buyQuote); + this.props.onAwaitingSignature(buyQuote); let txnHash; try { - txnHash = await this.props.assetBuyer.executeBuyQuoteAsync(this.props.buyQuote); - const txnReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txnHash); - this.props.onBuySuccess(this.props.buyQuote, txnReceipt.transactionHash); + txnHash = await assetBuyer.executeBuyQuoteAsync(buyQuote); + this.props.onProcessingTransaction(buyQuote, txnHash); + await web3Wrapper.awaitTransactionSuccessAsync(txnHash); + this.props.onBuySuccess(buyQuote, txnHash); } catch (e) { if (e instanceof Error && e.message === AssetBuyerError.SignatureRequestDenied) { - this.props.onBuyPrevented(this.props.buyQuote, e); + this.props.onBuyPrevented(buyQuote, e); return; } - this.props.onBuyFailure(this.props.buyQuote, txnHash); + this.props.onBuyFailure(buyQuote, txnHash); } }; } diff --git a/packages/instant/src/containers/selected_asset_buy_button.ts b/packages/instant/src/containers/selected_asset_buy_button.ts index 1d8b3b4bd..f55254daf 100644 --- a/packages/instant/src/containers/selected_asset_buy_button.ts +++ b/packages/instant/src/containers/selected_asset_buy_button.ts @@ -6,7 +6,7 @@ import { Dispatch } from 'redux'; import { Action, actions } from '../redux/actions'; import { State } from '../redux/reducer'; -import { AsyncProcessState, OrderProcessState } from '../types'; +import { OrderProcessState, OrderState } from '../types'; import { BuyButton } from '../components/buy_button'; @@ -18,7 +18,8 @@ interface ConnectedState { } interface ConnectedDispatch { - onClick: (buyQuote: BuyQuote) => void; + onAwaitingSignature: (buyQuote: BuyQuote) => void; + onProcessingTransaction: (buyQuote: BuyQuote, txnHash: string) => void; onBuySuccess: (buyQuote: BuyQuote, txnHash: string) => void; onBuyFailure: (buyQuote: BuyQuote) => void; onBuyPrevented: (buyQuote: BuyQuote, error: Error) => void; @@ -30,7 +31,14 @@ const mapStateToProps = (state: State, _ownProps: SelectedAssetBuyButtonProps): }); const mapDispatchToProps = (dispatch: Dispatch, ownProps: SelectedAssetBuyButtonProps): ConnectedDispatch => ({ - onClick: buyQuote => dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.AWAITING_SIGNATURE })), + onAwaitingSignature: (buyQuote: BuyQuote) => { + const newOrderState: OrderState = { processState: OrderProcessState.AWAITING_SIGNATURE }; + dispatch(actions.updateBuyOrderState(newOrderState)); + }, + onProcessingTransaction: (buyQuote: BuyQuote, txnHash: string) => { + const newOrderState: OrderState = { processState: OrderProcessState.PROCESSING, txnHash }; + dispatch(actions.updateBuyOrderState(newOrderState)); + }, onBuySuccess: (buyQuote: BuyQuote, txnHash: string) => dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.SUCCESS, txnHash })), onBuyFailure: buyQuote => dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.FAILURE })), diff --git a/packages/instant/src/types.ts b/packages/instant/src/types.ts index 91453eac8..47c60016c 100644 --- a/packages/instant/src/types.ts +++ b/packages/instant/src/types.ts @@ -19,6 +19,11 @@ export enum OrderProcessState { interface RegularOrderState { processState: OrderProcessState.NONE | OrderProcessState.AWAITING_SIGNATURE; } +// TODO: later turn into just a generic OrderStateWithTxn +interface ProcessingOrderState { + processState: OrderProcessState.PROCESSING; + txnHash: string; +} interface SuccessfulOrderState { processState: OrderProcessState.SUCCESS; txnHash: string; @@ -27,7 +32,7 @@ interface FailureOrderState { processState: OrderProcessState.FAILURE; txnHash?: string; } -export type OrderState = RegularOrderState | SuccessfulOrderState | FailureOrderState; +export type OrderState = RegularOrderState | ProcessingOrderState | SuccessfulOrderState | FailureOrderState; export enum DisplayStatus { Present, -- cgit v1.2.3 From b7f4062ac84159e58d0282a38fb64825c429cbd8 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 24 Oct 2018 16:17:01 -0700 Subject: feat(instant): Be able to view transaction when transaction is in progress --- packages/instant/src/components/buy_order_state_button.tsx | 6 +++--- packages/instant/src/components/instant_heading.tsx | 5 +++++ .../src/containers/selected_asset_view_transaction_button.tsx | 6 +++++- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'packages/instant') diff --git a/packages/instant/src/components/buy_order_state_button.tsx b/packages/instant/src/components/buy_order_state_button.tsx index b5b21fd1e..44115e5a1 100644 --- a/packages/instant/src/components/buy_order_state_button.tsx +++ b/packages/instant/src/components/buy_order_state_button.tsx @@ -13,12 +13,12 @@ export interface BuyOrderStateButtonProps { export const BuyOrderStateButton: React.StatelessComponent = props => { if (props.buyOrderProcessingState === OrderProcessState.FAILURE) { return ; - } else if (props.buyOrderProcessingState === OrderProcessState.SUCCESS) { - return ; } else if ( - props.buyOrderProcessingState === OrderProcessState.AWAITING_SIGNATURE || + props.buyOrderProcessingState === OrderProcessState.SUCCESS || props.buyOrderProcessingState === OrderProcessState.PROCESSING ) { + return ; + } else if (props.buyOrderProcessingState === OrderProcessState.AWAITING_SIGNATURE) { return ; } diff --git a/packages/instant/src/components/instant_heading.tsx b/packages/instant/src/components/instant_heading.tsx index 37d87580d..17ac65429 100644 --- a/packages/instant/src/components/instant_heading.tsx +++ b/packages/instant/src/components/instant_heading.tsx @@ -10,6 +10,7 @@ import { format } from '../util/format'; import { AmountPlaceholder } from './amount_placeholder'; import { Container, Flex, Text } from './ui'; import { Icon } from './ui/icon'; +import { Spinner } from './ui/spinner'; export interface InstantHeadingProps { selectedAssetAmount?: BigNumber; @@ -70,6 +71,8 @@ export class InstantHeading extends React.Component { if (processState === OrderProcessState.FAILURE) { return ; + } else if (processState === OrderProcessState.PROCESSING) { + return ; } else if (processState === OrderProcessState.SUCCESS) { return ; } @@ -80,6 +83,8 @@ export class InstantHeading extends React.Component { const processState = this.props.buyOrderState.processState; if (processState === OrderProcessState.FAILURE) { return 'Order failed'; + } else if (processState === OrderProcessState.PROCESSING) { + return 'Processing Order...'; } else if (processState === OrderProcessState.SUCCESS) { return 'Tokens received!'; } diff --git a/packages/instant/src/containers/selected_asset_view_transaction_button.tsx b/packages/instant/src/containers/selected_asset_view_transaction_button.tsx index 1f9bfd7a6..91e959246 100644 --- a/packages/instant/src/containers/selected_asset_view_transaction_button.tsx +++ b/packages/instant/src/containers/selected_asset_view_transaction_button.tsx @@ -16,7 +16,11 @@ interface ConnectedState { const mapStateToProps = (state: State, _ownProps: {}): ConnectedState => ({ onClick: () => { - if (state.assetBuyer && state.buyOrderState.processState === OrderProcessState.SUCCESS) { + if ( + state.assetBuyer && + (state.buyOrderState.processState === OrderProcessState.PROCESSING || + state.buyOrderState.processState === OrderProcessState.SUCCESS) + ) { const etherscanUrl = etherscanUtil.getEtherScanTxnAddressIfExists( state.buyOrderState.txnHash, state.assetBuyer.networkId, -- cgit v1.2.3 From dc3b867b35f8314a65c27aa25fe2c92268d92866 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 25 Oct 2018 09:22:49 -0700 Subject: Take out old TODO --- packages/instant/src/types.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages/instant') diff --git a/packages/instant/src/types.ts b/packages/instant/src/types.ts index 47c60016c..60f8b8e38 100644 --- a/packages/instant/src/types.ts +++ b/packages/instant/src/types.ts @@ -19,7 +19,6 @@ export enum OrderProcessState { interface RegularOrderState { processState: OrderProcessState.NONE | OrderProcessState.AWAITING_SIGNATURE; } -// TODO: later turn into just a generic OrderStateWithTxn interface ProcessingOrderState { processState: OrderProcessState.PROCESSING; txnHash: string; -- cgit v1.2.3 From 45d828e154b5400710582d1f5414f7446e8d3688 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 25 Oct 2018 09:25:49 -0700 Subject: take out unused imports --- .../instant/src/containers/selected_asset_buy_order_state_button.tsx | 2 +- .../instant/src/containers/selected_asset_view_transaction_button.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/instant') diff --git a/packages/instant/src/containers/selected_asset_buy_order_state_button.tsx b/packages/instant/src/containers/selected_asset_buy_order_state_button.tsx index c02228d76..7faa79912 100644 --- a/packages/instant/src/containers/selected_asset_buy_order_state_button.tsx +++ b/packages/instant/src/containers/selected_asset_buy_order_state_button.tsx @@ -3,7 +3,7 @@ import * as React from 'react'; import { connect } from 'react-redux'; import { State } from '../redux/reducer'; -import { AsyncProcessState, OrderProcessState } from '../types'; +import { OrderProcessState } from '../types'; import { BuyOrderStateButton } from '../components/buy_order_state_button'; diff --git a/packages/instant/src/containers/selected_asset_view_transaction_button.tsx b/packages/instant/src/containers/selected_asset_view_transaction_button.tsx index 91e959246..8239319a4 100644 --- a/packages/instant/src/containers/selected_asset_view_transaction_button.tsx +++ b/packages/instant/src/containers/selected_asset_view_transaction_button.tsx @@ -5,7 +5,7 @@ import { connect } from 'react-redux'; import { State } from '../redux/reducer'; import { ViewTransactionButton } from '../components/view_transaction_button'; -import { AsyncProcessState, OrderProcessState } from '../types'; +import { OrderProcessState } from '../types'; import { etherscanUtil } from '../util/etherscan'; export interface SelectedAssetViewTransactionButtonProps {} -- cgit v1.2.3 From acefeff5f08f123c7c5d372088f2af016e31c599 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 25 Oct 2018 13:18:17 -0700 Subject: new try/catch pattern and new prop names per code review feedback --- packages/instant/src/components/buy_button.tsx | 33 ++++++++++++++++------ .../src/containers/selected_asset_buy_button.ts | 8 +++--- 2 files changed, 28 insertions(+), 13 deletions(-) (limited to 'packages/instant') diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx index f70f2f5be..7004b6a18 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -12,10 +12,10 @@ export interface BuyButtonProps { buyQuote?: BuyQuote; assetBuyer?: AssetBuyer; onAwaitingSignature: (buyQuote: BuyQuote) => void; - onProcessingTransaction: (buyQuote: BuyQuote, txnHash: string) => void; + onSignatureDenied: (buyQuote: BuyQuote, preventedError: Error) => void; + onBuyProcessing: (buyQuote: BuyQuote, txnHash: string) => void; onBuySuccess: (buyQuote: BuyQuote, txnHash: string) => void; - onBuyFailure: (buyQuote: BuyQuote, tnxHash?: string) => void; - onBuyPrevented: (buyQuote: BuyQuote, preventedError: Error) => void; + onBuyFailure: (buyQuote: BuyQuote, txnHash?: string) => void; // TODO: make this non-optional } export class BuyButton extends React.Component { @@ -40,19 +40,34 @@ export class BuyButton extends React.Component { if (_.isUndefined(buyQuote) || _.isUndefined(assetBuyer)) { return; } + + let txnHash: string | undefined; this.props.onAwaitingSignature(buyQuote); - let txnHash; try { txnHash = await assetBuyer.executeBuyQuoteAsync(buyQuote); - this.props.onProcessingTransaction(buyQuote, txnHash); - await web3Wrapper.awaitTransactionSuccessAsync(txnHash); - this.props.onBuySuccess(buyQuote, txnHash); } catch (e) { if (e instanceof Error && e.message === AssetBuyerError.SignatureRequestDenied) { - this.props.onBuyPrevented(buyQuote, e); + this.props.onSignatureDenied(buyQuote, e); + } else { + throw e; + } + } + + // Have to let TS know that txHash is definitely defined now + if (!txnHash) { + throw new Error('No txHash available'); + } + + this.props.onBuyProcessing(buyQuote, txnHash); + try { + await web3Wrapper.awaitTransactionSuccessAsync(txnHash); + } catch (e) { + if (e instanceof Error && e.message.startsWith('Transaction failed')) { + this.props.onBuyFailure(buyQuote, txnHash); return; } - this.props.onBuyFailure(buyQuote, txnHash); + throw e; } + this.props.onBuySuccess(buyQuote, txnHash); }; } diff --git a/packages/instant/src/containers/selected_asset_buy_button.ts b/packages/instant/src/containers/selected_asset_buy_button.ts index f55254daf..17cc1a770 100644 --- a/packages/instant/src/containers/selected_asset_buy_button.ts +++ b/packages/instant/src/containers/selected_asset_buy_button.ts @@ -19,10 +19,10 @@ interface ConnectedState { interface ConnectedDispatch { onAwaitingSignature: (buyQuote: BuyQuote) => void; - onProcessingTransaction: (buyQuote: BuyQuote, txnHash: string) => void; + onSignatureDenied: (buyQuote: BuyQuote, error: Error) => void; + onBuyProcessing: (buyQuote: BuyQuote, txnHash: string) => void; onBuySuccess: (buyQuote: BuyQuote, txnHash: string) => void; onBuyFailure: (buyQuote: BuyQuote) => void; - onBuyPrevented: (buyQuote: BuyQuote, error: Error) => void; } const mapStateToProps = (state: State, _ownProps: SelectedAssetBuyButtonProps): ConnectedState => ({ @@ -35,14 +35,14 @@ const mapDispatchToProps = (dispatch: Dispatch, ownProps: SelectedAssetB const newOrderState: OrderState = { processState: OrderProcessState.AWAITING_SIGNATURE }; dispatch(actions.updateBuyOrderState(newOrderState)); }, - onProcessingTransaction: (buyQuote: BuyQuote, txnHash: string) => { + onBuyProcessing: (buyQuote: BuyQuote, txnHash: string) => { const newOrderState: OrderState = { processState: OrderProcessState.PROCESSING, txnHash }; dispatch(actions.updateBuyOrderState(newOrderState)); }, onBuySuccess: (buyQuote: BuyQuote, txnHash: string) => dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.SUCCESS, txnHash })), onBuyFailure: buyQuote => dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.FAILURE })), - onBuyPrevented: (buyQuote, error) => { + onSignatureDenied: (buyQuote, error) => { dispatch(actions.resetAmount()); dispatch(actions.setError(error)); }, -- cgit v1.2.3 From c5e8bb17635d8710f0db62a8887f990cb6ad482f Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 25 Oct 2018 13:32:37 -0700 Subject: txnHash -> txHash --- packages/instant/src/components/buy_button.tsx | 20 ++++++++++---------- .../src/containers/selected_asset_buy_button.ts | 12 ++++++------ .../selected_asset_view_transaction_button.tsx | 2 +- packages/instant/src/types.ts | 6 +++--- packages/instant/src/util/etherscan.ts | 4 ++-- 5 files changed, 22 insertions(+), 22 deletions(-) (limited to 'packages/instant') diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx index 7004b6a18..841a9593b 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -13,9 +13,9 @@ export interface BuyButtonProps { assetBuyer?: AssetBuyer; onAwaitingSignature: (buyQuote: BuyQuote) => void; onSignatureDenied: (buyQuote: BuyQuote, preventedError: Error) => void; - onBuyProcessing: (buyQuote: BuyQuote, txnHash: string) => void; - onBuySuccess: (buyQuote: BuyQuote, txnHash: string) => void; - onBuyFailure: (buyQuote: BuyQuote, txnHash?: string) => void; // TODO: make this non-optional + onBuyProcessing: (buyQuote: BuyQuote, txHash: string) => void; + onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void; + onBuyFailure: (buyQuote: BuyQuote, txHash?: string) => void; // TODO: make this non-optional } export class BuyButton extends React.Component { @@ -41,10 +41,10 @@ export class BuyButton extends React.Component { return; } - let txnHash: string | undefined; + let txHash: string | undefined; this.props.onAwaitingSignature(buyQuote); try { - txnHash = await assetBuyer.executeBuyQuoteAsync(buyQuote); + txHash = await assetBuyer.executeBuyQuoteAsync(buyQuote); } catch (e) { if (e instanceof Error && e.message === AssetBuyerError.SignatureRequestDenied) { this.props.onSignatureDenied(buyQuote, e); @@ -54,20 +54,20 @@ export class BuyButton extends React.Component { } // Have to let TS know that txHash is definitely defined now - if (!txnHash) { + if (!txHash) { throw new Error('No txHash available'); } - this.props.onBuyProcessing(buyQuote, txnHash); + this.props.onBuyProcessing(buyQuote, txHash); try { - await web3Wrapper.awaitTransactionSuccessAsync(txnHash); + await web3Wrapper.awaitTransactionSuccessAsync(txHash); } catch (e) { if (e instanceof Error && e.message.startsWith('Transaction failed')) { - this.props.onBuyFailure(buyQuote, txnHash); + this.props.onBuyFailure(buyQuote, txHash); return; } throw e; } - this.props.onBuySuccess(buyQuote, txnHash); + this.props.onBuySuccess(buyQuote, txHash); }; } diff --git a/packages/instant/src/containers/selected_asset_buy_button.ts b/packages/instant/src/containers/selected_asset_buy_button.ts index 17cc1a770..8d60715be 100644 --- a/packages/instant/src/containers/selected_asset_buy_button.ts +++ b/packages/instant/src/containers/selected_asset_buy_button.ts @@ -20,8 +20,8 @@ interface ConnectedState { interface ConnectedDispatch { onAwaitingSignature: (buyQuote: BuyQuote) => void; onSignatureDenied: (buyQuote: BuyQuote, error: Error) => void; - onBuyProcessing: (buyQuote: BuyQuote, txnHash: string) => void; - onBuySuccess: (buyQuote: BuyQuote, txnHash: string) => void; + onBuyProcessing: (buyQuote: BuyQuote, txHash: string) => void; + onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void; onBuyFailure: (buyQuote: BuyQuote) => void; } @@ -35,12 +35,12 @@ const mapDispatchToProps = (dispatch: Dispatch, ownProps: SelectedAssetB const newOrderState: OrderState = { processState: OrderProcessState.AWAITING_SIGNATURE }; dispatch(actions.updateBuyOrderState(newOrderState)); }, - onBuyProcessing: (buyQuote: BuyQuote, txnHash: string) => { - const newOrderState: OrderState = { processState: OrderProcessState.PROCESSING, txnHash }; + onBuyProcessing: (buyQuote: BuyQuote, txHash: string) => { + const newOrderState: OrderState = { processState: OrderProcessState.PROCESSING, txHash }; dispatch(actions.updateBuyOrderState(newOrderState)); }, - onBuySuccess: (buyQuote: BuyQuote, txnHash: string) => - dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.SUCCESS, txnHash })), + onBuySuccess: (buyQuote: BuyQuote, txHash: string) => + dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.SUCCESS, txHash })), onBuyFailure: buyQuote => dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.FAILURE })), onSignatureDenied: (buyQuote, error) => { dispatch(actions.resetAmount()); diff --git a/packages/instant/src/containers/selected_asset_view_transaction_button.tsx b/packages/instant/src/containers/selected_asset_view_transaction_button.tsx index 8239319a4..064b877be 100644 --- a/packages/instant/src/containers/selected_asset_view_transaction_button.tsx +++ b/packages/instant/src/containers/selected_asset_view_transaction_button.tsx @@ -22,7 +22,7 @@ const mapStateToProps = (state: State, _ownProps: {}): ConnectedState => ({ state.buyOrderState.processState === OrderProcessState.SUCCESS) ) { const etherscanUrl = etherscanUtil.getEtherScanTxnAddressIfExists( - state.buyOrderState.txnHash, + state.buyOrderState.txHash, state.assetBuyer.networkId, ); if (etherscanUrl) { diff --git a/packages/instant/src/types.ts b/packages/instant/src/types.ts index 60f8b8e38..255aee1eb 100644 --- a/packages/instant/src/types.ts +++ b/packages/instant/src/types.ts @@ -21,15 +21,15 @@ interface RegularOrderState { } interface ProcessingOrderState { processState: OrderProcessState.PROCESSING; - txnHash: string; + txHash: string; } interface SuccessfulOrderState { processState: OrderProcessState.SUCCESS; - txnHash: string; + txHash: string; } interface FailureOrderState { processState: OrderProcessState.FAILURE; - txnHash?: string; + txHash?: string; } export type OrderState = RegularOrderState | ProcessingOrderState | SuccessfulOrderState | FailureOrderState; diff --git a/packages/instant/src/util/etherscan.ts b/packages/instant/src/util/etherscan.ts index ffb08a382..cfc2578a3 100644 --- a/packages/instant/src/util/etherscan.ts +++ b/packages/instant/src/util/etherscan.ts @@ -14,11 +14,11 @@ const etherscanPrefix = (networkId: number): string | undefined => { }; export const etherscanUtil = { - getEtherScanTxnAddressIfExists: (txnHash: string, networkId: number) => { + getEtherScanTxnAddressIfExists: (txHash: string, networkId: number) => { const prefix = etherscanPrefix(networkId); if (_.isUndefined(prefix)) { return; } - return `https://${prefix}etherscan.io/tx/${txnHash}`; + return `https://${prefix}etherscan.io/tx/${txHash}`; }, }; -- cgit v1.2.3 From 3adc6b6daa16bb1dc80a8c4109b0bed56f937ea0 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 25 Oct 2018 13:36:45 -0700 Subject: Making failure txHash required --- packages/instant/src/components/buy_button.tsx | 2 +- packages/instant/src/containers/selected_asset_buy_button.ts | 5 +++-- packages/instant/src/types.ts | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'packages/instant') diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx index 841a9593b..6fe333dc7 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -15,7 +15,7 @@ export interface BuyButtonProps { onSignatureDenied: (buyQuote: BuyQuote, preventedError: Error) => void; onBuyProcessing: (buyQuote: BuyQuote, txHash: string) => void; onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void; - onBuyFailure: (buyQuote: BuyQuote, txHash?: string) => void; // TODO: make this non-optional + onBuyFailure: (buyQuote: BuyQuote, txHash: string) => void; } export class BuyButton extends React.Component { diff --git a/packages/instant/src/containers/selected_asset_buy_button.ts b/packages/instant/src/containers/selected_asset_buy_button.ts index 8d60715be..adcbd61bc 100644 --- a/packages/instant/src/containers/selected_asset_buy_button.ts +++ b/packages/instant/src/containers/selected_asset_buy_button.ts @@ -22,7 +22,7 @@ interface ConnectedDispatch { onSignatureDenied: (buyQuote: BuyQuote, error: Error) => void; onBuyProcessing: (buyQuote: BuyQuote, txHash: string) => void; onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void; - onBuyFailure: (buyQuote: BuyQuote) => void; + onBuyFailure: (buyQuote: BuyQuote, txHash: string) => void; } const mapStateToProps = (state: State, _ownProps: SelectedAssetBuyButtonProps): ConnectedState => ({ @@ -41,7 +41,8 @@ const mapDispatchToProps = (dispatch: Dispatch, ownProps: SelectedAssetB }, onBuySuccess: (buyQuote: BuyQuote, txHash: string) => dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.SUCCESS, txHash })), - onBuyFailure: buyQuote => dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.FAILURE })), + onBuyFailure: (buyQuote: BuyQuote, txHash: string) => + dispatch(actions.updateBuyOrderState({ processState: OrderProcessState.FAILURE, txHash })), onSignatureDenied: (buyQuote, error) => { dispatch(actions.resetAmount()); dispatch(actions.setError(error)); diff --git a/packages/instant/src/types.ts b/packages/instant/src/types.ts index 255aee1eb..ad8794c94 100644 --- a/packages/instant/src/types.ts +++ b/packages/instant/src/types.ts @@ -29,7 +29,7 @@ interface SuccessfulOrderState { } interface FailureOrderState { processState: OrderProcessState.FAILURE; - txHash?: string; + txHash: string; } export type OrderState = RegularOrderState | ProcessingOrderState | SuccessfulOrderState | FailureOrderState; -- cgit v1.2.3 From e55d8802e10afd20791aafd2b0958b674f9c0408 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 25 Oct 2018 13:53:35 -0700 Subject: Rework OrderState to have more simple definition --- packages/instant/src/types.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'packages/instant') diff --git a/packages/instant/src/types.ts b/packages/instant/src/types.ts index ad8794c94..63b49cb26 100644 --- a/packages/instant/src/types.ts +++ b/packages/instant/src/types.ts @@ -16,22 +16,14 @@ export enum OrderProcessState { FAILURE = 'Failure', } -interface RegularOrderState { +interface OrderStateWithoutTx { processState: OrderProcessState.NONE | OrderProcessState.AWAITING_SIGNATURE; } -interface ProcessingOrderState { - processState: OrderProcessState.PROCESSING; +interface OrderStateWithTx { + processState: OrderProcessState.PROCESSING | OrderProcessState.SUCCESS | OrderProcessState.FAILURE; txHash: string; } -interface SuccessfulOrderState { - processState: OrderProcessState.SUCCESS; - txHash: string; -} -interface FailureOrderState { - processState: OrderProcessState.FAILURE; - txHash: string; -} -export type OrderState = RegularOrderState | ProcessingOrderState | SuccessfulOrderState | FailureOrderState; +export type OrderState = OrderStateWithoutTx | OrderStateWithTx; export enum DisplayStatus { Present, -- cgit v1.2.3 From 062187f28d76bf420c235bc83a56926e35bd8db0 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 25 Oct 2018 13:58:32 -0700 Subject: better type names --- packages/instant/src/types.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/instant') diff --git a/packages/instant/src/types.ts b/packages/instant/src/types.ts index 63b49cb26..c63371fb4 100644 --- a/packages/instant/src/types.ts +++ b/packages/instant/src/types.ts @@ -16,14 +16,14 @@ export enum OrderProcessState { FAILURE = 'Failure', } -interface OrderStateWithoutTx { +interface OrderStatePreTx { processState: OrderProcessState.NONE | OrderProcessState.AWAITING_SIGNATURE; } -interface OrderStateWithTx { +interface OrderStatePostTx { processState: OrderProcessState.PROCESSING | OrderProcessState.SUCCESS | OrderProcessState.FAILURE; txHash: string; } -export type OrderState = OrderStateWithoutTx | OrderStateWithTx; +export type OrderState = OrderStatePreTx | OrderStatePostTx; export enum DisplayStatus { Present, -- cgit v1.2.3 From f04eba77736a429bea19a4544cfbabc38069d04d Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 25 Oct 2018 14:44:25 -0700 Subject: Added string to constants --- packages/instant/src/components/buy_button.tsx | 3 ++- packages/instant/src/constants.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'packages/instant') diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx index 6fe333dc7..a7a22e3bc 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -2,6 +2,7 @@ import { AssetBuyer, AssetBuyerError, BuyQuote } from '@0x/asset-buyer'; import * as _ from 'lodash'; import * as React from 'react'; +import { WEB_3_WRAPPER_TRANSACTION_FAILED_ERROR_MSG_PREFIX } from '../constants'; import { ColorOption } from '../style/theme'; import { util } from '../util/util'; import { web3Wrapper } from '../util/web3_wrapper'; @@ -62,7 +63,7 @@ export class BuyButton extends React.Component { try { await web3Wrapper.awaitTransactionSuccessAsync(txHash); } catch (e) { - if (e instanceof Error && e.message.startsWith('Transaction failed')) { + if (e instanceof Error && e.message.startsWith(WEB_3_WRAPPER_TRANSACTION_FAILED_ERROR_MSG_PREFIX)) { this.props.onBuyFailure(buyQuote, txHash); return; } diff --git a/packages/instant/src/constants.ts b/packages/instant/src/constants.ts index 31491c80a..48d0d4aa2 100644 --- a/packages/instant/src/constants.ts +++ b/packages/instant/src/constants.ts @@ -2,3 +2,4 @@ import { BigNumber } from '@0x/utils'; export const BIG_NUMBER_ZERO = new BigNumber(0); export const ethDecimals = 18; export const DEFAULT_ZERO_EX_CONTAINER_SELECTOR = '#zeroExInstantContainer'; +export const WEB_3_WRAPPER_TRANSACTION_FAILED_ERROR_MSG_PREFIX = 'Transaction failed'; -- cgit v1.2.3 From 89e59cca28a86763519237ab9c6971600e200b5e Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 25 Oct 2018 14:48:59 -0700 Subject: cleanup code --- packages/instant/src/components/buy_button.tsx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'packages/instant') diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx index a7a22e3bc..a70269dde 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -49,14 +49,9 @@ export class BuyButton extends React.Component { } catch (e) { if (e instanceof Error && e.message === AssetBuyerError.SignatureRequestDenied) { this.props.onSignatureDenied(buyQuote, e); - } else { - throw e; + return; } - } - - // Have to let TS know that txHash is definitely defined now - if (!txHash) { - throw new Error('No txHash available'); + throw e; } this.props.onBuyProcessing(buyQuote, txHash); -- cgit v1.2.3