mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 17:33:23 +01:00
ui - reducer - app - code cleanup
This commit is contained in:
parent
bd704b1d7e
commit
0ef679388a
@ -11,12 +11,12 @@ function reduceApp (state, action) {
|
|||||||
log.debug('App Reducer got ' + action.type)
|
log.debug('App Reducer got ' + action.type)
|
||||||
// clone and defaults
|
// clone and defaults
|
||||||
const selectedAddress = state.metamask.selectedAddress
|
const selectedAddress = state.metamask.selectedAddress
|
||||||
let pendingTxs = hasPendingTxs(state)
|
const hasUnconfActions = checkUnconfActions(state)
|
||||||
let name = 'accounts'
|
let name = 'accounts'
|
||||||
if (selectedAddress) {
|
if (selectedAddress) {
|
||||||
name = 'accountDetail'
|
name = 'accountDetail'
|
||||||
}
|
}
|
||||||
if (pendingTxs) {
|
if (hasUnconfActions) {
|
||||||
log.debug('pending txs detected, defaulting to conf-tx view.')
|
log.debug('pending txs detected, defaulting to conf-tx view.')
|
||||||
name = 'confTx'
|
name = 'confTx'
|
||||||
}
|
}
|
||||||
@ -304,7 +304,7 @@ function reduceApp (state, action) {
|
|||||||
case actions.SHOW_CONF_MSG_PAGE:
|
case actions.SHOW_CONF_MSG_PAGE:
|
||||||
return extend(appState, {
|
return extend(appState, {
|
||||||
currentView: {
|
currentView: {
|
||||||
name: pendingTxs ? 'confTx' : 'account-detail',
|
name: hasUnconfActions ? 'confTx' : 'account-detail',
|
||||||
context: 0,
|
context: 0,
|
||||||
},
|
},
|
||||||
transForward: true,
|
transForward: true,
|
||||||
@ -314,15 +314,11 @@ function reduceApp (state, action) {
|
|||||||
|
|
||||||
case actions.COMPLETED_TX:
|
case actions.COMPLETED_TX:
|
||||||
log.debug('reducing COMPLETED_TX for tx ' + action.value)
|
log.debug('reducing COMPLETED_TX for tx ' + action.value)
|
||||||
var { unapprovedTxs, unapprovedMsgs,
|
const otherUnconfActions = getUnconfActionList(state)
|
||||||
unapprovedPersonalMsgs, network } = state.metamask
|
|
||||||
|
|
||||||
var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network)
|
|
||||||
.filter(tx => tx.id !== action.value )
|
.filter(tx => tx.id !== action.value )
|
||||||
|
const hasOtherUnconfActions = otherUnconfActions.length > 0
|
||||||
|
|
||||||
pendingTxs = unconfTxList.length > 0
|
if (hasOtherUnconfActions) {
|
||||||
|
|
||||||
if (pendingTxs) {
|
|
||||||
log.debug('reducer detected txs - rendering confTx view')
|
log.debug('reducer detected txs - rendering confTx view')
|
||||||
return extend(appState, {
|
return extend(appState, {
|
||||||
transForward: false,
|
transForward: false,
|
||||||
@ -582,26 +578,23 @@ function reduceApp (state, action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasPendingTxs (state) {
|
function checkUnconfActions (state) {
|
||||||
var { unapprovedTxs, unapprovedMsgs,
|
const unconfActionList = getUnconfActionList(state)
|
||||||
|
const hasUnconfActions = unconfActionList.length > 0
|
||||||
|
return hasUnconfActions
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUnconfActionList (state) {
|
||||||
|
const { unapprovedTxs, unapprovedMsgs,
|
||||||
unapprovedPersonalMsgs, network } = state.metamask
|
unapprovedPersonalMsgs, network } = state.metamask
|
||||||
|
|
||||||
var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network)
|
const unconfActionList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network)
|
||||||
var has = unconfTxList.length > 0
|
return unconfActionList
|
||||||
return has
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function indexForPending (state, txId) {
|
function indexForPending (state, txId) {
|
||||||
var unapprovedTxs = state.metamask.unapprovedTxs
|
const unconfTxList = getUnconfActionList(state)
|
||||||
var unapprovedMsgs = state.metamask.unapprovedMsgs
|
const match = unconfTxList.find((tx) => tx.id === txId)
|
||||||
var unapprovedPersonalMsgs = state.metamask.unapprovedPersonalMsgs
|
const index = unconfTxList.indexOf(match)
|
||||||
var network = state.metamask.network
|
return index
|
||||||
var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network)
|
|
||||||
let idx
|
|
||||||
unconfTxList.forEach((tx, i) => {
|
|
||||||
if (tx.id === txId) {
|
|
||||||
idx = i
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return idx
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user