diff options
author | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-10-18 07:41:35 +0800 |
---|---|---|
committer | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-10-18 07:41:35 +0800 |
commit | 6cf8d57aee3ed332bd1109f8f39792894147d2dd (patch) | |
tree | 2a12a521fa6bba01f64799ad40acbb3b074f9cff /packages/instant/src/containers/selected_asset_amount_input.ts | |
parent | 7b43cd14b305e3f01081e7ea7d0385966e4529be (diff) | |
download | dexon-sol-tools-6cf8d57aee3ed332bd1109f8f39792894147d2dd.tar dexon-sol-tools-6cf8d57aee3ed332bd1109f8f39792894147d2dd.tar.gz dexon-sol-tools-6cf8d57aee3ed332bd1109f8f39792894147d2dd.tar.bz2 dexon-sol-tools-6cf8d57aee3ed332bd1109f8f39792894147d2dd.tar.lz dexon-sol-tools-6cf8d57aee3ed332bd1109f8f39792894147d2dd.tar.xz dexon-sol-tools-6cf8d57aee3ed332bd1109f8f39792894147d2dd.tar.zst dexon-sol-tools-6cf8d57aee3ed332bd1109f8f39792894147d2dd.zip |
add concept of quoteState
Diffstat (limited to 'packages/instant/src/containers/selected_asset_amount_input.ts')
-rw-r--r-- | packages/instant/src/containers/selected_asset_amount_input.ts | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/packages/instant/src/containers/selected_asset_amount_input.ts b/packages/instant/src/containers/selected_asset_amount_input.ts index 0d2c6dd7b..87bb0e335 100644 --- a/packages/instant/src/containers/selected_asset_amount_input.ts +++ b/packages/instant/src/containers/selected_asset_amount_input.ts @@ -37,24 +37,25 @@ const mapStateToProps = (state: State, _ownProps: SelectedAssetAmountInputProps) const updateBuyQuoteAsync = async ( dispatch: Dispatch<Action>, - assetData?: string, - assetAmount?: BigNumber, + assetData: string, + assetAmount: BigNumber, ): Promise<void> => { - if (_.isUndefined(assetAmount) || _.isUndefined(assetData)) { - return; - } // get a new buy quote. const baseUnitValue = Web3Wrapper.toBaseUnitAmount(assetAmount, zrxDecimals); + // mark quote as pending + dispatch(actions.updateBuyQuoteStatePending()); + let newBuyQuote: BuyQuote | undefined; try { newBuyQuote = await assetBuyer.getBuyQuoteAsync(assetData, baseUnitValue); - errorUtil.errorFlasher.clearError(dispatch); } catch (error) { + dispatch(actions.updateBuyQuoteStateFailure()); errorUtil.errorFlasher.flashNewError(dispatch, error); return; } - + // We have a successful new buy quote + errorUtil.errorFlasher.clearError(dispatch); // invalidate the last buy quote. dispatch(actions.updateLatestBuyQuote(newBuyQuote)); }; @@ -72,8 +73,13 @@ const mapDispatchToProps = ( dispatch(actions.updateLatestBuyQuote(undefined)); // reset our buy state dispatch(actions.updateSelectedAssetBuyState(AsyncProcessState.NONE)); - // tslint:disable-next-line:no-floating-promises - debouncedUpdateBuyQuoteAsync(dispatch, assetData, value); + + if (!_.isUndefined(value) && !_.isUndefined(assetData)) { + // even if it's debounced, give them the illusion it's loading + dispatch(actions.updateBuyQuoteStatePending()); + // tslint:disable-next-line:no-floating-promises + debouncedUpdateBuyQuoteAsync(dispatch, assetData, value); + } }, }); |