aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/redux
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-10-19 01:43:41 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-10-19 01:43:41 +0800
commita764dfa789ba44e519371b4a1e4569db7f551fb7 (patch)
tree80cd8aff6fcf941269afdec8022d0dd5759700fa /packages/instant/src/redux
parent5ec4b27200297708298deca97603849a37b2f66a (diff)
downloaddexon-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')
-rw-r--r--packages/instant/src/redux/actions.ts2
-rw-r--r--packages/instant/src/redux/async_data.ts4
-rw-r--r--packages/instant/src/redux/reducer.ts25
-rw-r--r--packages/instant/src/redux/store.ts14
4 files changed, 35 insertions, 10 deletions
diff --git a/packages/instant/src/redux/actions.ts b/packages/instant/src/redux/actions.ts
index 7d07b4950..fe055b75f 100644
--- a/packages/instant/src/redux/actions.ts
+++ b/packages/instant/src/redux/actions.ts
@@ -25,6 +25,7 @@ export enum ActionTypes {
UPDATE_SELECTED_ASSET_AMOUNT = 'UPDATE_SELECTED_ASSET_AMOUNT',
UPDATE_SELECTED_ASSET_BUY_STATE = 'UPDATE_SELECTED_ASSET_BUY_STATE',
UPDATE_LATEST_BUY_QUOTE = 'UPDATE_LATEST_BUY_QUOTE',
+ UPDATE_SELECTED_ASSET = 'UPDATE_SELECTED_ASSET',
}
export const actions = {
@@ -33,4 +34,5 @@ export const actions = {
updateSelectedAssetBuyState: (buyState: AsyncProcessState) =>
createAction(ActionTypes.UPDATE_SELECTED_ASSET_BUY_STATE, buyState),
updateLatestBuyQuote: (buyQuote?: BuyQuote) => createAction(ActionTypes.UPDATE_LATEST_BUY_QUOTE, buyQuote),
+ updateSelectedAsset: (assetData?: string) => createAction(ActionTypes.UPDATE_SELECTED_ASSET, assetData),
};
diff --git a/packages/instant/src/redux/async_data.ts b/packages/instant/src/redux/async_data.ts
index 348838307..4ed89bdc3 100644
--- a/packages/instant/src/redux/async_data.ts
+++ b/packages/instant/src/redux/async_data.ts
@@ -3,10 +3,10 @@ import { coinbaseApi } from '../util/coinbase_api';
import { ActionTypes } from './actions';
-import { store } from './store';
+import { Store } from './store';
export const asyncData = {
- fetchAndDispatchToStore: async () => {
+ fetchAndDispatchToStore: async (store: Store) => {
let ethUsdPrice = BIG_NUMBER_ZERO;
try {
ethUsdPrice = await coinbaseApi.getEthUsdPrice();
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;
}
diff --git a/packages/instant/src/redux/store.ts b/packages/instant/src/redux/store.ts
index fcd19f9a8..fc943f1be 100644
--- a/packages/instant/src/redux/store.ts
+++ b/packages/instant/src/redux/store.ts
@@ -1,6 +1,16 @@
import * as _ from 'lodash';
import { createStore, Store as ReduxStore } from 'redux';
-import { reducer, State } from './reducer';
+import { INITIAL_STATE, reducer, State } from './reducer';
-export const store: ReduxStore<State> = createStore(reducer);
+export type Store = ReduxStore<State>;
+
+export const store = {
+ create: (withState: Partial<State>): Store => {
+ const allInitialState = {
+ INITIAL_STATE,
+ ...withState,
+ };
+ return createStore(reducer, allInitialState);
+ },
+};