web3modal icon indicating copy to clipboard operation
web3modal copied to clipboard

WIP: remove ConnectionControllerClient and move behavior account behavior to ConnectionController

Open tomiir opened this issue 3 months ago • 9 comments

Description

Overview

This PR implements a significant architectural refactoring that moves account-related logic from AppKitBaseClient to ConnectionController and completely removes the connectionControllerClient abstraction layer. This change aligns with the AppKit stability improvements initiative and moves us closer to atomic state management.

🎯 Motivation

As outlined in the AppKit Refactor POC Findings & Recommendations, the current architecture has several issues: Circular Dependencies: Controllers have circular deps through client abstractions Tangled State: Multiple cross-controller dependencies make atomic updates impossible Blurry Boundaries: State responsibilities are unclear between controllers Proxy Pattern Anti-pattern: connectionControllerClient acts as unnecessary middleware

🔄 Changes Made

✅ Removed connectionControllerClient Completely

  • Eliminated the client abstraction layer that was creating circular dependencies
  • Direct controller-to-controller communication replaces client-mediated calls
  • Simplified the call chain: views → controllers → adapters (instead of views → controllers → client → adapters)

🏗️ Moved Account Logic to ConnectionController

The following methods were moved from AppKitBaseClient to ConnectionController:

Connection Management Methods:

  • connectExternal() - External wallet connection logic
  • reconnectExternal() - Reconnection handling
  • disconnect() - Disconnection flows
  • switchConnection() - Multi-wallet connection switching

Account Operations:

  • syncAccount() - Account synchronization
  • syncIdentity() - Identity/ENS resolution
  • updateBalance() - Balance updates

Provider execution

  • signMessage() - Message signing functionality
  • sendTransaction() - Transaction sending
  • estimateGas() - Gas estimation
  • writeContract() - Smart contract interactions
  • (new) request() - Generic RPC request. Removed specific namespace requests

Utility Methods:

  • parseUnits() / formatUnits() - Unit conversion utilities
  • getEnsAddress() / getEnsAvatar() - ENS resolution
  • checkInstalled() - Wallet installation checks

Updated Adapter Integration

Adapters now call ConnectionController methods directly instead of through client

  • Removed adapter dependency on connectionControllerClient
  • Simplified adapter initialization and connection flows

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)
  • [x] 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-3837

Checklist

  • [ ] Code in this PR is covered by automated tests (Unit tests, E2E tests)
  • [ ] 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] Consolidates account and provider operations into ConnectionController, removes ConnectionControllerClient, and updates adapters, UI, tests, and examples to the new API.

  • Core/AppKit:
    • Migrate connection/account flows and provider ops (connectExternal, reconnectExternal, disconnect, switchConnection, syncAccount, syncIdentity, updateBalance, signMessage, sendTransaction, estimateGas, writeContract, request) into ConnectionController.
    • Remove ConnectionControllerClient; simplify call chain and update AppKitBaseClient, appkit-core, and universal adapter client.
    • Adjust controller exports, types, and utils (balance/ENS/units) to route through ConnectionController.
  • Adapters:
    • Update wagmi, ethers/ethers5, solana, bitcoin, polkadot, ton clients to call ConnectionController directly; refresh tests and mocks.
  • UI/Scaffold:
    • Update modal/views/widgets to consume new controller APIs (connect, networks, send/swap/receive flows).
  • Controllers:
    • Refactor ChainController, SendController, SwapController, BlockchainApiController to align with new responsibilities and API surface.
  • Tests:
    • Broad test updates across appkit, controllers, adapters, and scaffold-ui; add/adjust cases for connection, balance, send/estimate, ENS, smart sessions.
  • Examples/Packages:
    • Align example apps and package configs to new API surface; minor package.json updates across apps/examples/packages.

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

tomiir avatar Sep 25 '25 11:09 tomiir

⚠️ No Changeset found

Latest commit: f872b740b5a31938915e5526f7c9ff3d94ec44f3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

changeset-bot[bot] avatar Sep 25 '25 11:09 changeset-bot[bot]

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

vercel[bot] avatar Sep 25 '25 11:09 vercel[bot]

Warnings
:warning:

🔑 Potential UUID detected in packages/controllers/src/controllers/BlockchainApiController.ts (line 47): 2b92315d-eab7-5bef-8...

:warning:

🔑 Potential UUID detected in packages/controllers/src/controllers/BlockchainApiController.ts (line 47): 2b92315d-eab7-5bef-8...

:warning:

🔑 Potential UUID detected in packages/adapters/ethers/src/tests/client.test.ts (line 980): ba0ba0cd-17c6-4806-a...

:warning:

🔑 Potential UUID detected in packages/adapters/wagmi/src/tests/client.test.ts (line 430): 07ba87ed-43aa-4adf-4...

Generated by :no_entry_sign: dangerJS against f872b740b5a31938915e5526f7c9ff3d94ec44f3

github-actions[bot] avatar Oct 15 '25 10:10 github-actions[bot]

📦 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:         79.64 kB with all dependencies, minified and gzipped
Loading time: 1.6 s    on slow 3G
Running time: 304 ms   on Snapdragon 410
Total time:   1.9 s
@reown/appkit/react
Size limit:   230 kB
Size:         228.72 kB with all dependencies, minified and gzipped
Loading time: 4.5 s     on slow 3G
Running time: 494 ms    on Snapdragon 410
Total time:   5 s
@reown/appkit/vue
Size limit:   80 kB
Size:         79.64 kB with all dependencies, minified and gzipped
Loading time: 1.6 s    on slow 3G
Running time: 208 ms   on Snapdragon 410
Total time:   1.8 s
@reown/appkit-scaffold-ui
Size limit:   220 kB
Size:         209.63 kB with all dependencies, minified and gzipped
Loading time: 4.1 s     on slow 3G
Running time: 383 ms    on Snapdragon 410
Total time:   4.5 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: 39 ms    on Snapdragon 410
Total time:   295 ms

github-actions[bot] avatar Oct 15 '25 10:10 github-actions[bot]

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 79.56% 37952 / 47697
🔵 Statements 79.56% 37952 / 47697
🔵 Functions 77.98% 4087 / 5241
🔵 Branches 86.45% 9234 / 10681
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/adapters/bitcoin/src/adapter.ts 83.8% 83.33% 73.33% 83.8% 67-80, 83, 200-201, 306-322, 379-380, 397-398, 414-415, 447-448, 460-461, 511-512, 568-571, 575-609, 613-614
packages/adapters/bitcoin/src/utils/BitcoinApi.ts 100% 100% 100% 100%
packages/adapters/ethers/src/client.ts 65.73% 75.78% 65.62% 65.73% 110-111, 125-126, 150-151, 165-189, 202-238, 244-245, 252-269, 389-411, 414-419, 432-433, 443-464, 470-472, 475-476, 501, 528-529, 537-538, 566-571, 590-636, 643-644, 666, 695-696, 707-708, 742-743, 747, 762-763, 780-785, 794-812, 818-819, 828-829, 840-841, 847-859
packages/adapters/ethers5/src/client.ts 60.82% 73.45% 65.62% 60.82% 68-89, 106-107, 121-122, 146-147, 161-185, 198-234, 240-241, 248-265, 383-405, 408-413, 426-427, 437-458, 464-466, 469-470, 495, 522-523, 531-532, 560-565, 569-615, 637-638, 660, 689-690, 702-703, 740-741, 745, 759-784, 792-810, 816-817, 826-827, 838-839, 845-857
packages/adapters/polkadot/src/client.ts 100% 100% 100% 100%
packages/adapters/solana/src/client.ts 72.78% 75.26% 40.54% 72.78% 98-105, 138-141, 144-145, 148-149, 152-153, 156-159, 162-170, 179-180, 190-212, 223-224, 227-233, 258-271, 275-276, 279-280, 288-289, 294-301, 320-333, 356-359, 383-384, 394-395, 414-415, 422-423, 447-448, 452-453, 456-457, 494-498, 521-522, 545-551, 611-612
packages/adapters/ton/src/adapter.ts 91.48% 91.3% 84.61% 91.48% 64-77, 80, 109-110, 174-175, 197-198, 311-312, 368-369
packages/adapters/wagmi/src/client.ts 76.4% 67.26% 81.39% 76.4% 126-127, 132-133, 144-146, 148, 249-252, 362-363, 377, 397-398, 475-476, 488-489, 528-529, 546-561, 575-592, 613-614, 627-636, 647-648, 652-653, 658-690, 709-718, 722-728, 731-742, 751-752, 763-764, 785-787, 801-802, 815-816, 831-832, 876-877, 900-901, 909-910, 915-916, 923-924, 932-933, 938-939, 948-949, 957-958, 963-964, 970-992, 995-1008
packages/adapters/wagmi/src/connectors/AuthConnector.ts 5.58% 100% 25% 5.58% 56-70, 73-103, 106-153, 156-314
packages/adapters/wagmi/src/tests/mocks/AppKit.ts 92.45% 100% 100% 92.45% 105-112
packages/appkit-utils/src/HelpersUtil.ts 85.71% 96.55% 85.71% 85.71% 99-101, 127-136, 134
packages/appkit-utils/src/ethers/EthersProvider.ts 0% 100% 0% 0% 3-12
packages/appkit-utils/src/ethers/InjectedProvider.ts 23.07% 100% 0% 23.07% 7-19
packages/appkit/src/client/appkit-base-client.ts 74.47% 85.67% 74.41% 74.47% 165, 178-181, 184, 196-197, 203-204, 207, 216, 263-264, 310-311, 352-353, 355-356, 439-440, 476-482, 508-526, 529-539, 581, 596-615, 629, 633-641, 675-676, 695-698, 702-703, 705-706, 728-739, 760-762, 766-794, 799-800, 808-809, 811-812, 879-880, 889-910, 934-954, 959-963, 984-999, 1002-1003, 1022-1025, 1061-1079, 1086-1087, 1124-1125, 1337-1338, 1375-1376, 1379-1380, 1396-1399, 1402-1403, 1423-1424, 1427-1428, 1440-1450, 1470-1471, 1474-1481, 1485-1486, 1500, 1508, 1513, 1518-1537, 1540-1549, 1556-1561, 1579-1580, 1583-1584, 1591-1592, 1631-1632, 1703-1704, 1707-1708, 1711-1714, 1717-1718, 1721-1722, 1725-1726, 1729-1730, 1733-1737, 1746-1756, 1765-1777, 735-906, 937, 1520-1541
packages/appkit/src/client/appkit-core.ts 97.14% 100% 100% 97.14% 36
packages/appkit/src/client/appkit.ts 54.5% 71.42% 91.66% 54.5% 56, 77-78, 83-84, 92-93, 96, 115-129, 132-139, 142-158, 161-173, 178-188, 197-203, 211-212, 220-221, 234-272, 276-278, 289-303, 305, 307-326, 328-342, 367-373, 389, 411-412, 428-429, 452-454, 462-463, 498-499, 506-507, 510-513, 257-270
packages/appkit/src/universal-adapter/client.ts 44.29% 72.72% 30.55% 44.29% 18-19, 33-42, 86-122, 125-159, 168-171, 174-177, 180-183, 185-188, 191-192, 195-196, 199-200, 203-204, 207-208, 211-212, 215-222, 235, 239-242, 258-259, 267-34, 87-181
packages/controllers/exports/index.ts 100% 100% 100% 100%
packages/controllers/exports/react.ts 61.59% 92.1% 38.88% 61.59% 59-68, 89-97, 104-111, 126, 134, 152, 350-435
packages/controllers/src/controllers/BlockchainApiController.ts 43.35% 77.27% 32.65% 43.35% 200-201, 225-263, 267-286, 290-302, 306-316, 327-350, 358-359, 374-393, 397-426, 430-455, 465-468, 497-507, 511-526, 530-540, 544-562, 566-594, 605-616, 620-656, 660-669, 672-688, 285-341, 392-454, 525-687
packages/controllers/src/controllers/ChainController.ts 72.31% 85.65% 71.57% 72.31% 135, 219-230, 234-247, 251-261, 265-287, 309-310, 333-334, 423-430, 434-447, 456-457, 468, 472-473, 479-482, 497-498, 520-523, 544-551, 562-584, 627-633, 674-675, 709-729, 757-758, 801-802, 815, 819-821, 829, 834-835, 845, 847-850, 854-861, 863-866, 875-892, 128-146, 453, 582, 755
packages/controllers/src/controllers/ConnectionController.ts 74.95% 79.79% 63.1% 74.95% 154, 205-209, 213-214, 220-221, 230-231, 245-246, 251-252, 263-264, 268-274, 330-351, 359-360, 367-386, 396-397, 402-403, 406-407, 412-413, 424-436, 443-444, 456-468, 503-524, 528-548, 552-571, 575-578, 668, 785-786, 789-801, 823-825, 836-837, 872-873, 883-884, 886-887, 895-896, 898-899, 918-919, 1024-1025, 1033-1049, 1061, 1078-1081, 1136, 1142-1145, 1173, 1175-1179, 1212-1213, 1234-1245, 1270-1281, 1287-1300, 1304-1309, 1350-1351, 1378-1387, 1391, 426-475, 1306
packages/controllers/src/controllers/SendController.ts 62.5% 67.69% 62.16% 62.5% 83, 137, 139-141, 143, 147-148, 160-161, 166-167, 170-171, 191-193, 195-214, 260-275, 280-314, 320-321, 331-364, 369-370, 374-375, 399-400, 182-356
packages/controllers/src/controllers/SwapController.ts 58.39% 80.25% 71.66% 58.39% 54-57, 192, 272-274, 283-284, 296-298, 308-316, 346, 355-356, 364-367, 408, 429-431, 438-455, 480-481, 492-493, 512-513, 517-525, 529, 531, 533, 535, 580-589, 625-655, 659-713, 717-771, 775-776, 791-792, 808-827, 831-913, 932-933, 825-909
packages/controllers/src/controllers/AdapterController/ChainAdapterBlueprint.ts 71.65% 85.07% 71.87% 71.65% 136-145, 229-230, 234-235, 258-262, 268-271, 301-302, 339-340, 353-354, 507-532, 545-573, 591-592, 605-632, 641-642, 757-758, 292-543
packages/controllers/src/controllers/AdapterController/index.ts 88.23% 80% 100% 88.23% 20-21
packages/controllers/src/utils/BalanceUtil.ts 96.42% 96.55% 100% 96.42% 63, 72, 128-129
packages/controllers/src/utils/SIWXUtil.ts 72.31% 67.1% 56% 72.31% 40-41, 45-54, 56-57, 61-63, 70-83, 86-103, 111-112, 115-116, 119-120, 132-136, 140-141, 174, 196-197, 199-200, 210-212, 215-230, 285, 309, 357-381, 475-487, 499-500, 50, 360-387
packages/controllers/src/utils/StorageUtil.ts 67.16% 83.12% 63.44% 67.16% 101-102, 120-123, 127-131, 139-140, 156-157, 166-169, 173-181, 188-189, 197-198, 207-210, 223-226, 233-234, 241-244, 248-252, 259-262, 266-271, 278-279, 286-287, 300-301, 312-313, 324-325, 337-338, 341-349, 352-356, 359-363, 371-372, 384-385, 391, 394, 396-397, 401-402, 410-417, 429-430, 435-443, 460-461, 476-477, 486-487, 495, 497-498, 501-502, 516-517, 527-528, 542-543, 554, 556-557, 560-561, 578-579, 589-590, 593-606, 609-616, 619-623, 633-634, 637-644, 854-862, 866-882, 885-915, 918-934, 937-945, 948-962, 968-978, 981-989, 999-1000, 1004-1007, 1015-1018, 1028-1029, 889-902
packages/experimental/src/smart-session/controllers/SmartSessionsController.ts 62.56% 60% 50% 62.56% 51-55, 57-80, 88-89, 96-97, 125-126, 159-160, 168-171, 175-176, 179-181, 189-190, 198, 204-242
packages/scaffold-ui/src/modal/w3m-modal/index.ts 87.62% 86.53% 100% 87.62% 79-82, 96-97, 107-108, 130, 158, 164-165, 207, 225-233, 271-272
packages/scaffold-ui/src/partials/w3m-account-default-widget/index.ts 78.96% 84.12% 65% 78.96% 74-79, 84, 88-90, 158, 164-165, 190, 213-214, 251, 259-260, 278, 285-286, 308, 312-313, 316-317, 320-321, 336, 340-350, 360-366, 368, 393-395, 398-399, 347
packages/scaffold-ui/src/views/w3m-account-settings-view/index.ts 86.11% 83.78% 86.66% 86.11% 53-57, 60-62, 65, 72-73, 145, 174, 198, 216-217, 244, 268-269, 275-280
packages/scaffold-ui/src/views/w3m-connect-view/index.ts 76.57% 79.06% 88.88% 76.57% 80-82, 85, 88-89, 93, 113, 161-162, 170, 176-177, 183, 217, 231, 242, 282, 286, 306, 321-338, 341-349, 364-365, 370-394, 404-405
packages/scaffold-ui/src/views/w3m-connecting-wc-view/index.ts 68.02% 62.06% 66.66% 68.02% 63-64, 76, 85, 97-98, 107, 123-134, 145, 147-157, 161, 164-168, 193-194, 208-209, 217-218, 229, 233-236, 241, 245, 262, 266-280
packages/scaffold-ui/src/views/w3m-deposit-from-exchange-view/index.ts 88.16% 84.61% 85.71% 88.16% 55-56, 86-87, 110-113, 206-212, 223-226, 251-253, 256-257, 265-266
packages/scaffold-ui/src/views/w3m-networks-view/index.ts 28.98% 100% 0% 28.98% 39-47, 50-51, 55-66, 70-81, 84-85, 92-120, 123-124
packages/scaffold-ui/src/views/w3m-profile-wallets-view/index.ts 81.54% 84.93% 77.5% 81.54% 124, 128, 137-139, 145-149, 155-156, 180, 195, 234, 252, 271, 278-279, 322-324, 332, 346, 367, 400, 403, 422, 450, 485, 489-507, 522-524, 532-537, 540, 558-559, 563-569, 577-578, 581-586, 598-601, 606-607, 612-613, 663, 692, 708-709, 724-729, 735-740, 743-748
packages/scaffold-ui/src/views/w3m-unsupported-chain-view/index.ts 69.44% 83.33% 70% 69.44% 48, 88, 94-100, 106, 119-120, 127-132, 168-188, 121
packages/scaffold-ui/src/views/w3m-wallet-send-view/index.ts 84.61% 94.23% 77.77% 84.61% 77-86, 92, 134, 154-157, 160-167, 198-199, 236, 250, 283-287, 83
packages/siwx/src/signers/DefaultSigner.ts 26.66% 100% 0% 26.66% 13-28
Generated in workflow #16362 for commit f872b74 by the Vitest Coverage Report Action

github-actions[bot] avatar Oct 15 '25 10:10 github-actions[bot]

Early found bugs up to this commit:

  • Disconnect from default wallet button is disconnecting single namespace
  • WC connections are being disconnected but ak state is not updating or non current namespace

tomiir avatar Oct 17 '25 14:10 tomiir

Visual Regression Test Results ❌ Failed

⚠️ 1 visual change(s) detected

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

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

github-actions[bot] avatar Oct 29 '25 17:10 github-actions[bot]