🩹 app: avoid zero address contract reads#802
Conversation
🦋 Changeset detectedLatest commit: 4aee44e The changes in this PR will be included in the next version bump. 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 |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughRemoved zeroAddress fallbacks across mobile components and utilities: hooks and contract calls now receive raw addresses or undefined, and queries/args are gated on actual address presence. Added a changeset documenting the patch release. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 of ChangesHello @cruzdanilo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refines how contract-related data is fetched by preventing queries from being initiated with a zero address. By ensuring that contract read hooks and refetch operations are only executed when a valid account address and necessary credentials are available, the changes enhance the application's robustness, reduce potential errors from invalid contract calls, and optimize network resource usage. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request consistently removes the unnecessary ?? zeroAddress fallback in wagmi hooks across multiple files. The changes correctly rely on the enabled query option to prevent contract reads with a zero address, which improves code clarity and robustness. I've found one place where this pattern was missed, and I've left a comment with a suggestion to fix it for consistency.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #802 +/- ##
==========================================
- Coverage 69.34% 69.34% -0.01%
==========================================
Files 208 208
Lines 7096 7092 -4
Branches 2264 2251 -13
==========================================
- Hits 4921 4918 -3
+ Misses 1991 1990 -1
Partials 184 184
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
src/components/pay-mode/PaySelector.tsx (1)
42-42:⚠️ Potential issue | 🟡 MinorMissed
zeroAddressfallback inPaySelector— inconsistent with the PR's objective.
useReadPreviewerExactlyin thePaySelectorcomponent still passesaddress ?? zeroAddressand has noaddress-presence gate, so a contract read against0x000…000fires wheneveraddressisundefined.🩹 Proposed fix
- const { data: markets } = useReadPreviewerExactly({ address: previewerAddress, args: [address ?? zeroAddress] }); + const { data: markets } = useReadPreviewerExactly({ + address: previewerAddress, + args: address ? [address] : undefined, + query: { enabled: !!address }, + });src/components/card/Card.tsx (1)
118-121:⚠️ Potential issue | 🟡 MinorMissed zero-address contract read:
useReadPreviewerExactlystill falls back tozeroAddress.This call has no
enabledguard and will unconditionally hit the RPC with0x0000…as the account argument whenaddressis undefined — the exact pattern the PR set out to eliminate.🛠️ Suggested fix
const { data: markets, refetch: refetchMarkets, isFetching: isFetchingMarkets, } = useReadPreviewerExactly({ address: previewerAddress, - args: [address ?? zeroAddress], + args: address ? [address] : undefined, + query: { enabled: !!address }, });src/components/home/Home.tsx (1)
103-103:⚠️ Potential issue | 🟡 MinorMissed zero-address contract read:
useReadPreviewerExactlystill falls back tozeroAddress.Same pattern as
Card.tsx(line 120): this call has noenabledguard and fires unconditionally with0x0000…as the account argument whenaccountis undefined, keeping thezeroAddressimport alive.🛠️ Suggested fix
const { data: markets, refetch: refetchMarkets, isPending: isPendingPreviewer, - } = useReadPreviewerExactly({ address: previewerAddress, args: [account ?? zeroAddress] }); + } = useReadPreviewerExactly({ + address: previewerAddress, + args: account ? [account] : undefined, + query: { enabled: !!account }, + });With this, the
zeroAddressimport on line 11 can also be removed.src/components/pay-mode/Pay.tsx (1)
339-359:⚠️ Potential issue | 🟡 MinorResidual
?? zeroAddressinuseSimulateContractargs is dead code — worth cleaning up for consistency.Line 342 still passes
selectedAsset.address ?? zeroAddressas thecollateralargument. The mode computation at lines 111–122 requiresselectedAsset.addressto be truthy formodeto ever equal"legacyCrossRepay", so the?? zeroAddressbranch is unreachable. Removing it (and the now-unusedzeroAddressimport, once line 433 is also addressed) would complete the PR's stated goal.🧹 Proposed fix
- args: [maturity ?? 0n, selectedAsset.address ?? zeroAddress], + args: [maturity ?? 0n, selectedAsset.address as `0x${string}`],Or, if the TypeScript narrowing from the mode guard is already sufficient to satisfy the type checker, a non-null assertion
selectedAsset.address!is also acceptable here.
Summary by CodeRabbit