diff options
Diffstat (limited to 'packages/instant/src/redux')
-rw-r--r-- | packages/instant/src/redux/actions.ts | 93 | ||||
-rw-r--r-- | packages/instant/src/redux/analytics_middleware.ts | 16 | ||||
-rw-r--r-- | packages/instant/src/redux/reducer.ts | 46 |
3 files changed, 77 insertions, 78 deletions
diff --git a/packages/instant/src/redux/actions.ts b/packages/instant/src/redux/actions.ts index 9d7a61fc7..ca0be543b 100644 --- a/packages/instant/src/redux/actions.ts +++ b/packages/instant/src/redux/actions.ts @@ -21,57 +21,56 @@ function createAction<T extends string, P>(type: T, data?: P): PlainAction<T> | } export enum ActionTypes { - SET_ACCOUNT_STATE_LOADING = 'SET_ACCOUNT_STATE_LOADING', - SET_ACCOUNT_STATE_LOCKED = 'SET_ACCOUNT_STATE_LOCKED', - SET_ACCOUNT_STATE_READY = 'SET_ACCOUNT_STATE_READY', - UPDATE_ACCOUNT_ETH_BALANCE = 'UPDATE_ACCOUNT_ETH_BALANCE', - UPDATE_ETH_USD_PRICE = 'UPDATE_ETH_USD_PRICE', - UPDATE_SELECTED_ASSET_UNIT_AMOUNT = 'UPDATE_SELECTED_ASSET_UNIT_AMOUNT', - SET_BUY_ORDER_STATE_NONE = 'SET_BUY_ORDER_STATE_NONE', - SET_BUY_ORDER_STATE_VALIDATING = 'SET_BUY_ORDER_STATE_VALIDATING', - SET_BUY_ORDER_STATE_PROCESSING = 'SET_BUY_ORDER_STATE_PROCESSING', - SET_BUY_ORDER_STATE_FAILURE = 'SET_BUY_ORDER_STATE_FAILURE', - SET_BUY_ORDER_STATE_SUCCESS = 'SET_BUY_ORDER_STATE_SUCCESS', - UPDATE_LATEST_BUY_QUOTE = 'UPDATE_LATEST_BUY_QUOTE', - UPDATE_SELECTED_ASSET = 'UPDATE_SELECTED_ASSET', - SET_AVAILABLE_ASSETS = 'SET_AVAILABLE_ASSETS', - SET_QUOTE_REQUEST_STATE_PENDING = 'SET_QUOTE_REQUEST_STATE_PENDING', - SET_QUOTE_REQUEST_STATE_FAILURE = 'SET_QUOTE_REQUEST_STATE_FAILURE', - SET_ERROR_MESSAGE = 'SET_ERROR_MESSAGE', - HIDE_ERROR = 'HIDE_ERROR', - CLEAR_ERROR = 'CLEAR_ERROR', - RESET_AMOUNT = 'RESET_AMOUNT', - OPEN_STANDARD_SLIDING_PANEL = 'OPEN_STANDARD_SLIDING_PANEL', - CLOSE_STANDARD_SLIDING_PANEL = 'CLOSE_STANDARD_SLIDING_PANEL', - UPDATE_BASE_CURRENCY = 'UPDATE_BASE_CURRENCY', + 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.SET_ACCOUNT_STATE_LOADING), - setAccountStateLocked: () => createAction(ActionTypes.SET_ACCOUNT_STATE_LOCKED), - setAccountStateReady: (address: string) => createAction(ActionTypes.SET_ACCOUNT_STATE_READY, address), + setAccountStateLoading: () => createAction(ActionTypes.SetAccountStateLoading), + setAccountStateLocked: () => createAction(ActionTypes.SetAccountStateLocked), + setAccountStateReady: (address: string) => createAction(ActionTypes.SetAccountStateReady, address), updateAccountEthBalance: (addressAndBalance: AddressAndEthBalanceInWei) => - createAction(ActionTypes.UPDATE_ACCOUNT_ETH_BALANCE, addressAndBalance), - updateEthUsdPrice: (price?: BigNumber) => createAction(ActionTypes.UPDATE_ETH_USD_PRICE, price), - updateSelectedAssetAmount: (amount?: BigNumber) => - createAction(ActionTypes.UPDATE_SELECTED_ASSET_UNIT_AMOUNT, amount), - setBuyOrderStateNone: () => createAction(ActionTypes.SET_BUY_ORDER_STATE_NONE), - setBuyOrderStateValidating: () => createAction(ActionTypes.SET_BUY_ORDER_STATE_VALIDATING), + 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.SET_BUY_ORDER_STATE_PROCESSING, { txHash, startTimeUnix, expectedEndTimeUnix }), - setBuyOrderStateFailure: (txHash: string) => createAction(ActionTypes.SET_BUY_ORDER_STATE_FAILURE, txHash), - setBuyOrderStateSuccess: (txHash: string) => createAction(ActionTypes.SET_BUY_ORDER_STATE_SUCCESS, txHash), - updateLatestBuyQuote: (buyQuote?: BuyQuote) => createAction(ActionTypes.UPDATE_LATEST_BUY_QUOTE, buyQuote), - updateSelectedAsset: (asset: Asset) => createAction(ActionTypes.UPDATE_SELECTED_ASSET, asset), - setAvailableAssets: (availableAssets: Asset[]) => createAction(ActionTypes.SET_AVAILABLE_ASSETS, availableAssets), - setQuoteRequestStatePending: () => createAction(ActionTypes.SET_QUOTE_REQUEST_STATE_PENDING), - setQuoteRequestStateFailure: () => createAction(ActionTypes.SET_QUOTE_REQUEST_STATE_FAILURE), - setErrorMessage: (errorMessage: string) => createAction(ActionTypes.SET_ERROR_MESSAGE, errorMessage), - hideError: () => createAction(ActionTypes.HIDE_ERROR), - clearError: () => createAction(ActionTypes.CLEAR_ERROR), - resetAmount: () => createAction(ActionTypes.RESET_AMOUNT), + 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.OPEN_STANDARD_SLIDING_PANEL, content), - closeStandardSlidingPanel: () => createAction(ActionTypes.CLOSE_STANDARD_SLIDING_PANEL), - updateBaseCurrency: (baseCurrency: BaseCurrency) => createAction(ActionTypes.UPDATE_BASE_CURRENCY, baseCurrency), + 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 index a86a16b1a..4b4d30213 100644 --- a/packages/instant/src/redux/analytics_middleware.ts +++ b/packages/instant/src/redux/analytics_middleware.ts @@ -21,7 +21,7 @@ export const analyticsMiddleware: Middleware = store => next => middlewareAction const curAccount = curState.providerState.account; switch (nextAction.type) { - case ActionTypes.SET_ACCOUNT_STATE_READY: + case ActionTypes.SetAccountStateReady: if (curAccount.state === AccountState.Ready) { const didJustTurnReady = prevAccount.state !== AccountState.Ready; const didJustUpdateAddress = @@ -38,13 +38,13 @@ export const analyticsMiddleware: Middleware = store => next => middlewareAction } } break; - case ActionTypes.SET_ACCOUNT_STATE_LOCKED: + 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.UPDATE_ACCOUNT_ETH_BALANCE: + case ActionTypes.UpdateAccountEthBalance: if ( curAccount.state === AccountState.Ready && curAccount.ethBalanceInWei && @@ -58,7 +58,7 @@ export const analyticsMiddleware: Middleware = store => next => middlewareAction analytics.addEventProperties({ ethBalanceInUnitAmount }); } break; - case ActionTypes.UPDATE_SELECTED_ASSET: + case ActionTypes.UpdateSelectedAsset: const selectedAsset = curState.selectedAsset; if (selectedAsset) { const assetName = selectedAsset.metaData.name; @@ -79,7 +79,7 @@ export const analyticsMiddleware: Middleware = store => next => middlewareAction analytics.addEventProperties(selectedAssetEventProperties); } break; - case ActionTypes.SET_AVAILABLE_ASSETS: + case ActionTypes.SetAvailableAssets: const availableAssets = curState.availableAssets; if (availableAssets) { analytics.addEventProperties({ @@ -87,19 +87,19 @@ export const analyticsMiddleware: Middleware = store => next => middlewareAction }); } break; - case ActionTypes.OPEN_STANDARD_SLIDING_PANEL: + case ActionTypes.OpenStandardSlidingPanel: const openSlidingContent = curState.standardSlidingPanelSettings.content; if (openSlidingContent === StandardSlidingPanelContent.InstallWallet) { analytics.trackInstallWalletModalOpened(); } break; - case ActionTypes.CLOSE_STANDARD_SLIDING_PANEL: + case ActionTypes.CloseStandardSlidingPanel: const closeSlidingContent = curState.standardSlidingPanelSettings.content; if (closeSlidingContent === StandardSlidingPanelContent.InstallWallet) { analytics.trackInstallWalletModalClosed(); } break; - case ActionTypes.UPDATE_BASE_CURRENCY: + case ActionTypes.UpdateBaseCurrency: analytics.trackBaseCurrencyChanged(curState.baseCurrency); analytics.addEventProperties({ baseCurrency: curState.baseCurrency }); } diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index 8c13c9c72..0d8bb4b05 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -72,11 +72,11 @@ export const DEFAULT_STATE: DefaultState = { export const createReducer = (initialState: State) => { const reducer = (state: State = initialState, action: Action): State => { switch (action.type) { - case ActionTypes.SET_ACCOUNT_STATE_LOADING: + case ActionTypes.SetAccountStateLoading: return reduceStateWithAccount(state, LOADING_ACCOUNT); - case ActionTypes.SET_ACCOUNT_STATE_LOCKED: + case ActionTypes.SetAccountStateLocked: return reduceStateWithAccount(state, LOCKED_ACCOUNT); - case ActionTypes.SET_ACCOUNT_STATE_READY: { + case ActionTypes.SetAccountStateReady: { const address = action.data; let newAccount: AccountReady = { state: AccountState.Ready, @@ -91,7 +91,7 @@ export const createReducer = (initialState: State) => { } return reduceStateWithAccount(state, newAccount); } - case ActionTypes.UPDATE_ACCOUNT_ETH_BALANCE: { + case ActionTypes.UpdateAccountEthBalance: { const { address, ethBalanceInWei } = action.data; const currentAccount = state.providerState.account; if (currentAccount.state !== AccountState.Ready || currentAccount.address !== address) { @@ -104,17 +104,17 @@ export const createReducer = (initialState: State) => { return reduceStateWithAccount(state, newAccount); } } - case ActionTypes.UPDATE_ETH_USD_PRICE: + case ActionTypes.UpdateEthUsdPrice: return { ...state, ethUsdPrice: action.data, }; - case ActionTypes.UPDATE_SELECTED_ASSET_UNIT_AMOUNT: + case ActionTypes.UpdateSelectedAssetUnitAmount: return { ...state, selectedAssetUnitAmount: action.data, }; - case ActionTypes.UPDATE_LATEST_BUY_QUOTE: + case ActionTypes.UpdateLatestBuyQuote: const newBuyQuoteIfExists = action.data; const shouldUpdate = _.isUndefined(newBuyQuoteIfExists) || doesBuyQuoteMatchState(newBuyQuoteIfExists, state); @@ -127,29 +127,29 @@ export const createReducer = (initialState: State) => { } else { return state; } - case ActionTypes.SET_QUOTE_REQUEST_STATE_PENDING: + case ActionTypes.SetQuoteRequestStatePending: return { ...state, latestBuyQuote: undefined, quoteRequestState: AsyncProcessState.Pending, }; - case ActionTypes.SET_QUOTE_REQUEST_STATE_FAILURE: + case ActionTypes.SetQuoteRequestStateFailure: return { ...state, latestBuyQuote: undefined, quoteRequestState: AsyncProcessState.Failure, }; - case ActionTypes.SET_BUY_ORDER_STATE_NONE: + case ActionTypes.SetBuyOrderStateNone: return { ...state, buyOrderState: { processState: OrderProcessState.None }, }; - case ActionTypes.SET_BUY_ORDER_STATE_VALIDATING: + case ActionTypes.SetBuyOrderStateValidating: return { ...state, buyOrderState: { processState: OrderProcessState.Validating }, }; - case ActionTypes.SET_BUY_ORDER_STATE_PROCESSING: + case ActionTypes.SetBuyOrderStateProcessing: const processingData = action.data; const { startTimeUnix, expectedEndTimeUnix } = processingData; return { @@ -163,7 +163,7 @@ export const createReducer = (initialState: State) => { }, }, }; - case ActionTypes.SET_BUY_ORDER_STATE_FAILURE: + case ActionTypes.SetBuyOrderStateFailure: const failureTxHash = action.data; if ('txHash' in state.buyOrderState) { if (state.buyOrderState.txHash === failureTxHash) { @@ -179,7 +179,7 @@ export const createReducer = (initialState: State) => { } } return state; - case ActionTypes.SET_BUY_ORDER_STATE_SUCCESS: + case ActionTypes.SetBuyOrderStateSuccess: const successTxHash = action.data; if ('txHash' in state.buyOrderState) { if (state.buyOrderState.txHash === successTxHash) { @@ -195,29 +195,29 @@ export const createReducer = (initialState: State) => { } } return state; - case ActionTypes.SET_ERROR_MESSAGE: + case ActionTypes.SetErrorMessage: return { ...state, latestErrorMessage: action.data, latestErrorDisplayStatus: DisplayStatus.Present, }; - case ActionTypes.HIDE_ERROR: + case ActionTypes.HideError: return { ...state, latestErrorDisplayStatus: DisplayStatus.Hidden, }; - case ActionTypes.CLEAR_ERROR: + case ActionTypes.ClearError: return { ...state, latestErrorMessage: undefined, latestErrorDisplayStatus: DisplayStatus.Hidden, }; - case ActionTypes.UPDATE_SELECTED_ASSET: + case ActionTypes.UpdateSelectedAsset: return { ...state, selectedAsset: action.data, }; - case ActionTypes.RESET_AMOUNT: + case ActionTypes.ResetAmount: return { ...state, latestBuyQuote: undefined, @@ -225,12 +225,12 @@ export const createReducer = (initialState: State) => { buyOrderState: { processState: OrderProcessState.None }, selectedAssetUnitAmount: undefined, }; - case ActionTypes.SET_AVAILABLE_ASSETS: + case ActionTypes.SetAvailableAssets: return { ...state, availableAssets: action.data, }; - case ActionTypes.OPEN_STANDARD_SLIDING_PANEL: + case ActionTypes.OpenStandardSlidingPanel: return { ...state, standardSlidingPanelSettings: { @@ -238,7 +238,7 @@ export const createReducer = (initialState: State) => { animationState: 'slidIn', }, }; - case ActionTypes.CLOSE_STANDARD_SLIDING_PANEL: + case ActionTypes.CloseStandardSlidingPanel: return { ...state, standardSlidingPanelSettings: { @@ -246,7 +246,7 @@ export const createReducer = (initialState: State) => { animationState: 'slidOut', }, }; - case ActionTypes.UPDATE_BASE_CURRENCY: + case ActionTypes.UpdateBaseCurrency: return { ...state, baseCurrency: action.data, |