Refactor status transitions in walletsReducer (#2282)
This commit is contained in:
parent
980f6da613
commit
0e71a85cd6
@ -27,9 +27,7 @@ export default function reducer (state, action) {
|
|||||||
.sort((a, b) => a.name.localeCompare(b.name))
|
.sort((a, b) => a.name.localeCompare(b.name))
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
status: statusLocked(state.status)
|
status: transitionStatus(action, state, wallets.length > 0 ? Status.HAS_WALLETS : Status.NO_WALLETS),
|
||||||
? state.status
|
|
||||||
: walletStatus(wallets),
|
|
||||||
wallets,
|
wallets,
|
||||||
templates
|
templates
|
||||||
}
|
}
|
||||||
@ -43,31 +41,32 @@ export default function reducer (state, action) {
|
|||||||
case WRONG_KEY:
|
case WRONG_KEY:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
status: Status.PASSPHRASE_REQUIRED
|
status: transitionStatus(action, state, Status.PASSPHRASE_REQUIRED)
|
||||||
}
|
}
|
||||||
case KEY_MATCH:
|
case KEY_MATCH:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
status: state.status === Status.LOADING_WALLETS
|
status: transitionStatus(action, state, state.wallets.length > 0 ? Status.HAS_WALLETS : Status.NO_WALLETS)
|
||||||
? state.status
|
|
||||||
: walletStatus(state.wallets)
|
|
||||||
}
|
}
|
||||||
case NO_KEY:
|
case NO_KEY:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
status: Status.WALLETS_UNAVAILABLE
|
status: transitionStatus(action, state, Status.WALLETS_UNAVAILABLE)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function statusLocked (status) {
|
function transitionStatus ({ type }, { status: from }, to) {
|
||||||
return [Status.PASSPHRASE_REQUIRED, Status.WALLETS_UNAVAILABLE].includes(status)
|
switch (type) {
|
||||||
}
|
case SET_WALLETS: {
|
||||||
|
return [Status.PASSPHRASE_REQUIRED, Status.WALLETS_UNAVAILABLE].includes(from) ? from : to
|
||||||
function walletStatus (wallets) {
|
}
|
||||||
return wallets.length > 0
|
case KEY_MATCH: {
|
||||||
? Status.HAS_WALLETS
|
return from === Status.LOADING_WALLETS ? from : to
|
||||||
: Status.NO_WALLETS
|
}
|
||||||
|
default:
|
||||||
|
return to
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user