feat: support explicit chain configuration in UI kit (Sepolia, Gnosis, local)#5
feat: support explicit chain configuration in UI kit (Sepolia, Gnosis, local)#5franrolotti wants to merge 4 commits intomainfrom
Conversation
✅ Deploy Preview for breadcoopstorybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🤖 AI Code ReviewCode Review: Explicit Chain Configuration Support 1. SummaryThis PR successfully migrates the Bread UI kit from an 2. Code QualityArchitectureDuplicated logic: Both // src/utils/chains.ts
export function resolveChain(chainId: number): Chain {
const chains = [gnosis, anvil, sepolia];
return chains.find(c => c.id === chainId) ?? sepolia;
}Missing context defaults: The provider destructures // Add sensible defaults in BreadUIKitProvider
const resolvedSupportedChainIds = supportedChainIds ?? [chainId ?? (isProd ? 100 : 31337)];Surprising fallback behavior: ReadabilityThe /** @deprecated Chain behavior is now controlled via BreadUIKitProvider config. */
isProd?: boolean;The 3. SecurityBlock explorer URL construction: The account widget constructs URLs with: const accountUrl = explorerUrl ? `${explorerUrl}/address/${userAddress || ""}` : undefined;
const explorerUrl = chain.blockExplorers?.default.url;
if (explorerUrl && !URL.canParse(explorerUrl)) {
console.error("Invalid explorer URL in chain config");
return undefined;
}Chain switching error handling: The switch-chain flow logs errors to console but doesn't surface them to users. Failed network switches should propagate to the UI so users aren't left wondering why nothing happened. 4. Suggestions
Type safety nit: In const currentChainId = walletChainId
? parseInt(walletChainId.split(":")[1], 10)
: undefined;
if (currentChainId && isNaN(currentChainId)) {
// handle malformed chain ID
}Overall AssessmentSolid migration that achieves its goals. The main blockers are the missing |
PR Review:
|
Summary
This PR removes
isProd-driven chain behavior from critical auth/read/status flows and introduces explicit chain configuration viaBreadUIKitProvider, so Sepolia (11155111) is supported as a first-class network without breaking Gnosis (100) or local (31337).What changed
1) Provider-level explicit chain config
chainIdandsupportedChainIdssupport inBreadUIKitProvider.isProd(true -> 100,false -> 31337).isProd-derived chain path.2) Login / switch-chain flow
Change networknow switches to configuredchainIdfrom context.isProddependency from login button flow.3) Connected user status logic
supportedChainIds.4) Read hooks
useBreadBalancenow reads with contextchainId(noisProdchain derivation).5) Account widget chain hardcoding removed
chain.blockExplorers?.default.urlchain.name6) Docs + helper updates
getActiveChainIdhelper to support explicit numeric chain IDs while retaining legacy boolean fallback.Expected behavior after this PR
11155111)100supportedChainIds100)31337)Backward compatibility
isProdfallback remains supported for existing consumers.chainId(+ optionalsupportedChainIds).