From 0a0f87439e9247ae800b444a903b4d7ced90893f Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Thu, 18 May 2023 11:08:34 +0100 Subject: [PATCH] fix: handle ledger errors in client errors --- packages/shared/lib/core/error/handlers/handleError.ts | 2 +- .../lib/core/error/handlers/walletRs/handleWalletRsError.ts | 4 ++-- .../handlers/walletRs/subhandlers/handleClientError.ts | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/shared/lib/core/error/handlers/handleError.ts b/packages/shared/lib/core/error/handlers/handleError.ts index 9f1d6d4b10e..f3a4e1c3777 100644 --- a/packages/shared/lib/core/error/handlers/handleError.ts +++ b/packages/shared/lib/core/error/handlers/handleError.ts @@ -11,7 +11,7 @@ import { handleWalletRsError } from './walletRs' export function handleError(err: IError, resetConfirmationPropsOnDenial = true): void { const _activeProfile = get(activeProfile) if (Object.values(WalletRsError).includes(err?.type as WalletRsError)) { - handleWalletRsError(err) + handleWalletRsError(err, resetConfirmationPropsOnDenial) } else if (_activeProfile.type === ProfileType.Ledger) { handleLedgerError(err, resetConfirmationPropsOnDenial) } else { diff --git a/packages/shared/lib/core/error/handlers/walletRs/handleWalletRsError.ts b/packages/shared/lib/core/error/handlers/walletRs/handleWalletRsError.ts index d3ad38393f5..2ab303d0842 100644 --- a/packages/shared/lib/core/error/handlers/walletRs/handleWalletRsError.ts +++ b/packages/shared/lib/core/error/handlers/walletRs/handleWalletRsError.ts @@ -8,11 +8,11 @@ import { handleNoOutputsToConsolidateError, } from './subhandlers' -export function handleWalletRsError(error: IError): void { +export function handleWalletRsError(error: IError, resetConfirmationPropsOnDenial = true): void { if (error?.type) { switch (error.type) { case WalletRsError.Client.valueOf(): - handleClientError(error) + handleClientError(error, resetConfirmationPropsOnDenial) break case WalletRsError.InsufficientFunds.valueOf(): handleInsufficientFundsError(error) diff --git a/packages/shared/lib/core/error/handlers/walletRs/subhandlers/handleClientError.ts b/packages/shared/lib/core/error/handlers/walletRs/subhandlers/handleClientError.ts index 012e7e97a02..cd513a2f0ec 100644 --- a/packages/shared/lib/core/error/handlers/walletRs/subhandlers/handleClientError.ts +++ b/packages/shared/lib/core/error/handlers/walletRs/subhandlers/handleClientError.ts @@ -3,8 +3,9 @@ import { ClientError, WalletRsError } from '../../../enums' import { IError } from '../../../interfaces' import { logAndNotifyError } from '../../../actions' import { handleGenericError } from '../../handleGenericError' +import { LedgerError, handleLedgerError } from '@core/ledger' -export function handleClientError(error: IError): void { +export function handleClientError(error: IError, resetConfirmationPropsOnDenial = true): void { const errorMessage = error?.error let errorKey if (errorMessage) { @@ -18,6 +19,9 @@ export function handleClientError(error: IError): void { case CLIENT_ERROR_REGEXES[ClientError.InsufficientAmount].test(errorMessage): errorKey = ClientError.InsufficientAmount break + case Object.values(LedgerError).some((ledgerError) => errorMessage.includes(ledgerError)): + handleLedgerError(error, resetConfirmationPropsOnDenial) + return } if (errorKey) { const errorObject = WALLET_RS_ERROR_PARAMETERS?.[WalletRsError.Client]?.[errorKey]