A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/ui/app/ducks/metamask/metamask.js

423 lines
11 KiB

const extend = require('xtend')
const actions = require('../../store/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
9 years ago
function reduceMetamask (state, action) {
9 years ago
let newState
// clone + defaults
var metamaskState = extend({
isInitialized: false,
isUnlocked: false,
7 years ago
isAccountMenuOpen: false,
isPopup: getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP,
rpcTarget: 'https://rawtestrpc.metamask.io/',
identities: {},
unapprovedTxs: {},
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,
7 years ago
featureFlags: {},
networkEndpointType: OLD_UI_NETWORK_TYPE,
isRevealingSeedWords: false,
welcomeScreenSeen: false,
currentLocale: '',
preferences: {
useNativeCurrencyAsPrimaryCurrency: true,
showFiatInTestnets: false,
},
Metametrics (#6171) * Add metametrics provider and util. * Add backend api and state for participating in metametrics. * Add frontend action for participating in metametrics. * Add metametrics opt-in screen. * Add metametrics events to first time flow. * Add metametrics events for route changes * Add metametrics events for send and confirm screens * Add metametrics events to dropdowns, transactions, log in and out, settings, sig requests and main screen * Ensures each log in is measured as a new visit by metametrics. * Ensure metametrics is called with an empty string for dimensions params if specified * Adds opt in metametrics modal after unlock for existing users * Adds settings page toggle for opting in and out of MetaMetrics * Switch metametrics dimensions to page level scope * Lint, test and translation fixes for metametrics. * Update design for metametrics opt-in screen * Complete responsive styling of metametrics-opt-in modal * Use new chart image on metrics opt in screens * Incorporate the metametrics opt-in screen into the new onboarding flow * Update e2e tests to accomodate metametrics changes * Mock out metametrics network requests in integration tests * Fix tx-list integration test to support metametrics provider. * Send number of tokens and accounts data with every metametrics event. * Update metametrics event descriptor schema and add new events. * Fix import tos bug and send gas button bug due to metametrics changes. * Various small fixes on the metametrics branch. * Add origin custom variable type to metametrics.util * Fix names of onboarding complete actions (metametrics). * Fix names of Metrics Options actions (metametrics). * Clean up code related to metametrics. * Fix bad merge conflict resolution and improve promise handling in sendMetaMetrics event and confrim tx base * Don't send a second metrics event if user has gone back during first time flow. * Collect metametrics on going back from onboarding create/import. * Add missing custom variable constants for metametrics * Fix metametrics provider * Make height of opt-in modal responsive. * Adjust text content for opt-in modal. * Update metametrics event names and clean up code in opt-in-modal * Put phishing warning step next to last in onboarding flow * Link terms of service on create and import screens of first time flow * Add subtext to options on the onboarding select action screen. * Fix styling of bullet points on end of onboarding screen. * Combine phishing warning and congratulations screens. * Fix placement of users if unlocking after an incomplete onboarding import flow. * Fix capitalization in opt-in screen * Fix last onboarding screen translations * Add link to 'Learn More' on the last screen of onboarding * Code clean up: metametrics branch * Update e2e tests for phishing warning step removal * e2e tests passing on metametrics branch * Different tracking urls for metametrics on development and prod
6 years ago
firstTimeFlowType: null,
completedOnboarding: false,
knownMethodData: {},
Metametrics (#6171) * Add metametrics provider and util. * Add backend api and state for participating in metametrics. * Add frontend action for participating in metametrics. * Add metametrics opt-in screen. * Add metametrics events to first time flow. * Add metametrics events for route changes * Add metametrics events for send and confirm screens * Add metametrics events to dropdowns, transactions, log in and out, settings, sig requests and main screen * Ensures each log in is measured as a new visit by metametrics. * Ensure metametrics is called with an empty string for dimensions params if specified * Adds opt in metametrics modal after unlock for existing users * Adds settings page toggle for opting in and out of MetaMetrics * Switch metametrics dimensions to page level scope * Lint, test and translation fixes for metametrics. * Update design for metametrics opt-in screen * Complete responsive styling of metametrics-opt-in modal * Use new chart image on metrics opt in screens * Incorporate the metametrics opt-in screen into the new onboarding flow * Update e2e tests to accomodate metametrics changes * Mock out metametrics network requests in integration tests * Fix tx-list integration test to support metametrics provider. * Send number of tokens and accounts data with every metametrics event. * Update metametrics event descriptor schema and add new events. * Fix import tos bug and send gas button bug due to metametrics changes. * Various small fixes on the metametrics branch. * Add origin custom variable type to metametrics.util * Fix names of onboarding complete actions (metametrics). * Fix names of Metrics Options actions (metametrics). * Clean up code related to metametrics. * Fix bad merge conflict resolution and improve promise handling in sendMetaMetrics event and confrim tx base * Don't send a second metrics event if user has gone back during first time flow. * Collect metametrics on going back from onboarding create/import. * Add missing custom variable constants for metametrics * Fix metametrics provider * Make height of opt-in modal responsive. * Adjust text content for opt-in modal. * Update metametrics event names and clean up code in opt-in-modal * Put phishing warning step next to last in onboarding flow * Link terms of service on create and import screens of first time flow * Add subtext to options on the onboarding select action screen. * Fix styling of bullet points on end of onboarding screen. * Combine phishing warning and congratulations screens. * Fix placement of users if unlocking after an incomplete onboarding import flow. * Fix capitalization in opt-in screen * Fix last onboarding screen translations * Add link to 'Learn More' on the last screen of onboarding * Code clean up: metametrics branch * Update e2e tests for phishing warning step removal * e2e tests passing on metametrics branch * Different tracking urls for metametrics on development and prod
6 years ago
participateInMetaMetrics: null,
metaMetricsSendCount: 0,
}, state.metamask)
switch (action.type) {
9 years ago
case actions.SHOW_ACCOUNTS_PAGE:
newState = extend(metamaskState, {
isRevealingSeedWords: false,
})
9 years ago
delete newState.seedWords
return newState
9 years ago
case actions.UPDATE_METAMASK_STATE:
return extend(metamaskState, action.value)
case actions.UNLOCK_METAMASK:
return extend(metamaskState, {
isUnlocked: true,
isInitialized: true,
selectedAddress: action.value,
9 years ago
})
case actions.LOCK_METAMASK:
return extend(metamaskState, {
isUnlocked: false,
})
case actions.SET_RPC_LIST:
return extend(metamaskState, {
frequentRpcList: action.value,
})
9 years ago
case actions.SET_RPC_TARGET:
return extend(metamaskState, {
provider: {
type: 'rpc',
rpcTarget: action.value,
9 years ago
},
})
case actions.SET_PROVIDER_TYPE:
return extend(metamaskState, {
provider: {
type: action.value,
},
})
case actions.COMPLETED_TX:
var stringId = String(action.id)
9 years ago
newState = extend(metamaskState, {
unapprovedTxs: {},
unapprovedMsgs: {},
9 years ago
})
for (const id in metamaskState.unapprovedTxs) {
9 years ago
if (id !== stringId) {
newState.unapprovedTxs[id] = metamaskState.unapprovedTxs[id]
9 years ago
}
}
for (const id in metamaskState.unapprovedMsgs) {
9 years ago
if (id !== stringId) {
newState.unapprovedMsgs[id] = metamaskState.unapprovedMsgs[id]
9 years ago
}
}
9 years ago
return newState
case actions.EDIT_TX:
return extend(metamaskState, {
send: {
...metamaskState.send,
editingTransactionId: action.value,
},
})
9 years ago
case actions.SHOW_NEW_VAULT_SEED:
return extend(metamaskState, {
isRevealingSeedWords: true,
seedWords: action.value,
9 years ago
})
case actions.CLEAR_SEED_WORD_CACHE:
9 years ago
newState = extend(metamaskState, {
9 years ago
isUnlocked: true,
isInitialized: true,
selectedAddress: action.value,
9 years ago
})
delete newState.seedWords
return newState
case actions.SHOW_ACCOUNT_DETAIL:
9 years ago
newState = extend(metamaskState, {
9 years ago
isUnlocked: true,
isInitialized: true,
selectedAddress: action.value,
9 years ago
})
delete newState.seedWords
return newState
case actions.SET_SELECTED_TOKEN:
newState = extend(metamaskState, {
selectedTokenAddress: action.value,
})
const newSend = extend(metamaskState.send)
if (metamaskState.send.editingTransactionId && !action.value) {
delete newSend.token
const unapprovedTx = newState.unapprovedTxs[newSend.editingTransactionId] || {}
const txParams = unapprovedTx.txParams || {}
newState.unapprovedTxs = extend(newState.unapprovedTxs, {
[newSend.editingTransactionId]: extend(unapprovedTx, {
txParams: extend(txParams, { data: '' }),
}),
})
newSend.tokenBalance = null
newSend.balance = '0'
}
newState.send = newSend
return newState
case actions.SET_ACCOUNT_LABEL:
9 years ago
const account = action.value.account
const name = action.value.label
7 years ago
const id = {}
9 years ago
id[account] = extend(metamaskState.identities[account], { name })
7 years ago
const identities = extend(metamaskState.identities, id)
9 years ago
return extend(metamaskState, { identities })
case actions.SET_CURRENT_FIAT:
8 years ago
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,
},
})
7 years ago
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:
7 years ago
const { id: txId, value } = action
let { selectedAddressTxList } = metamaskState
selectedAddressTxList = selectedAddressTxList.map(tx => {
7 years ago
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,
})
Metametrics (#6171) * Add metametrics provider and util. * Add backend api and state for participating in metametrics. * Add frontend action for participating in metametrics. * Add metametrics opt-in screen. * Add metametrics events to first time flow. * Add metametrics events for route changes * Add metametrics events for send and confirm screens * Add metametrics events to dropdowns, transactions, log in and out, settings, sig requests and main screen * Ensures each log in is measured as a new visit by metametrics. * Ensure metametrics is called with an empty string for dimensions params if specified * Adds opt in metametrics modal after unlock for existing users * Adds settings page toggle for opting in and out of MetaMetrics * Switch metametrics dimensions to page level scope * Lint, test and translation fixes for metametrics. * Update design for metametrics opt-in screen * Complete responsive styling of metametrics-opt-in modal * Use new chart image on metrics opt in screens * Incorporate the metametrics opt-in screen into the new onboarding flow * Update e2e tests to accomodate metametrics changes * Mock out metametrics network requests in integration tests * Fix tx-list integration test to support metametrics provider. * Send number of tokens and accounts data with every metametrics event. * Update metametrics event descriptor schema and add new events. * Fix import tos bug and send gas button bug due to metametrics changes. * Various small fixes on the metametrics branch. * Add origin custom variable type to metametrics.util * Fix names of onboarding complete actions (metametrics). * Fix names of Metrics Options actions (metametrics). * Clean up code related to metametrics. * Fix bad merge conflict resolution and improve promise handling in sendMetaMetrics event and confrim tx base * Don't send a second metrics event if user has gone back during first time flow. * Collect metametrics on going back from onboarding create/import. * Add missing custom variable constants for metametrics * Fix metametrics provider * Make height of opt-in modal responsive. * Adjust text content for opt-in modal. * Update metametrics event names and clean up code in opt-in-modal * Put phishing warning step next to last in onboarding flow * Link terms of service on create and import screens of first time flow * Add subtext to options on the onboarding select action screen. * Fix styling of bullet points on end of onboarding screen. * Combine phishing warning and congratulations screens. * Fix placement of users if unlocking after an incomplete onboarding import flow. * Fix capitalization in opt-in screen * Fix last onboarding screen translations * Add link to 'Learn More' on the last screen of onboarding * Code clean up: metametrics branch * Update e2e tests for phishing warning step removal * e2e tests passing on metametrics branch * Different tracking urls for metametrics on development and prod
6 years ago
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,
})
7 years ago
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,
})
}
Metametrics (#6171) * Add metametrics provider and util. * Add backend api and state for participating in metametrics. * Add frontend action for participating in metametrics. * Add metametrics opt-in screen. * Add metametrics events to first time flow. * Add metametrics events for route changes * Add metametrics events for send and confirm screens * Add metametrics events to dropdowns, transactions, log in and out, settings, sig requests and main screen * Ensures each log in is measured as a new visit by metametrics. * Ensure metametrics is called with an empty string for dimensions params if specified * Adds opt in metametrics modal after unlock for existing users * Adds settings page toggle for opting in and out of MetaMetrics * Switch metametrics dimensions to page level scope * Lint, test and translation fixes for metametrics. * Update design for metametrics opt-in screen * Complete responsive styling of metametrics-opt-in modal * Use new chart image on metrics opt in screens * Incorporate the metametrics opt-in screen into the new onboarding flow * Update e2e tests to accomodate metametrics changes * Mock out metametrics network requests in integration tests * Fix tx-list integration test to support metametrics provider. * Send number of tokens and accounts data with every metametrics event. * Update metametrics event descriptor schema and add new events. * Fix import tos bug and send gas button bug due to metametrics changes. * Various small fixes on the metametrics branch. * Add origin custom variable type to metametrics.util * Fix names of onboarding complete actions (metametrics). * Fix names of Metrics Options actions (metametrics). * Clean up code related to metametrics. * Fix bad merge conflict resolution and improve promise handling in sendMetaMetrics event and confrim tx base * Don't send a second metrics event if user has gone back during first time flow. * Collect metametrics on going back from onboarding create/import. * Add missing custom variable constants for metametrics * Fix metametrics provider * Make height of opt-in modal responsive. * Adjust text content for opt-in modal. * Update metametrics event names and clean up code in opt-in-modal * Put phishing warning step next to last in onboarding flow * Link terms of service on create and import screens of first time flow * Add subtext to options on the onboarding select action screen. * Fix styling of bullet points on end of onboarding screen. * Combine phishing warning and congratulations screens. * Fix placement of users if unlocking after an incomplete onboarding import flow. * Fix capitalization in opt-in screen * Fix last onboarding screen translations * Add link to 'Learn More' on the last screen of onboarding * Code clean up: metametrics branch * Update e2e tests for phishing warning step removal * e2e tests passing on metametrics branch * Different tracking urls for metametrics on development and prod
6 years ago
case actions.SET_FIRST_TIME_FLOW_TYPE: {
return extend(metamaskState, {
firstTimeFlowType: action.value,
})
}
9 years ago
default:
return metamaskState
}
}