Skip to content

[TASK-7461] feat: add wallet header component#593

Merged
kushagrasarathe merged 2 commits intopeanut-walletfrom
feat/wallet-header
Dec 31, 2024
Merged

[TASK-7461] feat: add wallet header component#593
kushagrasarathe merged 2 commits intopeanut-walletfrom
feat/wallet-header

Conversation

@kushagrasarathe
Copy link
Copy Markdown
Contributor

@kushagrasarathe kushagrasarathe commented Dec 27, 2024

  • added wallet header component

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced WalletHeader and HomeHeader components for enhanced wallet management and navigation.
    • Added CopyToClipboard component for easy text copying functionality.
    • New button variant 'yellow' for additional styling options.
    • New icons: arrow-down-filled and wallet added for improved UI representation.
    • Optional hideCloseButton property in modals for customizable close button visibility.
  • Bug Fixes

    • Reorganized imports and exports for clarity across various components.
  • Chores

    • Updated Tailwind CSS configuration with new shades of purple and yellow, along with a new button style.

@vercel
Copy link
Copy Markdown

vercel bot commented Dec 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
peanut-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 31, 2024 0:44am

@notion-workspace
Copy link
Copy Markdown

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 27, 2024

Walkthrough

This pull request introduces several enhancements to the application's user interface and component structure. The changes primarily focus on wallet management, adding a new WalletHeader component, updating icon exports, introducing a new button variant, and implementing a copy-to-clipboard functionality. The modifications span multiple files, including the home page, icons index, button component, and various global components, while maintaining existing functionality and logic.

Changes

File Change Summary
src/app/(mobile-ui)/home/page.tsx Added WalletHeader component to the render output. Reorganized import statements.
src/assets/icons/index.ts Reordered and updated icon exports, added new icons: ETHEREUM_ICON, GAS_ICON, Wallet_ICON. Removed GITHUB_ICON and GITHUB_INVERTED_ICON.
src/components/0_Bruddle/Button.tsx Added 'yellow' variant to ButtonVariant type and buttonVariants record.
src/components/Global/CopyToClipboard/index.tsx New component for copying text to clipboard with state management.
src/components/Global/Icon/index.tsx Added new icons: arrow-down-filled and wallet. Reordered import statements.
src/components/Global/Modal/index.tsx Added optional hideCloseButton prop to control close button visibility.
src/components/Global/WalletHeader/index.tsx New component for wallet header with wallet selection and management. Added WalletEntryCard and AddNewWallet components.
tailwind.config.js Added new purple color shade and yellow button style.

Sequence Diagram

sequenceDiagram
    participant User
    participant WalletHeader
    participant WalletModal
    participant WalletEntryCard
    
    User->>WalletHeader: Click wallet button
    WalletHeader->>WalletModal: Open wallet selection
    WalletModal->>WalletEntryCard: Display wallet list
    User->>WalletEntryCard: Select wallet
    WalletEntryCard->>WalletHeader: Update selected wallet
    WalletModal->>WalletHeader: Close modal
Loading

Suggested labels

Being worked on

Suggested reviewers

  • Hugo0

Poem

🐰 A Rabbit's Wallet Waltz 🐰
With headers bright and icons light,
Our wallets dance in pure delight.
A yellow button, a copy's gleam,
Blockchain magic, a coder's dream!
Hop along the crypto way! 🚀

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (6)
src/components/Global/CopyToClipboard/index.tsx (2)

5-9: Consider renaming “fill” prop for clarity.
The prop name “fill” may be ambiguous, especially for newcomers who might expect a “color” prop. Renaming this prop to something more explicit like “iconColor” or “iconFillColor” can help clarify its purpose.


22-30: Provide an accessible label or aria attribute for the Icon.
Because Icon usage here relies on the onClick event, some users relying on screen readers might not understand what this icon does. Adding an aria-label or an accessible tooltip ensures that all users can recognize the behavior of this component.

src/assets/icons/index.ts (1)

5-6: Unify or confirm naming conventions for icon exports.
Both uppercase and mixed-case identifiers (e.g., Wallet_ICON) are present. Consistently using an uppercase or PascalCase scheme for all icon exports could improve readability and maintainability.

Also applies to: 8-9, 17-17

src/components/Global/WalletHeader/index.tsx (3)

31-38: Efficient sorting approach
Using useMemo and a simple comparator to place the selected wallet at the top is a clean solution. Ensure large wallet lists won't degrade performance—check for any potential scaling issues if the user might have numerous wallets.


49-67: Yellow variant usage in Button
Leveraging the new 'yellow' variant is consistent with the updated Tailwind class .btn-yellow. This approach keeps styling consistent across the UI.

Optional: If the project style guide requires CTA alignment or descriptive text for accessibility, consider adding ARIA labels or informative text on the button if it’s critical for screen readers.


109-159: WalletEntryCard

  1. The dynamic background for the active wallet is a nice visual cue.
  2. The CopyToClipboard integration is consistent with the rest of the code.
  3. The usage of username for Peanut addresses is straightforward.

Potential improvement:

  • If the list grows large, consider virtualization or lazy rendering.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5baf56c and b58faa5.

⛔ Files ignored due to path filters (1)
  • src/assets/icons/wallet.svg is excluded by !**/*.svg
📒 Files selected for processing (8)
  • src/app/(mobile-ui)/home/page.tsx (2 hunks)
  • src/assets/icons/index.ts (1 hunks)
  • src/components/0_Bruddle/Button.tsx (2 hunks)
  • src/components/Global/CopyToClipboard/index.tsx (1 hunks)
  • src/components/Global/Icon/index.tsx (2 hunks)
  • src/components/Global/Modal/index.tsx (4 hunks)
  • src/components/Global/WalletHeader/index.tsx (1 hunks)
  • tailwind.config.js (2 hunks)
🔇 Additional comments (16)
src/assets/icons/index.ts (1)

5-6: Verify that references to the re-exported icons remain consistent.
The reintroduction or reorganization of ETHEREUM_ICON, GAS_ICON, and Wallet_ICON could affect components referencing these icons. Please confirm that all relevant imports and usage throughout the codebase are up to date and do not rely on removed exports.

Also applies to: 8-9, 17-17

✅ Verification successful

All icon references are consistent with the exports

Based on the search results, all references to the icons in question (ETHEREUM_ICON, GAS_ICON, Wallet_ICON, GITHUB_ICON, and GITHUB_INVERTED_ICON) are properly aligned with their exports in src/assets/icons/index.ts. Here's where they are used:

  • ETHEREUM_ICON is used in src/components/Profile/Components/SkeletonPage.tsx
  • Wallet_ICON is used in src/components/Global/WalletHeader/index.tsx
  • GITHUB_ICON and GITHUB_INVERTED_ICON are used in src/components/Global/Footer/consts.ts
  • GAS_ICON is exported but not currently used, which is fine

All imports and usages are consistent with the exports, and there are no broken references or imports relying on removed exports.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for references to old icon exports to ensure they are replaced or removed.
rg "GITHUB_ICON|GITHUB_INVERTED_ICON|ETHEREUM_ICON|GAS_ICON|Wallet_ICON" -A 5

Length of output: 3349

src/components/0_Bruddle/Button.tsx (1)

5-5: Confirm color contrast of the new 'yellow' variant.
The newly introduced 'yellow' variant uses a 'bg-yellow-1' class. Make sure it meets minimum accessibility guidelines and works well with existing text colors, especially on hover states.

Also applies to: 27-27

src/components/Global/Modal/index.tsx (2)

21-21: Ensure user can still close the modal when hideCloseButton is true.
When hideCloseButton is set, the user loses the explicit close button. Confirm that closing the modal via overlay click, keyboard escape, or another button is still possible for a smooth user experience.

Also applies to: 39-39, 104-116


21-21: Good approach for optional close button.
Allowing the modal consumer to hide or show the close button increases flexibility. The default of false is sensible, preserving the existing behavior.

Also applies to: 39-39, 104-116

src/app/(mobile-ui)/home/page.tsx (4)

4-5: Import statements for new header components look good
The imports for WalletHeader and HomeHeader are positioned logically and do not indicate any immediate issues.


9-10: Context imports are valid
Importing useAuth and useWallet seamlessly integrates authentication and wallet functionality into the Home component.


11-14: No apparent issues with utility and library imports
The usage of classnames, framer-motion, next/navigation, and React hooks (useEffect, useRef) is standard and poses no immediate problems.


55-55: Placing WalletHeader above the carousel
Positioning the WalletHeader in this location is consistent with the PR objective to enhance wallet management visibility. Consider adding a quick test or integration check to ensure the user experience remains intuitive on mobile devices.

src/components/Global/WalletHeader/index.tsx (4)

25-26: New 'WalletHeader' component introduced
The state for showing/hiding the modal is straightforward. Good job managing local state here.


41-44: Wallet selection logic
Closing the modal after wallet selection is user-friendly and minimal in complexity. Looks good.


70-104: Modal structure
The modal’s styling, custom classes, and semantic structure look good. It’s beneficial that the background, border, and wrap classes are separated for clarity. Consider verifying that the modal is fully keyboard-navigable.


161-171: AddNewWallet
Simple, clear, and consistent. The icon usage and text provide an obvious entry point to add new wallets.

tailwind.config.js (2)

15-15: New purple color
Adding 4: '#AE7AFF' extends the color palette suitably. Keep verifying that this new color aligns with the design system and is accessible when used against certain backgrounds.


250-252: .btn-yellow utility class
This new utility class follows the existing naming conventions. The hover state to darken the background is consistent with other color variants.

src/components/Global/Icon/index.tsx (2)

2-2: Re-adding twMerge
Uncommenting or adding the twMerge import improves class name management.


205-206: New icons: arrow-down-filled and wallet
Adding these icons follows the established icons mapping. Ensure they appear correctly and are tested in the UI.

Comment on lines +14 to +20
const handleCopy = (e: React.MouseEvent<SVGElement>) => {
e.stopPropagation()
navigator.clipboard.writeText(textToCopy).then(() => {
setCopied(true)
setTimeout(() => setCopied(false), 2000)
})
}
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Handle potential clipboard write failures.
Currently, if navigator.clipboard.writeText fails or is not supported by the browser (e.g., older browsers, certain WebView restrictions), no fallback handling occurs. You may wish to add error handling or a fallback for improved user experience in these cases.

 const handleCopy = (e: React.MouseEvent<SVGElement>) => {
   e.stopPropagation()
-  navigator.clipboard.writeText(textToCopy).then(() => {
-      setCopied(true)
-      setTimeout(() => setCopied(false), 2000)
-  })
+  navigator.clipboard.writeText(textToCopy)
+    .then(() => {
+      setCopied(true)
+      setTimeout(() => setCopied(false), 2000)
+    })
+    .catch(() => {
+      // Optional: fallback to a manual copy command or show an error message
+    })
 }

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use toast here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Hugo0, definitely! Incorporating a toast notification for success (“Copied!”) or failure (e.g., “Failed to copy”) would enhance the user experience. You can trigger a toast in the success callback and within the .catch() block if an error occurs. That way, users receive clear feedback on whether the copy action was successful or, if not, what went wrong.

Copy link
Copy Markdown
Contributor

@Hugo0 Hugo0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for wallet ordering, rest lgtm!

Comment on lines +14 to +20
const handleCopy = (e: React.MouseEvent<SVGElement>) => {
e.stopPropagation()
navigator.clipboard.writeText(textToCopy).then(() => {
setCopied(true)
setTimeout(() => setCopied(false), 2000)
})
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use toast here

<div className="flex w-[100%] flex-col gap-4 sm:w-[90%] sm:gap-2 md:w-[70%] lg:w-[50%]">
<HomeHeader />
<WalletHeader />
<div
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought: The carousel should prob be a component too

classNameWrapperDiv?: string
showPrev?: boolean
onPrev?: () => void
hideCloseButton?: boolean
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Why do we need a hide close button option?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was planning to move the modal to look like sheet for mobile screens, figured that's a little lengthy task and not high priority, for now reverted it to old structure, tracking it to and will tackle in another spirint

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (6)
src/components/Global/WalletHeader/index.tsx (6)

27-27: Remove unused isConnected variable.

The isConnected variable is destructured but only used in the JSX. Consider moving it directly to where it's used to improve code clarity.

-const { wallets, selectedWallet, setSelectedWallet, isConnected } = useWallet()
+const { wallets, selectedWallet, setSelectedWallet } = useWallet()

84-84: Fix duplicate opacity settings.

The button has two opacity modifiers: bg-yellow-4/80 and bg-opacity-20. This might lead to unexpected behavior. Choose one approach for consistency.

-<Button size="small" variant="yellow" className="w-fit bg-yellow-4/80 bg-opacity-20">
+<Button size="small" variant="yellow" className="w-fit bg-yellow-4/20">

78-78: Consider extracting modal styles to constants.

The modal's classWrap contains multiple hardcoded style values. Consider extracting these to constants or a configuration object for better maintainability.

const MODAL_STYLES = {
  wrapper: 'w-full items-center',
  content: 'bg-background rounded-none border-0 p-6 pt-14 w-full max-h-[65vh] md:max-h-full overflow-y-auto'
};

// Usage:
<Modal
  visible={showModal}
  onClose={() => setShowModal(false)}
  className={MODAL_STYLES.wrapper}
  classWrap={MODAL_STYLES.content}
>

114-116: Improve wallet image fallback logic.

The current fallback logic could be more robust. Consider adding error handling for cases where both connector.icon and PeanutWalletIcon fail to load.

const walletImage = useMemo(() => {
-   return isPeanutWallet ? PeanutWalletIcon : connector?.icon || PeanutWalletIcon
+   if (isPeanutWallet) return PeanutWalletIcon
+   if (connector?.icon) return connector.icon
+   return PeanutWalletIcon
}, [isPeanutWallet, connector])

108-157: Consider adding error boundaries.

The WalletEntryCard component handles sensitive wallet information. Consider wrapping it with an error boundary to gracefully handle rendering failures.

Example implementation:

class WalletEntryCardErrorBoundary extends React.Component {
  // ... error boundary implementation
}

// Usage:
<WalletEntryCardErrorBoundary>
  <WalletEntryCard {...props} />
</WalletEntryCardErrorBoundary>

160-169: Enhance accessibility for the AddNewWallet component.

Consider adding ARIA labels and roles to improve accessibility for screen readers.

const AddNewWallet = ({ onClick }: { onClick: () => void }) => (
-   <Card onClick={onClick}>
+   <Card onClick={onClick} role="button" aria-label="Add new wallet">
        <Card.Content className="flex min-h-16 w-full cursor-pointer items-center justify-center gap-3 bg-purple-4 bg-opacity-25 px-4 py-3 hover:bg-opacity-20">
            <div className="flex size-7 items-center justify-center rounded-full border border-n-1">
-               <Icon name="plus" fill="black" className="h-7 w-7" />
+               <Icon name="plus" fill="black" className="h-7 w-7" aria-hidden="true" />
            </div>
            <span className="font-bold">Add wallet</span>
        </Card.Content>
    </Card>
)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b58faa5 and c16e2ee.

📒 Files selected for processing (3)
  • src/components/Global/Modal/index.tsx (2 hunks)
  • src/components/Global/WalletHeader/index.tsx (1 hunks)
  • tailwind.config.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Global/Modal/index.tsx
🔇 Additional comments (2)
tailwind.config.js (1)

15-15: LGTM: Color palette extensions

The new color additions (purple-4: #AE7AFF and yellow-4: #FAE8A4) follow the existing color scheme pattern and naming conventions.

Also applies to: 21-21

src/components/Global/WalletHeader/index.tsx (1)

1-24: LGTM! Imports and interface definitions are well-structured.

The imports are properly organized, and the WalletEntryCardProps interface is well-defined with appropriate types.

Comment on lines +251 to +253
'.btn-yellow': {
'@apply btn bg-yellow-1 text-n-1 fill-n-1 hover:bg-yellow-1/90': {},
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

The btn-yellow class is defined but not used in the codebase

The verification shows that the .btn-yellow class is only defined in tailwind.config.js but is not currently used in any component files. While the implementation follows the correct pattern, it appears to be unused at the moment.

  • The class is defined in tailwind.config.js but no usage was found in any of the source files
  • Consider either:
    • Adding the intended usage of this button variant in the relevant components
    • Removing the unused class definition if it's not needed
🔗 Analysis chain

LGTM: Button variant implementation

The new .btn-yellow variant follows the established button styling patterns and correctly implements hover states. The implementation is consistent with other button variants in the codebase.

Let's verify the usage of this new button variant:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage of the new btn-yellow class
# Expected: Find components using this new button variant

rg -l "btn-yellow" --type tsx --type jsx

Length of output: 68


Script:

#!/bin/bash
# Let's try a different approach to find any usage of btn-yellow class
# Search in all files without type restriction as the file extensions might vary
rg "btn-yellow"

Length of output: 67


Script:

#!/bin/bash
# Let's also check the file extensions in the repository to understand what we should look for
fd -e tsx -e jsx -e js -e ts

Length of output: 13065

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants