aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/reducers/metamask.js
diff options
context:
space:
mode:
authorChi Kei Chan <chikeichan@gmail.com>2019-03-22 07:03:30 +0800
committerDan J Miller <danjm.com@gmail.com>2019-03-22 07:03:30 +0800
commit31175625b446cb5d18b17db23018bca8b14d280c (patch)
treef54e159883deef003fb281267025edf796eb8004 /ui/app/reducers/metamask.js
parent7287133e15fab22299e07704206e85bc855d1064 (diff)
downloadtangerine-wallet-browser-31175625b446cb5d18b17db23018bca8b14d280c.tar
tangerine-wallet-browser-31175625b446cb5d18b17db23018bca8b14d280c.tar.gz
tangerine-wallet-browser-31175625b446cb5d18b17db23018bca8b14d280c.tar.bz2
tangerine-wallet-browser-31175625b446cb5d18b17db23018bca8b14d280c.tar.lz
tangerine-wallet-browser-31175625b446cb5d18b17db23018bca8b14d280c.tar.xz
tangerine-wallet-browser-31175625b446cb5d18b17db23018bca8b14d280c.tar.zst
tangerine-wallet-browser-31175625b446cb5d18b17db23018bca8b14d280c.zip
Folder restructure (#6304)
* Remove ui/app/keychains/ * Remove ui/app/img/ (unused images) * Move conversion-util to helpers/utils/ * Move token-util to helpers/utils/ * Move /helpers/*.js inside /helpers/utils/ * Move util tests inside /helpers/utils/ * Renameand move confirm-transaction/util.js to helpers/utils/ * Move higher-order-components to helpers/higher-order-components/ * Move infura-conversion.json to helpers/constants/ * Move all utility functions to helpers/utils/ * Move pages directory to top-level * Move all constants to helpers/constants/ * Move metametrics inside helpers/ * Move app and root inside pages/ * Move routes inside helpers/ * Re-organize ducks/ * Move reducers to ducks/ * Move selectors inside selectors/ * Move test out of test folder * Move action, reducer, store inside store/ * Move ui components inside ui/ * Move UI components inside ui/ * Move connected components inside components/app/ * Move i18n-helper inside helpers/ * Fix unit tests * Fix unit test * Move pages components * Rename routes component * Move reducers to ducks/index * Fix bad path in unit test
Diffstat (limited to 'ui/app/reducers/metamask.js')
-rw-r--r--ui/app/reducers/metamask.js419
1 files changed, 0 insertions, 419 deletions
diff --git a/ui/app/reducers/metamask.js b/ui/app/reducers/metamask.js
deleted file mode 100644
index d4b920748..000000000
--- a/ui/app/reducers/metamask.js
+++ /dev/null
@@ -1,419 +0,0 @@
-const extend = require('xtend')
-const actions = require('../actions')
-const { getEnvironmentType } = require('../../../app/scripts/lib/util')
-const { ENVIRONMENT_TYPE_POPUP } = require('../../../app/scripts/lib/enums')
-const { OLD_UI_NETWORK_TYPE } = require('../../../app/scripts/controllers/network/enums')
-
-module.exports = reduceMetamask
-
-function reduceMetamask (state, action) {
- let newState
-
- // clone + defaults
- var metamaskState = extend({
- isInitialized: false,
- isUnlocked: false,
- isAccountMenuOpen: false,
- isPopup: getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP,
- rpcTarget: 'https://rawtestrpc.metamask.io/',
- identities: {},
- unapprovedTxs: {},
- noActiveNotices: true,
- nextUnreadNotice: undefined,
- frequentRpcList: [],
- addressBook: [],
- selectedTokenAddress: null,
- contractExchangeRates: {},
- tokenExchangeRates: {},
- tokens: [],
- pendingTokens: {},
- send: {
- gasLimit: null,
- gasPrice: null,
- gasTotal: null,
- tokenBalance: '0x0',
- from: '',
- to: '',
- amount: '0',
- memo: '',
- errors: {},
- maxModeOn: false,
- editingTransactionId: null,
- forceGasMin: null,
- toNickname: '',
- },
- coinOptions: {},
- useBlockie: false,
- featureFlags: {},
- networkEndpointType: OLD_UI_NETWORK_TYPE,
- isRevealingSeedWords: false,
- welcomeScreenSeen: false,
- currentLocale: '',
- preferences: {
- useNativeCurrencyAsPrimaryCurrency: true,
- showFiatInTestnets: false,
- },
- firstTimeFlowType: null,
- completedOnboarding: false,
- knownMethodData: {},
- participateInMetaMetrics: null,
- metaMetricsSendCount: 0,
- }, state.metamask)
-
- switch (action.type) {
-
- case actions.SHOW_ACCOUNTS_PAGE:
- newState = extend(metamaskState, {
- isRevealingSeedWords: false,
- })
- delete newState.seedWords
- return newState
-
- case actions.SHOW_NOTICE:
- return extend(metamaskState, {
- noActiveNotices: false,
- nextUnreadNotice: action.value,
- })
-
- case actions.CLEAR_NOTICES:
- return extend(metamaskState, {
- noActiveNotices: true,
- nextUnreadNotice: undefined,
- })
-
- case actions.UPDATE_METAMASK_STATE:
- return extend(metamaskState, action.value)
-
- case actions.UNLOCK_METAMASK:
- return extend(metamaskState, {
- isUnlocked: true,
- isInitialized: true,
- selectedAddress: action.value,
- })
-
- case actions.LOCK_METAMASK:
- return extend(metamaskState, {
- isUnlocked: false,
- })
-
- case actions.SET_RPC_LIST:
- return extend(metamaskState, {
- frequentRpcList: action.value,
- })
-
- case actions.SET_RPC_TARGET:
- return extend(metamaskState, {
- provider: {
- type: 'rpc',
- rpcTarget: action.value,
- },
- })
-
- case actions.SET_PROVIDER_TYPE:
- return extend(metamaskState, {
- provider: {
- type: action.value,
- },
- })
-
- case actions.COMPLETED_TX:
- var stringId = String(action.id)
- newState = extend(metamaskState, {
- unapprovedTxs: {},
- unapprovedMsgs: {},
- })
- for (const id in metamaskState.unapprovedTxs) {
- if (id !== stringId) {
- newState.unapprovedTxs[id] = metamaskState.unapprovedTxs[id]
- }
- }
- for (const id in metamaskState.unapprovedMsgs) {
- if (id !== stringId) {
- newState.unapprovedMsgs[id] = metamaskState.unapprovedMsgs[id]
- }
- }
- return newState
-
- case actions.EDIT_TX:
- return extend(metamaskState, {
- send: {
- ...metamaskState.send,
- editingTransactionId: action.value,
- },
- })
-
-
- case actions.SHOW_NEW_VAULT_SEED:
- return extend(metamaskState, {
- isRevealingSeedWords: true,
- seedWords: action.value,
- })
-
- case actions.CLEAR_SEED_WORD_CACHE:
- newState = extend(metamaskState, {
- isUnlocked: true,
- isInitialized: true,
- selectedAddress: action.value,
- })
- delete newState.seedWords
- return newState
-
- case actions.SHOW_ACCOUNT_DETAIL:
- newState = extend(metamaskState, {
- isUnlocked: true,
- isInitialized: true,
- selectedAddress: action.value,
- })
- delete newState.seedWords
- return newState
-
- case actions.SET_SELECTED_TOKEN:
- return extend(metamaskState, {
- selectedTokenAddress: action.value,
- })
-
- case actions.SET_ACCOUNT_LABEL:
- const account = action.value.account
- const name = action.value.label
- const id = {}
- id[account] = extend(metamaskState.identities[account], { name })
- const identities = extend(metamaskState.identities, id)
- return extend(metamaskState, { identities })
-
- case actions.SET_CURRENT_FIAT:
- return extend(metamaskState, {
- currentCurrency: action.value.currentCurrency,
- conversionRate: action.value.conversionRate,
- conversionDate: action.value.conversionDate,
- })
-
- case actions.UPDATE_TOKENS:
- return extend(metamaskState, {
- tokens: action.newTokens,
- })
-
- // metamask.send
- case actions.UPDATE_GAS_LIMIT:
- return extend(metamaskState, {
- send: {
- ...metamaskState.send,
- gasLimit: action.value,
- },
- })
-
- case actions.UPDATE_GAS_PRICE:
- return extend(metamaskState, {
- send: {
- ...metamaskState.send,
- gasPrice: action.value,
- },
- })
-
- case actions.TOGGLE_ACCOUNT_MENU:
- return extend(metamaskState, {
- isAccountMenuOpen: !metamaskState.isAccountMenuOpen,
- })
-
- case actions.UPDATE_GAS_TOTAL:
- return extend(metamaskState, {
- send: {
- ...metamaskState.send,
- gasTotal: action.value,
- },
- })
-
- case actions.UPDATE_SEND_TOKEN_BALANCE:
- return extend(metamaskState, {
- send: {
- ...metamaskState.send,
- tokenBalance: action.value,
- },
- })
-
- case actions.UPDATE_SEND_HEX_DATA:
- return extend(metamaskState, {
- send: {
- ...metamaskState.send,
- data: action.value,
- },
- })
-
- case actions.UPDATE_SEND_FROM:
- return extend(metamaskState, {
- send: {
- ...metamaskState.send,
- from: action.value,
- },
- })
-
- case actions.UPDATE_SEND_TO:
- return extend(metamaskState, {
- send: {
- ...metamaskState.send,
- to: action.value.to,
- toNickname: action.value.nickname,
- },
- })
-
- case actions.UPDATE_SEND_AMOUNT:
- return extend(metamaskState, {
- send: {
- ...metamaskState.send,
- amount: action.value,
- },
- })
-
- case actions.UPDATE_SEND_MEMO:
- return extend(metamaskState, {
- send: {
- ...metamaskState.send,
- memo: action.value,
- },
- })
-
- case actions.UPDATE_MAX_MODE:
- return extend(metamaskState, {
- send: {
- ...metamaskState.send,
- maxModeOn: action.value,
- },
- })
-
- case actions.UPDATE_SEND:
- return extend(metamaskState, {
- send: {
- ...metamaskState.send,
- ...action.value,
- },
- })
-
- case actions.CLEAR_SEND:
- return extend(metamaskState, {
- send: {
- gasLimit: null,
- gasPrice: null,
- gasTotal: null,
- tokenBalance: null,
- from: '',
- to: '',
- amount: '0x0',
- memo: '',
- errors: {},
- maxModeOn: false,
- editingTransactionId: null,
- forceGasMin: null,
- toNickname: '',
- },
- })
-
- case actions.UPDATE_TRANSACTION_PARAMS:
- const { id: txId, value } = action
- let { selectedAddressTxList } = metamaskState
- selectedAddressTxList = selectedAddressTxList.map(tx => {
- if (tx.id === txId) {
- tx.txParams = value
- }
- return tx
- })
-
- return extend(metamaskState, {
- selectedAddressTxList,
- })
-
- case actions.PAIR_UPDATE:
- const { value: { marketinfo: pairMarketInfo } } = action
- return extend(metamaskState, {
- tokenExchangeRates: {
- ...metamaskState.tokenExchangeRates,
- [pairMarketInfo.pair]: pairMarketInfo,
- },
- })
-
- case actions.SHAPESHIFT_SUBVIEW:
- const { value: { marketinfo: ssMarketInfo, coinOptions } } = action
- return extend(metamaskState, {
- tokenExchangeRates: {
- ...metamaskState.tokenExchangeRates,
- [ssMarketInfo.pair]: ssMarketInfo,
- },
- coinOptions,
- })
-
- case actions.SET_PARTICIPATE_IN_METAMETRICS:
- return extend(metamaskState, {
- participateInMetaMetrics: action.value,
- })
-
- case actions.SET_METAMETRICS_SEND_COUNT:
- return extend(metamaskState, {
- metaMetricsSendCount: action.value,
- })
-
- case actions.SET_USE_BLOCKIE:
- return extend(metamaskState, {
- useBlockie: action.value,
- })
-
- case actions.UPDATE_FEATURE_FLAGS:
- return extend(metamaskState, {
- featureFlags: action.value,
- })
-
- case actions.UPDATE_NETWORK_ENDPOINT_TYPE:
- return extend(metamaskState, {
- networkEndpointType: action.value,
- })
-
- case actions.CLOSE_WELCOME_SCREEN:
- return extend(metamaskState, {
- welcomeScreenSeen: true,
- })
-
- case actions.SET_CURRENT_LOCALE:
- return extend(metamaskState, {
- currentLocale: action.value,
- })
-
- case actions.SET_PENDING_TOKENS:
- return extend(metamaskState, {
- pendingTokens: { ...action.payload },
- })
-
- case actions.CLEAR_PENDING_TOKENS: {
- return extend(metamaskState, {
- pendingTokens: {},
- })
- }
-
- case actions.UPDATE_PREFERENCES: {
- return extend(metamaskState, {
- preferences: {
- ...metamaskState.preferences,
- ...action.payload,
- },
- })
- }
-
- case actions.COMPLETE_ONBOARDING: {
- return extend(metamaskState, {
- completedOnboarding: true,
- })
- }
-
- case actions.COMPLETE_UI_MIGRATION: {
- return extend(metamaskState, {
- completedUiMigration: true,
- })
- }
-
- case actions.SET_FIRST_TIME_FLOW_TYPE: {
- return extend(metamaskState, {
- firstTimeFlowType: action.value,
- })
- }
-
- default:
- return metamaskState
-
- }
-}