diff options
author | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-10-25 07:04:09 +0800 |
---|---|---|
committer | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-10-25 07:04:09 +0800 |
commit | 73f5ea2906502e89fa9bca275e229a1485d2f974 (patch) | |
tree | 94100c43f7ace72723235daaffc7f7281f30738e /packages/instant/src/components/buy_button.tsx | |
parent | db3ad83ebca88e0faf2529ec468044e6ce4d5746 (diff) | |
download | dexon-sol-tools-73f5ea2906502e89fa9bca275e229a1485d2f974.tar dexon-sol-tools-73f5ea2906502e89fa9bca275e229a1485d2f974.tar.gz dexon-sol-tools-73f5ea2906502e89fa9bca275e229a1485d2f974.tar.bz2 dexon-sol-tools-73f5ea2906502e89fa9bca275e229a1485d2f974.tar.lz dexon-sol-tools-73f5ea2906502e89fa9bca275e229a1485d2f974.tar.xz dexon-sol-tools-73f5ea2906502e89fa9bca275e229a1485d2f974.tar.zst dexon-sol-tools-73f5ea2906502e89fa9bca275e229a1485d2f974.zip |
Associate txnhash with processing state
Diffstat (limited to 'packages/instant/src/components/buy_button.tsx')
-rw-r--r-- | packages/instant/src/components/buy_button.tsx | 19 |
1 files changed, 11 insertions, 8 deletions
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<BuyButtonProps> { } 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); } }; } |