From db1a3dee4ee9e75378fe1cbc6829a2987e049b87 Mon Sep 17 00:00:00 2001 From: lendihop Date: Sun, 20 Aug 2023 16:23:31 +0200 Subject: [PATCH] show default error for all failed youves requests --- src/store/savings/epics.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/store/savings/epics.ts b/src/store/savings/epics.ts index 6714136ad..a7287e777 100644 --- a/src/store/savings/epics.ts +++ b/src/store/savings/epics.ts @@ -6,7 +6,7 @@ import { ofType } from 'ts-action-operators'; import { getUserStake, getYouvesSavingsItems$ } from 'src/apis/youves'; import { UserStakeValueInterface } from 'src/interfaces/user-stake-value.interface'; -import { showErrorToastByError } from 'src/toast/error-toast.utils'; +import { showErrorToast } from 'src/toast/error-toast.utils'; import { isDefined } from 'src/utils/is-defined'; import { withSelectedAccount, withUsdToTokenRates } from 'src/utils/wallet.utils'; @@ -18,6 +18,8 @@ import { loadSingleSavingStakeActions } from './actions'; +const DEFAULT_ERROR_MESSAGE = { description: 'Something went wrong. Please try again later.' }; + const loadSingleSavingLastStake: Epic = (action$: Observable, state$: Observable) => action$.pipe( ofType(loadSingleSavingStakeActions.submit), @@ -26,7 +28,7 @@ const loadSingleSavingLastStake: Epic = (action$: Observable, state$: Ob from(getUserStake(selectedAccount, savingsItem.id, savingsItem.type)).pipe( map(stake => loadSingleSavingStakeActions.success({ stake, contractAddress: savingsItem.contractAddress })), catchError(err => { - showErrorToastByError(err, undefined, true); + showErrorToast(DEFAULT_ERROR_MESSAGE); return of( loadSingleSavingStakeActions.fail({ @@ -45,14 +47,17 @@ const loadAllSavingsItems: Epic = (action$: Observable, state$: Observab withUsdToTokenRates(state$), switchMap(([, rates]) => getYouvesSavingsItems$(rates)), map(savings => loadAllSavingsActions.success(savings)), - catchError(err => { - showErrorToastByError(err, undefined, true); + catchError(() => { + showErrorToast(DEFAULT_ERROR_MESSAGE); return of(loadAllSavingsActions.fail()); }) ); -const showStakeLoadError = debounce((e: unknown) => showErrorToastByError(e), 500, { leading: true, trailing: false }); +const showStakeLoadError = debounce(() => showErrorToast(DEFAULT_ERROR_MESSAGE), 500, { + leading: true, + trailing: false +}); const loadAllSavingsItemsAndStakes: Epic = (action$: Observable, state$: Observable) => action$.pipe( @@ -69,9 +74,9 @@ const loadAllSavingsItemsAndStakes: Epic = (action$: Observable, state$: savings.map(savingsItem => getUserStake(selectedAccount, savingsItem.id, savingsItem.type) .then((stake): [string, UserStakeValueInterface | undefined] => [savingsItem.contractAddress, stake]) - .catch(e => { + .catch(() => { console.error('Error while loading farm stakes: ', savingsItem.contractAddress); - showStakeLoadError(e); + showStakeLoadError(); return [savingsItem.contractAddress, undefined]; }) @@ -85,8 +90,8 @@ const loadAllSavingsItemsAndStakes: Epic = (action$: Observable, state$: mergeMap(stakes => merge(of(loadAllSavingsActions.success(savings)), of(loadAllStakesActions.success(stakes)))) ); }), - catchError(err => { - showErrorToastByError(err, undefined, true); + catchError(() => { + showErrorToast(DEFAULT_ERROR_MESSAGE); return of(loadAllSavingsActions.fail(), loadAllStakesActions.fail()); })