aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/redux
diff options
context:
space:
mode:
authorHsuan Lee <hsuan@cobinhood.com>2019-01-19 18:42:04 +0800
committerHsuan Lee <hsuan@cobinhood.com>2019-01-19 18:42:04 +0800
commit7ae38906926dc09bc10670c361af0d2bf0050426 (patch)
tree5fb10ae366b987db09e4ddb4bc3ba0f75404ad08 /packages/instant/src/redux
parentb5fd3c72a08aaa6957917d74c333387a16edf66b (diff)
downloaddexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar
dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.gz
dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.bz2
dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.lz
dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.xz
dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.zst
dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.zip
Update dependency packages
Diffstat (limited to 'packages/instant/src/redux')
-rw-r--r--packages/instant/src/redux/actions.ts76
-rw-r--r--packages/instant/src/redux/analytics_middleware.ts108
-rw-r--r--packages/instant/src/redux/async_data.ts120
-rw-r--r--packages/instant/src/redux/reducer.ts297
-rw-r--r--packages/instant/src/redux/store.ts15
5 files changed, 0 insertions, 616 deletions
diff --git a/packages/instant/src/redux/actions.ts b/packages/instant/src/redux/actions.ts
deleted file mode 100644
index ca0be543b..000000000
--- a/packages/instant/src/redux/actions.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-import { BuyQuote } from '@0x/asset-buyer';
-import { BigNumber } from '@0x/utils';
-import * as _ from 'lodash';
-
-import { ActionsUnion, AddressAndEthBalanceInWei, Asset, BaseCurrency, StandardSlidingPanelContent } from '../types';
-
-export interface PlainAction<T extends string> {
- type: T;
-}
-
-export interface ActionWithPayload<T extends string, P> extends PlainAction<T> {
- data: P;
-}
-
-export type Action = ActionsUnion<typeof actions>;
-
-function createAction<T extends string>(type: T): PlainAction<T>;
-function createAction<T extends string, P>(type: T, data: P): ActionWithPayload<T, P>;
-function createAction<T extends string, P>(type: T, data?: P): PlainAction<T> | ActionWithPayload<T, P> {
- return _.isUndefined(data) ? { type } : { type, data };
-}
-
-export enum ActionTypes {
- SetAccountStateLoading = 'SET_ACCOUNT_STATE_LOADING',
- SetAccountStateLocked = 'SET_ACCOUNT_STATE_LOCKED',
- SetAccountStateReady = 'SET_ACCOUNT_STATE_READY',
- UpdateAccountEthBalance = 'UPDATE_ACCOUNT_ETH_BALANCE',
- UpdateEthUsdPrice = 'UPDATE_ETH_USD_PRICE',
- UpdateSelectedAssetUnitAmount = 'UPDATE_SELECTED_ASSET_UNIT_AMOUNT',
- SetBuyOrderStateNone = 'SET_BUY_ORDER_STATE_NONE',
- SetBuyOrderStateValidating = 'SET_BUY_ORDER_STATE_VALIDATING',
- SetBuyOrderStateProcessing = 'SET_BUY_ORDER_STATE_PROCESSING',
- SetBuyOrderStateFailure = 'SET_BUY_ORDER_STATE_FAILURE',
- SetBuyOrderStateSuccess = 'SET_BUY_ORDER_STATE_SUCCESS',
- UpdateLatestBuyQuote = 'UPDATE_LATEST_BUY_QUOTE',
- UpdateSelectedAsset = 'UPDATE_SELECTED_ASSET',
- SetAvailableAssets = 'SET_AVAILABLE_ASSETS',
- SetQuoteRequestStatePending = 'SET_QUOTE_REQUEST_STATE_PENDING',
- SetQuoteRequestStateFailure = 'SET_QUOTE_REQUEST_STATE_FAILURE',
- SetErrorMessage = 'SET_ERROR_MESSAGE',
- HideError = 'HIDE_ERROR',
- ClearError = 'CLEAR_ERROR',
- ResetAmount = 'RESET_AMOUNT',
- OpenStandardSlidingPanel = 'OPEN_STANDARD_SLIDING_PANEL',
- CloseStandardSlidingPanel = 'CLOSE_STANDARD_SLIDING_PANEL',
- UpdateBaseCurrency = 'UPDATE_BASE_CURRENCY',
-}
-
-export const actions = {
- setAccountStateLoading: () => createAction(ActionTypes.SetAccountStateLoading),
- setAccountStateLocked: () => createAction(ActionTypes.SetAccountStateLocked),
- setAccountStateReady: (address: string) => createAction(ActionTypes.SetAccountStateReady, address),
- updateAccountEthBalance: (addressAndBalance: AddressAndEthBalanceInWei) =>
- createAction(ActionTypes.UpdateAccountEthBalance, addressAndBalance),
- updateEthUsdPrice: (price?: BigNumber) => createAction(ActionTypes.UpdateEthUsdPrice, price),
- updateSelectedAssetAmount: (amount?: BigNumber) => createAction(ActionTypes.UpdateSelectedAssetUnitAmount, amount),
- setBuyOrderStateNone: () => createAction(ActionTypes.SetBuyOrderStateNone),
- setBuyOrderStateValidating: () => createAction(ActionTypes.SetBuyOrderStateValidating),
- setBuyOrderStateProcessing: (txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) =>
- createAction(ActionTypes.SetBuyOrderStateProcessing, { txHash, startTimeUnix, expectedEndTimeUnix }),
- setBuyOrderStateFailure: (txHash: string) => createAction(ActionTypes.SetBuyOrderStateFailure, txHash),
- setBuyOrderStateSuccess: (txHash: string) => createAction(ActionTypes.SetBuyOrderStateSuccess, txHash),
- updateLatestBuyQuote: (buyQuote?: BuyQuote) => createAction(ActionTypes.UpdateLatestBuyQuote, buyQuote),
- updateSelectedAsset: (asset: Asset) => createAction(ActionTypes.UpdateSelectedAsset, asset),
- setAvailableAssets: (availableAssets: Asset[]) => createAction(ActionTypes.SetAvailableAssets, availableAssets),
- setQuoteRequestStatePending: () => createAction(ActionTypes.SetQuoteRequestStatePending),
- setQuoteRequestStateFailure: () => createAction(ActionTypes.SetQuoteRequestStateFailure),
- setErrorMessage: (errorMessage: string) => createAction(ActionTypes.SetErrorMessage, errorMessage),
- hideError: () => createAction(ActionTypes.HideError),
- clearError: () => createAction(ActionTypes.ClearError),
- resetAmount: () => createAction(ActionTypes.ResetAmount),
- openStandardSlidingPanel: (content: StandardSlidingPanelContent) =>
- createAction(ActionTypes.OpenStandardSlidingPanel, content),
- closeStandardSlidingPanel: () => createAction(ActionTypes.CloseStandardSlidingPanel),
- updateBaseCurrency: (baseCurrency: BaseCurrency) => createAction(ActionTypes.UpdateBaseCurrency, baseCurrency),
-};
diff --git a/packages/instant/src/redux/analytics_middleware.ts b/packages/instant/src/redux/analytics_middleware.ts
deleted file mode 100644
index 4b4d30213..000000000
--- a/packages/instant/src/redux/analytics_middleware.ts
+++ /dev/null
@@ -1,108 +0,0 @@
-import { AssetProxyId } from '@0x/types';
-import { Web3Wrapper } from '@0x/web3-wrapper';
-import * as _ from 'lodash';
-import { Middleware } from 'redux';
-
-import { ETH_DECIMALS } from '../constants';
-import { AccountState, StandardSlidingPanelContent } from '../types';
-import { analytics, AnalyticsEventOptions } from '../util/analytics';
-
-import { Action, ActionTypes } from './actions';
-
-import { State } from './reducer';
-
-export const analyticsMiddleware: Middleware = store => next => middlewareAction => {
- const prevState = store.getState() as State;
- const prevAccount = prevState.providerState.account;
-
- const nextAction = next(middlewareAction) as Action;
-
- const curState = store.getState() as State;
- const curAccount = curState.providerState.account;
-
- switch (nextAction.type) {
- case ActionTypes.SetAccountStateReady:
- if (curAccount.state === AccountState.Ready) {
- const didJustTurnReady = prevAccount.state !== AccountState.Ready;
- const didJustUpdateAddress =
- prevAccount.state === AccountState.Ready && prevAccount.address !== curAccount.address;
- const ethAddress = curAccount.address;
- if (didJustTurnReady) {
- analytics.trackAccountReady(ethAddress);
- analytics.addUserProperties({ lastKnownEthAddress: ethAddress });
- analytics.addEventProperties({ ethAddress });
- } else if (didJustUpdateAddress) {
- analytics.trackAccountAddressChanged(ethAddress);
- analytics.addUserProperties({ lastKnownEthAddress: ethAddress });
- analytics.addEventProperties({ ethAddress });
- }
- }
- break;
- case ActionTypes.SetAccountStateLocked:
- if (prevAccount.state !== AccountState.Locked && curAccount.state === AccountState.Locked) {
- // if we are moving from account not locked to account locked, track `Account - Locked`
- analytics.trackAccountLocked();
- }
- break;
- case ActionTypes.UpdateAccountEthBalance:
- if (
- curAccount.state === AccountState.Ready &&
- curAccount.ethBalanceInWei &&
- !_.isEqual(curAccount, prevAccount)
- ) {
- const ethBalanceInUnitAmount = Web3Wrapper.toUnitAmount(
- curAccount.ethBalanceInWei,
- ETH_DECIMALS,
- ).toString();
- analytics.addUserProperties({ lastEthBalanceInUnitAmount: ethBalanceInUnitAmount });
- analytics.addEventProperties({ ethBalanceInUnitAmount });
- }
- break;
- case ActionTypes.UpdateSelectedAsset:
- const selectedAsset = curState.selectedAsset;
- if (selectedAsset) {
- const assetName = selectedAsset.metaData.name;
- const assetData = selectedAsset.assetData;
- analytics.trackTokenSelectorChose({
- assetName,
- assetData,
- });
-
- const selectedAssetEventProperties: AnalyticsEventOptions = {
- selectedAssetName: assetName,
- selectedAssetData: assetData,
- };
- if (selectedAsset.metaData.assetProxyId === AssetProxyId.ERC20) {
- selectedAssetEventProperties.selectedAssetDecimals = selectedAsset.metaData.decimals;
- selectedAssetEventProperties.selectedAssetSymbol = selectedAsset.metaData.symbol;
- }
- analytics.addEventProperties(selectedAssetEventProperties);
- }
- break;
- case ActionTypes.SetAvailableAssets:
- const availableAssets = curState.availableAssets;
- if (availableAssets) {
- analytics.addEventProperties({
- numberAvailableAssets: availableAssets.length,
- });
- }
- break;
- case ActionTypes.OpenStandardSlidingPanel:
- const openSlidingContent = curState.standardSlidingPanelSettings.content;
- if (openSlidingContent === StandardSlidingPanelContent.InstallWallet) {
- analytics.trackInstallWalletModalOpened();
- }
- break;
- case ActionTypes.CloseStandardSlidingPanel:
- const closeSlidingContent = curState.standardSlidingPanelSettings.content;
- if (closeSlidingContent === StandardSlidingPanelContent.InstallWallet) {
- analytics.trackInstallWalletModalClosed();
- }
- break;
- case ActionTypes.UpdateBaseCurrency:
- analytics.trackBaseCurrencyChanged(curState.baseCurrency);
- analytics.addEventProperties({ baseCurrency: curState.baseCurrency });
- }
-
- return nextAction;
-};
diff --git a/packages/instant/src/redux/async_data.ts b/packages/instant/src/redux/async_data.ts
deleted file mode 100644
index f20fe319f..000000000
--- a/packages/instant/src/redux/async_data.ts
+++ /dev/null
@@ -1,120 +0,0 @@
-import { AssetProxyId } from '@0x/types';
-import { Web3Wrapper } from '@0x/web3-wrapper';
-import * as _ from 'lodash';
-import { Dispatch } from 'redux';
-
-import { BIG_NUMBER_ZERO } from '../constants';
-import { AccountState, BaseCurrency, ERC20Asset, OrderProcessState, ProviderState, QuoteFetchOrigin } from '../types';
-import { analytics } from '../util/analytics';
-import { assetUtils } from '../util/asset';
-import { buyQuoteUpdater } from '../util/buy_quote_updater';
-import { coinbaseApi } from '../util/coinbase_api';
-import { errorFlasher } from '../util/error_flasher';
-import { errorReporter } from '../util/error_reporter';
-
-import { actions } from './actions';
-import { State } from './reducer';
-
-export const asyncData = {
- fetchEthPriceAndDispatchToStore: async (dispatch: Dispatch) => {
- try {
- const ethUsdPrice = await coinbaseApi.getEthUsdPrice();
- dispatch(actions.updateEthUsdPrice(ethUsdPrice));
- } catch (e) {
- const errorMessage = 'Error fetching ETH/USD price';
- errorFlasher.flashNewErrorMessage(dispatch, errorMessage);
- dispatch(actions.updateEthUsdPrice(BIG_NUMBER_ZERO));
- dispatch(actions.updateBaseCurrency(BaseCurrency.ETH));
- errorReporter.report(e);
- analytics.trackUsdPriceFailed();
- }
- },
- fetchAvailableAssetDatasAndDispatchToStore: async (state: State, dispatch: Dispatch) => {
- const { providerState, assetMetaDataMap, network } = state;
- const assetBuyer = providerState.assetBuyer;
- try {
- const assetDatas = await assetBuyer.getAvailableAssetDatasAsync();
- const deduplicatedAssetDatas = _.uniq(assetDatas);
- const assets = assetUtils.createAssetsFromAssetDatas(deduplicatedAssetDatas, assetMetaDataMap, network);
- dispatch(actions.setAvailableAssets(assets));
- } catch (e) {
- const errorMessage = 'Could not find any assets';
- errorFlasher.flashNewErrorMessage(dispatch, errorMessage);
- // On error, just specify that none are available
- dispatch(actions.setAvailableAssets([]));
- errorReporter.report(e);
- }
- },
- fetchAccountInfoAndDispatchToStore: async (
- providerState: ProviderState,
- dispatch: Dispatch,
- shouldAttemptUnlock: boolean = false,
- shouldSetToLoading: boolean = false,
- ) => {
- const web3Wrapper = providerState.web3Wrapper;
- const provider = providerState.provider;
- if (shouldSetToLoading && providerState.account.state !== AccountState.Loading) {
- dispatch(actions.setAccountStateLoading());
- }
- let availableAddresses: string[];
- try {
- // TODO(bmillman): Add support at the web3Wrapper level for calling `eth_requestAccounts` instead of calling enable here
- const isPrivacyModeEnabled = !_.isUndefined((provider as any).enable);
- availableAddresses =
- isPrivacyModeEnabled && shouldAttemptUnlock
- ? await (provider as any).enable()
- : await web3Wrapper.getAvailableAddressesAsync();
- } catch (e) {
- analytics.trackAccountUnlockDenied();
- dispatch(actions.setAccountStateLocked());
- return;
- }
- if (!_.isEmpty(availableAddresses)) {
- const activeAddress = availableAddresses[0];
- dispatch(actions.setAccountStateReady(activeAddress));
- // tslint:disable-next-line:no-floating-promises
- asyncData.fetchAccountBalanceAndDispatchToStore(activeAddress, providerState.web3Wrapper, dispatch);
- } else {
- dispatch(actions.setAccountStateLocked());
- }
- },
- fetchAccountBalanceAndDispatchToStore: async (address: string, web3Wrapper: Web3Wrapper, dispatch: Dispatch) => {
- try {
- const ethBalanceInWei = await web3Wrapper.getBalanceInWeiAsync(address);
- dispatch(actions.updateAccountEthBalance({ address, ethBalanceInWei }));
- } catch (e) {
- errorReporter.report(e);
- // leave balance as is
- return;
- }
- },
- fetchCurrentBuyQuoteAndDispatchToStore: async (
- state: State,
- dispatch: Dispatch,
- fetchOrigin: QuoteFetchOrigin,
- options: { updateSilently: boolean },
- ) => {
- const { buyOrderState, providerState, selectedAsset, selectedAssetUnitAmount, affiliateInfo } = state;
- const assetBuyer = providerState.assetBuyer;
- if (
- !_.isUndefined(selectedAssetUnitAmount) &&
- !_.isUndefined(selectedAsset) &&
- selectedAssetUnitAmount.isGreaterThan(BIG_NUMBER_ZERO) &&
- buyOrderState.processState === OrderProcessState.None &&
- selectedAsset.metaData.assetProxyId === AssetProxyId.ERC20
- ) {
- await buyQuoteUpdater.updateBuyQuoteAsync(
- assetBuyer,
- dispatch,
- selectedAsset as ERC20Asset,
- selectedAssetUnitAmount,
- fetchOrigin,
- {
- setPending: !options.updateSilently,
- dispatchErrors: !options.updateSilently,
- affiliateInfo,
- },
- );
- }
- },
-};
diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts
deleted file mode 100644
index 0d8bb4b05..000000000
--- a/packages/instant/src/redux/reducer.ts
+++ /dev/null
@@ -1,297 +0,0 @@
-import { BuyQuote } from '@0x/asset-buyer';
-import { AssetProxyId, ObjectMap } from '@0x/types';
-import { BigNumber } from '@0x/utils';
-import { Web3Wrapper } from '@0x/web3-wrapper';
-import * as _ from 'lodash';
-
-import { LOADING_ACCOUNT, LOCKED_ACCOUNT } from '../constants';
-import { assetMetaDataMap } from '../data/asset_meta_data_map';
-import {
- Account,
- AccountReady,
- AccountState,
- AffiliateInfo,
- Asset,
- AssetMetaData,
- AsyncProcessState,
- BaseCurrency,
- DisplayStatus,
- Network,
- OrderProcessState,
- OrderState,
- ProviderState,
- StandardSlidingPanelContent,
- StandardSlidingPanelSettings,
-} from '../types';
-
-import { Action, ActionTypes } from './actions';
-
-// State that is required and we have defaults for, before props are passed in
-export interface DefaultState {
- network: Network;
- assetMetaDataMap: ObjectMap<AssetMetaData>;
- buyOrderState: OrderState;
- latestErrorDisplayStatus: DisplayStatus;
- quoteRequestState: AsyncProcessState;
- standardSlidingPanelSettings: StandardSlidingPanelSettings;
- baseCurrency: BaseCurrency;
-}
-
-// State that is required but needs to be derived from the props
-interface PropsDerivedState {
- providerState: ProviderState;
-}
-
-// State that is optional
-interface OptionalState {
- selectedAsset: Asset;
- availableAssets: Asset[];
- selectedAssetUnitAmount: BigNumber;
- ethUsdPrice: BigNumber;
- latestBuyQuote: BuyQuote;
- latestErrorMessage: string;
- affiliateInfo: AffiliateInfo;
- walletDisplayName: string;
-}
-
-export type State = DefaultState & PropsDerivedState & Partial<OptionalState>;
-
-export const DEFAULT_STATE: DefaultState = {
- network: Network.Mainnet,
- assetMetaDataMap,
- buyOrderState: { processState: OrderProcessState.None },
- latestErrorDisplayStatus: DisplayStatus.Hidden,
- quoteRequestState: AsyncProcessState.None,
- standardSlidingPanelSettings: {
- animationState: 'none',
- content: StandardSlidingPanelContent.None,
- },
- baseCurrency: BaseCurrency.USD,
-};
-
-export const createReducer = (initialState: State) => {
- const reducer = (state: State = initialState, action: Action): State => {
- switch (action.type) {
- case ActionTypes.SetAccountStateLoading:
- return reduceStateWithAccount(state, LOADING_ACCOUNT);
- case ActionTypes.SetAccountStateLocked:
- return reduceStateWithAccount(state, LOCKED_ACCOUNT);
- case ActionTypes.SetAccountStateReady: {
- const address = action.data;
- let newAccount: AccountReady = {
- state: AccountState.Ready,
- address,
- };
- const currentAccount = state.providerState.account;
- if (currentAccount.state === AccountState.Ready && currentAccount.address === address) {
- newAccount = {
- ...newAccount,
- ethBalanceInWei: currentAccount.ethBalanceInWei,
- };
- }
- return reduceStateWithAccount(state, newAccount);
- }
- case ActionTypes.UpdateAccountEthBalance: {
- const { address, ethBalanceInWei } = action.data;
- const currentAccount = state.providerState.account;
- if (currentAccount.state !== AccountState.Ready || currentAccount.address !== address) {
- return state;
- } else {
- const newAccount: AccountReady = {
- ...currentAccount,
- ethBalanceInWei,
- };
- return reduceStateWithAccount(state, newAccount);
- }
- }
- case ActionTypes.UpdateEthUsdPrice:
- return {
- ...state,
- ethUsdPrice: action.data,
- };
- case ActionTypes.UpdateSelectedAssetUnitAmount:
- return {
- ...state,
- selectedAssetUnitAmount: action.data,
- };
- case ActionTypes.UpdateLatestBuyQuote:
- const newBuyQuoteIfExists = action.data;
- const shouldUpdate =
- _.isUndefined(newBuyQuoteIfExists) || doesBuyQuoteMatchState(newBuyQuoteIfExists, state);
- if (shouldUpdate) {
- return {
- ...state,
- latestBuyQuote: newBuyQuoteIfExists,
- quoteRequestState: AsyncProcessState.Success,
- };
- } else {
- return state;
- }
- case ActionTypes.SetQuoteRequestStatePending:
- return {
- ...state,
- latestBuyQuote: undefined,
- quoteRequestState: AsyncProcessState.Pending,
- };
- case ActionTypes.SetQuoteRequestStateFailure:
- return {
- ...state,
- latestBuyQuote: undefined,
- quoteRequestState: AsyncProcessState.Failure,
- };
- case ActionTypes.SetBuyOrderStateNone:
- return {
- ...state,
- buyOrderState: { processState: OrderProcessState.None },
- };
- case ActionTypes.SetBuyOrderStateValidating:
- return {
- ...state,
- buyOrderState: { processState: OrderProcessState.Validating },
- };
- case ActionTypes.SetBuyOrderStateProcessing:
- const processingData = action.data;
- const { startTimeUnix, expectedEndTimeUnix } = processingData;
- return {
- ...state,
- buyOrderState: {
- processState: OrderProcessState.Processing,
- txHash: processingData.txHash,
- progress: {
- startTimeUnix,
- expectedEndTimeUnix,
- },
- },
- };
- case ActionTypes.SetBuyOrderStateFailure:
- const failureTxHash = action.data;
- if ('txHash' in state.buyOrderState) {
- if (state.buyOrderState.txHash === failureTxHash) {
- const { txHash, progress } = state.buyOrderState;
- return {
- ...state,
- buyOrderState: {
- processState: OrderProcessState.Failure,
- txHash,
- progress,
- },
- };
- }
- }
- return state;
- case ActionTypes.SetBuyOrderStateSuccess:
- const successTxHash = action.data;
- if ('txHash' in state.buyOrderState) {
- if (state.buyOrderState.txHash === successTxHash) {
- const { txHash, progress } = state.buyOrderState;
- return {
- ...state,
- buyOrderState: {
- processState: OrderProcessState.Success,
- txHash,
- progress,
- },
- };
- }
- }
- return state;
- case ActionTypes.SetErrorMessage:
- return {
- ...state,
- latestErrorMessage: action.data,
- latestErrorDisplayStatus: DisplayStatus.Present,
- };
- case ActionTypes.HideError:
- return {
- ...state,
- latestErrorDisplayStatus: DisplayStatus.Hidden,
- };
- case ActionTypes.ClearError:
- return {
- ...state,
- latestErrorMessage: undefined,
- latestErrorDisplayStatus: DisplayStatus.Hidden,
- };
- case ActionTypes.UpdateSelectedAsset:
- return {
- ...state,
- selectedAsset: action.data,
- };
- case ActionTypes.ResetAmount:
- return {
- ...state,
- latestBuyQuote: undefined,
- quoteRequestState: AsyncProcessState.None,
- buyOrderState: { processState: OrderProcessState.None },
- selectedAssetUnitAmount: undefined,
- };
- case ActionTypes.SetAvailableAssets:
- return {
- ...state,
- availableAssets: action.data,
- };
- case ActionTypes.OpenStandardSlidingPanel:
- return {
- ...state,
- standardSlidingPanelSettings: {
- content: action.data,
- animationState: 'slidIn',
- },
- };
- case ActionTypes.CloseStandardSlidingPanel:
- return {
- ...state,
- standardSlidingPanelSettings: {
- content: state.standardSlidingPanelSettings.content,
- animationState: 'slidOut',
- },
- };
- case ActionTypes.UpdateBaseCurrency:
- return {
- ...state,
- baseCurrency: action.data,
- };
- default:
- return state;
- }
- };
- return reducer;
-};
-
-const reduceStateWithAccount = (state: State, account: Account) => {
- const oldProviderState = state.providerState;
- const newProviderState: ProviderState = {
- ...oldProviderState,
- account,
- };
- return {
- ...state,
- providerState: newProviderState,
- };
-};
-
-const doesBuyQuoteMatchState = (buyQuote: BuyQuote, state: State): boolean => {
- const selectedAssetIfExists = state.selectedAsset;
- const selectedAssetUnitAmountIfExists = state.selectedAssetUnitAmount;
- // if no selectedAsset or selectedAssetAmount exists on the current state, return false
- if (_.isUndefined(selectedAssetIfExists) || _.isUndefined(selectedAssetUnitAmountIfExists)) {
- return false;
- }
- // if buyQuote's assetData does not match that of the current selected asset, return false
- if (selectedAssetIfExists.assetData !== buyQuote.assetData) {
- return false;
- }
- // if ERC20 and buyQuote's assetBuyAmount does not match selectedAssetAmount, return false
- // if ERC721, return true
- const selectedAssetMetaData = selectedAssetIfExists.metaData;
- if (selectedAssetMetaData.assetProxyId === AssetProxyId.ERC20) {
- const selectedAssetAmountBaseUnits = Web3Wrapper.toBaseUnitAmount(
- selectedAssetUnitAmountIfExists,
- selectedAssetMetaData.decimals,
- );
- const doesAssetAmountMatch = selectedAssetAmountBaseUnits.eq(buyQuote.assetBuyAmount);
- return doesAssetAmountMatch;
- } else {
- return true;
- }
-};
diff --git a/packages/instant/src/redux/store.ts b/packages/instant/src/redux/store.ts
deleted file mode 100644
index 11bba3876..000000000
--- a/packages/instant/src/redux/store.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import * as _ from 'lodash';
-import { applyMiddleware, createStore, Store as ReduxStore } from 'redux';
-import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly';
-
-import { analyticsMiddleware } from './analytics_middleware';
-import { createReducer, State } from './reducer';
-
-export type Store = ReduxStore<State>;
-
-export const store = {
- create: (initialState: State): Store => {
- const reducer = createReducer(initialState);
- return createStore(reducer, initialState, composeWithDevTools(applyMiddleware(analyticsMiddleware)));
- },
-};