Skip to content

🐛 Fix: Approve CAP error shows before wallet confirmation#187

Open
chinaxiao123 wants to merge 1 commit into
capofficial:mainfrom
chinaxiao123:main
Open

🐛 Fix: Approve CAP error shows before wallet confirmation#187
chinaxiao123 wants to merge 1 commit into
capofficial:mainfrom
chinaxiao123:main

Conversation

@chinaxiao123
Copy link
Copy Markdown

Fixes #32

Problem

When clicking "Approve CAP" on the Stake modal, an error was displayed before the wallet (MetaMask) confirmation. This was caused by:

  1. Missing loading state — The Approve button had no isSubmitting state, so users saw no feedback during wallet interaction
  2. No silent handling of user rejection — When users rejected the MetaMask prompt, the raw error was shown as a modal
  3. No allowance refresh — After successful approval, the allowance wasn't refreshed immediately

Changes

src/api/assets.jsapproveAsset()

  • Added silent handling for user denied / user rejected / user cancelled errors (no error popup when user cancels in MetaMask)

src/components/modals/StakeCAP.svelte_approveAsset()

  • Added isSubmitting = true before calling approveAsset
  • Added isSubmitting = false after completion
  • Added allowance refresh (checkAllowance()) after successful approval
  • Added loading state to the Approve CAP button (isLoading={isSubmitting})

Testing

  1. Open Stake CAP modal
  2. Click "Approve CAP" → Button shows loading state
  3. Confirm in MetaMask → Allowance updates, "Stake" button appears
  4. Click "Approve CAP" → Click Cancel in MetaMask → No error shown, button resets

Fix for issue capofficial#32:
- Add loading state (isSubmitting) to Approve CAP button
- Handle MetaMask rejection silently (no error popup)
- Refresh allowance check after successful approval
- Prevent error display while waiting for wallet confirmation
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