diff options
Diffstat (limited to 'packages/instant/src/redux/reducer.ts')
-rw-r--r-- | packages/instant/src/redux/reducer.ts | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index adecf2ab7..9922131b4 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -1,14 +1,17 @@ -import { BuyQuote } from '@0xproject/asset-buyer'; +import { AssetBuyer, BuyQuote } from '@0xproject/asset-buyer'; +import { ObjectMap } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; -import { zrxAssetData } from '../constants'; -import { AsyncProcessState } from '../types'; +import { Asset, AssetMetaData, AsyncProcessState } from '../types'; +import { assetUtils } from '../util/asset'; import { Action, ActionTypes } from './actions'; export interface State { - selectedAssetData?: string; + assetBuyer?: AssetBuyer; + assetMetaDataMap: ObjectMap<AssetMetaData>; + selectedAsset?: Asset; selectedAssetAmount?: BigNumber; selectedAssetBuyState: AsyncProcessState; ethUsdPrice?: BigNumber; @@ -16,14 +19,14 @@ export interface State { } export const INITIAL_STATE: State = { - // TODO: Remove hardcoded zrxAssetData - selectedAssetData: zrxAssetData, selectedAssetAmount: undefined, + assetMetaDataMap: {}, selectedAssetBuyState: AsyncProcessState.NONE, ethUsdPrice: undefined, latestBuyQuote: undefined, }; +// TODO: Figure out why there is an INITIAL_STATE key in the store... export const reducer = (state: State = INITIAL_STATE, action: Action): State => { switch (action.type) { case ActionTypes.UPDATE_ETH_USD_PRICE: @@ -46,6 +49,16 @@ export const reducer = (state: State = INITIAL_STATE, action: Action): State => ...state, selectedAssetBuyState: action.data, }; + case ActionTypes.UPDATE_SELECTED_ASSET: + const newSelectedAssetData = action.data; + let newSelectedAsset: Asset | undefined; + if (!_.isUndefined(newSelectedAssetData)) { + newSelectedAsset = assetUtils.createAssetFromAssetData(newSelectedAssetData, state.assetMetaDataMap); + } + return { + ...state, + selectedAsset: newSelectedAsset, + }; default: return state; } |