aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/containers
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-10-18 07:41:35 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-10-18 07:41:35 +0800
commit6cf8d57aee3ed332bd1109f8f39792894147d2dd (patch)
tree2a12a521fa6bba01f64799ad40acbb3b074f9cff /packages/instant/src/containers
parent7b43cd14b305e3f01081e7ea7d0385966e4529be (diff)
downloaddexon-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')
-rw-r--r--packages/instant/src/containers/selected_asset_amount_input.ts24
-rw-r--r--packages/instant/src/containers/selected_asset_instant_heading.ts3
2 files changed, 18 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);
+ }
},
});
diff --git a/packages/instant/src/containers/selected_asset_instant_heading.ts b/packages/instant/src/containers/selected_asset_instant_heading.ts
index c97cfe11a..be31527f1 100644
--- a/packages/instant/src/containers/selected_asset_instant_heading.ts
+++ b/packages/instant/src/containers/selected_asset_instant_heading.ts
@@ -5,6 +5,7 @@ import { connect } from 'react-redux';
import { oc } from 'ts-optchain';
import { State } from '../redux/reducer';
+import { AsyncProcessState } from '../types';
import { InstantHeading } from '../components/instant_heading';
@@ -14,12 +15,14 @@ interface ConnectedState {
selectedAssetAmount?: BigNumber;
totalEthBaseAmount?: BigNumber;
ethUsdPrice?: BigNumber;
+ quoteState: AsyncProcessState;
}
const mapStateToProps = (state: State, _ownProps: InstantHeadingProps): ConnectedState => ({
selectedAssetAmount: state.selectedAssetAmount,
totalEthBaseAmount: oc(state).latestBuyQuote.worstCaseQuoteInfo.totalEthAmount(),
ethUsdPrice: state.ethUsdPrice,
+ quoteState: state.quoteState,
});
export const SelectedAssetInstantHeading: React.ComponentClass<InstantHeadingProps> = connect(mapStateToProps)(