Add useWalletLink hook#2
Conversation
Signed-off-by: Vishwajeet Tulse <145775116+VishwajeetTulse@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThis change adds chain-aware transport typing to wallet configuration and introduces a public headless ChangesWalletLink API
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant useWalletLink
participant wagmiHooks
participant Connector
Client->>useWalletLink: invoke hook
useWalletLink->>wagmiHooks: read connectors and account state
wagmiHooks-->>useWalletLink: wallets and connection state
Client->>useWalletLink: call connect(parameters)
useWalletLink->>wagmiHooks: invoke connect with connector and chainId
wagmiHooks->>Connector: connect wallet
Connector-->>wagmiHooks: return accounts and chainId
wagmiHooks-->>useWalletLink: update connection state
useWalletLink-->>Client: return result and state
Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Adds
useWalletLink, the headless half of the library, and tightens thetransportstyping oncreateWalletLinkConfig.useWalletLinkWraps wagmi's
useConnectors/useAccount/useConnect/useDisconnectinto a single hook, so a dapp gets the EIP-6963-discovered wallets,
connect/disconnect, and the current account from one import.
Returns
wallets,connect/connectAsync,disconnect/disconnectAsync,the account (
address,chain,chainId,connector,status, and theisConnected/isConnecting/isReconnecting/isDisconnectedflags),plus
pendingWallet,error, andreset.Two details worth a reviewer's eye:
pendingWalletreports the specific wallet mid-connect, so the UI can showa pending state on the button the user actually clicked. It's gated on
isPendingbecause react-query'svariablesoutlive the mutation and wouldotherwise keep naming a wallet after the attempt settled.
'use client'directive, deliberately. tsup silently strips it, andmaking it survive would be wrong anyway: the bundle is a single file, so the
directive would be hoisted over
createWalletLinkConfigand make it aclient-only export, breaking
cookieToInitialState(config, ...), which has torun in a Server Component and is exactly what the SSR cookie storage exists to
serve. The hook is client-only regardless; the calling component supplies the
boundary. See "Follow-ups" below.
Fix:
transportsmust cover every chaintransportswasRecord<number, Transport>, which is looser than theRecord<chains[number]['id'], Transport>wagmi itself enforces. A map missing achain compiled clean and then threw
TypeError: rest.transports[chainId] is not a functionfrom inside wagmi, thefirst time anything touched that chain, far from the cause.
Keying it to
chainsrestores the compile-time check, and aconsttypeparameter narrows the chain ids to literals so the error names the missing chain:
Omitting
transportsstill generates a complete set ofhttp()defaults.Testing
typecheck,lint,format:check, andbuildall pass. Verified by probe thata partial
transportsmap is now rejected at compile time while a complete mapand an omitted one both compile; smoke-tested the built CJS bundle for its
exports and for no regression in the config.
Summary by CodeRabbit