aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/redux
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-10-20 06:40:44 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-10-20 06:40:44 +0800
commit30b077099306b8f2b522d0bc462da49fa9ee42e2 (patch)
tree05df98f7788993c2953d00acf64840de2ad6e9d4 /packages/instant/src/redux
parentd2766d7ced990efd5a91441b459f36e8a21f8513 (diff)
parenta017f5e38561a152e8a757b340c1b0c6b3a3e21f (diff)
downloaddexon-sol-tools-30b077099306b8f2b522d0bc462da49fa9ee42e2.tar
dexon-sol-tools-30b077099306b8f2b522d0bc462da49fa9ee42e2.tar.gz
dexon-sol-tools-30b077099306b8f2b522d0bc462da49fa9ee42e2.tar.bz2
dexon-sol-tools-30b077099306b8f2b522d0bc462da49fa9ee42e2.tar.lz
dexon-sol-tools-30b077099306b8f2b522d0bc462da49fa9ee42e2.tar.xz
dexon-sol-tools-30b077099306b8f2b522d0bc462da49fa9ee42e2.tar.zst
dexon-sol-tools-30b077099306b8f2b522d0bc462da49fa9ee42e2.zip
Merge branch 'feature/instant/beta-render-et-al' into feature/instant/failure-state
Diffstat (limited to 'packages/instant/src/redux')
-rw-r--r--packages/instant/src/redux/actions.ts10
-rw-r--r--packages/instant/src/redux/reducer.ts44
-rw-r--r--packages/instant/src/redux/store.ts11
3 files changed, 31 insertions, 34 deletions
diff --git a/packages/instant/src/redux/actions.ts b/packages/instant/src/redux/actions.ts
index d6388d77e..bdb53a395 100644
--- a/packages/instant/src/redux/actions.ts
+++ b/packages/instant/src/redux/actions.ts
@@ -26,8 +26,8 @@ export enum ActionTypes {
UPDATE_SELECTED_ASSET_BUY_STATE = 'UPDATE_SELECTED_ASSET_BUY_STATE',
UPDATE_LATEST_BUY_QUOTE = 'UPDATE_LATEST_BUY_QUOTE',
UPDATE_SELECTED_ASSET = 'UPDATE_SELECTED_ASSET',
- UPDATE_BUY_QUOTE_STATE_PENDING = 'UPDATE_BUY_QUOTE_STATE_PENDING',
- UPDATE_BUY_QUOTE_STATE_FAILURE = 'UPDATE_BUY_QUOTE_STATE_FAILURE',
+ SET_QUOTE_REQUEST_STATE_PENDING = 'SET_QUOTE_REQUEST_STATE_PENDING',
+ SET_QUOTE_REQUEST_STATE_FAILURE = 'SET_QUOTE_REQUEST_STATE_FAILURE',
SET_ERROR = 'SET_ERROR',
HIDE_ERROR = 'HIDE_ERROR',
CLEAR_ERROR = 'CLEAR_ERROR',
@@ -37,12 +37,12 @@ export enum ActionTypes {
export const actions = {
updateEthUsdPrice: (price?: BigNumber) => createAction(ActionTypes.UPDATE_ETH_USD_PRICE, price),
updateSelectedAssetAmount: (amount?: BigNumber) => createAction(ActionTypes.UPDATE_SELECTED_ASSET_AMOUNT, amount),
- updatebuyOrderState: (buyState: AsyncProcessState) =>
+ updateBuyOrderState: (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),
- updateBuyQuoteStatePending: () => createAction(ActionTypes.UPDATE_BUY_QUOTE_STATE_PENDING),
- updateBuyQuoteStateFailure: () => createAction(ActionTypes.UPDATE_BUY_QUOTE_STATE_FAILURE),
+ setQuoteRequestStatePending: () => createAction(ActionTypes.SET_QUOTE_REQUEST_STATE_PENDING),
+ setQuoteRequestStateFailure: () => createAction(ActionTypes.SET_QUOTE_REQUEST_STATE_FAILURE),
setError: (error?: any) => createAction(ActionTypes.SET_ERROR, error),
hideError: () => createAction(ActionTypes.HIDE_ERROR),
clearError: () => createAction(ActionTypes.CLEAR_ERROR),
diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts
index 10e56f152..260039e3d 100644
--- a/packages/instant/src/redux/reducer.ts
+++ b/packages/instant/src/redux/reducer.ts
@@ -3,16 +3,14 @@ import { ObjectMap } from '@0x/types';
import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
-import { Asset, AssetMetaData, AsyncProcessState } from '../types';
+import { assetMetaDataMap } from '../data/asset_meta_data_map';
+import { Asset, AssetMetaData, AsyncProcessState, DisplayStatus, Network } from '../types';
import { assetUtils } from '../util/asset';
import { Action, ActionTypes } from './actions';
-export enum LatestErrorDisplay {
- Present,
- Hidden,
-}
export interface State {
+ network: Network;
assetBuyer?: AssetBuyer;
assetMetaDataMap: ObjectMap<AssetMetaData>;
selectedAsset?: Asset;
@@ -20,23 +18,23 @@ export interface State {
buyOrderState: AsyncProcessState;
ethUsdPrice?: BigNumber;
latestBuyQuote?: BuyQuote;
- quoteState: AsyncProcessState;
+ quoteRequestState: AsyncProcessState;
latestError?: any;
- latestErrorDisplay: LatestErrorDisplay;
+ latestErrorDisplay: DisplayStatus;
}
export const INITIAL_STATE: State = {
+ network: Network.Mainnet,
selectedAssetAmount: undefined,
- assetMetaDataMap: {},
+ assetMetaDataMap,
buyOrderState: AsyncProcessState.NONE,
ethUsdPrice: undefined,
latestBuyQuote: undefined,
latestError: undefined,
- latestErrorDisplay: LatestErrorDisplay.Hidden,
- quoteState: AsyncProcessState.NONE,
+ latestErrorDisplay: DisplayStatus.Hidden,
+ quoteRequestState: AsyncProcessState.NONE,
};
-// 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:
@@ -53,19 +51,19 @@ export const reducer = (state: State = INITIAL_STATE, action: Action): State =>
return {
...state,
latestBuyQuote: action.data,
- quoteState: AsyncProcessState.SUCCESS,
+ quoteRequestState: AsyncProcessState.SUCCESS,
};
- case ActionTypes.UPDATE_BUY_QUOTE_STATE_PENDING:
+ case ActionTypes.SET_QUOTE_REQUEST_STATE_PENDING:
return {
...state,
latestBuyQuote: undefined,
- quoteState: AsyncProcessState.PENDING,
+ quoteRequestState: AsyncProcessState.PENDING,
};
- case ActionTypes.UPDATE_BUY_QUOTE_STATE_FAILURE:
+ case ActionTypes.SET_QUOTE_REQUEST_STATE_FAILURE:
return {
...state,
latestBuyQuote: undefined,
- quoteState: AsyncProcessState.FAILURE,
+ quoteRequestState: AsyncProcessState.FAILURE,
};
case ActionTypes.UPDATE_SELECTED_ASSET_BUY_STATE:
return {
@@ -76,24 +74,28 @@ export const reducer = (state: State = INITIAL_STATE, action: Action): State =>
return {
...state,
latestError: action.data,
- latestErrorDisplay: LatestErrorDisplay.Present,
+ latestErrorDisplay: DisplayStatus.Present,
};
case ActionTypes.HIDE_ERROR:
return {
...state,
- latestErrorDisplay: LatestErrorDisplay.Hidden,
+ latestErrorDisplay: DisplayStatus.Hidden,
};
case ActionTypes.CLEAR_ERROR:
return {
...state,
latestError: undefined,
- latestErrorDisplay: LatestErrorDisplay.Hidden,
+ latestErrorDisplay: DisplayStatus.Hidden,
};
case ActionTypes.UPDATE_SELECTED_ASSET:
const newSelectedAssetData = action.data;
let newSelectedAsset: Asset | undefined;
if (!_.isUndefined(newSelectedAssetData)) {
- newSelectedAsset = assetUtils.createAssetFromAssetData(newSelectedAssetData, state.assetMetaDataMap);
+ newSelectedAsset = assetUtils.createAssetFromAssetData(
+ newSelectedAssetData,
+ state.assetMetaDataMap,
+ state.network,
+ );
}
return {
...state,
@@ -103,7 +105,7 @@ export const reducer = (state: State = INITIAL_STATE, action: Action): State =>
return {
...state,
latestBuyQuote: undefined,
- quoteState: AsyncProcessState.NONE,
+ quoteRequestState: AsyncProcessState.NONE,
buyOrderState: AsyncProcessState.NONE,
selectedAssetAmount: undefined,
};
diff --git a/packages/instant/src/redux/store.ts b/packages/instant/src/redux/store.ts
index 505234299..01deb8690 100644
--- a/packages/instant/src/redux/store.ts
+++ b/packages/instant/src/redux/store.ts
@@ -2,17 +2,12 @@ import * as _ from 'lodash';
import { createStore, Store as ReduxStore } from 'redux';
import { devToolsEnhancer } from 'redux-devtools-extension/developmentOnly';
-import { INITIAL_STATE, reducer, State } from './reducer';
+import { reducer, State } from './reducer';
export type Store = ReduxStore<State>;
export const store = {
- create: (withState: Partial<State>): Store => {
- const allInitialState = {
- INITIAL_STATE,
- ...withState,
- };
- return createStore(reducer, allInitialState, devToolsEnhancer({}));
+ create: (state: State): Store => {
+ return createStore(reducer, state, devToolsEnhancer({}));
},
};
-