1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
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, {
rpcTarget: 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
}
}
|