Skip to content

Fix premature error when approving CAP for staking#162

Open
rebel117 wants to merge 2 commits into
capofficial:mainfrom
rebel117:fix-32-stake-approve-error
Open

Fix premature error when approving CAP for staking#162
rebel117 wants to merge 2 commits into
capofficial:mainfrom
rebel117:fix-32-stake-approve-error

Conversation

@rebel117
Copy link
Copy Markdown

Problem

When a user clicks "Approve CAP" in the Stake modal, an error is displayed before the user has confirmed or rejected the approval in their wallet. This is confusing because the wallet confirmation dialog is still open.

Root Cause

  1. The Approve button had no loading state, so users could click it multiple times while the wallet dialog was open
  2. The approveAsset() function showed errors for wallet rejections (code 4001/ACTION_REJECTED) instead of silently handling them
  3. Other background operations could trigger error modals while the approve transaction was pending

Fix

  • Added isApproving loading state to the StakeCAP modal — button shows spinner while waiting
  • Added explicit handling for wallet rejection codes (4001, ACTION_REJECTED) in approveAsset() — returns false silently instead of showing error
  • The existing parseError() already handles "user denied"/"user rejected" strings, this adds the code-level check as a safety net

Testing

  • Click Approve CAP → wallet opens → button shows loading spinner
  • Confirm in wallet → approval succeeds, no error shown
  • Reject in wallet → no error shown, button returns to normal state

Closes #32

rebel117 added 2 commits May 15, 2026 22:04
Display the current liquidation price alongside the new calculated
price when adding or removing margin, so users can see the impact
of their margin adjustment at a glance.
- Add loading state to Approve button in StakeCAP modal
- Prevent showing error when user hasn't yet confirmed in wallet
- Handle wallet rejection (code 4001/ACTION_REJECTED) gracefully
- Return false on rejection instead of showing error modal
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