mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 10:30:04 +01:00
e6c4d63ccd
Calls to `eth.sign` are now transiently persisted in memory, and displayed in a chronological stack with pending transactions (which are still persisted to disk). This allows the user a method to sign/cancel transactions even if they miss the Chrome notification. Improved a lot of the view routing, to avoid cases where routes would show an empty account view, or transition to the accounts list when it shouldn't. Broke the transaction approval view into a couple components so messages and transactions could have their own templates.
80 lines
1.7 KiB
JavaScript
80 lines
1.7 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, {
|
|
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
|
|
|
|
}
|
|
}
|