From f3391e1250767eb9ef7a74f78eded38fa3c94586 Mon Sep 17 00:00:00 2001 From: fragosti Date: Fri, 12 Oct 2018 11:00:36 -0700 Subject: feat: make redux actions type-sage --- .../src/containers/selected_asset_amount_input.ts | 12 +++++++----- .../instant/src/containers/selected_asset_buy_button.ts | 16 ++++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) (limited to 'packages/instant/src/containers') diff --git a/packages/instant/src/containers/selected_asset_amount_input.ts b/packages/instant/src/containers/selected_asset_amount_input.ts index fa675b385..9e3063ecc 100644 --- a/packages/instant/src/containers/selected_asset_amount_input.ts +++ b/packages/instant/src/containers/selected_asset_amount_input.ts @@ -6,9 +6,10 @@ import { connect } from 'react-redux'; import { Dispatch } from 'redux'; import { zrxContractAddress, zrxDecimals } from '../constants'; +import { Action, actions } from '../redux/actions'; import { State } from '../redux/reducer'; import { ColorOption } from '../style/theme'; -import { Action, ActionTypes, AsyncProcessState } from '../types'; +import { AsyncProcessState } from '../types'; import { assetBuyer } from '../util/asset_buyer'; import { AmountInput } from '../components/amount_input'; @@ -38,7 +39,7 @@ const updateBuyQuote = async (dispatch: Dispatch, assetAmount?: BigNumbe 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 }); + dispatch(actions.updateLatestBuyQuote(newBuyQuote)); }; const debouncedUpdateBuyQuote = _.debounce(updateBuyQuote, 200, { trailing: true }); @@ -46,11 +47,12 @@ const debouncedUpdateBuyQuote = _.debounce(updateBuyQuote, 200, { trailing: true const mapDispatchToProps = (dispatch: Dispatch): ConnectedDispatch => ({ onChange: async value => { // Update the input - dispatch({ type: ActionTypes.UPDATE_SELECTED_ASSET_AMOUNT, data: value }); + dispatch(actions.updateSelectedAssetAmount(value)); // invalidate the last buy quote. - dispatch({ type: ActionTypes.UPDATE_LATEST_BUY_QUOTE, data: undefined }); + dispatch(actions.updateLatestBuyQuote(undefined)); // reset our buy state - dispatch({ type: ActionTypes.UPDATE_SELECTED_ASSET_BUY_STATE, data: AsyncProcessState.NONE }); + dispatch(actions.updateSelectedAssetBuyState(AsyncProcessState.NONE)); + // tslint:disable-next-line:no-floating-promises debouncedUpdateBuyQuote(dispatch, value); }, }); diff --git a/packages/instant/src/containers/selected_asset_buy_button.ts b/packages/instant/src/containers/selected_asset_buy_button.ts index 678c7e445..4cbaf5537 100644 --- a/packages/instant/src/containers/selected_asset_buy_button.ts +++ b/packages/instant/src/containers/selected_asset_buy_button.ts @@ -4,12 +4,11 @@ import * as React from 'react'; import { connect } from 'react-redux'; import { Dispatch } from 'redux'; +import { Action, actions } from '../redux/actions'; import { State } from '../redux/reducer'; -import { Action, ActionTypes, AsyncProcessState } from '../types'; -import { assetBuyer } from '../util/asset_buyer'; -import { web3Wrapper } from '../util/web3_wrapper'; +import { AsyncProcessState } from '../types'; -import { BuyButton, BuyButtonProps } from '../components/buy_button'; +import { BuyButton } from '../components/buy_button'; export interface SelectedAssetBuyButtonProps {} @@ -45,12 +44,9 @@ const mapStateToProps = (state: State, _ownProps: SelectedAssetBuyButtonProps): }); const mapDispatchToProps = (dispatch: Dispatch, ownProps: SelectedAssetBuyButtonProps): ConnectedDispatch => ({ - onClick: buyQuote => - dispatch({ type: ActionTypes.UPDATE_SELECTED_ASSET_BUY_STATE, data: AsyncProcessState.PENDING }), - onBuySuccess: buyQuote => - dispatch({ type: ActionTypes.UPDATE_SELECTED_ASSET_BUY_STATE, data: AsyncProcessState.SUCCESS }), - onBuyFailure: buyQuote => - dispatch({ type: ActionTypes.UPDATE_SELECTED_ASSET_BUY_STATE, data: AsyncProcessState.FAILURE }), + onClick: buyQuote => dispatch(actions.updateSelectedAssetBuyState(AsyncProcessState.PENDING)), + onBuySuccess: buyQuote => dispatch(actions.updateSelectedAssetBuyState(AsyncProcessState.SUCCESS)), + onBuyFailure: buyQuote => dispatch(actions.updateSelectedAssetBuyState(AsyncProcessState.FAILURE)), }); export const SelectedAssetBuyButton: React.ComponentClass = connect( -- cgit v1.2.3