diff options
author | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-10-31 07:40:51 +0800 |
---|---|---|
committer | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-10-31 07:40:51 +0800 |
commit | 1c0569cfc61d7b166d79d2d73e9bbc6d11a5b4e8 (patch) | |
tree | f777e047a103bcd124cf28a3ce2be30167f8a104 /packages/instant/src/components | |
parent | 9cc82308e504a62a2bd3b16e79173a98279fdb66 (diff) | |
download | dexon-sol-tools-1c0569cfc61d7b166d79d2d73e9bbc6d11a5b4e8.tar dexon-sol-tools-1c0569cfc61d7b166d79d2d73e9bbc6d11a5b4e8.tar.gz dexon-sol-tools-1c0569cfc61d7b166d79d2d73e9bbc6d11a5b4e8.tar.bz2 dexon-sol-tools-1c0569cfc61d7b166d79d2d73e9bbc6d11a5b4e8.tar.lz dexon-sol-tools-1c0569cfc61d7b166d79d2d73e9bbc6d11a5b4e8.tar.xz dexon-sol-tools-1c0569cfc61d7b166d79d2d73e9bbc6d11a5b4e8.tar.zst dexon-sol-tools-1c0569cfc61d7b166d79d2d73e9bbc6d11a5b4e8.zip |
Use simulated progress bar for txn
Diffstat (limited to 'packages/instant/src/components')
-rw-r--r-- | packages/instant/src/components/buy_button.tsx | 14 | ||||
-rw-r--r-- | packages/instant/src/components/buy_order_state_buttons.tsx | 39 |
2 files changed, 34 insertions, 19 deletions
diff --git a/packages/instant/src/components/buy_button.tsx b/packages/instant/src/components/buy_button.tsx index ec1010fe9..d10936d05 100644 --- a/packages/instant/src/components/buy_button.tsx +++ b/packages/instant/src/components/buy_button.tsx @@ -19,9 +19,9 @@ export interface BuyButtonProps { onValidationPending: (buyQuote: BuyQuote) => void; onValidationFail: (buyQuote: BuyQuote, errorMessage: AssetBuyerError | ZeroExInstantError) => void; onSignatureDenied: (buyQuote: BuyQuote) => void; - onBuyProcessing: (buyQuote: BuyQuote, txHash: string, estimatedTimeMs?: number) => void; - onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void; - onBuyFailure: (buyQuote: BuyQuote, txHash: string) => void; + onBuyProcessing: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => void; + onBuySuccess: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => void; + onBuyFailure: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => void; } export class BuyButton extends React.Component<BuyButtonProps> { @@ -73,16 +73,18 @@ export class BuyButton extends React.Component<BuyButtonProps> { throw e; } - this.props.onBuyProcessing(buyQuote, txHash, gasInfo.estimatedTimeMs); + const startTimeUnix = new Date().getTime(); + const expectedEndTimeUnix = startTimeUnix + gasInfo.estimatedTimeMs; + this.props.onBuyProcessing(buyQuote, txHash, startTimeUnix, expectedEndTimeUnix); try { await web3Wrapper.awaitTransactionSuccessAsync(txHash); } catch (e) { if (e instanceof Error && e.message.startsWith(WEB_3_WRAPPER_TRANSACTION_FAILED_ERROR_MSG_PREFIX)) { - this.props.onBuyFailure(buyQuote, txHash); + this.props.onBuyFailure(buyQuote, txHash, startTimeUnix, expectedEndTimeUnix); return; } throw e; } - this.props.onBuySuccess(buyQuote, txHash); + this.props.onBuySuccess(buyQuote, txHash, startTimeUnix, expectedEndTimeUnix); }; } diff --git a/packages/instant/src/components/buy_order_state_buttons.tsx b/packages/instant/src/components/buy_order_state_buttons.tsx index d01e9ff57..6f197a772 100644 --- a/packages/instant/src/components/buy_order_state_buttons.tsx +++ b/packages/instant/src/components/buy_order_state_buttons.tsx @@ -6,6 +6,7 @@ import { SecondaryButton } from '../components/secondary_button'; import { Flex } from '../components/ui/flex'; import { PlacingOrderButton } from '../components/placing_order_button'; +import { SimulatedProgressBar } from '../components/simulated_progress_bar'; import { ColorOption } from '../style/theme'; import { OrderProcessState, ZeroExInstantError } from '../types'; @@ -20,10 +21,13 @@ export interface BuyOrderStateButtonProps { onValidationPending: (buyQuote: BuyQuote) => void; onValidationFail: (buyQuote: BuyQuote, errorMessage: AssetBuyerError | ZeroExInstantError) => void; onSignatureDenied: (buyQuote: BuyQuote) => void; - onBuyProcessing: (buyQuote: BuyQuote, txHash: string) => void; - onBuySuccess: (buyQuote: BuyQuote, txHash: string) => void; - onBuyFailure: (buyQuote: BuyQuote, txHash: string) => void; + onBuyProcessing: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => void; + onBuySuccess: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => void; + onBuyFailure: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => void; onRetry: () => void; + + // TODO: dont commit! + secondaryProgressDemo: () => void; } // TODO: rename to buttons @@ -50,16 +54,25 @@ export const BuyOrderStateButtons: React.StatelessComponent<BuyOrderStateButtonP return <PlacingOrderButton />; } + const curTime = new Date().getTime(); + const expectedEndTime = curTime + 5000; return ( - <BuyButton - buyQuote={props.buyQuote} - assetBuyer={props.assetBuyer} - onValidationPending={props.onValidationPending} - onValidationFail={props.onValidationFail} - onSignatureDenied={props.onSignatureDenied} - onBuyProcessing={props.onBuyProcessing} - onBuySuccess={props.onBuySuccess} - onBuyFailure={props.onBuyFailure} - /> + <div> + {/* <div style={{ marginBottom: '20px' }}> + <SimulatedProgressBar startTimeUnix={curTime} expectedEndTimeUnix={expectedEndTime} ended={false} /> + </div> */} + + <SecondaryButton onClick={props.secondaryProgressDemo}>New progress bar demo</SecondaryButton> + <BuyButton + buyQuote={props.buyQuote} + assetBuyer={props.assetBuyer} + onValidationPending={props.onValidationPending} + onValidationFail={props.onValidationFail} + onSignatureDenied={props.onSignatureDenied} + onBuyProcessing={props.onBuyProcessing} + onBuySuccess={props.onBuySuccess} + onBuyFailure={props.onBuyFailure} + /> + </div> ); }; |