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 3e35c23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/utils/src/ErrorContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ describe("handleTezError", () => {
expect(res).toBe("The delegate is unchanged. Delegation to this address is already done.");
});

it("returns undefined for unknown errors", () => {
it("returns default text for unknown errors", () => {
const err = new Error("unknown error");
expect(handleTezError(err)).toBeUndefined();
expect(handleTezError(err)).toBe("Tezos blockchain rejected the transaction: unknown error. Please try again or contact support if the issue persists.");
});
});
7 changes: 5 additions & 2 deletions packages/utils/src/ErrorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class WalletConnectError extends CustomError {
}

// Converts a known L1 error message to a more user-friendly one
export const handleTezError = (err: Error): string | undefined => {
export const handleTezError = (err: Error): string => {
if (err.message.includes("subtraction_underflow")) {
return "Insufficient balance, please make sure you have enough funds.";
} else if (err.message.includes("contract.non_existing_contract")) {
Expand All @@ -36,7 +36,10 @@ 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.";
}
return `Tezos blockchain rejected the transaction: ${err.message}. Please try again or contact support if the issue persists.`;
};

export const getErrorContext = (error: any): ErrorContext => {
Expand All @@ -59,7 +62,7 @@ export const getErrorContext = (error: any): ErrorContext => {
description = error.message;
technicalDetails = "";
} else if (error instanceof Error) {
description = handleTezError(error) ?? description;
description = handleTezError(error);
}

return {
Expand Down

0 comments on commit 3e35c23

Please sign in to comment.