aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'packages/instant/src/components')
-rw-r--r--packages/instant/src/components/buy_button.tsx13
-rw-r--r--packages/instant/src/components/buy_order_state_buttons.tsx12
2 files changed, 14 insertions, 11 deletions
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<boolean>;
}
export class BuyButton extends React.Component<BuyButtonProps> {
@@ -45,14 +46,16 @@ export class BuyButton extends React.Component<BuyButtonProps> {
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<boolean>;
+ onValidationFail: (buyQuote: BuyQuote, error: ZeroExInstantError) => void;
}
// TODO: rename to buttons
@@ -46,7 +46,7 @@ export const BuyOrderStateButtons: React.StatelessComponent<BuyOrderStateButtonP
props.buyOrderProcessingState === OrderProcessState.PROCESSING
) {
return <SecondaryButton onClick={props.onViewTransaction}>View Transaction</SecondaryButton>;
- } else if (props.buyOrderProcessingState === OrderProcessState.AWAITING_SIGNATURE) {
+ } else if (props.buyOrderProcessingState === OrderProcessState.VALIDATING) {
return <PlacingOrderButton />;
}
@@ -54,12 +54,12 @@ export const BuyOrderStateButtons: React.StatelessComponent<BuyOrderStateButtonP
<BuyButton
buyQuote={props.buyQuote}
assetBuyer={props.assetBuyer}
- onAwaitingSignature={props.onAwaitingSignature}
+ onPendingValidation={props.onPendingValidation}
onSignatureDenied={props.onSignatureDenied}
onBuyProcessing={props.onBuyProcessing}
onBuySuccess={props.onBuySuccess}
onBuyFailure={props.onBuyFailure}
- validateWalletBeforeBuy={props.validateWalletBeforeBuy}
+ onValidationFail={props.onValidationFail}
/>
);
};