Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

mantle-demo - frontend - Move the side effects from reducers. #73

Open
TdfGomes opened this issue Dec 5, 2018 · 0 comments
Open

mantle-demo - frontend - Move the side effects from reducers. #73

TdfGomes opened this issue Dec 5, 2018 · 0 comments
Labels
frontend Issues and features relating to frontend

Comments

@TdfGomes
Copy link

TdfGomes commented Dec 5, 2018

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.

@TdfGomes TdfGomes added enhancement frontend Issues and features relating to frontend labels Dec 5, 2018
@makevoid makevoid changed the title Move the side effects from reducers. launchpad-frontend - Move the side effects from reducers. Dec 7, 2018
@zube zube bot removed the enhancement label Jan 2, 2019
@makevoid makevoid changed the title launchpad-frontend - Move the side effects from reducers. mantle-demo - frontend - Move the side effects from reducers. Jan 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frontend Issues and features relating to frontend
Projects
None yet
Development

No branches or pull requests

1 participant