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

Show 0 available balance when first time donate has been loaded #4415

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

kkatusic
Copy link
Collaborator

@kkatusic kkatusic commented Jul 16, 2024

Resolve #3002

@divine-comedian fixed 0 balance in first load

Summary by CodeRabbit

  • Enhancements
    • Improved the display logic for token balances in the CryptoDonation component.
    • Token balance now only displays when a selectedOneTimeToken is present.
    • Dynamically formatted token balance for easier readability.
    • Added a conditional check to refetch data when necessary, providing more accurate and dynamic information.

Copy link

vercel bot commented Jul 16, 2024

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

Name Status Preview Comments Updated (UTC)
giveth-dapps-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 16, 2024 5:07pm

Copy link
Contributor

coderabbitai bot commented Jul 17, 2024

Walkthrough

The recent update enhances the CryptoDonation component by modifying the display logic for token balances. Now, the component conditionally shows the balance based on the presence of a selected token and includes a function to format the displayed balance. Additionally, a check for refetching status is introduced to the IconWrapper component to improve interactivity.

Changes

Files Change Summary
src/components/views/donate/OnTime/OneTimeDonationCard.tsx Updated display logic within the CryptoDonation component to conditionally show token balances based on selectedOneTimeToken, used truncateToDecimalPlaces to format the balance, and included isRefetching check in IconWrapper

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CryptoDonation
    participant TokenService

    User->>CryptoDonation: Select token
    CryptoDonation->>TokenService: Fetch token balances
    TokenService-->>CryptoDonation: Return token balances
    CryptoDonation->>CryptoDonation: Update balance display
    CryptoDonation-->>User: Display formatted balance
Loading

Assessment against linked issues

Objective Addressed Explanation
Show them their token balances right inside the modal (#3002)
Query their balances for many tokens (#3002)
The list should then be sorted to show the highest balances at the top of the list (#3002) Sorting functionality is not mentioned in the current changes.
Users can click a toggle that hides tokens with zero balances (#3002) Toggle to hide zero balances is not implemented in the changes.

Poem

In code we trust, tokens align,
Balances displayed, oh so fine.
Refetch with a click, no more delay,
Crypto donations now show the way.
With logic sharp and functions neat,
The user experience is complete. 🚀


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d1ab92c and db8668c.

Files selected for processing (1)
  • src/components/views/donate/OnTime/OneTimeDonationCard.tsx (1 hunks)
Additional comments not posted (2)
src/components/views/donate/OnTime/OneTimeDonationCard.tsx (2)

363-371: Review the balance display and formatting logic.

The logic to display the balance has been updated to use the truncateToDecimalPlaces function, which formats the balance to a fraction of its decimal places. This is a crucial change for user experience but needs verification to ensure it handles all edge cases correctly, especially with different token decimal settings.

Verification successful

The balance formatting logic using truncateToDecimalPlaces is correctly implemented.

The function truncateToDecimalPlaces handles edge cases such as the absence of a decimal point and requests for fewer than one decimal place. The usage in OneTimeDonationCard.tsx and other files is consistent with its purpose, ensuring appropriate balance display.

  • src/lib/helpers.ts: Definition of truncateToDecimalPlaces.
  • src/components/views/donate/OnTime/OneTimeDonationCard.tsx: Correct usage of truncateToDecimalPlaces.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the balance formatting function for edge cases.
# Test: Search for the `truncateToDecimalPlaces` function usage. Expect: Only occurances with correct decimal handling.
rg --type typescript -A 5 $'truncateToDecimalPlaces'

Length of output: 86


Script:

#!/bin/bash
# Description: Verify the balance formatting function for edge cases.
# Test: Search for the `truncateToDecimalPlaces` function usage. Expect: Only occurrences with correct decimal handling.
rg --type ts -A 5 'truncateToDecimalPlaces'

Length of output: 6986


Line range hint 348-364: Verify the donation logic for accuracy and completeness.

The handleDonate function checks several conditions before allowing a donation to proceed. Ensure that all conditions are correctly evaluated and that there are no logical errors or missing conditions that could affect the donation process.

Verification successful

Line range hint 348-364: Verified donation logic for accuracy and completeness.

The handleDonate function in OneTimeDonationCard.tsx correctly checks for sufficient balance, network eligibility, and user authentication before proceeding with the donation. The logic is comprehensive and handles various states appropriately.

  • src/components/views/donate/OnTime/OneTimeDonationCard.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the donation logic in other parts of the codebase.
# Test: Search for the `handleDonate` function usage. Expect: Consistent and correct usage across the codebase.
rg --type typescript -A 5 $'handleDonate'

Length of output: 75


Script:

#!/bin/bash
# Description: Verify the donation logic in other parts of the codebase.
# Test: Search for the `handleDonate` function usage. Expect: Consistent and correct usage across the codebase.
rg --type-add 'ts:*.ts' --type ts -A 5 'handleDonate'

Length of output: 3408


Script:

#!/bin/bash
# Description: Search for the `handleDonate` function definition.
# Test: Locate the definition of the `handleDonate` function to understand its implementation.
rg --type-add 'ts:*.ts' --type ts 'function handleDonate'

Length of output: 59


Script:

#!/bin/bash
# Description: Search for the `handleDonate` function definition.
# Test: Locate the definition of the `handleDonate` function to understand its implementation.
rg --type-add 'ts:*.ts' --type ts -A 10 'const handleDonate ='

Length of output: 2783


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

@kkatusic kkatusic requested a review from RamRamez July 17, 2024 08:37
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

Outside diff range, codebase verification and nitpick comments (1)
src/components/views/donate/OnTime/OneTimeDonationCard.tsx (1)

Line range hint 248-259: Ensure robust error handling in GraphQL queries.

The useEffect hook fetching project accepted tokens uses Apollo client. While the basic structure is correct, consider enhancing error handling to provide more specific feedback to the user or retries in case of transient errors.

- showToastError(error);
+ showToastError("Failed to fetch accepted tokens: " + error.message);  // Provide more specific error messages

@kkatusic kkatusic self-assigned this Jul 21, 2024
Copy link
Collaborator

@MohammadPCh MohammadPCh left a comment

Choose a reason for hiding this comment

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

@kkatusic Thanks, LGTM

@kkatusic
Copy link
Collaborator Author

@LatifatAbdullahi please when you get time can you test this issue task:

Users can click a toggle that hides tokens with zero balances (#3002)

Link for vercel temp link is here

@kkatusic kkatusic merged commit 50c01a1 into develop Jul 22, 2024
3 checks passed
@kkatusic kkatusic deleted the resolve_balance_sorting branch July 22, 2024 14:16
@LatifatAbdullahi
Copy link

LatifatAbdullahi commented Jul 23, 2024

@divine-comedian @kkatusic

Test Update
Show 0 available balance when first time donate has been loaded: Pass
Users can click a toggle that hides tokens with zero balances: Pass

This works as expected

8

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Show token balances in drop down token list
3 participants