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 makes Bitcoin adapter + OKX/Unisat connectors network-aware via caipNetworkId, with updated types and corrected event/account handling.

  • Adapters (Bitcoin)
    • Pass caipNetworkId to connector.connect and getAccounts in src/adapter.ts.
    • Improve onChainChanged: resolve chain, reconnect, fetch network-scoped accounts, update connection, emit switchNetwork with resolved chain.id.
    • syncConnectors: instantiate OKXConnector; add when client-side.
  • Connectors
    • OKXConnector:
      • Add Signet mapping (bitcoinSignet) and window typings.
      • Refactor to resolve wallet per network; bind/unbind listeners per wallet; expose getWallet().
      • connect/getAccountAddresses/sendTransfer/signPSBT now network-aware; on Signet use selectedAccount.
      • switchNetwork unbinds listeners and emits chainChanged with resolved chain.id.
    • UnisatConnector:
      • After switchChain, emit chainChanged with resolved chain.id.
  • Types/Controllers
    • Provider.connect accepts { caipNetworkId, onUri }.
    • AdapterBlueprint.GetAccountsParams adds optional caipNetworkId.
    • BitcoinConnector.getAccountAddresses accepts optional { caipNetworkId }.
  • Solana
    • Optimize connect: reuse existing connection only when params.address provided.
  • Tests/Changeset
    • Update unit tests for network-aware behavior and events; patch bumps for affected packages.

Written by Cursor Bugbot for commit 07e3d7a. 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: 07e3d7a

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 Ready Ready Preview Comment Dec 8, 2025 8:28pm
appkit-demo Ready Ready Preview Comment Dec 8, 2025 8:28pm
appkit-gallery Ready Ready Preview Comment Dec 8, 2025 8:28pm
appkit-headless-sample-app Ready Ready Preview Comment Dec 8, 2025 8:28pm
appkit-laboratory Ready Ready Preview Comment Dec 8, 2025 8:28pm
10 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
appkit-basic-example Ignored Ignored Dec 8, 2025 8:28pm
appkit-basic-sign-client-example Ignored Ignored Dec 8, 2025 8:28pm
appkit-basic-up-example Ignored Ignored Dec 8, 2025 8:28pm
appkit-ethers5-bera Ignored Ignored Dec 8, 2025 8:28pm
appkit-nansen-demo Ignored Ignored Dec 8, 2025 8:28pm
appkit-vue-solana Ignored Ignored Dec 8, 2025 8:28pm
appkit-wagmi-cdn-example Ignored Ignored Dec 8, 2025 8:28pm
ethereum-provider-wagmi-example Ignored Ignored Dec 8, 2025 8:28pm
next-wagmi-solana-bitcoin-example Ignored Ignored Dec 8, 2025 8:28pm
vue-wagmi-example Ignored Ignored Dec 8, 2025 8:28pm

@github-actions
Copy link
Contributor

github-actions bot commented Nov 12, 2025

Visual Regression Test Results ❌ Failed

⚠️ 6 visual change(s) detected

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

👉 Please review the visual changes in Chromatic and accept or reject them.

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:         71.39 kB with all dependencies, minified and gzipped
Loading time: 1.4 s    on slow 3G
Running time: 533 ms   on Snapdragon 410
Total time:   2 s
@reown/appkit/react
Size limit:   230 kB
Size:         228.46 kB with all dependencies, minified and gzipped
Loading time: 4.5 s     on slow 3G
Running time: 794 ms    on Snapdragon 410
Total time:   5.3 s
@reown/appkit/vue
Size limit:   80 kB
Size:         71.39 kB with all dependencies, minified and gzipped
Loading time: 1.4 s    on slow 3G
Running time: 262 ms   on Snapdragon 410
Total time:   1.7 s
@reown/appkit-scaffold-ui
Size limit:   220 kB
Size:         209.78 kB with all dependencies, minified and gzipped
Loading time: 4.1 s     on slow 3G
Running time: 484 ms    on Snapdragon 410
Total time:   4.6 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: 52 ms    on Snapdragon 410
Total time:   309 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