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

fix: show brc20 token fiat balance, closes #5626 #5655

Merged
merged 1 commit into from
Jul 16, 2024
Merged

Conversation

alter-eggo
Copy link
Contributor

@alter-eggo alter-eggo commented Jul 16, 2024

Try out Leather build 807fa67Extension build, Test report, Storybook, Chromatic

This pr fixes brc20 token fiat balance display

Summary by CodeRabbit

  • New Features
    • Display of fiat balances for Brc20 tokens in the asset list, enhancing the visualization of token value based on market data.

Copy link

coderabbitai bot commented Jul 16, 2024

Walkthrough

A new function, getBrc20TokenFiatBalance, has been added to the Brc20TokenAssetList component. This function calculates the fiat balance for each Brc20 token by using the token's available balance and current market data. The computed fiat balance is then displayed in the asset list.

Changes

File Path Change Summary
src/app/features/asset-list/bitcoin/brc20-token-asset-list/... Added the getBrc20TokenFiatBalance function to calculate and display the fiat balance for Brc20 tokens.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Brc20TokenAssetList
    participant MarketDataService
    
    User->>Brc20TokenAssetList: Load asset list
    Brc20TokenAssetList->>MarketDataService: Fetch token market data
    MarketDataService-->>Brc20TokenAssetList: Return market data
    Brc20TokenAssetList->>Brc20TokenAssetList: Calculate fiat balance using getBrc20TokenFiatBalance
    Brc20TokenAssetList-->>User: Display token list with fiat balances
Loading

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@alter-eggo alter-eggo linked an issue Jul 16, 2024 that may be closed by this pull request
Copy link

@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

Outside diff range, codebase verification and nitpick comments (2)
src/app/features/asset-list/bitcoin/brc20-token-asset-list/brc20-token-asset-list.tsx (2)

Line range hint 34-68: Review of the Brc20TokenAssetList function.

The Brc20TokenAssetList function integrates the new getBrc20TokenFiatBalance function to display fiat balances for each token. The function handles navigation and conditional rendering based on the presence of tokens and BTC balance conditions.

A few points to consider:

  1. The function could benefit from memoization or useCallback for the navigateToBrc20SendForm function to avoid unnecessary re-renders when the component updates but the tokens data hasn't changed.
  2. The use of RouteUrls.SendBrc20SendForm.replace(':ticker', info.symbol) directly in the navigate function could be abstracted into a utility function for better readability and reusability.
  3. Error handling should be considered, especially in scenarios where the navigation might fail or the tokens data might be malformed.
- function navigateToBrc20SendForm(token: Brc20TokenAssetDetails) {
+ const navigateToBrc20SendForm = useCallback((token: Brc20TokenAssetDetails) => {
    const { balance, holderAddress, info, marketData } = token;
    navigate(RouteUrls.SendBrc20SendForm.replace(':ticker', info.symbol), {
      state: {
        balance: balance.availableBalance,
        holderAddress,
        marketData,
        ticker: info.symbol,
      },
    });
- }
+ }, [navigate, tokens]);

Consider adding error handling for navigation and data validation to improve robustness and user experience.


28-33: Add null checks in getBrc20TokenFiatBalance function.

The function getBrc20TokenFiatBalance currently does not include null or undefined checks for token.balance or token.marketData. This can lead to runtime errors if these properties are null or undefined. Please add appropriate checks to ensure the function handles such cases gracefully.

  • File: src/app/features/asset-list/bitcoin/brc20-token-asset-list/brc20-token-asset-list.tsx
  • Lines: 28-33
Analysis chain

Review of the newly added getBrc20TokenFiatBalance function.

The function getBrc20TokenFiatBalance correctly uses convertAssetBalanceToFiat to compute the fiat balance based on the token's available balance and market data. This implementation seems straightforward and efficient, leveraging existing utilities to perform its task.

However, it would be beneficial to ensure that the input token is validated before use, particularly to check if token.balance and token.marketData are not null or undefined, which could cause runtime errors if not handled.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all necessary null checks are in place for token properties in `getBrc20TokenFiatBalance`.

# Test: Search for null checks in the function. Expect: Proper null checks before accessing properties.
rg --type tsx -A 5 "getBrc20TokenFiatBalance" src/app/features/asset-list/bitcoin/brc20-token-asset-list/brc20-token-asset-list.tsx

Length of output: 159


Script:

#!/bin/bash
# Description: Verify that all necessary null checks are in place for token properties in `getBrc20TokenFiatBalance`.

# Test: Search for null checks in the function. Expect: Proper null checks before accessing properties.
rg "function getBrc20TokenFiatBalance" -A 10 src/app/features/asset-list/bitcoin/brc20-token-asset-list/brc20-token-asset-list.tsx

Length of output: 524

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1b9f9a2 and 807fa67.

Files selected for processing (1)
  • src/app/features/asset-list/bitcoin/brc20-token-asset-list/brc20-token-asset-list.tsx (3 hunks)

@alter-eggo alter-eggo requested review from fbwoolf and edgarkhanzadian and removed request for fbwoolf and edgarkhanzadian July 16, 2024 12:06
@alter-eggo alter-eggo added this pull request to the merge queue Jul 16, 2024
Merged via the queue into dev with commit adf8c19 Jul 16, 2024
31 checks passed
@alter-eggo alter-eggo deleted the fix/brc-20-fiat branch July 16, 2024 13:59
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.

BRC-20 USD balances no longer appearing
2 participants