From b0b99fa7482f81dca1950772b4c7c8ff27c44404 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Wed, 8 Apr 2020 21:35:37 -0300 Subject: [PATCH] Move action constants to separate module (#8308) The "global" action constants (the ones previously in `actions.js`) have been moved to a separate module. This was necessary to avoid a circular dependency in an upcoming change that was causing problems. In general the "ducks" pattern of organizing Redux stores does result in circular dependency problems. This is because reuse of actions between reducers is encouraged, so it's not uncommon for two reducers to want to reference an action from the other. Going forward we can avoid this problem by moving action constants that are shared between reducers into this shared module. --- test/unit/actions/config_test.js | 4 +- test/unit/actions/set_account_label_test.js | 2 +- .../unit/actions/set_selected_account_test.js | 2 +- test/unit/actions/tx_test.js | 3 +- test/unit/ui/app/reducers/app.spec.js | 2 +- test/unit/ui/app/reducers/metamask.spec.js | 58 ++++----- ui/app/ducks/app/app.js | 82 ++++++------ ui/app/ducks/locale/locale.js | 2 +- ui/app/ducks/metamask/metamask.js | 74 +++++------ ui/app/store/actionConstants.js | 119 +++++++++++++++++ ui/app/store/actions.js | 120 +----------------- 11 files changed, 235 insertions(+), 233 deletions(-) create mode 100644 ui/app/store/actionConstants.js diff --git a/test/unit/actions/config_test.js b/test/unit/actions/config_test.js index 7418f0bd5..121a176c4 100644 --- a/test/unit/actions/config_test.js +++ b/test/unit/actions/config_test.js @@ -1,7 +1,7 @@ import assert from 'assert' import freeze from 'deep-freeze-strict' import reducers from '../../../ui/app/ducks' -import * as actions from '../../../ui/app/store/actions' +import actionConstants from '../../../ui/app/store/actionConstants' describe('config view actions', function () { const initialState = { @@ -20,7 +20,7 @@ describe('config view actions', function () { describe('SET_RPC_TARGET', function () { it('sets the state.metamask.rpcTarget property of the state to the action.value', function () { const action = { - type: actions.actionConstants.SET_RPC_TARGET, + type: actionConstants.SET_RPC_TARGET, value: 'foo', } diff --git a/test/unit/actions/set_account_label_test.js b/test/unit/actions/set_account_label_test.js index 19e375fe4..bf7ef4ae8 100644 --- a/test/unit/actions/set_account_label_test.js +++ b/test/unit/actions/set_account_label_test.js @@ -1,7 +1,7 @@ import assert from 'assert' import freeze from 'deep-freeze-strict' import reducers from '../../../ui/app/ducks' -import { actionConstants } from '../../../ui/app/store/actions' +import actionConstants from '../../../ui/app/store/actionConstants' describe('SET_ACCOUNT_LABEL', function () { it('updates the state.metamask.identities[:i].name property of the state to the action.value.label', function () { diff --git a/test/unit/actions/set_selected_account_test.js b/test/unit/actions/set_selected_account_test.js index 6a1921160..375d97879 100644 --- a/test/unit/actions/set_selected_account_test.js +++ b/test/unit/actions/set_selected_account_test.js @@ -1,7 +1,7 @@ import assert from 'assert' import freeze from 'deep-freeze-strict' import reducers from '../../../ui/app/ducks' -import { actionConstants } from '../../../ui/app/store/actions' +import actionConstants from '../../../ui/app/store/actionConstants' describe('SHOW_ACCOUNT_DETAIL', function () { it('updates metamask state', function () { diff --git a/test/unit/actions/tx_test.js b/test/unit/actions/tx_test.js index dc3accf56..427b806fd 100644 --- a/test/unit/actions/tx_test.js +++ b/test/unit/actions/tx_test.js @@ -2,6 +2,7 @@ import assert from 'assert' import configureMockStore from 'redux-mock-store' import thunk from 'redux-thunk' import * as actions from '../../../ui/app/store/actions' +import actionConstants from '../../../ui/app/store/actionConstants' const middlewares = [thunk] const mockStore = configureMockStore(middlewares) @@ -40,7 +41,7 @@ describe('tx confirmation screen', function () { await store.dispatch(actions.cancelTx({ id: txId })) const storeActions = store.getActions() - const completedTxAction = storeActions.find(({ type }) => type === actions.actionConstants.COMPLETED_TX) + const completedTxAction = storeActions.find(({ type }) => type === actionConstants.COMPLETED_TX) const { id } = completedTxAction.value assert.equal(id, txId) }) diff --git a/test/unit/ui/app/reducers/app.spec.js b/test/unit/ui/app/reducers/app.spec.js index 8cfc47fb2..d5a4531f7 100644 --- a/test/unit/ui/app/reducers/app.spec.js +++ b/test/unit/ui/app/reducers/app.spec.js @@ -1,6 +1,6 @@ import assert from 'assert' import reduceApp from '../../../../../ui/app/ducks/app/app' -import { actionConstants } from '../../../../../ui/app/store/actions' +import actionConstants from '../../../../../ui/app/store/actionConstants' const actions = actionConstants diff --git a/test/unit/ui/app/reducers/metamask.spec.js b/test/unit/ui/app/reducers/metamask.spec.js index eac5e2644..66afeabbc 100644 --- a/test/unit/ui/app/reducers/metamask.spec.js +++ b/test/unit/ui/app/reducers/metamask.spec.js @@ -1,6 +1,6 @@ import assert from 'assert' import reduceMetamask from '../../../../../ui/app/ducks/metamask/metamask' -import { actionConstants as actions } from '../../../../../ui/app/store/actions' +import actionConstants from '../../../../../ui/app/store/actionConstants' describe('MetaMask Reducers', function () { @@ -16,7 +16,7 @@ describe('MetaMask Reducers', function () { selectedAddress: 'test address', } const lockMetaMask = reduceMetamask(unlockMetaMaskState, { - type: actions.LOCK_METAMASK, + type: actionConstants.LOCK_METAMASK, }) assert.equal(lockMetaMask.isUnlocked, false) @@ -24,7 +24,7 @@ describe('MetaMask Reducers', function () { it('sets rpc target', function () { const state = reduceMetamask({}, { - type: actions.SET_RPC_TARGET, + type: actionConstants.SET_RPC_TARGET, value: 'https://custom.rpc', }) @@ -33,7 +33,7 @@ describe('MetaMask Reducers', function () { it('sets provider type', function () { const state = reduceMetamask({}, { - type: actions.SET_PROVIDER_TYPE, + type: actionConstants.SET_PROVIDER_TYPE, value: 'provider type', }) @@ -43,7 +43,7 @@ describe('MetaMask Reducers', function () { it('shows account detail', function () { const state = reduceMetamask({}, { - type: actions.SHOW_ACCOUNT_DETAIL, + type: actionConstants.SHOW_ACCOUNT_DETAIL, value: 'test address', }) @@ -54,7 +54,7 @@ describe('MetaMask Reducers', function () { it('sets select ', function () { const state = reduceMetamask({}, { - type: actions.SET_SELECTED_TOKEN, + type: actionConstants.SET_SELECTED_TOKEN, value: 'test token', }) @@ -63,7 +63,7 @@ describe('MetaMask Reducers', function () { it('sets account label', function () { const state = reduceMetamask({}, { - type: actions.SET_ACCOUNT_LABEL, + type: actionConstants.SET_ACCOUNT_LABEL, value: { account: 'test account', label: 'test label', @@ -81,7 +81,7 @@ describe('MetaMask Reducers', function () { } const state = reduceMetamask({}, { - type: actions.SET_CURRENT_FIAT, + type: actionConstants.SET_CURRENT_FIAT, value, }) @@ -98,7 +98,7 @@ describe('MetaMask Reducers', function () { } const state = reduceMetamask({}, { - type: actions.UPDATE_TOKENS, + type: actionConstants.UPDATE_TOKENS, newTokens, }) @@ -108,7 +108,7 @@ describe('MetaMask Reducers', function () { it('updates send gas limit', function () { const state = reduceMetamask({}, { - type: actions.UPDATE_GAS_LIMIT, + type: actionConstants.UPDATE_GAS_LIMIT, value: '0xGasLimit', }) @@ -117,7 +117,7 @@ describe('MetaMask Reducers', function () { it('updates send gas price', function () { const state = reduceMetamask({}, { - type: actions.UPDATE_GAS_PRICE, + type: actionConstants.UPDATE_GAS_PRICE, value: '0xGasPrice', }) @@ -126,7 +126,7 @@ describe('MetaMask Reducers', function () { it('toggles account menu ', function () { const state = reduceMetamask({}, { - type: actions.TOGGLE_ACCOUNT_MENU, + type: actionConstants.TOGGLE_ACCOUNT_MENU, }) assert.equal(state.isAccountMenuOpen, true) @@ -134,7 +134,7 @@ describe('MetaMask Reducers', function () { it('updates gas total', function () { const state = reduceMetamask({}, { - type: actions.UPDATE_GAS_TOTAL, + type: actionConstants.UPDATE_GAS_TOTAL, value: '0xGasTotal', }) @@ -143,7 +143,7 @@ describe('MetaMask Reducers', function () { it('updates send token balance', function () { const state = reduceMetamask({}, { - type: actions.UPDATE_SEND_TOKEN_BALANCE, + type: actionConstants.UPDATE_SEND_TOKEN_BALANCE, value: '0xTokenBalance', }) @@ -152,7 +152,7 @@ describe('MetaMask Reducers', function () { it('updates data', function () { const state = reduceMetamask({}, { - type: actions.UPDATE_SEND_HEX_DATA, + type: actionConstants.UPDATE_SEND_HEX_DATA, value: '0xData', }) @@ -161,7 +161,7 @@ describe('MetaMask Reducers', function () { it('updates send to', function () { const state = reduceMetamask({}, { - type: actions.UPDATE_SEND_TO, + type: actionConstants.UPDATE_SEND_TO, value: { to: '0xAddress', nickname: 'nickname', @@ -174,7 +174,7 @@ describe('MetaMask Reducers', function () { it('update send amount', function () { const state = reduceMetamask({}, { - type: actions.UPDATE_SEND_AMOUNT, + type: actionConstants.UPDATE_SEND_AMOUNT, value: '0xAmount', }) @@ -183,7 +183,7 @@ describe('MetaMask Reducers', function () { it('updates max mode', function () { const state = reduceMetamask({}, { - type: actions.UPDATE_MAX_MODE, + type: actionConstants.UPDATE_MAX_MODE, value: true, }) @@ -210,7 +210,7 @@ describe('MetaMask Reducers', function () { } const sendState = reduceMetamask({}, { - type: actions.UPDATE_SEND, + type: actionConstants.UPDATE_SEND, value, }) @@ -255,7 +255,7 @@ describe('MetaMask Reducers', function () { const state = reduceMetamask(sendState, { - type: actions.CLEAR_SEND, + type: actionConstants.CLEAR_SEND, }) assert.deepEqual(state.send, initStateSend.send) @@ -272,7 +272,7 @@ describe('MetaMask Reducers', function () { } const state = reduceMetamask(oldState, { - type: actions.UPDATE_TRANSACTION_PARAMS, + type: actionConstants.UPDATE_TRANSACTION_PARAMS, id: 1, value: 'bar', }) @@ -282,7 +282,7 @@ describe('MetaMask Reducers', function () { it('sets blockies', function () { const state = reduceMetamask({}, { - type: actions.SET_USE_BLOCKIE, + type: actionConstants.SET_USE_BLOCKIE, value: true, }) @@ -291,7 +291,7 @@ describe('MetaMask Reducers', function () { it('updates an arbitrary feature flag', function () { const state = reduceMetamask({}, { - type: actions.UPDATE_FEATURE_FLAGS, + type: actionConstants.UPDATE_FEATURE_FLAGS, value: { foo: true, }, @@ -302,7 +302,7 @@ describe('MetaMask Reducers', function () { it('close welcome screen', function () { const state = reduceMetamask({}, { - type: actions.CLOSE_WELCOME_SCREEN, + type: actionConstants.CLOSE_WELCOME_SCREEN, }) assert.equal(state.welcomeScreenSeen, true) @@ -310,7 +310,7 @@ describe('MetaMask Reducers', function () { it('sets current locale', function () { const state = reduceMetamask({}, { - type: actions.SET_CURRENT_LOCALE, + type: actionConstants.SET_CURRENT_LOCALE, value: { locale: 'ge' }, }) @@ -325,7 +325,7 @@ describe('MetaMask Reducers', function () { } const pendingTokensState = reduceMetamask({}, { - type: actions.SET_PENDING_TOKENS, + type: actionConstants.SET_PENDING_TOKENS, payload, }) @@ -344,7 +344,7 @@ describe('MetaMask Reducers', function () { } const state = reduceMetamask(pendingTokensState, { - type: actions.CLEAR_PENDING_TOKENS, + type: actionConstants.CLEAR_PENDING_TOKENS, }) assert.deepEqual(state.pendingTokens, {}) @@ -352,7 +352,7 @@ describe('MetaMask Reducers', function () { it('update ensResolution', function () { const state = reduceMetamask({}, { - type: actions.UPDATE_SEND_ENS_RESOLUTION, + type: actionConstants.UPDATE_SEND_ENS_RESOLUTION, payload: '0x1337', }) @@ -362,7 +362,7 @@ describe('MetaMask Reducers', function () { it('update ensResolutionError', function () { const state = reduceMetamask({}, { - type: actions.UPDATE_SEND_ENS_RESOLUTION_ERROR, + type: actionConstants.UPDATE_SEND_ENS_RESOLUTION_ERROR, payload: 'ens name not found', }) diff --git a/ui/app/ducks/app/app.js b/ui/app/ducks/app/app.js index 79cd87e38..16feeb73d 100644 --- a/ui/app/ducks/app/app.js +++ b/ui/app/ducks/app/app.js @@ -1,6 +1,6 @@ -import { actionConstants as actions } from '../../store/actions' +import actionConstants from '../../store/actionConstants' -// Actions +// actionConstants const SET_THREEBOX_LAST_UPDATED = 'metamask/app/SET_THREEBOX_LAST_UPDATED' export default function reduceApp (state = {}, action) { @@ -58,20 +58,20 @@ export default function reduceApp (state = {}, action) { switch (action.type) { // dropdown methods - case actions.NETWORK_DROPDOWN_OPEN: + case actionConstants.NETWORK_DROPDOWN_OPEN: return { ...appState, networkDropdownOpen: true, } - case actions.NETWORK_DROPDOWN_CLOSE: + case actionConstants.NETWORK_DROPDOWN_CLOSE: return { ...appState, networkDropdownOpen: false, } // sidebar methods - case actions.SIDEBAR_OPEN: + case actionConstants.SIDEBAR_OPEN: return { ...appState, sidebar: { @@ -80,7 +80,7 @@ export default function reduceApp (state = {}, action) { }, } - case actions.SIDEBAR_CLOSE: + case actionConstants.SIDEBAR_CLOSE: return { ...appState, sidebar: { @@ -90,14 +90,14 @@ export default function reduceApp (state = {}, action) { } // alert methods - case actions.ALERT_OPEN: + case actionConstants.ALERT_OPEN: return { ...appState, alertOpen: true, alertMessage: action.value, } - case actions.ALERT_CLOSE: + case actionConstants.ALERT_CLOSE: return { ...appState, alertOpen: false, @@ -105,7 +105,7 @@ export default function reduceApp (state = {}, action) { } // qr scanner methods - case actions.QR_CODE_DETECTED: + case actionConstants.QR_CODE_DETECTED: return { ...appState, qrCodeData: action.value, @@ -113,7 +113,7 @@ export default function reduceApp (state = {}, action) { // modal methods: - case actions.MODAL_OPEN: + case actionConstants.MODAL_OPEN: const { name, ...modalProps } = action.payload return { @@ -128,7 +128,7 @@ export default function reduceApp (state = {}, action) { }, } - case actions.MODAL_CLOSE: + case actionConstants.MODAL_CLOSE: return { ...appState, modal: Object.assign( @@ -140,26 +140,26 @@ export default function reduceApp (state = {}, action) { } // transition methods - case actions.TRANSITION_FORWARD: + case actionConstants.TRANSITION_FORWARD: return { ...appState, transForward: true, } - case actions.FORGOT_PASSWORD: + case actionConstants.FORGOT_PASSWORD: return { ...appState, forgottenPassword: action.value, } - case actions.SHOW_SEND_TOKEN_PAGE: + case actionConstants.SHOW_SEND_TOKEN_PAGE: return { ...appState, transForward: true, warning: null, } - case actions.LOCK_METAMASK: + case actionConstants.LOCK_METAMASK: return { ...appState, transForward: false, @@ -168,7 +168,7 @@ export default function reduceApp (state = {}, action) { // accounts - case actions.GO_HOME: + case actionConstants.GO_HOME: return { ...appState, accountDetail: { @@ -180,7 +180,7 @@ export default function reduceApp (state = {}, action) { warning: null, } - case actions.SHOW_ACCOUNT_DETAIL: + case actionConstants.SHOW_ACCOUNT_DETAIL: return { ...appState, forgottenPassword: appState.forgottenPassword ? !appState.forgottenPassword : null, @@ -192,7 +192,7 @@ export default function reduceApp (state = {}, action) { transForward: false, } - case actions.SHOW_ACCOUNTS_PAGE: + case actionConstants.SHOW_ACCOUNTS_PAGE: return { ...appState, transForward: true, @@ -202,7 +202,7 @@ export default function reduceApp (state = {}, action) { forgottenPassword: false, } - case actions.SHOW_CONF_TX_PAGE: + case actionConstants.SHOW_CONF_TX_PAGE: return { ...appState, txId: action.id, @@ -211,7 +211,7 @@ export default function reduceApp (state = {}, action) { isLoading: false, } - case actions.COMPLETED_TX: + case actionConstants.COMPLETED_TX: if (action.value.unconfirmedActionsCount > 0) { return { ...appState, @@ -233,24 +233,24 @@ export default function reduceApp (state = {}, action) { } } - case actions.TRANSACTION_ERROR: + case actionConstants.TRANSACTION_ERROR: return { ...appState, } - case actions.UNLOCK_FAILED: + case actionConstants.UNLOCK_FAILED: return { ...appState, warning: action.value || 'Incorrect password. Try again.', } - case actions.UNLOCK_SUCCEEDED: + case actionConstants.UNLOCK_SUCCEEDED: return { ...appState, warning: '', } - case actions.SET_HARDWARE_WALLET_DEFAULT_HD_PATH: + case actionConstants.SET_HARDWARE_WALLET_DEFAULT_HD_PATH: const { device, path } = action.value const newDefaults = { ...appState.defaultHdPaths } newDefaults[device] = path @@ -260,33 +260,33 @@ export default function reduceApp (state = {}, action) { defaultHdPaths: newDefaults, } - case actions.SHOW_LOADING: + case actionConstants.SHOW_LOADING: return { ...appState, isLoading: true, loadingMessage: action.value, } - case actions.HIDE_LOADING: + case actionConstants.HIDE_LOADING: return { ...appState, isLoading: false, } - case actions.DISPLAY_WARNING: + case actionConstants.DISPLAY_WARNING: return { ...appState, warning: action.value, isLoading: false, } - case actions.HIDE_WARNING: + case actionConstants.HIDE_WARNING: return { ...appState, warning: undefined, } - case actions.SHOW_PRIVATE_KEY: + case actionConstants.SHOW_PRIVATE_KEY: return { ...appState, accountDetail: { @@ -296,31 +296,31 @@ export default function reduceApp (state = {}, action) { }, } - case actions.SET_MOUSE_USER_STATE: + case actionConstants.SET_MOUSE_USER_STATE: return { ...appState, isMouseUser: action.value, } - case actions.GAS_LOADING_STARTED: + case actionConstants.GAS_LOADING_STARTED: return { ...appState, gasIsLoading: true, } - case actions.GAS_LOADING_FINISHED: + case actionConstants.GAS_LOADING_FINISHED: return { ...appState, gasIsLoading: false, } - case actions.SET_NETWORK_NONCE: + case actionConstants.SET_NETWORK_NONCE: return { ...appState, networkNonce: action.value, } - case actions.SET_PREVIOUS_PROVIDER: + case actionConstants.SET_PREVIOUS_PROVIDER: if (action.value === 'loading') { return appState } @@ -329,25 +329,25 @@ export default function reduceApp (state = {}, action) { lastSelectedProvider: action.value, } - case actions.SET_SELECTED_SETTINGS_RPC_URL: + case actionConstants.SET_SELECTED_SETTINGS_RPC_URL: return { ...appState, networksTabSelectedRpcUrl: action.value, } - case actions.SET_NETWORKS_TAB_ADD_MODE: + case actionConstants.SET_NETWORKS_TAB_ADD_MODE: return { ...appState, networksTabIsInAddMode: action.value, } - case actions.LOADING_METHOD_DATA_STARTED: + case actionConstants.LOADING_METHOD_DATA_STARTED: return { ...appState, loadingMethodData: true, } - case actions.LOADING_METHOD_DATA_FINISHED: + case actionConstants.LOADING_METHOD_DATA_FINISHED: return { ...appState, loadingMethodData: false, @@ -359,19 +359,19 @@ export default function reduceApp (state = {}, action) { threeBoxLastUpdated: action.value, } - case actions.SET_REQUEST_ACCOUNT_TABS: + case actionConstants.SET_REQUEST_ACCOUNT_TABS: return { ...appState, requestAccountTabs: action.value, } - case actions.SET_OPEN_METAMASK_TAB_IDS: + case actionConstants.SET_OPEN_METAMASK_TAB_IDS: return { ...appState, openMetaMaskTabs: action.value, } - case actions.SET_CURRENT_WINDOW_TAB: + case actionConstants.SET_CURRENT_WINDOW_TAB: return { ...appState, currentWindowTab: action.value, diff --git a/ui/app/ducks/locale/locale.js b/ui/app/ducks/locale/locale.js index 323a82d46..2d13bea1d 100644 --- a/ui/app/ducks/locale/locale.js +++ b/ui/app/ducks/locale/locale.js @@ -1,4 +1,4 @@ -import { actionConstants } from '../../store/actions' +import actionConstants from '../../store/actionConstants' export default function reduceLocaleMessages (state = {}, { type, value }) { switch (type) { diff --git a/ui/app/ducks/metamask/metamask.js b/ui/app/ducks/metamask/metamask.js index 3cafd1011..c0fe48364 100644 --- a/ui/app/ducks/metamask/metamask.js +++ b/ui/app/ducks/metamask/metamask.js @@ -1,4 +1,4 @@ -import { actionConstants as actions } from '../../store/actions' +import actionConstants from '../../store/actionConstants' export default function reduceMetamask (state = {}, action) { const metamaskState = Object.assign({ @@ -53,16 +53,16 @@ export default function reduceMetamask (state = {}, action) { switch (action.type) { - case actions.UPDATE_METAMASK_STATE: + case actionConstants.UPDATE_METAMASK_STATE: return { ...metamaskState, ...action.value } - case actions.LOCK_METAMASK: + case actionConstants.LOCK_METAMASK: return { ...metamaskState, isUnlocked: false, } - case actions.SET_RPC_TARGET: + case actionConstants.SET_RPC_TARGET: return { ...metamaskState, provider: { @@ -71,7 +71,7 @@ export default function reduceMetamask (state = {}, action) { }, } - case actions.SET_PROVIDER_TYPE: + case actionConstants.SET_PROVIDER_TYPE: return { ...metamaskState, provider: { @@ -79,7 +79,7 @@ export default function reduceMetamask (state = {}, action) { }, } - case actions.SHOW_ACCOUNT_DETAIL: + case actionConstants.SHOW_ACCOUNT_DETAIL: return { ...metamaskState, isUnlocked: true, @@ -87,7 +87,7 @@ export default function reduceMetamask (state = {}, action) { selectedAddress: action.value, } - case actions.SET_SELECTED_TOKEN: { + case actionConstants.SET_SELECTED_TOKEN: { const newState = { ...metamaskState, selectedTokenAddress: action.value, @@ -114,7 +114,7 @@ export default function reduceMetamask (state = {}, action) { return newState } - case actions.SET_ACCOUNT_LABEL: + case actionConstants.SET_ACCOUNT_LABEL: const account = action.value.account const name = action.value.label const id = {} @@ -122,21 +122,21 @@ export default function reduceMetamask (state = {}, action) { const identities = Object.assign({}, metamaskState.identities, id) return Object.assign(metamaskState, { identities }) - case actions.SET_CURRENT_FIAT: + case actionConstants.SET_CURRENT_FIAT: return Object.assign(metamaskState, { currentCurrency: action.value.currentCurrency, conversionRate: action.value.conversionRate, conversionDate: action.value.conversionDate, }) - case actions.UPDATE_TOKENS: + case actionConstants.UPDATE_TOKENS: return { ...metamaskState, tokens: action.newTokens, } // metamask.send - case actions.UPDATE_GAS_LIMIT: + case actionConstants.UPDATE_GAS_LIMIT: return { ...metamaskState, send: { @@ -144,12 +144,12 @@ export default function reduceMetamask (state = {}, action) { gasLimit: action.value, }, } - case actions.UPDATE_CUSTOM_NONCE: + case actionConstants.UPDATE_CUSTOM_NONCE: return { ...metamaskState, customNonceValue: action.value, } - case actions.UPDATE_GAS_PRICE: + case actionConstants.UPDATE_GAS_PRICE: return { ...metamaskState, send: { @@ -158,13 +158,13 @@ export default function reduceMetamask (state = {}, action) { }, } - case actions.TOGGLE_ACCOUNT_MENU: + case actionConstants.TOGGLE_ACCOUNT_MENU: return { ...metamaskState, isAccountMenuOpen: !metamaskState.isAccountMenuOpen, } - case actions.UPDATE_GAS_TOTAL: + case actionConstants.UPDATE_GAS_TOTAL: return { ...metamaskState, send: { @@ -173,7 +173,7 @@ export default function reduceMetamask (state = {}, action) { }, } - case actions.UPDATE_SEND_TOKEN_BALANCE: + case actionConstants.UPDATE_SEND_TOKEN_BALANCE: return { ...metamaskState, send: { @@ -182,7 +182,7 @@ export default function reduceMetamask (state = {}, action) { }, } - case actions.UPDATE_SEND_HEX_DATA: + case actionConstants.UPDATE_SEND_HEX_DATA: return { ...metamaskState, send: { @@ -191,7 +191,7 @@ export default function reduceMetamask (state = {}, action) { }, } - case actions.UPDATE_SEND_TO: + case actionConstants.UPDATE_SEND_TO: return { ...metamaskState, send: { @@ -201,7 +201,7 @@ export default function reduceMetamask (state = {}, action) { }, } - case actions.UPDATE_SEND_AMOUNT: + case actionConstants.UPDATE_SEND_AMOUNT: return { ...metamaskState, send: { @@ -210,7 +210,7 @@ export default function reduceMetamask (state = {}, action) { }, } - case actions.UPDATE_MAX_MODE: + case actionConstants.UPDATE_MAX_MODE: return { ...metamaskState, send: { @@ -219,7 +219,7 @@ export default function reduceMetamask (state = {}, action) { }, } - case actions.UPDATE_SEND: + case actionConstants.UPDATE_SEND: return Object.assign(metamaskState, { send: { ...metamaskState.send, @@ -227,7 +227,7 @@ export default function reduceMetamask (state = {}, action) { }, }) - case actions.UPDATE_SEND_ENS_RESOLUTION: + case actionConstants.UPDATE_SEND_ENS_RESOLUTION: return { ...metamaskState, send: { @@ -237,7 +237,7 @@ export default function reduceMetamask (state = {}, action) { }, } - case actions.UPDATE_SEND_ENS_RESOLUTION_ERROR: + case actionConstants.UPDATE_SEND_ENS_RESOLUTION_ERROR: return { ...metamaskState, send: { @@ -247,7 +247,7 @@ export default function reduceMetamask (state = {}, action) { }, } - case actions.CLEAR_SEND: + case actionConstants.CLEAR_SEND: return { ...metamaskState, send: { @@ -267,7 +267,7 @@ export default function reduceMetamask (state = {}, action) { }, } - case actions.UPDATE_TRANSACTION_PARAMS: + case actionConstants.UPDATE_TRANSACTION_PARAMS: const { id: txId, value } = action let { currentNetworkTxList } = metamaskState currentNetworkTxList = currentNetworkTxList.map((tx) => { @@ -284,56 +284,56 @@ export default function reduceMetamask (state = {}, action) { currentNetworkTxList, } - case actions.SET_PARTICIPATE_IN_METAMETRICS: + case actionConstants.SET_PARTICIPATE_IN_METAMETRICS: return { ...metamaskState, participateInMetaMetrics: action.value, } - case actions.SET_METAMETRICS_SEND_COUNT: + case actionConstants.SET_METAMETRICS_SEND_COUNT: return { ...metamaskState, metaMetricsSendCount: action.value, } - case actions.SET_USE_BLOCKIE: + case actionConstants.SET_USE_BLOCKIE: return { ...metamaskState, useBlockie: action.value, } - case actions.UPDATE_FEATURE_FLAGS: + case actionConstants.UPDATE_FEATURE_FLAGS: return { ...metamaskState, featureFlags: action.value, } - case actions.CLOSE_WELCOME_SCREEN: + case actionConstants.CLOSE_WELCOME_SCREEN: return { ...metamaskState, welcomeScreenSeen: true, } - case actions.SET_CURRENT_LOCALE: + case actionConstants.SET_CURRENT_LOCALE: return { ...metamaskState, currentLocale: action.value.locale, } - case actions.SET_PENDING_TOKENS: + case actionConstants.SET_PENDING_TOKENS: return { ...metamaskState, pendingTokens: { ...action.payload }, } - case actions.CLEAR_PENDING_TOKENS: { + case actionConstants.CLEAR_PENDING_TOKENS: { return { ...metamaskState, pendingTokens: {}, } } - case actions.UPDATE_PREFERENCES: { + case actionConstants.UPDATE_PREFERENCES: { return { ...metamaskState, preferences: { @@ -343,21 +343,21 @@ export default function reduceMetamask (state = {}, action) { } } - case actions.COMPLETE_ONBOARDING: { + case actionConstants.COMPLETE_ONBOARDING: { return { ...metamaskState, completedOnboarding: true, } } - case actions.SET_FIRST_TIME_FLOW_TYPE: { + case actionConstants.SET_FIRST_TIME_FLOW_TYPE: { return { ...metamaskState, firstTimeFlowType: action.value, } } - case actions.SET_NEXT_NONCE: { + case actionConstants.SET_NEXT_NONCE: { return { ...metamaskState, nextNonce: action.value, diff --git a/ui/app/store/actionConstants.js b/ui/app/store/actionConstants.js new file mode 100644 index 000000000..3f6d7e2d0 --- /dev/null +++ b/ui/app/store/actionConstants.js @@ -0,0 +1,119 @@ + +export default { + GO_HOME: 'GO_HOME', + // modal state + MODAL_OPEN: 'UI_MODAL_OPEN', + MODAL_CLOSE: 'UI_MODAL_CLOSE', + // notification state + CLOSE_NOTIFICATION_WINDOW: 'CLOSE_NOTIFICATION_WINDOW', + // sidebar state + SIDEBAR_OPEN: 'UI_SIDEBAR_OPEN', + SIDEBAR_CLOSE: 'UI_SIDEBAR_CLOSE', + // alert state + ALERT_OPEN: 'UI_ALERT_OPEN', + ALERT_CLOSE: 'UI_ALERT_CLOSE', + QR_CODE_DETECTED: 'UI_QR_CODE_DETECTED', + // network dropdown open + NETWORK_DROPDOWN_OPEN: 'UI_NETWORK_DROPDOWN_OPEN', + NETWORK_DROPDOWN_CLOSE: 'UI_NETWORK_DROPDOWN_CLOSE', + // transition state + TRANSITION_FORWARD: 'TRANSITION_FORWARD', + // remote state + UPDATE_METAMASK_STATE: 'UPDATE_METAMASK_STATE', + FORGOT_PASSWORD: 'FORGOT_PASSWORD', + CLOSE_WELCOME_SCREEN: 'CLOSE_WELCOME_SCREEN', + // unlock screen + UNLOCK_IN_PROGRESS: 'UNLOCK_IN_PROGRESS', + UNLOCK_FAILED: 'UNLOCK_FAILED', + UNLOCK_SUCCEEDED: 'UNLOCK_SUCCEEDED', + LOCK_METAMASK: 'LOCK_METAMASK', + // error handling + DISPLAY_WARNING: 'DISPLAY_WARNING', + HIDE_WARNING: 'HIDE_WARNING', + // accounts screen + SET_SELECTED_TOKEN: 'SET_SELECTED_TOKEN', + SHOW_ACCOUNT_DETAIL: 'SHOW_ACCOUNT_DETAIL', + SHOW_ACCOUNTS_PAGE: 'SHOW_ACCOUNTS_PAGE', + SHOW_CONF_TX_PAGE: 'SHOW_CONF_TX_PAGE', + SET_CURRENT_FIAT: 'SET_CURRENT_FIAT', + // account detail screen + SHOW_SEND_TOKEN_PAGE: 'SHOW_SEND_TOKEN_PAGE', + SHOW_PRIVATE_KEY: 'SHOW_PRIVATE_KEY', + SET_ACCOUNT_LABEL: 'SET_ACCOUNT_LABEL', + SET_NETWORK_NONCE: 'SET_NETWORK_NONCE', + // tx conf screen + COMPLETED_TX: 'COMPLETED_TX', + TRANSACTION_ERROR: 'TRANSACTION_ERROR', + UPDATE_TRANSACTION_PARAMS: 'UPDATE_TRANSACTION_PARAMS', + SET_NEXT_NONCE: 'SET_NEXT_NONCE', + // send screen + UPDATE_GAS_LIMIT: 'UPDATE_GAS_LIMIT', + UPDATE_GAS_PRICE: 'UPDATE_GAS_PRICE', + UPDATE_GAS_TOTAL: 'UPDATE_GAS_TOTAL', + UPDATE_SEND_HEX_DATA: 'UPDATE_SEND_HEX_DATA', + UPDATE_SEND_TOKEN_BALANCE: 'UPDATE_SEND_TOKEN_BALANCE', + UPDATE_SEND_TO: 'UPDATE_SEND_TO', + UPDATE_SEND_AMOUNT: 'UPDATE_SEND_AMOUNT', + UPDATE_SEND_ERRORS: 'UPDATE_SEND_ERRORS', + UPDATE_MAX_MODE: 'UPDATE_MAX_MODE', + UPDATE_SEND: 'UPDATE_SEND', + CLEAR_SEND: 'CLEAR_SEND', + GAS_LOADING_STARTED: 'GAS_LOADING_STARTED', + GAS_LOADING_FINISHED: 'GAS_LOADING_FINISHED', + UPDATE_SEND_ENS_RESOLUTION: 'UPDATE_SEND_ENS_RESOLUTION', + UPDATE_SEND_ENS_RESOLUTION_ERROR: 'UPDATE_SEND_ENS_RESOLUTION_ERROR', + // config screen + SET_RPC_TARGET: 'SET_RPC_TARGET', + SET_PROVIDER_TYPE: 'SET_PROVIDER_TYPE', + SET_PREVIOUS_PROVIDER: 'SET_PREVIOUS_PROVIDER', + UPDATE_TOKENS: 'UPDATE_TOKENS', + SET_HARDWARE_WALLET_DEFAULT_HD_PATH: 'SET_HARDWARE_WALLET_DEFAULT_HD_PATH', + // loading overlay + SHOW_LOADING: 'SHOW_LOADING_INDICATION', + HIDE_LOADING: 'HIDE_LOADING_INDICATION', + // buy Eth with coinbase + BUY_ETH: 'BUY_ETH', + + TOGGLE_ACCOUNT_MENU: 'TOGGLE_ACCOUNT_MENU', + + SET_USE_BLOCKIE: 'SET_USE_BLOCKIE', + SET_USE_NONCEFIELD: 'SET_USE_NONCEFIELD', + UPDATE_CUSTOM_NONCE: 'UPDATE_CUSTOM_NONCE', + SET_IPFS_GATEWAY: 'SET_IPFS_GATEWAY', + + SET_PARTICIPATE_IN_METAMETRICS: 'SET_PARTICIPATE_IN_METAMETRICS', + SET_METAMETRICS_SEND_COUNT: 'SET_METAMETRICS_SEND_COUNT', + + // locale + SET_CURRENT_LOCALE: 'SET_CURRENT_LOCALE', + + // Feature Flags + UPDATE_FEATURE_FLAGS: 'UPDATE_FEATURE_FLAGS', + + // Preferences + UPDATE_PREFERENCES: 'UPDATE_PREFERENCES', + + // Onboarding + COMPLETE_ONBOARDING: 'COMPLETE_ONBOARDING', + + SET_MOUSE_USER_STATE: 'SET_MOUSE_USER_STATE', + + // Network + SET_PENDING_TOKENS: 'SET_PENDING_TOKENS', + CLEAR_PENDING_TOKENS: 'CLEAR_PENDING_TOKENS', + + SET_FIRST_TIME_FLOW_TYPE: 'SET_FIRST_TIME_FLOW_TYPE', + + SET_SELECTED_SETTINGS_RPC_URL: 'SET_SELECTED_SETTINGS_RPC_URL', + SET_NETWORKS_TAB_ADD_MODE: 'SET_NETWORKS_TAB_ADD_MODE', + + LOADING_METHOD_DATA_STARTED: 'LOADING_METHOD_DATA_STARTED', + LOADING_METHOD_DATA_FINISHED: 'LOADING_METHOD_DATA_FINISHED', + + LOADING_TOKEN_PARAMS_STARTED: 'LOADING_TOKEN_PARAMS_STARTED', + LOADING_TOKEN_PARAMS_FINISHED: 'LOADING_TOKEN_PARAMS_FINISHED', + + SET_REQUEST_ACCOUNT_TABS: 'SET_REQUEST_ACCOUNT_TABS', + SET_CURRENT_WINDOW_TAB: 'SET_CURRENT_WINDOW_TAB', + SET_OPEN_METAMASK_TAB_IDS: 'SET_OPEN_METAMASK_TAB_IDS', +} diff --git a/ui/app/store/actions.js b/ui/app/store/actions.js index 45d0a77e4..9b2db460c 100644 --- a/ui/app/store/actions.js +++ b/ui/app/store/actions.js @@ -14,125 +14,7 @@ import { hasUnconfirmedTransactions } from '../helpers/utils/confirm-tx.util' import { setCustomGasLimit } from '../ducks/gas/gas.duck' import txHelper from '../../lib/tx-helper' import { getEnvironmentType } from '../../../app/scripts/lib/util' - -export const actionConstants = { - GO_HOME: 'GO_HOME', - // modal state - MODAL_OPEN: 'UI_MODAL_OPEN', - MODAL_CLOSE: 'UI_MODAL_CLOSE', - // notification state - CLOSE_NOTIFICATION_WINDOW: 'CLOSE_NOTIFICATION_WINDOW', - // sidebar state - SIDEBAR_OPEN: 'UI_SIDEBAR_OPEN', - SIDEBAR_CLOSE: 'UI_SIDEBAR_CLOSE', - // alert state - ALERT_OPEN: 'UI_ALERT_OPEN', - ALERT_CLOSE: 'UI_ALERT_CLOSE', - QR_CODE_DETECTED: 'UI_QR_CODE_DETECTED', - // network dropdown open - NETWORK_DROPDOWN_OPEN: 'UI_NETWORK_DROPDOWN_OPEN', - NETWORK_DROPDOWN_CLOSE: 'UI_NETWORK_DROPDOWN_CLOSE', - // transition state - TRANSITION_FORWARD: 'TRANSITION_FORWARD', - // remote state - UPDATE_METAMASK_STATE: 'UPDATE_METAMASK_STATE', - FORGOT_PASSWORD: 'FORGOT_PASSWORD', - CLOSE_WELCOME_SCREEN: 'CLOSE_WELCOME_SCREEN', - // unlock screen - UNLOCK_IN_PROGRESS: 'UNLOCK_IN_PROGRESS', - UNLOCK_FAILED: 'UNLOCK_FAILED', - UNLOCK_SUCCEEDED: 'UNLOCK_SUCCEEDED', - LOCK_METAMASK: 'LOCK_METAMASK', - // error handling - DISPLAY_WARNING: 'DISPLAY_WARNING', - HIDE_WARNING: 'HIDE_WARNING', - // accounts screen - SET_SELECTED_TOKEN: 'SET_SELECTED_TOKEN', - SHOW_ACCOUNT_DETAIL: 'SHOW_ACCOUNT_DETAIL', - SHOW_ACCOUNTS_PAGE: 'SHOW_ACCOUNTS_PAGE', - SHOW_CONF_TX_PAGE: 'SHOW_CONF_TX_PAGE', - SET_CURRENT_FIAT: 'SET_CURRENT_FIAT', - // account detail screen - SHOW_SEND_TOKEN_PAGE: 'SHOW_SEND_TOKEN_PAGE', - SHOW_PRIVATE_KEY: 'SHOW_PRIVATE_KEY', - SET_ACCOUNT_LABEL: 'SET_ACCOUNT_LABEL', - SET_NETWORK_NONCE: 'SET_NETWORK_NONCE', - // tx conf screen - COMPLETED_TX: 'COMPLETED_TX', - TRANSACTION_ERROR: 'TRANSACTION_ERROR', - UPDATE_TRANSACTION_PARAMS: 'UPDATE_TRANSACTION_PARAMS', - SET_NEXT_NONCE: 'SET_NEXT_NONCE', - // send screen - UPDATE_GAS_LIMIT: 'UPDATE_GAS_LIMIT', - UPDATE_GAS_PRICE: 'UPDATE_GAS_PRICE', - UPDATE_GAS_TOTAL: 'UPDATE_GAS_TOTAL', - UPDATE_SEND_HEX_DATA: 'UPDATE_SEND_HEX_DATA', - UPDATE_SEND_TOKEN_BALANCE: 'UPDATE_SEND_TOKEN_BALANCE', - UPDATE_SEND_TO: 'UPDATE_SEND_TO', - UPDATE_SEND_AMOUNT: 'UPDATE_SEND_AMOUNT', - UPDATE_SEND_ERRORS: 'UPDATE_SEND_ERRORS', - UPDATE_MAX_MODE: 'UPDATE_MAX_MODE', - UPDATE_SEND: 'UPDATE_SEND', - CLEAR_SEND: 'CLEAR_SEND', - GAS_LOADING_STARTED: 'GAS_LOADING_STARTED', - GAS_LOADING_FINISHED: 'GAS_LOADING_FINISHED', - UPDATE_SEND_ENS_RESOLUTION: 'UPDATE_SEND_ENS_RESOLUTION', - UPDATE_SEND_ENS_RESOLUTION_ERROR: 'UPDATE_SEND_ENS_RESOLUTION_ERROR', - // config screen - SET_RPC_TARGET: 'SET_RPC_TARGET', - SET_PROVIDER_TYPE: 'SET_PROVIDER_TYPE', - SET_PREVIOUS_PROVIDER: 'SET_PREVIOUS_PROVIDER', - UPDATE_TOKENS: 'UPDATE_TOKENS', - SET_HARDWARE_WALLET_DEFAULT_HD_PATH: 'SET_HARDWARE_WALLET_DEFAULT_HD_PATH', - // loading overlay - SHOW_LOADING: 'SHOW_LOADING_INDICATION', - HIDE_LOADING: 'HIDE_LOADING_INDICATION', - // buy Eth with coinbase - BUY_ETH: 'BUY_ETH', - - TOGGLE_ACCOUNT_MENU: 'TOGGLE_ACCOUNT_MENU', - - SET_USE_BLOCKIE: 'SET_USE_BLOCKIE', - SET_USE_NONCEFIELD: 'SET_USE_NONCEFIELD', - UPDATE_CUSTOM_NONCE: 'UPDATE_CUSTOM_NONCE', - SET_IPFS_GATEWAY: 'SET_IPFS_GATEWAY', - - SET_PARTICIPATE_IN_METAMETRICS: 'SET_PARTICIPATE_IN_METAMETRICS', - SET_METAMETRICS_SEND_COUNT: 'SET_METAMETRICS_SEND_COUNT', - - // locale - SET_CURRENT_LOCALE: 'SET_CURRENT_LOCALE', - - // Feature Flags - UPDATE_FEATURE_FLAGS: 'UPDATE_FEATURE_FLAGS', - - // Preferences - UPDATE_PREFERENCES: 'UPDATE_PREFERENCES', - - // Onboarding - COMPLETE_ONBOARDING: 'COMPLETE_ONBOARDING', - - SET_MOUSE_USER_STATE: 'SET_MOUSE_USER_STATE', - - // Network - SET_PENDING_TOKENS: 'SET_PENDING_TOKENS', - CLEAR_PENDING_TOKENS: 'CLEAR_PENDING_TOKENS', - - SET_FIRST_TIME_FLOW_TYPE: 'SET_FIRST_TIME_FLOW_TYPE', - - SET_SELECTED_SETTINGS_RPC_URL: 'SET_SELECTED_SETTINGS_RPC_URL', - SET_NETWORKS_TAB_ADD_MODE: 'SET_NETWORKS_TAB_ADD_MODE', - - LOADING_METHOD_DATA_STARTED: 'LOADING_METHOD_DATA_STARTED', - LOADING_METHOD_DATA_FINISHED: 'LOADING_METHOD_DATA_FINISHED', - - LOADING_TOKEN_PARAMS_STARTED: 'LOADING_TOKEN_PARAMS_STARTED', - LOADING_TOKEN_PARAMS_FINISHED: 'LOADING_TOKEN_PARAMS_FINISHED', - - SET_REQUEST_ACCOUNT_TABS: 'SET_REQUEST_ACCOUNT_TABS', - SET_CURRENT_WINDOW_TAB: 'SET_CURRENT_WINDOW_TAB', - SET_OPEN_METAMASK_TAB_IDS: 'SET_OPEN_METAMASK_TAB_IDS', -} +import actionConstants from './actionConstants' let background = null export function _setBackgroundConnection (backgroundConnection) {