diff --git a/apps/desktop/src/components/SendFlow/utils.tsx b/apps/desktop/src/components/SendFlow/utils.tsx index 5cb1eff3b3..e14b2142f2 100644 --- a/apps/desktop/src/components/SendFlow/utils.tsx +++ b/apps/desktop/src/components/SendFlow/utils.tsx @@ -157,22 +157,17 @@ export const useSignPageHelpers = ( ).catch(() => setEstimationFailed(true)); const onSign = async (tezosToolkit: TezosToolkit) => - handleAsyncAction( - async () => { - const operation = await executeOperations( - { ...operations, estimates: form.watch("executeParams") }, - tezosToolkit - ); - if (mode === "batch") { - clearBatch(operations.sender); - } - await openWith(); - return operation; - }, - { - description: "Something went wrong, please try again.", + handleAsyncAction(async () => { + const operation = await executeOperations( + { ...operations, estimates: form.watch("executeParams") }, + tezosToolkit + ); + if (mode === "batch") { + clearBatch(operations.sender); } - ); + await openWith(); + return operation; + }); return { fee: totalFee(form.watch("executeParams")), diff --git a/apps/web/src/components/Menu/ErrorLogsMenu/ErrorLogsMenu.tsx b/apps/web/src/components/Menu/ErrorLogsMenu/ErrorLogsMenu.tsx index 9faf330c18..9bd816a3f8 100644 --- a/apps/web/src/components/Menu/ErrorLogsMenu/ErrorLogsMenu.tsx +++ b/apps/web/src/components/Menu/ErrorLogsMenu/ErrorLogsMenu.tsx @@ -58,9 +58,11 @@ export const ErrorLogsMenu = () => { {errorLog.timestamp} - - {errorLog.technicalDetails} - + {errorLog.technicalDetails && ( + + {errorLog.technicalDetails} + + )} diff --git a/apps/web/src/components/SendFlow/utils.tsx b/apps/web/src/components/SendFlow/utils.tsx index b277be4a1b..2b1c3e3a3c 100644 --- a/apps/web/src/components/SendFlow/utils.tsx +++ b/apps/web/src/components/SendFlow/utils.tsx @@ -123,18 +123,14 @@ export const useSignPageHelpers = ( ).catch(() => setEstimationFailed(true)); const onSign = async (tezosToolkit: TezosToolkit) => - handleAsyncAction( - async () => { - const operation = await executeOperations( - { ...operations, estimates: form.watch("executeParams") }, - tezosToolkit - ); - await openWith(); - return operation; - }, - // Here we should show a generic error message, keeping the original error for errors list - { description: "Something went wrong, please try again." } - ); + handleAsyncAction(async () => { + const operation = await executeOperations( + { ...operations, estimates: form.watch("executeParams") }, + tezosToolkit + ); + await openWith(); + return operation; + }); return { fee: totalFee(form.watch("executeParams")), diff --git a/packages/core/src/ErrorContext.test.ts b/packages/core/src/ErrorContext.test.ts index 95087996f6..c6ea72ec4c 100644 --- a/packages/core/src/ErrorContext.test.ts +++ b/packages/core/src/ErrorContext.test.ts @@ -1,12 +1,55 @@ import { getErrorContext } from "./ErrorContext"; +import { handleTezError } from "./estimate"; + +jest.mock("./estimate", () => ({ + handleTezError: jest.fn(), +})); describe("getErrorContext", () => { - it("should get error context", () => { - const { description, stacktrace } = getErrorContext({ + beforeEach(() => { + jest.clearAllMocks(); + }); + + it("should handle error object with message and stack", () => { + jest.mocked(handleTezError).mockReturnValue(undefined); + const error = { message: "some error message", stack: "some stacktrace", - }); - expect(description).toEqual("some error message"); - expect(stacktrace).toEqual("some stacktrace"); + }; + + const context = getErrorContext(error); + + expect(context.technicalDetails).toBe("some error message"); + expect(context.stacktrace).toBe("some stacktrace"); + expect(context.description).toBe( + "Something went wrong. Please try again or contact support if the issue persists." + ); + expect(context.timestamp).toBeDefined(); + }); + + it("should handle string errors", () => { + jest.mocked(handleTezError).mockReturnValue(undefined); + const error = "string error message"; + + const context = getErrorContext(error); + + expect(context.technicalDetails).toBe("string error message"); + expect(context.stacktrace).toBe(""); + expect(context.description).toBe( + "Something went wrong. Please try again or contact support if the issue persists." + ); + expect(context.timestamp).toBeDefined(); + }); + + it("should handle Error instances with Tezos-specific errors", () => { + jest.mocked(handleTezError).mockReturnValue("Handled tez error message"); + const error = new Error("test error"); + + const context = getErrorContext(error); + + expect(context.technicalDetails).toBe("test error"); + expect(context.description).toBe("Handled tez error message"); + expect(context.stacktrace).toBeDefined(); + expect(context.timestamp).toBeDefined(); }); }); diff --git a/packages/core/src/ErrorContext.ts b/packages/core/src/ErrorContext.ts index 14b6104e3c..f6a28298d0 100644 --- a/packages/core/src/ErrorContext.ts +++ b/packages/core/src/ErrorContext.ts @@ -8,7 +8,6 @@ export type ErrorContext = { }; export const getErrorContext = (error: any): ErrorContext => { - console.log({ error }); let description = "Something went wrong. Please try again or contact support if the issue persists."; let technicalDetails; diff --git a/packages/core/src/estimate.test.ts b/packages/core/src/estimate.test.ts index 141bf148ca..e42f408f44 100644 --- a/packages/core/src/estimate.test.ts +++ b/packages/core/src/estimate.test.ts @@ -34,21 +34,33 @@ describe("estimate", () => { ); }); - it("catches subtraction_underflow", () => { - const res = handleTezError(new Error("subtraction_underflow")); - expect(res).toEqual("Insufficient balance, please make sure you have enough funds."); - }); - - it("catches non_existing_contract", () => { - const res = handleTezError(new Error("contract.non_existing_contract")); - expect(res).toEqual( - "Contract does not exist, please check if the correct network is selected." - ); - }); - - it("returns the original error if not known", () => { - const err = new Error("unknown error"); - expect(handleTezError(err)).toEqual("unknown error"); + describe("handleTezError", () => { + it("catches subtraction_underflow", () => { + const res = handleTezError(new Error("subtraction_underflow")); + expect(res).toBe("Insufficient balance, please make sure you have enough funds."); + }); + + it("catches non_existing_contract", () => { + const res = handleTezError(new Error("contract.non_existing_contract")); + expect(res).toBe( + "Contract does not exist, please check if the correct network is selected." + ); + }); + + it("catches staking_to_delegate_that_refuses_external_staking", () => { + const res = handleTezError(new Error("staking_to_delegate_that_refuses_external_staking")); + expect(res).toBe("The baker you are trying to stake to does not accept external staking."); + }); + + it("catches empty_implicit_delegated_contract", () => { + const res = handleTezError(new Error("empty_implicit_delegated_contract")); + expect(res).toBe("Emptying an implicit delegated account is not allowed."); + }); + + it("returns undefined for unknown errors", () => { + const err = new Error("unknown error"); + expect(handleTezError(err)).toBeUndefined(); + }); }); });