Skip to content

Commit

Permalink
feat: wrap registerNanoContract effect on safeEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
alexruzenhack committed Sep 5, 2024
1 parent fc11ad5 commit e5c0a2a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/sagas/nanoContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
import { logger } from '../logger';
import { NANO_CONTRACT_TX_HISTORY_SIZE } from '../constants';
import { consumeGenerator, getNanoContractFeatureToggle } from '../utils';
import { getRegisteredNanoContracts } from './helpers';
import { getRegisteredNanoContracts, safeEffect } from './helpers';
import { isWalletServiceEnabled } from './wallet';

const log = logger('nano-contract-saga');
Expand Down Expand Up @@ -158,6 +158,16 @@ export function* registerNanoContract({ payload }) {
// emit action NANOCONTRACT_REGISTER_SUCCESS with feedback to user
yield put(nanoContractRegisterSuccess({ entryKey: ncId, entryValue: nc, hasFeedback: true }));
}
/**
* Effect invoked by safeEffect if an unexpected error occurs.
*
* @param {Object} error The error captured.
*/
function* registerNanoContractOnError(error) {
log.error('Unexpected error while registering Nano Contract.', error);
yield put(nanoContractRegisterFailure(failureMessage.blueprintInfoFailure));
yield put(onExceptionCaptured(new Error(failureMessage.nanoContractFailure), false));
}

/**
* @typedef {Object} RawNcTxHistory
Expand Down Expand Up @@ -440,7 +450,7 @@ export function* requestBlueprintInfo({ payload }) {
export function* saga() {
yield all([
debounce(500, [[types.START_WALLET_SUCCESS, types.NANOCONTRACT_INIT]], init),
takeEvery(types.NANOCONTRACT_REGISTER_REQUEST, registerNanoContract),
takeEvery(types.NANOCONTRACT_REGISTER_REQUEST, safeEffect(registerNanoContract, registerNanoContractOnError)),

Check failure on line 453 in src/sagas/nanoContract.js

View workflow job for this annotation

GitHub Actions / test (20.x)

This line has a length of 114. Maximum allowed is 100
takeEvery(types.NANOCONTRACT_HISTORY_REQUEST, requestHistoryNanoContract),
takeEvery(types.NANOCONTRACT_UNREGISTER_REQUEST, unregisterNanoContract),
takeEvery(types.NANOCONTRACT_ADDRESS_CHANGE_REQUEST, requestNanoContractAddressChange),
Expand Down

0 comments on commit e5c0a2a

Please sign in to comment.