This repository was archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
mantle-demo - frontend - Move the side effects from reducers. #73
Copy link
Copy link
Open
Labels
frontendIssues and features relating to frontendIssues and features relating to frontend
Description
Other thing I change in the project I worked using this base-app was in the auth reducer.
I move this :
case LOAD_MNEMONIC_SUCCESS:
localStorage.setItem(localStorage.keys.tempMnemonic, action.payload.mnemonic)and this :
case LOAD_MNEMONIC_PERSIST: {
const mnemonic = localStorage.getItem(localStorage.keys.tempMnemonic)
localStorage.removeItem(localStorage.keys.tempMnemonic)to the auth saga
so I wrap the saga like this:
export function* loadAccount(action) {
let mnemonic
if (action.payload === 'from_store') {
mnemonic = yield select(state => state.auth.mnemonic)
} else {
mnemonic = action.payload
}
if (mnemonic) {
try {
const authData = performLoadMnemonic(mnemonic)
yield put(loadAccountSuccess(authData))
if (action.payload !== 'from_store') {
yield call(
[ localStorage, 'setItem' ],
localStorage.keys.tempMnemonic, action.payload
)
} else {
yield call(
[ localStorage, 'setItem' ],
localStorage.keys.tempMnemonic, mnemonic
)
}
const mnemonicFromStorage = yield call(
[ localStorage, 'getItem' ],
localStorage.keys.tempMnemonic
)
yield call([ localStorage, 'removeItem' ], localStorage.keys.tempMnemonic)
yield put(loadAccountPersist(mnemonicFromStorage))
} catch (error) {
console.error(error)
yield put(loadAccountFail())
}
}
}I think it's better to have this localstorage calls inside the a saga.
I agree this saga could be improved but I think it's a start.
Metadata
Metadata
Assignees
Labels
frontendIssues and features relating to frontendIssues and features relating to frontend