Skip to content

handling of broken token logo with placeholder#280

Merged
RanaBug merged 2 commits intostagingfrom
feat/PRO-3165/placeholders-tokens-no-logo
Apr 2, 2025
Merged

handling of broken token logo with placeholder#280
RanaBug merged 2 commits intostagingfrom
feat/PRO-3165/placeholders-tokens-no-logo

Conversation

@RanaBug
Copy link
Collaborator

@RanaBug RanaBug commented Apr 1, 2025

Description

  • Handling of broken image (token logo) with token placeholder

How Has This Been Tested?

  • Existing Unit Tests and Manual Testing

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Summary by CodeRabbit

  • New Features
    • Enhanced token image error handling across the interface. Now when a token logo fails to load, a clear fallback overlay is displayed. This improvement ensures users experience a consistent and reliable display even if token images are unavailable or encounter loading issues.
  • Dependencies
    • Updated date-fns package from version ^3.6.0 to ^4.1.0.
    • Added new dependency @types/styled-components with version ^5.1.34.

@RanaBug RanaBug requested a review from IAmKio April 1, 2025 16:52
@RanaBug RanaBug self-assigned this Apr 1, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 1, 2025

Walkthrough

The changes across multiple components introduce a new state variable, isBrokenImage, to track image loading failures. In each component, the conditional rendering logic for displaying the token logo is updated so that if the image fails to load (as detected by the onError handler), a fallback (overlay text or placeholder) is displayed instead. This ensures a graceful user experience when token logo images are broken or missing.

Changes

Files Change Summary
src/apps/.../HorizontalToken.tsx, src/apps/.../TokenInfoHorizontal.tsx Added isBrokenImage state and modified conditional rendering to show fallback overlay text if the token logo fails to load.
src/apps/.../TokenLogo.tsx Introduced isBrokenImage state; updated <img> element with an onError handler to set the state and adjust overlay text rendering.
src/apps/.../TokenCard.tsx, src/apps/.../TokenGraphColumn.tsx, src/apps/.../TokenResultCard.tsx Implemented isBrokenImage state to manage image loading; enhanced conditional rendering to display fallback content on image error, with TokenGraphColumn showing a placeholder avatar using the token’s name.

Sequence Diagram(s)

sequenceDiagram
    participant C as Component
    participant I as Image Element
    C->>I: Render token logo
    I-->>C: Attempt to load image
    Note right of I: If image fails to load
    I->>C: Trigger onError event
    C->>C: setIsBrokenImage(true)
    C->>C: Re-render with fallback content
Loading

Suggested reviewers

  • IAmKio

Poem

I'm a little rabbit hopping through the code,
Delighting in a smoother, error-free load.
When images break, I twitch my nose,
Watching fallbacks bloom like a garden that grows.
Coding with joy, on my happy little road! 🐇
(\/)

( •
•) Let's keep those bugs away!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0eddd2c and ac2cf1d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • package.json (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: lint
  • GitHub Check: unit-tests
  • GitHub Check: build
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (2)
package.json (2)

53-53: Reviewing Dependency Upgrade for date-fns

The dependency "date-fns": "^4.1.0" has been upgraded from ^3.6.0. Please ensure that any API changes or breaking changes in date-fns v4 are handled appropriately throughout the codebase.


123-123: Check Type Definitions and Version Consistency for styled-components

The new dev dependency "@types/styled-components": "^5.1.34" has been introduced. Note that the resolutions enforce "styled-components": "^5" while the production dependency at line 96 remains "styled-components": "^6.1.1". Please verify that this discrepancy is intentional and that the type definitions align with the effective version of styled-components used in the project.


🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Apr 1, 2025

Deploying x with  Cloudflare Pages  Cloudflare Pages

Latest commit: ac2cf1d
Status: ✅  Deploy successful!
Preview URL: https://16d020ba.x-e62.pages.dev
Branch Preview URL: https://feat-pro-3165-placeholders-t.x-e62.pages.dev

View logs

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

🧹 Nitpick comments (4)
src/apps/the-exchange/components/TokenLogo/TokenLogo.tsx (1)

56-60: Consider adding error handling for the chain logo as well.

While you've implemented error handling for the token logo, the chain logo doesn't have similar error handling. For consistency, consider adding an error handler to the chain logo image as well.

<img
  src={tokenChainLogo}
  alt="chain-logo"
  className={`w-full h-full object-fill rounded-full grayscale ${!tokenChainLogo && 'hidden'}`}
+ onError={(e) => e.currentTarget.style.display = 'none'}
/>
src/apps/pillarx-app/components/TokenInfoHorizontal/TokenInfoHorizontal.tsx (1)

78-82: Consider adding error handling for the blockchain logo.

Similar to the token logo, the blockchain logo might also fail to load. Consider adding error handling for this image as well for consistent behavior.

<img
  src={blockchainLogo}
  alt="logo"
  className="w-full h-full object-contain"
+ onError={(e) => e.currentTarget.style.display = 'none'}
/>
src/apps/pillarx-app/components/HorizontalToken/HorizontalToken.tsx (1)

88-92: Consider adding error handling for the blockchain logo.

For consistency with the token logo error handling, consider implementing similar error handling for the blockchain logo.

<img
  src={blockchainLogo}
  alt="logo"
  className="w-full h-full object-contain"
+ onError={(e) => e.currentTarget.style.display = 'none'}
/>
src/apps/token-atlas/components/TokenCard/TokenCard.tsx (1)

1-72: Consider creating a reusable hook for image error handling.

This pattern of tracking broken images with a state variable appears to be duplicated across multiple components according to the PR summary. Consider creating a custom hook like useImageErrorHandling to reduce code duplication.

// Example implementation
function useImageErrorHandling() {
  const [isBrokenImage, setIsBrokenImage] = useState<boolean>(false);
  const handleImageError = () => setIsBrokenImage(true);
  
  return { isBrokenImage, handleImageError };
}

// Usage in component
const { isBrokenImage, handleImageError } = useImageErrorHandling();
// ...
<img src={tokenLogo} onError={handleImageError} />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 603e5d5 and 0eddd2c.

⛔ Files ignored due to path filters (16)
  • src/apps/pillarx-app/components/HorizontalToken/test/__snapshots__/HorizontalToken.test.tsx.snap is excluded by !**/*.snap
  • src/apps/pillarx-app/components/MediaGridCollection/tests/__snapshots__/DisplayCollectionImage.test.tsx.snap is excluded by !**/*.snap
  • src/apps/pillarx-app/components/PointsTile/test/__snapshots__/PointsTile.test.tsx.snap is excluded by !**/*.snap
  • src/apps/pillarx-app/components/TokenInfoHorizontal/test/__snapshots__/TokenInfoHorizontal.test.tsx.snap is excluded by !**/*.snap
  • src/apps/pillarx-app/components/TokensHorizontalTile/test/__snapshots__/TokensHorizontalTile.test.tsx.snap is excluded by !**/*.snap
  • src/apps/pillarx-app/components/TokensVerticalTile/test/__snapshots__/TokensVerticalTile.test.tsx.snap is excluded by !**/*.snap
  • src/apps/the-exchange/components/CardsSwap/test/__snapshots__/CardSwap.test.tsx.snap is excluded by !**/*.snap
  • src/apps/the-exchange/components/DropdownTokensList/test/__snapshots__/DropdownTokensList.test.tsx.snap is excluded by !**/*.snap
  • src/apps/the-exchange/components/ExchangeAction/test/__snapshots__/ExchangeAction.test.tsx.snap is excluded by !**/*.snap
  • src/apps/the-exchange/components/SelectToken/test/__snapshots__/SelectToken.test.tsx.snap is excluded by !**/*.snap
  • src/apps/the-exchange/components/TokenListItem/test/__snapshots__/TokenListItem.test.tsx.snap is excluded by !**/*.snap
  • src/apps/the-exchange/components/TokenLogo/test/__snapshots__/TokenLogo.test.tsx.snap is excluded by !**/*.snap
  • src/apps/token-atlas/components/TokenCard/test/__snapshots__/TokenCard.test.tsx.snap is excluded by !**/*.snap
  • src/apps/token-atlas/components/TokenGraphColumn/test/__snapshots__/TokenGraphColumn.test.tsx.snap is excluded by !**/*.snap
  • src/apps/token-atlas/components/TokenResultCard/test/__snapshots__/TokenResultCard.test.tsx.snap is excluded by !**/*.snap
  • src/apps/token-atlas/components/TokensSearchResult/test/__snapshots__/TokensSearchResult.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • src/apps/pillarx-app/components/HorizontalToken/HorizontalToken.tsx (3 hunks)
  • src/apps/pillarx-app/components/TokenInfoHorizontal/TokenInfoHorizontal.tsx (3 hunks)
  • src/apps/the-exchange/components/TokenLogo/TokenLogo.tsx (3 hunks)
  • src/apps/token-atlas/components/TokenCard/TokenCard.tsx (4 hunks)
  • src/apps/token-atlas/components/TokenGraphColumn/TokenGraphColumn.tsx (3 hunks)
  • src/apps/token-atlas/components/TokenResultCard/TokenResultCard.tsx (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (10)
src/apps/token-atlas/components/TokenResultCard/TokenResultCard.tsx (1)

27-28: Good implementation of image error handling.

The addition of the isBrokenImage state variable and the conditional rendering logic provides a robust solution for handling broken token logos. The implementation follows React best practices and ensures a consistent user experience.

Also applies to: 38-38, 43-43, 52-52

src/apps/the-exchange/components/TokenLogo/TokenLogo.tsx (1)

21-22: Good implementation of image error handling.

The implementation for handling broken token logo images looks good. The state tracking and conditional rendering provide an effective solution.

Also applies to: 30-30, 35-35, 44-44

src/apps/pillarx-app/components/TokenInfoHorizontal/TokenInfoHorizontal.tsx (1)

35-36: Good implementation of image error handling.

The addition of the isBrokenImage state and the associated logic for displaying a placeholder when the image fails to load provides a good user experience.

Also applies to: 54-54, 60-60, 69-69

src/apps/pillarx-app/components/HorizontalToken/HorizontalToken.tsx (1)

41-42: Good implementation of image error handling.

The broken image handling using the isBrokenImage state provides a robust solution for displaying fallback content when token logos fail to load.

Also applies to: 64-64, 70-70, 79-79

src/apps/token-atlas/components/TokenCard/TokenCard.tsx (3)

1-1: Good addition of the useState hook and isBrokenImage state.

This state variable will effectively track image loading failures.

Also applies to: 22-23


41-48: Good implementation of image fallback logic.

The condition now correctly checks both for the existence of the token logo and that the image hasn't failed to load. The onError handler properly sets the broken image state when loading fails.


56-60: Good fallback overlay implementation.

The overlay text now correctly appears when either the token logo is missing or when the image fails to load.

src/apps/token-atlas/components/TokenGraphColumn/TokenGraphColumn.tsx (3)

53-53: Good addition of isBrokenImage state.

This state variable will effectively track image loading failures.


137-144: Good implementation of image fallback logic.

The condition now correctly checks both for the existence of the token logo and that the image hasn't failed to load. The onError handler properly sets the broken image state when loading fails.


152-156: Good fallback overlay implementation.

The overlay text now correctly appears when either the token logo is missing or when the image fails to load.

@github-actions github-actions bot requested a deployment to Preview (feat/PRO-3165/placeholders-tokens-no-logo) April 1, 2025 17:00 Abandoned
Copy link
Collaborator

@IAmKio IAmKio left a comment

Choose a reason for hiding this comment

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

LGTM

@RanaBug RanaBug merged commit 302b140 into staging Apr 2, 2025
7 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Apr 24, 2025
3 tasks
@github-actions github-actions bot requested a deployment to Preview (feat/debug-one-person-issue) November 24, 2025 12:22 Abandoned
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