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/reducers/metamask.js

138 lines
3.4 KiB

const extend = require('xtend')
const actions = require('../actions')
module.exports = reduceMetamask
8 years ago
function reduceMetamask (state, action) {
8 years ago
let newState
// clone + defaults
var metamaskState = extend({
isInitialized: false,
isUnlocked: false,
rpcTarget: 'https://rawtestrpc.metamask.io/',
identities: {},
unapprovedTxs: {},
noActiveNotices: true,
lastUnreadNotice: undefined,
frequentRpcList: [],
addressBook: [],
}, state.metamask)
switch (action.type) {
8 years ago
case actions.SHOW_ACCOUNTS_PAGE:
8 years ago
newState = extend(metamaskState)
delete newState.seedWords
return newState
8 years ago
case actions.SHOW_NOTICE:
return extend(metamaskState, {
noActiveNotices: false,
lastUnreadNotice: action.value,
})
case actions.CLEAR_NOTICES:
return extend(metamaskState, {
noActiveNotices: true,
})
8 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,
8 years ago
})
case actions.LOCK_METAMASK:
return extend(metamaskState, {
isUnlocked: false,
})
case actions.SET_RPC_LIST:
return extend(metamaskState, {
frequentRpcList: action.value,
})
8 years ago
case actions.SET_RPC_TARGET:
return extend(metamaskState, {
provider: {
type: 'rpc',
rpcTarget: action.value,
8 years ago
},
})
case actions.SET_PROVIDER_TYPE:
return extend(metamaskState, {
provider: {
type: action.value,
},
})
case actions.COMPLETED_TX:
var stringId = String(action.id)
8 years ago
newState = extend(metamaskState, {
unapprovedTxs: {},
unapprovedMsgs: {},
8 years ago
})
for (const id in metamaskState.unapprovedTxs) {
8 years ago
if (id !== stringId) {
newState.unapprovedTxs[id] = metamaskState.unapprovedTxs[id]
8 years ago
}
}
for (const id in metamaskState.unapprovedMsgs) {
8 years ago
if (id !== stringId) {
newState.unapprovedMsgs[id] = metamaskState.unapprovedMsgs[id]
8 years ago
}
}
8 years ago
return newState
case actions.SHOW_NEW_VAULT_SEED:
return extend(metamaskState, {
isUnlocked: true,
isInitialized: false,
seedWords: action.value,
8 years ago
})
case actions.CLEAR_SEED_WORD_CACHE:
8 years ago
newState = extend(metamaskState, {
8 years ago
isUnlocked: true,
isInitialized: true,
selectedAddress: action.value,
8 years ago
})
delete newState.seedWords
return newState
case actions.SHOW_ACCOUNT_DETAIL:
8 years ago
newState = extend(metamaskState, {
8 years ago
isUnlocked: true,
isInitialized: true,
selectedAddress: action.value,
8 years ago
})
delete newState.seedWords
return newState
case actions.SAVE_ACCOUNT_LABEL:
const account = action.value.account
const name = action.value.label
var id = {}
id[account] = extend(metamaskState.identities[account], { name })
var identities = extend(metamaskState.identities, id)
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,
})
8 years ago
default:
return metamaskState
}
}