Skip to content

feat(examples): structured error handling and user messaging#92

Draft
danielrx-echo wants to merge 2 commits into
mainfrom
daniel/sonar-111
Draft

feat(examples): structured error handling and user messaging#92
danielrx-echo wants to merge 2 commits into
mainfrom
daniel/sonar-111

Conversation

@danielrx-echo
Copy link
Copy Markdown
Contributor

Summary

  • Adds messages.ts to all 4 example apps as a single source of truth for all user-facing strings (entity state, purchase readiness, errors, contract errors)
  • Adds parseError.ts to each app with chain-specific error parsers: parseEVMError (viem cause-chain unwrapping, ABI error name lookup), parseSVMError (Anchor error code extraction via regex from logs, IDL-derived friendly message map), and parsePermitError (API/network errors)
  • Adds ErrorToast component with auto-dismiss and manual close
  • Splits purchase() try-catch in CommitCard so permit API errors use parsePermitError and transaction errors use the chain-specific parser
  • Uses granular loading state ("idle" | "permit" | "submitting") so the commit button shows "Generating permit..." vs "Submitting..." vs "Loading..."
  • Disables the commit button when isWrongChain (EVM) or notInCommitmentStage, with updated messaging

Test plan

  • Connect wallet on wrong network (EVM) — commit button should be disabled with "Wrong network — switch to Base Sepolia to commit." banner
  • Click Commit on correct network — button should show "Generating permit..." then "Submitting..."
  • Reject wallet prompt — toast should show "Transaction cancelled."
  • Simulate network error during permit generation — toast should show network error message
  • Simulate contract revert — toast should show the mapped ABI/program error message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants