diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-10-19 01:43:41 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-10-19 01:43:41 +0800 |
commit | a764dfa789ba44e519371b4a1e4569db7f551fb7 (patch) | |
tree | 80cd8aff6fcf941269afdec8022d0dd5759700fa /packages/instant/src/redux/reducer.ts | |
parent | 5ec4b27200297708298deca97603849a37b2f66a (diff) | |
download | dexon-sol-tools-a764dfa789ba44e519371b4a1e4569db7f551fb7.tar dexon-sol-tools-a764dfa789ba44e519371b4a1e4569db7f551fb7.tar.gz dexon-sol-tools-a764dfa789ba44e519371b4a1e4569db7f551fb7.tar.bz2 dexon-sol-tools-a764dfa789ba44e519371b4a1e4569db7f551fb7.tar.lz dexon-sol-tools-a764dfa789ba44e519371b4a1e4569db7f551fb7.tar.xz dexon-sol-tools-a764dfa789ba44e519371b4a1e4569db7f551fb7.tar.zst dexon-sol-tools-a764dfa789ba44e519371b4a1e4569db7f551fb7.zip |
feat: MVP of passing in sraApiUrl, assetData and other settings from render method
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; } |