diff --git a/lib/src/error.ts b/lib/src/error.ts index 1fe75e2..4dd6dfe 100644 --- a/lib/src/error.ts +++ b/lib/src/error.ts @@ -42,6 +42,12 @@ export class SignatureStepError extends ExchangeError { this.name = "SignatureStepError"; } } +export class IgnoredSignatureStepError extends ExchangeError { + constructor(nestedError?: Error) { + super("swap003Ignored", nestedError); + this.name = "SignatureStepError"; + } +} export class NotEnoughFunds extends ExchangeError { constructor() { diff --git a/lib/src/handleErrors.ts b/lib/src/handleErrors.ts index 5b0b35d..b3d6ad7 100644 --- a/lib/src/handleErrors.ts +++ b/lib/src/handleErrors.ts @@ -31,7 +31,7 @@ export function handleErrors(walletAPI: WalletAPIClient, error: any) { } // Log and throw to Ledger Live if not ignored - if (error instanceof ExchangeError && cause) { + if (error instanceof ExchangeError && cause && cause.swapCode !== "swap003Ignored") { walletAPI.custom.exchange.throwExchangeErrorToLedgerLive({ error }); } diff --git a/lib/src/sdk.test.ts b/lib/src/sdk.test.ts index c34cc22..35c2688 100644 --- a/lib/src/sdk.test.ts +++ b/lib/src/sdk.test.ts @@ -18,7 +18,7 @@ import { } from "./api"; import { ExchangeSDK, FeeStrategy } from "./sdk"; import { getCustomModule } from "./wallet-api"; -import { CompleteExchangeError, PayinExtraIdError, SignatureStepError } from "./error"; +import { CompleteExchangeError, IgnoredSignatureStepError, PayinExtraIdError, SignatureStepError } from "./error"; jest.mock("./api"); @@ -197,11 +197,11 @@ describe("swap", () => { }; mockCompleteSwap.mockRejectedValueOnce( - new SignatureStepError(new CompleteExchangeError("SIGN_COIN_TRANSACTION", "error message")) + new IgnoredSignatureStepError(new CompleteExchangeError("SIGN_COIN_TRANSACTION", "error message")) ); // WHEN - await expect(sdk.swap(swapData)).rejects.toThrow(SignatureStepError); + await expect(sdk.swap(swapData)).rejects.toThrow(IgnoredSignatureStepError); // THEN expect(cancelSwap as jest.Mock).toHaveBeenCalledWith({ diff --git a/lib/src/sdk.ts b/lib/src/sdk.ts index 2d3ddc3..1ad0f90 100644 --- a/lib/src/sdk.ts +++ b/lib/src/sdk.ts @@ -22,6 +22,7 @@ import { } from "./api"; import { CompleteExchangeError, + IgnoredSignatureStepError, NonceStepError, NotEnoughFunds, PayloadStepError, @@ -287,7 +288,7 @@ export class ExchangeSDK { throw error; } - const err = new SignatureStepError(error); + const err = new IgnoredSignatureStepError(error); this.handleError(err); throw err; });