aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/instant/src/containers/selected_asset_amount_input.ts24
1 files changed, 14 insertions, 10 deletions
diff --git a/packages/instant/src/containers/selected_asset_amount_input.ts b/packages/instant/src/containers/selected_asset_amount_input.ts
index b731b889a..fa675b385 100644
--- a/packages/instant/src/containers/selected_asset_amount_input.ts
+++ b/packages/instant/src/containers/selected_asset_amount_input.ts
@@ -30,6 +30,19 @@ const mapStateToProps = (state: State, _ownProps: SelectedAssetAmountInputProps)
value: state.selectedAssetAmount,
});
+const updateBuyQuote = async (dispatch: Dispatch<Action>, assetAmount?: BigNumber): Promise<void> => {
+ if (_.isUndefined(assetAmount)) {
+ return;
+ }
+ // get a new buy quote.
+ const baseUnitValue = Web3Wrapper.toBaseUnitAmount(assetAmount, zrxDecimals);
+ const newBuyQuote = await assetBuyer.getBuyQuoteForERC20TokenAddressAsync(zrxContractAddress, baseUnitValue);
+ // invalidate the last buy quote.
+ dispatch({ type: ActionTypes.UPDATE_LATEST_BUY_QUOTE, data: newBuyQuote });
+};
+
+const debouncedUpdateBuyQuote = _.debounce(updateBuyQuote, 200, { trailing: true });
+
const mapDispatchToProps = (dispatch: Dispatch<Action>): ConnectedDispatch => ({
onChange: async value => {
// Update the input
@@ -38,16 +51,7 @@ const mapDispatchToProps = (dispatch: Dispatch<Action>): ConnectedDispatch => ({
dispatch({ type: ActionTypes.UPDATE_LATEST_BUY_QUOTE, data: undefined });
// reset our buy state
dispatch({ type: ActionTypes.UPDATE_SELECTED_ASSET_BUY_STATE, data: AsyncProcessState.NONE });
- if (!_.isUndefined(value)) {
- // get a new buy quote.
- const baseUnitValue = Web3Wrapper.toBaseUnitAmount(value, zrxDecimals);
- const newBuyQuote = await assetBuyer.getBuyQuoteForERC20TokenAddressAsync(
- zrxContractAddress,
- baseUnitValue,
- );
- // invalidate the last buy quote.
- dispatch({ type: ActionTypes.UPDATE_LATEST_BUY_QUOTE, data: newBuyQuote });
- }
+ debouncedUpdateBuyQuote(dispatch, value);
},
});