Skip to content

Conversation

@tomiir
Copy link
Collaborator

@tomiir tomiir commented Nov 12, 2025

Description

Context

Addresses APKT-4196: Signet network was not working correctly in Bitcoin flows, particularly with OKX. This PR standardizes network awareness across connectors and adapters, adds Signet support, and fixes event emission and account fetching across networks.

What’s Changed

  • controllers

    • AdapterController/ChainAdapterBlueprint.ts
      • Extend GetAccountsParams with optional caipNetworkId to allow network-scoped account retrieval.
    • utils/TypeUtil.ts
      • Extend Provider.connect to accept optional { caipNetworkId, onUri } for network-aware connections.
  • appkit-utils

    • bitcoin/BitcoinTypesUtil.ts
      • BitcoinConnector.getAccountAddresses accepts optional { caipNetworkId } to fetch accounts for a specific network.
  • adapters/bitcoin

    • adapter.ts
      • Pass caipNetworkId when calling connector.connect and getAccounts to ensure correct network context.
      • On switchNetwork, await provider switch and rely on event-driven updates.
      • Improve onChainChanged: resolve the chain, reconnect to obtain address, fetch accounts for that specific caipNetworkId, update connection, then emit switchNetwork with the resolved chain.id.
    • connectors/UnisatConnector
      • After switchChain, find the chain and emit chainChanged with chain.id for consistent event semantics.
    • connectors/OKXConnector
      • Add Signet support: map bitcoinSignet.caipNetworkId to window.okxwallet.bitcoinSignet.
      • Refactor to be network-aware:
        • Introduce _connect(caipNetworkId) and connect({ caipNetworkId? }).
        • Resolve wallet per network via getWallet({ requestedCaipNetworkId }) at call time.
        • Bind/unbind listeners per wallet instance; keep connector stateless relative to a single wallet object.
      • getAccountAddresses({ caipNetworkId? }): for Signet, return selectedAccount; otherwise use getAccounts + getPublicKey.
      • sendTransfer and signPSBT now resolve the wallet for the active/requested network before acting.
      • switchNetwork: unbind current listeners and emit chainChanged with the resolved chain.id (OKX lacks a true switch RPC), relying on reconnect flow for actual wallet context.
      • Add bitcoinSignet import and mapping; extend window.okxwallet typing for Signet.
      • Convert getWallet to an instance method returning the wallet handle (not a new connector).

Why

  • Fix Signet: OKX’s Bitcoin provider exposes separate wallet handles per network. Without network-aware resolution, Signet fell back to mainnet/testnet behavior and failed.
  • Consistency: Standardize passing caipNetworkId across connect/account flows so adapters and connectors operate on the intended network.
  • Events: Ensure chainChanged and switchNetwork are emitted with the correct chain.id and timing after state updates.

Behavior Notes

  • Connectors may now receive caipNetworkId in connect and getAccountAddresses. If ignored, they continue to work as before; implementing the hint enables correct multi-network behavior.
  • OKX on Signet returns a single selected account; we reflect that via selectedAccount.
  • BitcoinAdapter.switchNetwork now awaits provider switching and relies on subsequent events to complete the flow; functional behavior unchanged for consumers.

Breaking/Surface Changes

  • Low risk for consumers; types expanded but backward-compatible:
    • Provider.connect(params?: { caipNetworkId?: CaipNetworkId; onUri?: fn })
    • BitcoinConnector.getAccountAddresses(params?: { caipNetworkId?: CaipNetworkId })
  • Adapter/connector implementers should optionally handle caipNetworkId to be multi-network correct.

Type of change

  • Chore (non-breaking change that addresses non-functional tasks, maintenance, or code quality improvements)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Associated Issues

Closes APKT-4196

Checklist

  • Code in this PR is covered by automated tests (Unit tests, E2E tests) => WIP
  • My changes generate no new warnings
  • I have reviewed my own code
  • I have filled out all required sections
  • I have tested my changes on the preview link
  • Approver of this PR confirms that the changes are tested on the preview link

Note

Adds Signet support and network-scoped connections for Bitcoin by passing caipNetworkId, refactors OKX to resolve per-network wallets, standardizes events, and updates types; minor Solana connect optimization.

  • Bitcoin:
    • Adapter (packages/adapters/bitcoin/src/adapter.ts):
      • Pass caipNetworkId to connector.connect and getAccounts; short-circuit if already connected to params.address.
      • Add OKXConnector via new OKXConnector({ requestedChains, requestedCaipNetworkId }).
      • Improve onChainChanged: resolve chain, reconnect, fetch accounts with caipNetworkId, update connection, emit switchNetwork with chain.id.
    • OKX Connector (packages/adapters/bitcoin/src/connectors/OKXConnector.ts):
      • Add Signet mapping (bitcoinSignet) and window typings; expose icon via window.okxwallet.cardano.icon.
      • Make network-aware: connect({ caipNetworkId? }), getAccountAddresses({ caipNetworkId? }), sendTransfer, signPSBT resolve wallet per network; for Signet, return selectedAccount.
      • Refactor to instance getWallet(...), bind/unbind events per wallet; switchNetwork unbinds and emits chainChanged with resolved chain.id.
    • Unisat Connector (packages/adapters/bitcoin/src/connectors/UnisatConnector/index.ts):
      • After switchChain, emit chainChanged with resolved chain.id; include Signet in chains.
  • Types/Controllers:
    • packages/appkit-utils/src/bitcoin/BitcoinTypesUtil.ts: BitcoinConnector.getAccountAddresses({ caipNetworkId? }).
    • packages/controllers/src/utils/TypeUtil.ts: Provider.connect({ caipNetworkId?, onUri? }).
    • packages/controllers/src/controllers/AdapterController/ChainAdapterBlueprint.ts: extend GetAccountsParams with caipNetworkId.
  • Solana:
    • packages/adapters/solana/src/client.ts: short-circuit connect path when params.address matches existing connection.
  • Tests:
    • Update/expand Bitcoin adapter and OKX/Unisat tests for Signet, per-network wallet resolution, and chainChanged semantics.
  • Changeset:
    • Patch releases for @reown/appkit-adapter-bitcoin, @reown/appkit-utils, @reown/appkit-controllers.

Written by Cursor Bugbot for commit c777d18. This will update automatically on new commits. Configure here.

Copilot AI review requested due to automatic review settings November 12, 2025 11:07
@linear
Copy link

linear bot commented Nov 12, 2025

@changeset-bot
Copy link

changeset-bot bot commented Nov 12, 2025

🦋 Changeset detected

Latest commit: c777d18

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 25 packages
Name Type
@reown/appkit-adapter-bitcoin Patch
@reown/appkit-utils Patch
@reown/appkit-controllers Patch
@reown/appkit-adapter-ethers Patch
@reown/appkit-adapter-ethers5 Patch
@reown/appkit-adapter-solana Patch
@reown/appkit-adapter-ton Patch
@reown/appkit-adapter-wagmi Patch
@reown/appkit Patch
@reown/appkit-scaffold-ui Patch
@reown/appkit-siwe Patch
@reown/appkit-siwx Patch
@reown/appkit-wallet-button Patch
@reown/appkit-experimental Patch
@reown/appkit-pay Patch
@reown/appkit-ui Patch
@reown/appkit-core Patch
@reown/appkit-cdn Patch
@reown/appkit-universal-connector Patch
@reown/appkit-testing Patch
@reown/appkit-common Patch
@reown/appkit-polyfills Patch
@reown/appkit-wallet Patch
@reown/appkit-cli Patch
@reown/appkit-codemod Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Nov 12, 2025

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

Project Deployment Preview Comments Updated (UTC)
appkit-basic-html Canceled Canceled Nov 12, 2025 0:02am
appkit-demo Canceled Canceled Nov 12, 2025 0:02am
appkit-gallery Canceled Canceled Comment Nov 12, 2025 0:02am
appkit-headless-sample-app Ready Ready Preview Comment Nov 12, 2025 0:02am
appkit-laboratory Canceled Canceled Comment Nov 12, 2025 0:02am
10 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
appkit-basic-example Ignored Ignored Nov 12, 2025 0:02am
appkit-basic-sign-client-example Ignored Ignored Nov 12, 2025 0:02am
appkit-basic-up-example Ignored Ignored Nov 12, 2025 0:02am
appkit-ethers5-bera Ignored Ignored Nov 12, 2025 0:02am
appkit-nansen-demo Ignored Ignored Nov 12, 2025 0:02am
appkit-vue-solana Ignored Ignored Nov 12, 2025 0:02am
appkit-wagmi-cdn-example Ignored Ignored Nov 12, 2025 0:02am
ethereum-provider-wagmi-example Ignored Ignored Nov 12, 2025 0:02am
next-wagmi-solana-bitcoin-example Ignored Ignored Nov 12, 2025 0:02am
vue-wagmi-example Ignored Ignored Nov 12, 2025 0:02am

Copilot finished reviewing on behalf of tomiir November 12, 2025 11:08
@github-actions
Copy link
Contributor

github-actions bot commented Nov 12, 2025

Visual Regression Test Results ✅ Passed

✨ No visual changes detected

Chromatic Build: https://www.chromatic.com/build?appId=6493191bf4b10fed8ca7353f&number=405
Storybook Preview: https://6493191bf4b10fed8ca7353f-yiaonetqhc.chromatic.com/

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds Signet support to Bitcoin flows and makes connectors network-aware. It fixes issues where Signet network was not working correctly with OKX, by standardizing how caipNetworkId is passed through the connection flow.

Key changes:

  • Extended type interfaces to accept optional caipNetworkId for network-scoped operations
  • Refactored OKX connector to resolve wallet handles per network at call time rather than storing a single instance
  • Updated adapters to pass caipNetworkId through connect and account retrieval flows

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
packages/controllers/src/utils/TypeUtil.ts Extended Provider.connect interface to accept optional caipNetworkId
packages/controllers/src/controllers/AdapterController/ChainAdapterBlueprint.ts Added caipNetworkId to GetAccountsParams for network-scoped account retrieval
packages/appkit-utils/src/bitcoin/BitcoinTypesUtil.ts Extended getAccountAddresses to accept optional caipNetworkId parameter
packages/adapters/bitcoin/src/connectors/UnisatConnector/index.ts Added chainChanged event emission after network switch
packages/adapters/bitcoin/src/connectors/OKXConnector.ts Major refactor: added Signet support, made connector network-aware with dynamic wallet resolution
packages/adapters/bitcoin/src/adapter.ts Updated to pass caipNetworkId through connect/getAccounts calls and improved onChainChanged flow

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 12, 2025

📦 Bundle Size Check

All bundles are within size limits

📊 View detailed bundle sizes

> @reown/[email protected] size /home/runner/work/appkit/appkit


> size-limit

@reown/appkit - Main Entry
Size limit:   80 kB
Size:         73.9 kB with all dependencies, minified and gzipped
Loading time: 1.5 s   on slow 3G
Running time: 262 ms  on Snapdragon 410
Total time:   1.8 s
@reown/appkit/react
Size limit:   230 kB
Size:         224.75 kB with all dependencies, minified and gzipped
Loading time: 4.4 s     on slow 3G
Running time: 561 ms    on Snapdragon 410
Total time:   5 s
@reown/appkit/vue
Size limit:   80 kB
Size:         73.9 kB with all dependencies, minified and gzipped
Loading time: 1.5 s   on slow 3G
Running time: 251 ms  on Snapdragon 410
Total time:   1.7 s
@reown/appkit-scaffold-ui
Size limit:   220 kB
Size:         206.54 kB with all dependencies, minified and gzipped
Loading time: 4.1 s     on slow 3G
Running time: 356 ms    on Snapdragon 410
Total time:   4.4 s
@reown/appkit-ui
Size limit:   500 kB
Size:         13.15 kB with all dependencies, minified and gzipped
Loading time: 257 ms   on slow 3G
Running time: 97 ms    on Snapdragon 410
Total time:   354 ms

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.

4 participants