Skip to content

Commit

Permalink
fix: better errors text for WalletConnect
Browse files Browse the repository at this point in the history
  • Loading branch information
dianasavvatina committed Jan 3, 2025
1 parent 188d44e commit 57f0e71
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/utils/src/ErrorContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ describe("getErrorContext", () => {
expect(context.timestamp).toBeDefined();
});

it("should handle Error instances with unknown Tezos-specific errors", () => {
const error = new Error("protocol.unknown.error");

const context = getErrorContext(error);

expect(context.technicalDetails).toBe("protocol.unknown.error");
expect(context.description).toBe(
"Tezos blockchain rejected the transaction: protocol.unknown.error. Please try again or contact support if the issue persists."
);
expect(context.stacktrace).toBeDefined();
expect(context.timestamp).toBeDefined();
});

it("should handle CustomError instances", () => {
const error = new CustomError("Custom error message");

Expand Down Expand Up @@ -93,6 +106,13 @@ describe("handleTezError", () => {
expect(res).toBe("The delegate is unchanged. Delegation to this address is already done.");
});

it("catches contract.manager.unregistered_delegate", () => {
const res = handleTezError(new Error("contract.manager.unregistered_delegate"));
expect(res).toBe(
"The provided delegate address is not registered as a delegate. Verify the delegate address and ensure it is active."
);
});

it("returns undefined for unknown errors", () => {
const err = new Error("unknown error");
expect(handleTezError(err)).toBeUndefined();
Expand Down
6 changes: 5 additions & 1 deletion packages/utils/src/ErrorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const handleTezError = (err: Error): string | undefined => {
return "Emptying an implicit delegated account is not allowed. End delegation before trying again.";
} else if (err.message.includes("delegate.unchanged")) {
return "The delegate is unchanged. Delegation to this address is already done.";
} else if (err.message.includes("contract.manager.unregistered_delegate")) {
return "The provided delegate address is not registered as a delegate. Verify the delegate address and ensure it is active.";
}
};

Expand All @@ -59,7 +61,9 @@ export const getErrorContext = (error: any): ErrorContext => {
description = error.message;
technicalDetails = "";
} else if (error instanceof Error) {
description = handleTezError(error) ?? description;
description =
handleTezError(error) ||
`Tezos blockchain rejected the transaction: ${error.message}. Please try again or contact support if the issue persists.`;
}

return {
Expand Down

1 comment on commit 57f0e71

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title Lines Statements Branches Functions
apps/desktop Coverage: 83%
83.81% (1786/2131) 79.58% (850/1068) 78.27% (454/580)
apps/web Coverage: 83%
83.81% (1786/2131) 79.58% (850/1068) 78.27% (454/580)
packages/components Coverage: 97%
97.51% (196/201) 95.91% (94/98) 88.13% (52/59)
packages/core Coverage: 81%
82.47% (207/251) 72.72% (88/121) 81.35% (48/59)
packages/crypto Coverage: 100%
100% (43/43) 90.9% (10/11) 100% (7/7)
packages/data-polling Coverage: 97%
95.27% (141/148) 87.5% (21/24) 92.85% (39/42)
packages/multisig Coverage: 98%
98.47% (129/131) 85.71% (18/21) 100% (36/36)
packages/social-auth Coverage: 100%
100% (21/21) 100% (11/11) 100% (3/3)
packages/state Coverage: 85%
84.79% (820/967) 81.03% (188/232) 78.59% (301/383)
packages/tezos Coverage: 89%
88.72% (118/133) 94.59% (35/37) 86.84% (33/38)
packages/tzkt Coverage: 89%
87.32% (62/71) 87.5% (14/16) 80.48% (33/41)

Please sign in to comment.