Skip to content

Conversation

jjramirezn
Copy link
Contributor

Check everywhere when the addresses are shortened if we have an ens. If we have a ens we should not shorten it

Copy link

vercel bot commented Oct 8, 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 Oct 8, 2024 8:13pm

Copy link
Contributor

coderabbitai bot commented Oct 8, 2024

📝 Walkthrough

Walkthrough

This pull request introduces modifications across multiple components to standardize the display of recipient addresses by replacing the utility function utils.shortenAddressLong with utils.printableAddress. Additionally, updates were made to error handling and variable naming for clarity. The overall structure and functionality of the components remain unchanged, ensuring consistency in how addresses are presented throughout the application.

Changes

File Path Change Summary
src/components/Claim/Link/Onchain/Confirm.view.tsx Updated recipient's address rendering to use utils.printableAddress.
src/components/Create/Link/Confirm.view.tsx Modified label rendering for recipient's address to use utils.printableAddress when createType is 'direct'.
src/components/Create/Link/Initial.view.tsx Changed recipient address display in recent recipients list to utils.printableAddress and refined error handling.
src/components/Create/Link/Input.view.tsx Updated label for recipient's address to use utils.printableAddress when createType is 'direct'.
src/components/Create/Link/Success.view.tsx Modified success message to display recipient's address using utils.printableAddress.
src/components/Dashboard/components/MobileComponent.tsx Replaced address formatting with utils.printableAddress.
src/components/Dashboard/index.tsx Updated address display in the dashboard to use utils.printableAddress and corrected variable name.
src/components/Profile/Components/TableComponent.tsx Changed address display logic in 'history' tab to use utils.printableAddress.
src/components/Profile/index.tsx Updated address formatting in multiple locations to use utils.printableAddress and altered state initialization.
src/components/Request/Pay/Views/Success.view.tsx Modified recipient address display to use utils.printableAddress and updated useEffect dependencies.
src/utils/general.utils.ts Added printableAddress function and updated shortenAddressLong return type to string.

Possibly related PRs

Suggested labels

Being worked on

Suggested reviewers

  • Hugo0

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 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
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: 2

🧹 Outside diff range and nitpick comments (6)
src/components/Dashboard/index.tsx (1)

115-115: Approved: Address display improved

The change from utils.shortenAddressLong(address) to utils.printableAddress(address) aligns with the PR objective of not shortening ENS names. This improvement ensures that ENS names are displayed in full, enhancing user experience and readability.

Consider adding a comment explaining the behavior of utils.printableAddress for future maintainers, e.g.:

// utils.printableAddress displays full ENS names or shortened addresses
`See all links created and claimed  ${address ? `with ${utils.printableAddress(address)}` : 'on this device'}`
src/components/Claim/Link/Onchain/Confirm.view.tsx (2)

187-187: LGTM! Consider adding a comment for clarity.

The change from utils.shortenAddressLong to utils.printableAddress aligns well with the PR objective of not shortening ENS names. This modification ensures that ENS names are displayed in full while still potentially shortening regular addresses.

Consider adding a brief comment explaining the purpose of utils.printableAddress, such as:

// Use printableAddress to display full ENS names or shortened addresses
{recipient.name ? recipient.name : utils.printableAddress(recipient.address ?? '')}

This would help future developers understand the intent behind using this specific function.


Line range hint 1-324: Overall impact: Improved address display without side effects

The change to use utils.printableAddress instead of utils.shortenAddressLong successfully addresses the PR objective of not shortening ENS names. This modification enhances the user experience by displaying ENS names in full while likely still shortening regular addresses.

The localized nature of this change means that:

  1. It doesn't introduce any apparent negative impacts on the component's functionality or performance.
  2. No other modifications to the component were necessary to accommodate this change.

To further improve the component's robustness and maintainability, consider:

  1. Documenting the expected behavior of utils.printableAddress in the project's documentation or as a comment near its implementation.
  2. Adding unit tests to verify that ENS names and regular addresses are displayed correctly in various scenarios.
src/components/Create/Link/Confirm.view.tsx (1)

189-189: LGTM! Consider a minor refactor for clarity.

The change successfully implements the requirement to not shorten ENS names while standardizing the display of addresses using utils.printableAddress. This aligns well with the PR objectives.

For improved readability, consider extracting the address display logic into a separate function:

const getDisplayAddress = (name: string | undefined, address: string | undefined) => {
  if (name?.endsWith('.eth')) return name;
  return utils.printableAddress(address ?? '');
};

// Then use it in the JSX:
`Send to ${getDisplayAddress(recipient.name, recipient.address)}`

This refactoring would make the code more maintainable and easier to understand at a glance.

src/components/Profile/Components/TableComponent.tsx (1)

Verify address handling across additional files

The initial change in TableComponent.tsx is effective. However, address shortening is also used in multiple other locations. To ensure consistency across the codebase, please update the following instances to use the new printableAddress function:

  • src/utils/general.utils.ts
  • src/components/Request/Pay/Views/Success.view.tsx
  • src/components/Claim/Generic/SenderClaim.view.tsx
  • src/components/Request/Pay/Views/Initial.view.tsx
  • src/components/Claim/Link/Initial.view.tsx
  • src/components/Claim/Link/Onchain/Confirm.view.tsx
  • src/components/Claim/Link/Onchain/Success.view.tsx
  • src/components/Global/Header/index.tsx
  • src/components/Global/ImageGeneration/LinkPreview.tsx

Updating these instances will ensure uniform address handling throughout the application.

🔗 Analysis chain

Line range hint 1-268: Verify address handling across the codebase

The change in this component looks good, but to fully meet the PR objective, we should ensure that all instances of address display throughout the codebase are using the new printableAddress function.

Run the following script to identify other potential locations where address shortening might still be in use:

If any results are found, consider updating those instances to use printableAddress as well.


🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for instances of address shortening across the codebase
rg --type typescript 'shortenAddress|shortenAddressLong'

Length of output: 93


Script:

#!/bin/bash
# Search for instances of address shortening across TypeScript files
rg --glob "*.ts" --glob "*.tsx" 'shortenAddress|shortenAddressLong'

Length of output: 2281

src/utils/general.utils.ts (1)

20-23: LGTM: New printableAddress function addresses ENS name handling.

The new printableAddress function effectively addresses the PR objective of not shortening ENS names. It provides a consistent way to display addresses, whether they are ENS names or regular addresses. The implementation is concise and clear.

Consider adding a check for null or undefined input to make the function more robust:

 export const printableAddress = (address: string): string => {
+    if (!address) return '';
     if (address.endsWith('.eth')) return address
     return shortenAddressLong(address)
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7439b76 and 7bf84d5.

📒 Files selected for processing (11)
  • src/components/Claim/Link/Onchain/Confirm.view.tsx (1 hunks)
  • src/components/Create/Link/Confirm.view.tsx (1 hunks)
  • src/components/Create/Link/Initial.view.tsx (1 hunks)
  • src/components/Create/Link/Input.view.tsx (1 hunks)
  • src/components/Create/Link/Success.view.tsx (1 hunks)
  • src/components/Dashboard/components/MobileComponent.tsx (1 hunks)
  • src/components/Dashboard/index.tsx (2 hunks)
  • src/components/Profile/Components/TableComponent.tsx (1 hunks)
  • src/components/Profile/index.tsx (4 hunks)
  • src/components/Request/Pay/Views/Success.view.tsx (1 hunks)
  • src/utils/general.utils.ts (2 hunks)
🧰 Additional context used
📓 Learnings (1)
src/components/Request/Pay/Views/Success.view.tsx (3)
Learnt from: jjramirezn
PR: peanutprotocol/peanut-ui#409
File: src/components/Request/Pay/Views/Success.view.tsx:23-23
Timestamp: 2024-10-08T20:13:44.480Z
Learning: In the `SuccessView` component, `transactionHash` remains constant because we are in a success view, so it's unnecessary to include it in the dependency array of `useEffect` hooks.
Learnt from: jjramirezn
PR: peanutprotocol/peanut-ui#409
File: src/components/Request/Pay/Views/Success.view.tsx:23-23
Timestamp: 2024-10-08T20:13:42.967Z
Learning: In the `SuccessView` component, `transactionHash` remains constant because we are in a success view, so it's unnecessary to include it in the dependency array of `useEffect` hooks.
Learnt from: jjramirezn
PR: peanutprotocol/peanut-ui#409
File: src/components/Request/Pay/Views/Success.view.tsx:23-23
Timestamp: 2024-10-03T12:52:52.740Z
Learning: In the `SuccessView` component, `transactionHash` remains constant because we are in a success view, so it's unnecessary to include it in the dependency array of `useEffect` hooks.
🔇 Additional comments (14)
src/components/Request/Pay/Views/Success.view.tsx (2)

29-29: Approved: Improved address handling

The change from a conditional check to utils.printableAddress(requestLinkData.recipientAddress) is a good improvement. This modification aligns with the PR objective of not shortening ENS names and simplifies the code. The printableAddress function is likely designed to handle both regular addresses and ENS names appropriately, ensuring consistent and correct display across the application.


Line range hint 23-27: Correct: useEffect dependency array

The useEffect hook correctly omits transactionHash from its dependency array. This aligns with the previous learnings, which state that in a success view, transactionHash remains constant. Therefore, it doesn't need to be included in the dependency array. Good job maintaining this implementation!

src/components/Dashboard/components/MobileComponent.tsx (1)

47-47: LGTM! Verify printableAddress implementation.

The change from utils.shortenAddressLong to utils.printableAddress aligns well with the PR objective of not shortening ENS names. This modification ensures that both regular addresses and ENS names are handled appropriately in the UI.

To ensure the correct implementation of printableAddress, please run the following script:

This will help confirm that the printableAddress function is correctly implemented and consistently used across the codebase.

✅ Verification successful

printableAddress implementation verified.

The printableAddress function is correctly implemented in src/utils/general.utils.ts and is consistently used across the codebase, ensuring that ENS names are not shortened as intended.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of printableAddress function

# Test: Check the implementation of printableAddress
ast-grep --lang typescript --pattern 'function printableAddress($_) {
  $$$
}'

# Test: Verify usage of printableAddress across the codebase
rg --type typescript 'printableAddress'

Length of output: 155


Script:

#!/bin/bash
# Description: Verify the implementation of printableAddress function

# Test: Check the implementation of printableAddress
ast-grep --lang typescript --pattern 'function printableAddress($_) {
  $$$
}'

# Test: Verify usage of printableAddress across the codebase
rg --glob "*.ts" --glob "*.tsx" 'printableAddress'

Length of output: 2404

src/components/Create/Link/Initial.view.tsx (1)

234-234: LGTM! Verify ENS name handling.

The change from utils.shortenAddressLong(recipient.address, 6) to utils.printableAddress(recipient.address) aligns with the PR objective of not shortening ENS names. This implementation should correctly handle both regular addresses and ENS names.

To ensure the correct handling of ENS names, please run the following verification script:

This script will help us confirm that the printableAddress function is correctly implemented and consistently used across the codebase.

✅ Verification successful

Verified: ENS names are correctly handled without being shortened. The printableAddress function accurately distinguishes between ENS names and regular addresses, ensuring ENS names remain intact in the UI.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of printableAddress function

# Test: Check the implementation of printableAddress
rg --type typescript 'function printableAddress' -A 10

# Test: Verify usage of printableAddress across the codebase
rg --type typescript 'printableAddress'

Length of output: 166


Script:

#!/bin/bash
# Description: Locate the implementation of printableAddress function using file extension

# Test: Find the implementation of printableAddress in .ts and .tsx files
rg 'function printableAddress' --glob '*.ts' --glob '*.tsx' -A 10

# Test: Find all usages of printableAddress in .ts and .tsx files
rg 'printableAddress' --glob '*.ts' --glob '*.tsx' -A 5

Length of output: 10264

src/components/Dashboard/index.tsx (2)

Line range hint 1-287: Summary: Address display improvements implemented successfully

The changes in this file consistently replace utils.shortenAddressLong with utils.printableAddress for displaying addresses. This modification aligns well with the PR objective of not shortening ENS names, potentially improving user experience and readability throughout the dashboard.

Key points:

  1. The changes are minimal and focused, reducing the risk of introducing new bugs.
  2. The modifications are applied consistently in both the dashboard label and the table display.
  3. Existing fallback logic using nullish coalescing operators is preserved.

To ensure a comprehensive implementation:

  1. Verify that utils.printableAddress is correctly implemented to handle both ENS names and regular addresses.
  2. Check for any other occurrences of address shortening in the codebase that might need similar updates.
  3. Consider adding unit tests for the utils.printableAddress function to ensure its correct behavior with various input types.

187-187: Approved: Consistent address display in table

The change from utils.shortenAddressLong to utils.printableAddress is consistent with the previous modification and aligns with the PR objective of not shortening ENS names. This ensures a uniform display of addresses throughout the dashboard.

To ensure the correct behavior of utils.printableAddress, please run the following verification script:

This script will help confirm that utils.printableAddress is correctly implemented and consistently used across the codebase.

✅ Verification successful

Further Verification Needed: Issues with Current Verification Scripts

The initial verification attempts did not yield results due to unrecognized file types and no matches found for utils.printableAddress. To accurately verify the implementation and usage of utils.printableAddress, please run the following updated verification scripts:

These scripts aim to locate the printableAddress function by removing file type restrictions and explicitly searching within .ts and .tsx files. This should help determine whether the function exists and is properly utilized across the codebase.


Further Verification Needed: Unable to Locate utils.printableAddress Function Definition

The initial verification scripts did not locate the printableAddress function definition, likely due to differing function declaration styles or incorrect file type specifications. To accurately verify the implementation and usage of utils.printableAddress, please run the following updated verification scripts:

These scripts aim to identify the printableAddress function regardless of its declaration style and ensure that the correct file types are targeted during the search. This will help confirm the existence and implementation details of utils.printableAddress across the codebase.


Verified: utils.printableAddress is correctly implemented and consistently used

The utils.printableAddress function is properly defined in src/utils/general.utils.ts and is consistently utilized across multiple components within the codebase. The change from utils.shortenAddressLong to utils.printableAddress ensures a uniform display of addresses, aligning with the PR objective.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of utils.printableAddress

# Test: Check if utils.printableAddress exists and handles both ENS names and regular addresses
ast-grep --lang typescript --pattern $'function printableAddress(address: string): string {
  $$$
}'

# Test: Verify usage of printableAddress in other components
rg --type typescript 'utils\.printableAddress'

Length of output: 185


Script:

#!/bin/bash
# Description: Verify the implementation of utils.printableAddress with adjusted file types

# Test: Check if utils.printableAddress exists and handles both ENS names and regular addresses
ast-grep --lang typescript --pattern $'function printableAddress(address: string): string {
  $$$
}'

# Test: Verify usage of printableAddress in other components without specifying file type
rg 'utils\.printableAddress'

Length of output: 2315


Script:

#!/bin/bash
# Description: Alternative verification for utils.printableAddress

# Test: Search for printableAddress function in .ts and .tsx files explicitly
fd --extension ts --extension tsx 'printableAddress' | xargs grep -H 'function printableAddress'

# Test: List all TypeScript files to ensure correct file type usage
fd --extension ts --extension tsx

Length of output: 9484


Script:

#!/bin/bash
# Description: Enhanced verification of utils.printableAddress implementation

# Test 1: Check for function declaration in various styles
ast-grep --lang typescript --pattern $'function printableAddress(address: string): string {
  $$$
}'
ast-grep --lang typescript --pattern $'const printableAddress = (address: string): string => {
  $$$
}'
ast-grep --lang typescript --pattern $'export const printableAddress = (address: string): string => {
  $$$
}'

# Test 2: Verify usage of printableAddress across .ts and .tsx files
rg 'utils\.printableAddress' --type ts --type tsx

Length of output: 944


Script:

#!/bin/bash
# Description: Alternative verification for utils.printableAddress with corrected file types

# Test 1: Search for printableAddress function declarations as constants or exports
rg 'const printableAddress\s*=' --type ts --type tsx
rg 'export\s+const printableAddress\s*=' --type ts --type tsx

# Test 2: List all TypeScript and TSX files to ensure correct file type usage
fd --extension ts --extension tsx

Length of output: 9562

src/components/Profile/Components/TableComponent.tsx (1)

111-111: LGTM! Verify ENS name handling.

The change from utils.shortenAddressLong to utils.printableAddress aligns with the PR objective of not shortening ENS names. This should correctly handle both regular addresses and ENS names.

To ensure the change works as intended, please verify:

  1. The printableAddress function in the utils file correctly identifies and preserves ENS names.
  2. Test the component with both regular addresses and ENS names to confirm proper rendering.
src/components/Profile/index.tsx (5)

80-80: LGTM: Consistent address display

The change from utils.shortenAddressLong to utils.printableAddress aligns with the PR objective of not shortening ENS names. This ensures a consistent and appropriate display of addresses throughout the component.


274-274: LGTM: Consistent contact address display

The replacement of utils.shortenAddressLong with utils.printableAddress for contact addresses is consistent with the previous change. This ensures that ENS names for contacts are displayed appropriately without being shortened.


395-395: LGTM: Consistent user identifier display

The use of utils.printableAddress instead of utils.shortenAddressLong for the user's email or account identifier is consistent with the previous changes. This ensures that if an ENS name is used as the account identifier, it will be displayed appropriately without being shortened.


564-564: LGTM: Consistent referral address display and overall improvement

The use of utils.printableAddress for referral addresses is consistent with the previous changes, ensuring that ENS names for referrals are displayed appropriately without being shortened.

Overall, these changes successfully implement the PR objective of not shortening ENS names throughout the Profile component. The consistent use of utils.printableAddress across different parts of the component (initial user name, contacts, user identifier, and referrals) ensures a uniform and correct display of addresses and ENS names.


Line range hint 80-564: Summary: Successful implementation of ENS name handling

This PR successfully implements the objective of not shortening ENS names throughout the Profile component. The consistent replacement of utils.shortenAddressLong with utils.printableAddress across various parts of the component ensures that:

  1. User account identifiers are displayed correctly
  2. Contact addresses are shown appropriately
  3. User's own email or account identifier is handled properly
  4. Referral addresses are presented without shortening

These changes improve the user experience by maintaining the integrity of ENS names in the UI. The implementation is consistent and well-executed across the component.

src/utils/general.utils.ts (2)

1-5: LGTM: Import statements updated appropriately.

The removal of the interfaces import and the addition of the peanut import from the SDK are appropriate changes. This suggests a shift towards using the SDK directly, which can lead to better consistency and easier maintenance.


12-18: LGTM: Improved type safety for shortenAddressLong.

The addition of an explicit return type : string to the shortenAddressLong function enhances type safety and improves code readability. The function logic remains unchanged, maintaining existing behavior.

@dushebaa
Copy link
Contributor

dushebaa commented Oct 9, 2024

printableAddress(undefined) throws an error due to removed null check

Copy link
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.

nice and simple

Thought: Ideally we should standardize how we treat addresses across the app

ie, if they have a penaut name or ens name, show that, if not, shortened address, and have it be copiable

Stuff for down the line

@Hugo0 Hugo0 merged commit 0e335e0 into develop Oct 9, 2024
2 checks passed
@jjramirezn jjramirezn deleted the fix/ens-on-profile branch October 9, 2024 16:10
This was referenced Oct 14, 2024
@coderabbitai coderabbitai bot mentioned this pull request Dec 16, 2024
@coderabbitai coderabbitai bot mentioned this pull request Mar 19, 2025
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.

3 participants