Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add toast message template for tx revert exception #149

Merged
merged 1 commit into from
May 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/utils/notifyWithTost.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,21 @@ const messageTemplates = {
render({ data }) {
console.log({ data });
if (data.code === 4001) return "User denied transaction";
if (data?.error?.code === -32603) return <TxRevertMessage errorMessage={data.error.message} />;
return "Failed to execute transaction";
},
},
},
// add more message types here as needed
};

const TxRevertMessage = ({ errorMessage }) => {
Copy link
Member

@0xferit 0xferit May 19, 2023

Choose a reason for hiding this comment

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

Could we generalize this so it works for success messages as well? And do you think it would be good?

Copy link
Member Author

Choose a reason for hiding this comment

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

Certainly! There is a lot of room for improving this layer. I was going to address your suggestion in #128 issue

const [title, reason] = errorMessage.split(":");
console.log({ title, reason });
return (
<>
<div style={{ fontSize: "20px", textTransform: "capitalize" }}>{title}</div>
<div style={{ fontSize: "16px" }}>{reason}</div>
</>
)
}