I have this function generator
function* importWall(action) {
const { mnemonic, password, num_addresses, address, navigation } = action;
const network = yield select(getSelectedNetwork);
const importedWallet = yield call(
importAccount,
mnemonic,
password,
num_addresses,
network.name
);
const newAccount = {
name: 'Account 1',
password: action.password,
nonce: 0,
id: 0,
address: importedWallet,
mnemonic: action.mnemonic,
};
yield put(setUser(newAccount));
yield addWallet({
...newAccount,
active: true,
});
yield put(getWalletBalance(newAccount, network));
if (address === undefined) {
yield takeLatest(actionTypes.IMPORT_WALLET, importWall);
console.log('w');
} else {
navigation.navigate('Main');
}
}
Everything is working fine except my conditional statement,I tried several ways but I'm unable to call this generator once again if address is undefined. Any suggestions on how to achieve it please?
Your takeLatest should not be inside the effect handler 'importWall'
function* runSagas () {
yield takeLatest(actionTypes.IMPORT_WALLET, importWall);
}
Take latest is a fork effect that starts an action channel for type 'IMPORT_WALLET' and will run importWall to handle those actions. You don't need to re (take-latest) from within the effect handler.
If what you need is a retry mechanism. Then simply re-fire the original action.
if (address === undefined) {
yield put(action);
}