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.
96 lines
2.2 KiB
96 lines
2.2 KiB
6 years ago
|
const clone = require('clone')
|
||
9 years ago
|
const extend = require('xtend')
|
||
7 years ago
|
const copyToClipboard = require('copy-to-clipboard')
|
||
9 years ago
|
|
||
|
//
|
||
|
// Sub-Reducers take in the complete state and return their sub-state
|
||
|
//
|
||
6 years ago
|
const reduceMetamask = require('./metamask/metamask')
|
||
|
const reduceApp = require('./app/app')
|
||
|
const reduceLocale = require('./locale/locale')
|
||
|
const reduceSend = require('./send/send.duck').default
|
||
|
import reduceConfirmTransaction from './confirm-transaction/confirm-transaction.duck'
|
||
|
import reduceGas from './gas/gas.duck'
|
||
9 years ago
|
|
||
9 years ago
|
window.METAMASK_CACHED_LOG_STATE = null
|
||
|
|
||
9 years ago
|
module.exports = rootReducer
|
||
|
|
||
9 years ago
|
function rootReducer (state, action) {
|
||
9 years ago
|
// clone
|
||
|
state = extend(state)
|
||
|
|
||
9 years ago
|
if (action.type === 'GLOBAL_FORCE_UPDATE') {
|
||
|
return action.value
|
||
|
}
|
||
|
|
||
9 years ago
|
//
|
||
|
// MetaMask
|
||
|
//
|
||
|
|
||
|
state.metamask = reduceMetamask(state, action)
|
||
|
|
||
|
//
|
||
|
// AppState
|
||
|
//
|
||
|
|
||
|
state.appState = reduceApp(state, action)
|
||
|
|
||
7 years ago
|
//
|
||
|
// LocaleMessages
|
||
|
//
|
||
|
|
||
|
state.localeMessages = reduceLocale(state, action)
|
||
|
|
||
7 years ago
|
//
|
||
|
// Send
|
||
|
//
|
||
|
|
||
|
state.send = reduceSend(state, action)
|
||
|
|
||
7 years ago
|
state.confirmTransaction = reduceConfirmTransaction(state, action)
|
||
|
|
||
6 years ago
|
state.gas = reduceGas(state, action)
|
||
6 years ago
|
|
||
9 years ago
|
window.METAMASK_CACHED_LOG_STATE = state
|
||
9 years ago
|
return state
|
||
|
}
|
||
9 years ago
|
|
||
6 years ago
|
window.getCleanAppState = function () {
|
||
|
const state = clone(window.METAMASK_CACHED_LOG_STATE)
|
||
|
// append additional information
|
||
|
state.version = global.platform.getVersion()
|
||
|
state.browser = window.navigator.userAgent
|
||
|
// ensure seedWords are not included
|
||
|
if (state.metamask) delete state.metamask.seedWords
|
||
|
if (state.appState.currentView) delete state.appState.currentView.seedWords
|
||
|
return state
|
||
|
}
|
||
|
|
||
7 years ago
|
window.logStateString = function (cb) {
|
||
6 years ago
|
const state = window.getCleanAppState()
|
||
|
global.platform.getPlatformInfo((err, platform) => {
|
||
|
if (err) return cb(err)
|
||
7 years ago
|
state.platform = platform
|
||
7 years ago
|
const stateString = JSON.stringify(state, removeSeedWords, 2)
|
||
6 years ago
|
cb(null, stateString)
|
||
7 years ago
|
})
|
||
9 years ago
|
}
|
||
8 years ago
|
|
||
7 years ago
|
window.logState = function (toClipboard) {
|
||
|
return window.logStateString((err, result) => {
|
||
|
if (err) {
|
||
|
console.error(err.message)
|
||
|
} else if (toClipboard) {
|
||
|
copyToClipboard(result)
|
||
|
console.log('State log copied')
|
||
|
} else {
|
||
|
console.log(result)
|
||
|
}
|
||
7 years ago
|
})
|
||
|
}
|
||
|
|
||
8 years ago
|
function removeSeedWords (key, value) {
|
||
|
return key === 'seedWords' ? undefined : value
|
||
|
}
|