Skip to content

Conversation

@tarrencev
Copy link
Contributor

@tarrencev tarrencev commented Sep 23, 2025

Summary

  • Updated controller package to use official StarkNet wallet API types from @starknet-io/types-js
  • Ensures compliance with the wallet API specification for better interoperability
  • Improves type safety and error handling consistency
  • NEW: Handle USER_REFUSED_OP when users close modal by clicking outside

Changes

Initial Changes (Wallet API Alignment)

  • Error Handling: Replaced custom error code 63 with standard error code 163 (UNKNOWN_ERROR)
  • Type Standardization: Use Address type instead of string for account addresses
  • Error Types: Added standard wallet API error types (USER_REFUSED_OP, INVALID_REQUEST_PAYLOAD, etc.)
  • Import Cleanup: Fixed type imports across wallet adapters (Argent, Braavos)
  • Response Types: Updated response interfaces to match wallet API spec

New Changes (USER_REFUSED_OP Handling)

  • Cancellation Support: Added onCancel callback to IFrame base class to detect when users click outside modal
  • Error Helper: Created createUserRejectedError() helper for consistent USER_REFUSED_OP error creation
  • Connect Method: Updated controller connect to track and reject pending promises on cancellation
  • Execute/Sign Methods: Enhanced account methods to properly reject with USER_REFUSED_OP when modal is closed
  • withCancellation Helper: Added utility method to wrap operations with cancellation support

Test Plan

  • Build succeeds without TypeScript errors
  • Code formatting passes (pnpm format:check)
  • Connect flow properly rejects with USER_REFUSED_OP when clicking outside modal
  • Execute transactions properly reject with USER_REFUSED_OP when clicking outside modal
  • Sign message operations properly reject with USER_REFUSED_OP when clicking outside modal
  • Existing wallet integrations continue to work
  • Error handling behaves correctly with new error codes

Breaking Changes

None - all changes maintain backward compatibility while improving spec compliance.

🤖 Generated with Claude Code

Updated controller package to use standard types from @starknet-io/types-js:
- Replace custom error codes with standard wallet API error types (UNKNOWN_ERROR, etc.)
- Use standard Address type instead of string for account addresses
- Update error handling to use proper error codes (163 instead of 63)
- Import standard types consistently across wallet adapters
- Add WalletApiError union type for better error type safety

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@vercel
Copy link

vercel bot commented Sep 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
controller-example-next Ready Ready Preview Sep 24, 2025 9:16pm
controller-example-next-compat Ready Ready Preview Sep 24, 2025 9:16pm
keychain Ready Ready Preview Sep 24, 2025 9:16pm
keychain-storybook Ready Ready Preview Sep 24, 2025 9:16pm

- Add createUserRejectedError helper function for consistent error creation
- Update IFrame base class to support cancellation callbacks via onCancel
- Implement cancellation handling in controller connect method
- Add withCancellation method to wrap operations with cancel support
- Update account execute and signMessage to reject with USER_REFUSED_OP on cancel
- Ensure all pending promises are properly rejected when user clicks outside modal

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
cursor[bot]

This comment was marked as outdated.

Applied prettier formatting from turbo lint:fix

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
return operation.finally(() => {
this.onCancel = originalOnCancel;
});
}
Copy link

Choose a reason for hiding this comment

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

Bug: Concurrent Operations Overwrite Cancellation Handlers

The withCancellation method has a race condition where concurrent operations overwrite the shared onCancel handler. This means only the most recent operation's cancellation handler is active, causing earlier operations to lose their ability to be cancelled when the user clicks outside.

Fix in Cursor Fix in Web

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