Skip to content
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

Add a new formatDenomWithBadge that returns a ReactNode #252

Merged
merged 4 commits into from
Feb 7, 2025

Conversation

hansl
Copy link
Contributor

@hansl hansl commented Feb 7, 2025

This will add a badge if the denom is verified.

Fixes #250

Summary by CodeRabbit

  • New Features
    • Enhanced the display of transaction fees and token messages with a visual badge, making verified denominations clearer to users.
    • Introduced a new DenomVerifiedBadge component for better modularity in displaying verified denominations.

  • Refactor
    • Standardized the formatting of denomination details across multiple views for improved consistency and visual appeal.
    • Improved the rendering logic for transaction fees to provide additional context.

This will add a badge if the denom is verified.

Fixes liftedinit#250
@hansl hansl requested a review from fmorency February 7, 2025 06:29
Copy link
Contributor

coderabbitai bot commented Feb 7, 2025

Walkthrough

The changes update how token denominations are formatted and displayed. In the bank components, the old formatDenom calls are replaced with formatDenomWithBadge to include a badge in the fee display. The token message creation logic now also uses the new function. A new DenomVerifiedBadge component is introduced in the factory components to encapsulate verification logic. Additionally, the utils have been updated: the formatDenom function is refactored, and a new file, formatNode.tsx, is added for enhanced formatting and export adjustments.

Changes

File(s) Change Summary
components/bank/…/historyBox.tsx,
components/bank/…/createMessageUtils.tsx
Replaced calls to formatDenom with formatDenomWithBadge for fee display and token message creation, updating the rendering logic for formatted denomination output.
components/factory/…/DenomDisplay.tsx Introduced a new DenomVerifiedBadge component and refactored DenomDisplay to use it, thereby isolating the token verification display logic.
utils/format.ts,
utils/formatNode.tsx,
utils/index.ts
Enhanced denomination formatting: refactored formatDenom with mutable handling, added a new formatDenomWithBadge function in formatNode.tsx to return React nodes with a badge, and updated exports.

Sequence Diagram(s)

sequenceDiagram
    participant HB as HistoryBox
    participant FN as formatDenomWithBadge (Utils)
    participant DD as DenomVerifiedBadge
    HB->>FN: Call formatDenomWithBadge(fee.denom, small?)
    FN->>FN: Clean and format denom (via formatDenom)
    alt Verified Token
        FN->>DD: Render verification badge
        DD-->>FN: Return badge component
    end
    FN-->>HB: Return formatted node with badge
    HB->>HB: Render fee display with verified badge
Loading

Assessment against linked issues

Objective Addressed Explanation
Identify Verified tokens in transaction history (#250)

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • chalabi2
  • fmorency

Poem

I'm a little rabbit, hopping through the code,
With badges on tokens, a bright new ode.
Verified tokens shimmer, crisp and clear,
In every fee and message, magic appears.
Carrots and commits—oh what a joyful load!
🥕💻 Hop on to the next bright node!


📜 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 64a8822 and eead99d.

📒 Files selected for processing (1)
  • utils/format.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • utils/format.ts

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

codecov bot commented Feb 7, 2025

Codecov Report

Attention: Patch coverage is 97.05882% with 1 line in your changes missing coverage. Please review.

Project coverage is 55.06%. Comparing base (64be274) to head (eead99d).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
utils/format.ts 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #252      +/-   ##
==========================================
+ Coverage   55.02%   55.06%   +0.04%     
==========================================
  Files         204      205       +1     
  Lines       17636    17654      +18     
==========================================
+ Hits         9704     9722      +18     
  Misses       7932     7932              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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 (2)
components/factory/components/DenomDisplay.tsx (1)

5-12: Consider making the verification check configurable.

The verification check is hardcoded to 'umfx'. Consider making this configurable through environment variables or a configuration object for better maintainability and flexibility.

+import env from '@/config/env';
+
 export const DenomVerifiedBadge = ({
   base,
   ...props
 }: { base?: string } & { [i: string]: unknown }) => {
-  const verified = base === 'umfx';
+  const verified = base === env.VERIFIED_DENOM;

   return verified ? <VerifiedIcon {...props} /> : <></>;
 };
components/bank/handlers/createMessageUtils.tsx (1)

2-8: Consider removing unused import.

The formatDenom import appears to be unused since it's been replaced by formatDenomWithBadge.

 import {
   denomToAsset,
   formatAmount,
-  formatDenom,
   formatDenomWithBadge,
   formatLargeNumber,
 } from '@/utils';
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 244c1e6 and a5a6c19.

📒 Files selected for processing (4)
  • components/bank/components/historyBox.tsx (2 hunks)
  • components/bank/handlers/createMessageUtils.tsx (2 hunks)
  • components/factory/components/DenomDisplay.tsx (2 hunks)
  • utils/format.tsx (2 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
utils/format.tsx

[warning] 60-60: utils/format.tsx#L60
Added line #L60 was not covered by tests

🔇 Additional comments (5)
components/factory/components/DenomDisplay.tsx (1)

35-38: LGTM!

The integration of DenomVerifiedBadge into DenomDisplay is clean and well-structured.

components/bank/handlers/createMessageUtils.tsx (1)

21-22: LGTM!

The replacement of formatDenom with formatDenomWithBadge is correctly implemented.

utils/format.tsx (2)

36-50: LGTM!

The new formatDenomWithBadge function is well-documented and properly implemented.


59-61: Add test coverage for IBC denom handling.

The IBC denom handling logic is not covered by tests according to static analysis.

Could you add test cases to cover this scenario? Here's a suggested test structure:

describe('formatDenom', () => {
  it('should handle IBC denoms correctly', () => {
    const mockAssetInfo = { display: 'ATOM' };
    jest.spyOn(utils, 'denomToAsset').mockReturnValue(mockAssetInfo);
    
    expect(formatDenom('ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2'))
      .toBe('ATOM');
  });
});
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 60-60: utils/format.tsx#L60
Added line #L60 was not covered by tests

components/bank/components/historyBox.tsx (1)

162-169: LGTM!

The fee display logic is well-structured and correctly uses the new formatDenomWithBadge function with the appropriate size prop.

Copy link
Contributor

@fmorency fmorency left a comment

Choose a reason for hiding this comment

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

It works! However, the spacing looks a little off.

2025-02-07_09-25

@hansl
Copy link
Contributor Author

hansl commented Feb 7, 2025

It's the same spacing as the others. The fees could look better let me see.

@hansl
Copy link
Contributor Author

hansl commented Feb 7, 2025

@fmorency Let me know if this looks better:

CleanShot 2025-02-07 at 10 59 55@2x

@hansl hansl requested a review from fmorency February 7, 2025 19:00
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: 1

🧹 Nitpick comments (1)
utils/formatNode.tsx (1)

9-23: Consider improving the badge positioning.

The function implementation is clean and well-documented. However, using relative positioning with bottom-1 for the badge might be fragile across different contexts.

Consider using flexbox alignment instead:

-  const classes = `${small ? 'w-3' : 'w-5'} inline relative bottom-1 text-primary`;
+  const classes = `${small ? 'w-3' : 'w-5'} inline-flex items-center text-primary`;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 994fdbd and 64a8822.

📒 Files selected for processing (3)
  • utils/format.ts (2 hunks)
  • utils/formatNode.tsx (1 hunks)
  • utils/index.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • utils/index.ts
🔇 Additional comments (2)
utils/formatNode.tsx (1)

1-8: LGTM! Well-documented file purpose and clean imports.

The file is well-documented with a clear purpose statement and has clean, organized imports.

utils/format.ts (1)

4-6: LGTM! Clean import organization.

The new imports are well-organized and properly scoped.

utils/format.ts Outdated
Comment on lines 40 to 47
let cleanDenom = denom.replace(/^factory\/[^/]+\//, '');

// Skip cleaning for IBC denoms as they should be resolved via assetInfo
if (cleanDenom.startsWith('ibc/')) {
return assetInfo?.display.toUpperCase() ?? '';
}

if (cleanDenom?.startsWith('u')) {
return cleanDenom.slice(1).toUpperCase();
cleanDenom = assetInfo?.display.toUpperCase() ?? '';
} else if (cleanDenom.startsWith('u')) {
cleanDenom = cleanDenom.slice(1).toUpperCase();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider handling empty assetInfo.display case.

The code handles IBC denoms by using assetInfo?.display, but if assetInfo exists with an empty display property, it would still fallback to an empty string.

Let's verify if this edge case is handled elsewhere:

Also, consider adding a fallback:

-    cleanDenom = assetInfo?.display.toUpperCase() ?? '';
+    cleanDenom = assetInfo?.display?.toUpperCase() ?? cleanDenom;

🏁 Script executed:

#!/bin/bash
# Search for assetInfo.display usage to check edge case handling
ast-grep --pattern 'assetInfo?.display'

Length of output: 346


IBC Denom Formatting Edge Case – Consider Fallback Improvement

The analysis confirms that in utils/format.ts the IBC denom branch uses the expression

  assetInfo?.display.toUpperCase() ?? ''

which will return an empty string if assetInfo exists but its display property is an empty string. The same edge case isn’t specially handled elsewhere in the codebase (as seen in pages/bank.tsx and other files where a similar pattern is used). This inconsistency may lead to an undesired empty result for IBC denoms.

• Update the logic to ensure a fallback to the computed cleanDenom value rather than an empty string. For example, consider changing the line to:
  cleanDenom = assetInfo?.display?.toUpperCase() ?? cleanDenom;

@fmorency fmorency merged commit 02c576b into liftedinit:main Feb 7, 2025
4 checks passed
@hansl hansl deleted the fix-250 branch February 7, 2025 21:02
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.

Identify Verified tokens in transaction history
2 participants