Skip to content

fix: prevent premature error on approveAsset (bounty #32)#152

Open
jjb9707 wants to merge 1 commit into
capofficial:mainfrom
jjb9707:fix/approve-asset-error-handling
Open

fix: prevent premature error on approveAsset (bounty #32)#152
jjb9707 wants to merge 1 commit into
capofficial:mainfrom
jjb9707:fix/approve-asset-error-handling

Conversation

@jjb9707
Copy link
Copy Markdown

@jjb9707 jjb9707 commented May 15, 2026

Fixes #32

Problem

approveAsset() in src/api/assets.js called getContract() and accessed .address before the try-catch block. When contracts failed to resolve (e.g. wrong network), the error leaked before the wallet interaction, showing a premature error toast.

Changes

  • Move getContract() calls inside the try-catch block
  • Add null checks for resolved contracts with a friendly error message
  • Suppress user-rejection errors (MetaMask ACTION_REJECTED / code 4001)

Testing

  • If wallet is on wrong network: shows "Contract not found. Please check your network connection." instead of crashing
  • If user rejects MetaMask approval: no error shown (silent return)
  • Normal flow: unchanged — wallet popup → approve → success toast

Bounty

This resolves bounty #32 ($25 paid in crypto).

…side try-catch

- Move getContract() calls inside the try-catch block to prevent
  uncaught errors before wallet interaction (issue capofficial#32)
- Add null checks for contract resolution failures
- Suppress user-rejection errors (MetaMask ACTION_REJECTED / 4001)
- Show friendly error when network connection is missing
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.

Wrong error message while approving CAP on Stake function

1 participant