Skip to content

Commit

Permalink
Add generic message for errors during sign operation
Browse files Browse the repository at this point in the history
  • Loading branch information
OKendigelyan committed Dec 5, 2024
1 parent 76011d1 commit d03573c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 29 deletions.
25 changes: 15 additions & 10 deletions apps/desktop/src/components/SendFlow/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,22 @@ 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);
handleAsyncAction(
async () => {
const operation = await executeOperations(
{ ...operations, estimates: form.watch("executeParams") },
tezosToolkit
);
if (mode === "batch") {
clearBatch(operations.sender);
}
await openWith(<SuccessStep hash={operation.opHash} />);
return operation;
},
{
description: "Something went wrong, please try again.",
}
await openWith(<SuccessStep hash={operation.opHash} />);
return operation;
});
);

return {
fee: totalFee(form.watch("executeParams")),
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/components/Menu/ErrorLogsMenu/ErrorLogsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export const ErrorLogsMenu = () => {
<Text color={color("700")} size="sm">
{errorLog.timestamp}
</Text>
<Text marginTop="12px" color={color("700")} size="sm">
{errorLog.technicalDetails}
</Text>
</Flex>
</Flex>
</Box>
Expand Down
20 changes: 12 additions & 8 deletions apps/web/src/components/SendFlow/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,18 @@ 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(<SuccessStep hash={operation.opHash} />);
return operation;
});
handleAsyncAction(
async () => {
const operation = await executeOperations(
{ ...operations, estimates: form.watch("executeParams") },
tezosToolkit
);
await openWith(<SuccessStep hash={operation.opHash} />);
return operation;
},
// Here we should show a generic error message, keeping the original error for errors list
{ description: "Something went wrong, please try again." }
);

return {
fee: totalFee(form.watch("executeParams")),
Expand Down
24 changes: 18 additions & 6 deletions packages/core/src/ErrorContext.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import { handleTezError } from "./estimate";

export type ErrorContext = {
timestamp: string;
description: string;
stacktrace: string;
technicalDetails: string;
};

export const getErrorContext = (error: any): ErrorContext => {
let description = "Something went wrong";
if (typeof error === "object" && "message" in error) {
description = error.message;
} else if (typeof error === "string") {
description = error;
}
console.log({ error });
let description =
"Something went wrong. Please try again or contact support if the issue persists.";
let technicalDetails;

let stacktrace = "";
if (typeof error === "object" && "stack" in error) {
stacktrace = error.stack;
}

if (error instanceof Error) {
description = handleTezError(error) ?? description;
}

if (typeof error === "object" && "message" in error) {
technicalDetails = error.message;
} else if (typeof error === "string") {
technicalDetails = error;
}

return {
timestamp: new Date().toISOString(),
description,
stacktrace,
technicalDetails,
};
};
9 changes: 4 additions & 5 deletions packages/core/src/estimate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ export const estimate = async (
if (!isRevealed) {
throw new Error(`Signer address is not revealed on the ${network.name}.`);
}
if (err instanceof Error) {
err.message = handleTezError(err);
}

throw err;
}
};
Expand All @@ -59,13 +57,14 @@ const estimateToEstimation = (estimate: Estimate): Estimation => ({
});

// Converts a known L1 error message to a more user-friendly one
export const handleTezError = (err: Error): string => {
export const handleTezError = (err: Error): string | undefined => {
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")) {
return "Contract does not exist, please check if the correct network is selected.";
} else if (err.message.includes("staking_to_delegate_that_refuses_external_staking")) {
return "The baker you are trying to stake to does not accept external staking.";
} else if (err.message.includes("empty_implicit_delegated_contract")) {
return "Emptying an implicit delegated account is not allowed.";
}
return err.message;
};

0 comments on commit d03573c

Please sign in to comment.