diff options
author | Steve Klebanoff <steve@0xproject.com> | 2018-10-30 01:12:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-30 01:12:44 +0800 |
commit | 4e4291eccdd6c837bbec70603aa6eb64d3aa8d85 (patch) | |
tree | edf8006576143d5cd1c32b052164ac898c57c8b2 /packages/instant/src/components/buy_button.tsx | |
parent | ae6202ed3d777605a3fd02cd29141a3ba40f4b34 (diff) | |
parent | 7ed44f7b2f0224b4169f0a8f34bae09e8c6b986f (diff) | |
download | dexon-0x-contracts-4e4291eccdd6c837bbec70603aa6eb64d3aa8d85.tar.gz dexon-0x-contracts-4e4291eccdd6c837bbec70603aa6eb64d3aa8d85.tar.zst dexon-0x-contracts-4e4291eccdd6c837bbec70603aa6eb64d3aa8d85.zip |
Merge pull request #1193 from 0xProject/feature/not-enough-eth
[instant] Not enough ETH error message
Diffstat (limited to 'packages/instant/src/components/buy_button.tsx')
-rw-r--r-- | packages/instant/src/components/buy_button.tsx | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx index a70269dde..bcd435250 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -4,6 +4,9 @@ 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'; import { web3Wrapper } from '../util/web3_wrapper'; @@ -12,7 +15,8 @@ import { Button, Text } from './ui'; export interface BuyButtonProps { buyQuote?: BuyQuote; assetBuyer?: AssetBuyer; - onAwaitingSignature: (buyQuote: BuyQuote) => void; + onValidationPending: (buyQuote: BuyQuote) => 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; @@ -42,14 +46,27 @@ export class BuyButton extends React.Component<BuyButtonProps> { return; } + this.props.onValidationPending(buyQuote); + const takerAddress = await getBestAddress(); + + const hasSufficentEth = await balanceUtil.hasSufficentEth(takerAddress, buyQuote, web3Wrapper); + if (!hasSufficentEth) { + this.props.onValidationFail(buyQuote, ZeroExInstantError.InsufficientETH); + return; + } + let txHash: string | undefined; - this.props.onAwaitingSignature(buyQuote); try { - txHash = await assetBuyer.executeBuyQuoteAsync(buyQuote); + 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; } |