-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: only use 1 source wallet | memoize components that call balances #255
Conversation
Warning Rate limit exceeded@chalabi2 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 2 minutes and 57 seconds before requesting another review. ⌛ 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. 📒 Files selected for processing (2)
WalkthroughThe pull request refactors multiple components related to token transfers and wallet connections. Osmosis-specific props have been removed across several components, and component exports are now wrapped with Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (6)
components/bank/forms/ibcSendForm.tsx (6)
82-84
: Check error handling for hooking.
These lines correctly retrieve signer, tx, and fee estimation from the chosen chain, but consider adding fallback or error handling if the chain is unavailable or undefined.
89-89
: Remove or replace console.log for production.
It’s best to switch to a logging mechanism or remove console logs to avoid exposing sensitive data in production.- console.log(balances); + // console.log(balances); // Remove or replace for production
91-91
: Handle potential signer retrieval failures.
getOfflineSignerAmino might throw if the chain is not found or user rejects the wallet connection. Consider a try/catch or user feedback.
110-114
: Optimize filter for repeated toLowerCase calls.
Filtering balances is straightforward, but repeatedly calling toLowerCase can be factored out for micro-performance gains if the lists or search terms are large.const lowerCaseSearchTerm = searchTerm.toLowerCase(); return balances?.filter(token => { const displayName = token.metadata?.display ?? token.denom; - return displayName.toLowerCase().includes(searchTerm.toLowerCase()); + return displayName.toLowerCase().includes(lowerCaseSearchTerm); });
122-122
: Consider showing a loading indicator.
Returning null avoids rendering, but a small loader or user feedback might improve UX when balances are loading or no initial token is found.
216-216
: Use a stricter type for user.
(user: { address: any }) is very broad. If possible, define a type with address: string to reduce potential runtime issues.- addressList: userAddresses.map((user: { address: any }) => user.address), + type UserAddress = { address: string; chainID: string }; + addressList: userAddresses.map((user: UserAddress) => user.address),
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
components/bank/components/sendBox.tsx
(5 hunks)components/bank/components/tokenList.tsx
(4 hunks)components/bank/forms/ibcSendForm.tsx
(8 hunks)components/bank/modals/sendModal.tsx
(5 hunks)components/react/modal.tsx
(2 hunks)components/wallet.tsx
(2 hunks)pages/bank.tsx
(4 hunks)
🔇 Additional comments (23)
components/bank/forms/ibcSendForm.tsx (4)
38-38
: Consider verifying chain existence.
When calling useChain(env.chain), ensure that env.chain is a valid ID recognized by @cosmos-kit. Otherwise, getOfflineSignerAmino may fail.
56-56
: Clarify the isGroup prop usage.
Confirm that isGroup is properly passed in and used consistently. If it’s optional or toggles group logic, testing edge cases would be advisable.
[approve]
118-119
: Ensure fallback for no tokens scenario.
This logic is sound; just confirm the UI or flow is acceptable when balances are empty or selectedDenom is not present.
198-207
: Validate userAddresses structure.
Make sure chainID and address are valid. If user input can be manipulated, consider sanitizing or ensuring addresses are valid.components/bank/modals/sendModal.tsx (5)
1-1
: Check for side-effect imports.
useEffect and useMemo were added; ensure they are both necessary and keep your import list minimal and explicit.
22-22
: Good use of React.memo.
Wrapping the component in React.memo helps prevent unnecessary re-renders, improving performance.
54-55
: Memoize balances array.
Using memoizedBalances is a neat approach. Confirm that balances are not mutated elsewhere, which could break memoization.
95-95
: Pass memoizedBalances to child.
This is consistent with the new changes. The child components can now skip re-renders when balances remains unchanged.
129-129
: Ensure final export remains typed.
Returning null is valid for SSR checks. Wrapping the entire component with React.memo is correct.components/bank/components/sendBox.tsx (6)
7-7
: Avoid overshadowing React.
If other local variables named React are in use, ensure they're not overshadowed. Otherwise this import is standard practice.
17-17
: React.memo for performance.
Wrapping SendBox with React.memo is a good improvement, preventing rerenders when props do not change.
68-68
: Use useMemo for balances.
Good practice; helps with performance. Just confirm that the balances array is truly immutable to leverage memo effectively.
128-128
: Correct usage of memoizedBalances.
Passing memoizedBalances to IbcSendForm helps ensure we don’t trigger excessive re-renders.
141-141
: Consistent memo usage across child forms.
Same logic applies for SendForm. Confirm that references to balances are replaced or updated if we rely on reactivity.
156-156
: Finalizing with memo export.
The file’s structure looks clean, and the new export with React.memo is consistent with your optimization approach.components/bank/components/tokenList.tsx (2)
22-22
: Good performance optimization using memoization!The component is now memoized using
React.memo
and the balances prop is memoized usinguseMemo
. This will prevent unnecessary re-renders when parent components update with the same balances data.Also applies to: 84-84
223-223
: Consistent usage of memoized value.The memoized balances are correctly passed to the SendModal component, maintaining the performance optimization throughout the component tree.
components/wallet.tsx (2)
5-5
: Good simplification of wallet connection handling!The switch from
useChains
touseChain
aligns with the single source wallet approach, making the code more focused and easier to maintain.Also applies to: 40-40
95-98
: Clean wallet state management.Direct access to wallet properties through
useChain
simplifies the code by removing the need to manage multiple chain states.pages/bank.tsx (2)
32-32
: Good simplification of wallet state management!Using
useChain
with a single chain name simplifies the code and aligns with the PR's objective of using a single source wallet.
34-34
: Consistent address handling across hooks.The wallet address is consistently obtained from the single chain and properly used across all hooks and child components.
Also applies to: 39-39, 89-89, 230-230, 242-242
components/react/modal.tsx (2)
95-98
: Good simplification of wallet repository access!Direct access to the current wallet from
walletRepo
simplifies the code by removing the need to manage multiple chain states.
447-447
: Clean disconnect handling.The disconnect function call is properly updated to use the current wallet's disconnect method directly.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #255 +/- ##
==========================================
+ Coverage 55.06% 55.11% +0.04%
==========================================
Files 205 205
Lines 17654 17432 -222
==========================================
- Hits 9722 9608 -114
+ Misses 7932 7824 -108 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
components/bank/forms/__tests__/ibcSendForm.test.tsx (1)
46-74
: Consider updating defaultProps and adding new test cases.Given the reversion to single chain usage:
- Consider removing unused multi-chain related props from defaultProps (e.g., chains object with multiple entries).
- Add test cases for error scenarios specific to single chain usage.
components/bank/components/sendBox.tsx (2)
38-63
: Consider using local assets consistently across all chains.While Manifest and Osmosis icons are now using local assets with proper leading slashes, the Axelar icon still uses an external URL. This inconsistency could lead to loading issues if the external resource is unavailable.
Consider downloading and serving the Axelar icon locally:
- icon: 'https://github.com/cosmos/chain-registry/raw/refs/heads/master/axelar/images/axl.svg', + icon: '/axelar.svg',
68-68
: Consider optimizing the balances memoization.The current memoization just wraps the balances array. If the parent component ensures stable references for the balances array, this memoization might be unnecessary.
Verify if the parent component already provides a stable reference for balances. If not, consider transforming the data within the memoization to make it more useful:
- const memoizedBalances = useMemo(() => balances, [balances]); + const memoizedBalances = useMemo(() => + balances.map(balance => ({ + ...balance, + // Add derived/computed properties here if needed + })), + [balances] + );
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
components/bank/components/__tests__/sendBox.test.tsx
(0 hunks)components/bank/components/sendBox.tsx
(6 hunks)components/bank/forms/__tests__/ibcSendForm.test.tsx
(2 hunks)
💤 Files with no reviewable changes (1)
- components/bank/components/tests/sendBox.test.tsx
🔇 Additional comments (5)
components/bank/forms/__tests__/ibcSendForm.test.tsx (3)
19-26
: LGTM! Well-structured mock for next/image.The mock follows best practices by providing a simple img element replacement and proper ESModule configuration.
169-170
: LGTM! Test skip aligns with PR objectives.The test is correctly skipped as it's no longer applicable due to the reversion to single chain usage, as mentioned in the PR objectives.
172-172
: LGTM! Simplified async call.Good simplification of the async/await pattern while maintaining the core test functionality.
components/bank/components/sendBox.tsx (2)
1-37
: LGTM! Good use of React.memo and props cleanup.The component signature changes align well with the PR objectives. Wrapping with React.memo will help prevent unnecessary re-renders, and removing Osmosis-specific props simplifies the interface.
84-156
: LGTM! Consistent use of memoizedBalances.The component correctly uses the memoized balances in both forms while maintaining the existing conditional rendering logic.
This PR
Summary by CodeRabbit