aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-04-01 03:38:20 +0800
committerkumavis <aaron@kumavis.me>2017-04-01 03:38:20 +0800
commit0ef679388a9604c39a432408826c080d2d17c221 (patch)
treeffbb4da0160dcefab31fd85d097c3fedc5523e2f /ui
parentbd704b1d7e7208fe1989bd7dde6ab81cb39bbfcc (diff)
downloadtangerine-wallet-browser-0ef679388a9604c39a432408826c080d2d17c221.tar
tangerine-wallet-browser-0ef679388a9604c39a432408826c080d2d17c221.tar.gz
tangerine-wallet-browser-0ef679388a9604c39a432408826c080d2d17c221.tar.bz2
tangerine-wallet-browser-0ef679388a9604c39a432408826c080d2d17c221.tar.lz
tangerine-wallet-browser-0ef679388a9604c39a432408826c080d2d17c221.tar.xz
tangerine-wallet-browser-0ef679388a9604c39a432408826c080d2d17c221.tar.zst
tangerine-wallet-browser-0ef679388a9604c39a432408826c080d2d17c221.zip
ui - reducer - app - code cleanup
Diffstat (limited to 'ui')
-rw-r--r--ui/app/reducers/app.js47
1 files changed, 20 insertions, 27 deletions
diff --git a/ui/app/reducers/app.js b/ui/app/reducers/app.js
index 7595c60b3..e0c001546 100644
--- a/ui/app/reducers/app.js
+++ b/ui/app/reducers/app.js
@@ -11,12 +11,12 @@ function reduceApp (state, action) {
log.debug('App Reducer got ' + action.type)
// clone and defaults
const selectedAddress = state.metamask.selectedAddress
- let pendingTxs = hasPendingTxs(state)
+ const hasUnconfActions = checkUnconfActions(state)
let name = 'accounts'
if (selectedAddress) {
name = 'accountDetail'
}
- if (pendingTxs) {
+ if (hasUnconfActions) {
log.debug('pending txs detected, defaulting to conf-tx view.')
name = 'confTx'
}
@@ -304,7 +304,7 @@ function reduceApp (state, action) {
case actions.SHOW_CONF_MSG_PAGE:
return extend(appState, {
currentView: {
- name: pendingTxs ? 'confTx' : 'account-detail',
+ name: hasUnconfActions ? 'confTx' : 'account-detail',
context: 0,
},
transForward: true,
@@ -314,15 +314,11 @@ function reduceApp (state, action) {
case actions.COMPLETED_TX:
log.debug('reducing COMPLETED_TX for tx ' + action.value)
- var { unapprovedTxs, unapprovedMsgs,
- unapprovedPersonalMsgs, network } = state.metamask
-
- var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network)
+ const otherUnconfActions = getUnconfActionList(state)
.filter(tx => tx.id !== action.value )
+ const hasOtherUnconfActions = otherUnconfActions.length > 0
- pendingTxs = unconfTxList.length > 0
-
- if (pendingTxs) {
+ if (hasOtherUnconfActions) {
log.debug('reducer detected txs - rendering confTx view')
return extend(appState, {
transForward: false,
@@ -582,26 +578,23 @@ function reduceApp (state, action) {
}
}
-function hasPendingTxs (state) {
- var { unapprovedTxs, unapprovedMsgs,
+function checkUnconfActions (state) {
+ const unconfActionList = getUnconfActionList(state)
+ const hasUnconfActions = unconfActionList.length > 0
+ return hasUnconfActions
+}
+
+function getUnconfActionList (state) {
+ const { unapprovedTxs, unapprovedMsgs,
unapprovedPersonalMsgs, network } = state.metamask
- var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network)
- var has = unconfTxList.length > 0
- return has
+ const unconfActionList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network)
+ return unconfActionList
}
function indexForPending (state, txId) {
- var unapprovedTxs = state.metamask.unapprovedTxs
- var unapprovedMsgs = state.metamask.unapprovedMsgs
- var unapprovedPersonalMsgs = state.metamask.unapprovedPersonalMsgs
- var network = state.metamask.network
- var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network)
- let idx
- unconfTxList.forEach((tx, i) => {
- if (tx.id === txId) {
- idx = i
- }
- })
- return idx
+ const unconfTxList = getUnconfActionList(state)
+ const match = unconfTxList.find((tx) => tx.id === txId)
+ const index = unconfTxList.indexOf(match)
+ return index
}