Skip to content

Commit

Permalink
Fix parsing logic for starknet tx execution error (#924)
Browse files Browse the repository at this point in the history
* Fix parsing logic for starknet tx execution error

* Align error alert title left

* Align icon and title to flex-start instead of center

* Update error summry when class hash is not declared
  • Loading branch information
JunichiSugiura authored Oct 25, 2024
1 parent 5ea6272 commit 4f8f6bc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
7 changes: 7 additions & 0 deletions packages/keychain/src/components/ErrorAlert.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ export const Info: Story = {
variant: "info",
},
};

export const LongTitle: Story = {
args: {
title:
"Long text should align left and blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah.",
},
};
3 changes: 2 additions & 1 deletion packages/keychain/src/components/ErrorAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function ErrorAlert({
<AccordionButton
disabled={!description || (isExpanded && !allowToggle)}
>
<HStack>
<HStack alignItems="flex-start">
{(() => {
switch (variant) {
case "info":
Expand All @@ -87,6 +87,7 @@ export function ErrorAlert({
fontSize="2xs"
color="inherit"
textTransform="uppercase"
align="left"
>
{title}
</Text>
Expand Down
4 changes: 2 additions & 2 deletions packages/keychain/src/hooks/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const useUpgrade = (controller: Controller): UpgradeInterface => {
}

return [controller.cartridge.upgrade(LATEST_CONTROLLER.hash)];
}, [controller, LATEST_CONTROLLER]);
}, [controller]);

const onUpgrade = useCallback(async () => {
if (!controller || !LATEST_CONTROLLER) {
Expand All @@ -110,7 +110,7 @@ export const useUpgrade = (controller: Controller): UpgradeInterface => {
console.log({ e });
setError(e);
}
}, [controller, LATEST_CONTROLLER, calls]);
}, [controller, calls]);

return {
available,
Expand Down
8 changes: 7 additions & 1 deletion packages/keychain/src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export function parseExecutionError(
error: string[];
}[];
} {
let executionError: string = error.data?.execution_error;
let executionError: string = (
typeof error.data === "string" ? JSON.parse(error.data) : error.data
)?.execution_error;
if (!executionError) {
return {
raw: JSON.stringify(error.data),
Expand Down Expand Up @@ -146,6 +148,10 @@ export function parseExecutionError(
} else if (lastErrorMessage === "session/already-registered") {
summary = "Session already registered";
lastError[lastError.length - 1] = summary;
} else if (
/.*Class with hash.*is not declared.$/.test(lastErrorMessage)
) {
summary = "Class hash is not declared.";
} else {
summary = lastErrorMessage;
lastError[lastError.length - 1] = summary;
Expand Down

0 comments on commit 4f8f6bc

Please sign in to comment.