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

133 lines
3.3 KiB

const extend = require('xtend')
const actions = require('../actions')
module.exports = reduceMetamask
9 years ago
function reduceMetamask (state, action) {
9 years ago
let newState
// clone + defaults
var metamaskState = extend({
isInitialized: false,
isUnlocked: false,
isEthConfirmed: false,
currentDomain: 'example.com',
rpcTarget: 'https://rawtestrpc.metamask.io/',
identities: {},
unconfTxs: {},
currentFiat: 'USD',
conversionRate: 0,
conversionDate: 'N/A',
}, state.metamask)
switch (action.type) {
9 years ago
case actions.SHOW_ACCOUNTS_PAGE:
9 years ago
newState = extend(metamaskState)
delete newState.seedWords
return newState
9 years ago
case actions.UPDATE_METAMASK_STATE:
return extend(metamaskState, action.value)
case actions.AGREE_TO_DISCLAIMER:
return extend(metamaskState, {
isConfirmed: true,
})
case actions.AGREE_TO_ETH_WARNING:
return extend(metamaskState, {
isEthConfirmed: !metamaskState.isEthConfirmed,
})
9 years ago
case actions.UNLOCK_METAMASK:
return extend(metamaskState, {
isUnlocked: true,
isInitialized: true,
selectedAccount: action.value,
})
case actions.LOCK_METAMASK:
return extend(metamaskState, {
isUnlocked: false,
})
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)
9 years ago
newState = extend(metamaskState, {
9 years ago
unconfTxs: {},
unconfMsgs: {},
})
9 years ago
for (const id in metamaskState.unconfTxs) {
9 years ago
if (id !== stringId) {
newState.unconfTxs[id] = metamaskState.unconfTxs[id]
}
}
9 years ago
for (const id in metamaskState.unconfMsgs) {
9 years ago
if (id !== stringId) {
newState.unconfMsgs[id] = metamaskState.unconfMsgs[id]
}
}
9 years ago
return newState
case actions.SHOW_NEW_VAULT_SEED:
return extend(metamaskState, {
isUnlocked: true,
isInitialized: false,
})
case actions.CLEAR_SEED_WORD_CACHE:
9 years ago
newState = extend(metamaskState, {
9 years ago
isUnlocked: true,
isInitialized: true,
selectedAccount: action.value,
})
delete newState.seedWords
return newState
case actions.SHOW_ACCOUNT_DETAIL:
9 years ago
newState = extend(metamaskState, {
9 years ago
isUnlocked: true,
isInitialized: true,
selectedAccount: action.value,
selectedAddress: action.value,
})
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, {
currentFiat: action.value.currentFiat,
conversionRate: action.value.conversionRate,
conversionDate: action.value.conversionDate,
})
9 years ago
default:
return metamaskState
}
}