-
Notifications
You must be signed in to change notification settings - Fork 14
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
[TASK-8097] feat: order wallet cards #627
Conversation
First peanut wallet, then external wallets by date created
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe pull request introduces a sorting mechanism for wallet arrays in the Changes
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 (1)
src/context/walletContext/walletContext.tsx (1)
113-122
: Improve the sorting implementation for better maintainability and robustness.The current sorting logic can be enhanced in several ways:
- .sort((a, b) => { - if (interfaces.AccountType.PEANUT_WALLET === a.account_type) { - return -1 - } else if (interfaces.AccountType.PEANUT_WALLET === b.account_type) { - return 1 - } - const dateA = new Date(a.created_at) - const dateB = new Date(b.created_at) - return dateA.getTime() - dateB.getTime() - }) + // Extract the sort function for better maintainability + const sortWallets = useMemo(() => (a: typeof user.accounts[0], b: typeof user.accounts[0]) => { + // Simplify the Peanut wallet comparison + if (a.account_type !== b.account_type) { + return a.account_type === interfaces.AccountType.PEANUT_WALLET ? -1 : 1 + } + // Handle potential invalid dates + const dateA = new Date(a.created_at).getTime() + const dateB = new Date(b.created_at).getTime() + return isNaN(dateA) || isNaN(dateB) ? 0 : dateA - dateB + }, []) + + // Use the memoized sort function + .sort(sortWallets)This refactor:
- Extracts the sort function for better maintainability
- Simplifies the Peanut wallet comparison
- Handles potential invalid dates
- Memoizes the sort function to prevent unnecessary re-sorting
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/context/walletContext/walletContext.tsx
(1 hunks)
🔇 Additional comments (1)
src/context/walletContext/walletContext.tsx (1)
113-122
: Add tests for the wallet sorting logic.To ensure the sorting behavior remains correct, consider adding unit tests that verify:
- Peanut wallets are always sorted first
- Non-Peanut wallets are correctly sorted by creation date
- The sorting handles edge cases (invalid dates, missing properties)
Would you like me to help create the test cases for the sorting logic?
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.
Logic looks good. Can you double check that we also use this in the wallet header, not just in home screen cards?
Wallet header uses the same wallet list from the wallet context so it should also be ordered |
First peanut wallet, then external wallets by date created
Summary by CodeRabbit