refactor: replace withWalletStatusVerifier HoC with useWalletStatus hook#427
refactor: replace withWalletStatusVerifier HoC with useWalletStatus hook#427fernandomg wants to merge 7 commits intodevelopfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Refactors wallet-status gating from the withWalletStatusVerifier HoC pattern to a state-only useWalletStatus hook, keeping WalletStatusVerifier as the primary wrapper API while making shared buttons self-contained. Also includes related demo migrations and documentation/test configuration updates.
Changes:
- Added
useWalletStatushook and refactoredWalletStatusVerifier,TransactionButton, andSignButtonto use it (HoC removed). - Extracted a shared
SwitchChainButtonand migrated demos to use<WalletStatusVerifier>. - Reduced TypeDoc warnings via
blockTagsconfig updates and improved test typing viatsconfig.jsontypes.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| typedoc.json | Expands recognized TSDoc block tags to reduce TypeDoc warnings. |
| tsconfig.json | Adds jest-dom Vitest matcher types to TS global types. |
| src/hooks/useWalletStatus.ts | Introduces hook providing wallet gating state based on useWeb3Status. |
| src/hooks/useWalletStatus.test.ts | Unit tests for useWalletStatus behavior and chain selection. |
| src/components/sharedComponents/ui/SwitchChainButton.tsx | Extracts reusable styled “switch chain” button. |
| src/components/sharedComponents/WalletStatusVerifier.tsx | Refactors wrapper component to use useWalletStatus (HoC removed). |
| src/components/sharedComponents/WalletStatusVerifier.test.tsx | Adds tests covering fallback, chain switch UI, and children rendering. |
| src/components/sharedComponents/TransactionButton.tsx | Internalizes wallet verification and chain switching before sending tx. |
| src/components/sharedComponents/TransactionButton.test.tsx | Adds tests for connect fallback, chain switch UI, and ready state rendering. |
| src/components/sharedComponents/SignButton.tsx | Internalizes wallet verification and chain switching before signing. |
| src/components/sharedComponents/SignButton.test.tsx | Adds tests for connect fallback, chain switch UI, and ready state rendering. |
| src/components/pageComponents/home/Examples/demos/TransactionButton/NativeToken.tsx | Migrates demo from HoC usage to <WalletStatusVerifier>. |
| src/components/pageComponents/home/Examples/demos/TransactionButton/ERC20ApproveAndTransferButton/index.tsx | Migrates demo from HoC to wrapper; keeps suspense wrapper. |
| src/components/pageComponents/home/Examples/demos/OptimismCrossDomainMessenger/index.tsx | Migrates demo from HoC usage to <WalletStatusVerifier>. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...pageComponents/home/Examples/demos/TransactionButton/ERC20ApproveAndTransferButton/index.tsx
Outdated
Show resolved
Hide resolved
Yay. |
New state-only hook that answers "is the wallet ready to interact with this chain?" Built on top of useWeb3Status. Closes part of #303
The withWalletStatusVerifier HoC is removed. The WalletStatusVerifier wrapper component now uses the useWalletStatus hook internally. Extracts shared SwitchChainButton to ui/SwitchChainButton.tsx. Same external API — no breaking change for wrapper consumers. Closes part of #303
TransactionButton now uses useWalletStatus hook directly instead of being wrapped with withWalletStatusVerifier HoC. Adds optional chainId, fallback, and switchChainLabel props. Closes part of #303
SignButton now uses useWalletStatus hook directly instead of withWalletStatusVerifier HoC. Adds optional chainId, fallback, and switchChainLabel props. Closes part of #303
… HoC NativeToken, ERC20ApproveAndTransferButton, and OptimismCrossDomainMessenger now use the declarative <WalletStatusVerifier> wrapper instead of withWalletStatusVerifier. Suspense HoCs (withSuspense, withSuspenseAndRetry) are preserved. Closes #303
- Add targetChainId to useWalletStatus return, removing unsafe `as ChainsIds` casts from all consumers - Fix onSuccess callback in ERC20ApproveAndTransferButton demo (was returning refetchBalance instead of passing it directly)
| import { useSignMessage } from 'wagmi' | ||
|
|
||
| interface SignButtonProps extends Omit<ButtonProps, 'onError'> { | ||
| /** Target chain ID for wallet status verification. */ |
There was a problem hiding this comment.
I'm not sure we need all these comments, the prop names are descriptive enough.
11a06e7 to
2bbdfd4
Compare
| import { useWaitForTransactionReceipt } from 'wagmi' | ||
|
|
||
| interface TransactionButtonProps extends ButtonProps { | ||
| /** Target chain ID for wallet status verification. */ |
| import PrimaryButton from '@/src/components/sharedComponents/ui/PrimaryButton' | ||
| import { chakra } from '@chakra-ui/react' | ||
|
|
||
| const SwitchChainButton = chakra(PrimaryButton, { |
There was a problem hiding this comment.
(feel free to ignore)
Do wee need this as a separate component for this? I don't remember if PrimaryButton has variants (we should use it if it does), but also I don't know if the changes here are so profound that merit a new component.
Maybe we could just use PrimaryButton and be done with it.
| /** Custom fallback when wallet needs connection. Defaults to ConnectWalletButton. */ | ||
| fallback?: ReactElement | ||
| /** Alternative label for the button. */ | ||
| label?: string |
There was a problem hiding this comment.
label is not used and destructured with ...restProps, it should be removed
| @@ -48,75 +29,22 @@ const WalletStatusVerifier: FC<WalletStatusVerifierProps> = ({ | |||
| fallback = <ConnectWalletButton />, | |||
| labelSwitchChain = 'Switch to', | |||
There was a problem hiding this comment.
This is called switchChainLabel in SignButton.tsx and TransactionButton.tsx, probably better if all are called the same.
|
The demo for Optimism throws if the wallet's not connected: possibly because Maybe wrapping with I think something similar should be done in |
gabitoesmiapodo
left a comment
There was a problem hiding this comment.
I left a few comments, I think only the last one is critical.
Summary
Replaces the
withWalletStatusVerifierHoC with a newuseWalletStatushook. Shared components (TransactionButton,SignButton) now internalize wallet verification — they're fully self-contained. TheWalletStatusVerifierwrapper component stays as the primary external API for app developers and agents.Closes #303
Changes
useWalletStatushook — state-only, built on top ofuseWeb3StatusWalletStatusVerifierrefactored to use the hook, HoC export removedTransactionButtonandSignButtoninternalize wallet verification via the hook<WalletStatusVerifier>wrapperSwitchChainButtonextracted to sharedui/to avoid duplicationblockTagsconfig fixed (reduced warnings from 330 to 9)Design decisions
WalletStatusVerifierwrapper for external consumers (declarative, agent-friendly),useWalletStatushook for internal/advanced useChainsIdstype used throughout instead of plainnumberAcceptance criteria
withWalletStatusVerifierHoC removed — zero references insrc/WalletStatusVerifierwrapper component API unchangedTransactionButtonandSignButtonself-contained with wallet verificationTest plan
pnpm test— 12 files, 67 tests, all greenpnpm tsc --noEmit— cleanpnpm typedoc:build— 9 warnings (pre-existing, unrelated files)pnpm docs:build— successgrep -r "withWalletStatusVerifier" src/— zero resultsBreaking changes
withWalletStatusVerifierremoved. All consumers updated in this PR. Not a public API yet (dAppBooster is a template, not a published SDK).Checklist