1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/app/reducers/metamask.js
Dan Finlay d8bee4f599 Make default providers more easiliy configurable for metamask devs
No longer do our `mainnet` and `testnet` buttons set specific RPC urls. Now they set `provider.type`, which gets interpreted with code.

Currently the provider types of `mainnet` and `testnet` point to our new scalable backends, but these could be re-interpreted to use any other provider, be it etherscan, peer to peer, or otherwise.

Makes it easier for us to upgrade our infrastructure without incorporating migration logic into the program.
2016-05-10 15:37:13 -07:00

90 lines
1.9 KiB
JavaScript

const extend = require('xtend')
const actions = require('../actions')
module.exports = reduceMetamask
function reduceMetamask(state, action) {
// clone + defaults
var metamaskState = extend({
isInitialized: false,
isUnlocked: false,
currentDomain: 'example.com',
rpcTarget: 'https://rawtestrpc.metamask.io/',
identities: {},
unconfTxs: {},
}, state.metamask)
switch (action.type) {
case actions.SHOW_ACCOUNTS_PAGE:
var state = extend(metamaskState)
delete state.seedWords
return state
case actions.UPDATE_METAMASK_STATE:
return extend(metamaskState, action.value)
case actions.UNLOCK_METAMASK:
return extend(metamaskState, {
isUnlocked: true,
isInitialized: true,
})
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)
var newState = extend(metamaskState, {
unconfTxs: {},
unconfMsgs: {},
})
for (var id in metamaskState.unconfTxs) {
if (id !== stringId) {
newState.unconfTxs[id] = metamaskState.unconfTxs[id]
}
}
for (var id in metamaskState.unconfMsgs) {
if (id !== stringId) {
newState.unconfMsgs[id] = metamaskState.unconfMsgs[id]
}
}
return newState
case actions.CLEAR_SEED_WORD_CACHE:
var newState = extend(metamaskState, {
isInitialized: true,
})
delete newState.seedWords
return newState
case actions.CREATE_NEW_VAULT_IN_PROGRESS:
return extend(metamaskState, {
isUnlocked: true,
isInitialized: true,
})
default:
return metamaskState
}
}