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

Feat/add cbbtc recurring #4949

Merged
merged 2 commits into from
Jan 20, 2025
Merged

Feat/add cbbtc recurring #4949

merged 2 commits into from
Jan 20, 2025

Conversation

kkatusic
Copy link
Collaborator

@kkatusic kkatusic commented Jan 20, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for tokens with 8 decimal places in donation and input components
  • Improvements

    • Enhanced token handling for recurring donations
    • Improved decimal place validation for user inputs
    • Updated token configuration to include Coinbase Wrapped BTC
  • Bug Fixes

    • Corrected amount calculation for tokens with different decimal precisions

@kkatusic kkatusic self-assigned this Jan 20, 2025
Copy link

vercel bot commented Jan 20, 2025

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 Jan 20, 2025 3:58pm

Copy link
Contributor

coderabbitai bot commented Jan 20, 2025

Walkthrough

The pull request introduces changes to handle tokens with 8 decimal places across multiple components. The modifications primarily focus on updating the logic for processing donation amounts, input validation, and token configuration. The changes ensure that the application can correctly handle tokens with different decimal precisions, specifically expanding support for tokens with 6 and 8 decimal places in the donation and input mechanisms.

Changes

File Change Summary
src/components/AmountInput/AmountInput.tsx Added maxDecimals variable to control decimal place display based on token decimals. Modified onUserInput to validate input with a maximum of 8 decimal places for tokens with 8 decimals.
src/components/views/donate/Recurring/RecurringDonationCard.tsx Updated token decimal checks to include 8-decimal tokens. Modified scaling factor calculations for different decimal configurations.
src/components/views/donate/Recurring/RecurringDonationModal/RecurringDonationModal.tsx Expanded decimal precision handling for donation amounts. Updated amount conversion logic to support tokens with 6 and 8 decimals.
src/config/production.tsx Reactivated "Coinbase Wrapped BTC" token configuration. Updated token properties for various tokens including decimal places and identifiers.

Sequence Diagram

sequenceDiagram
    participant User
    participant AmountInput
    participant DonationModal
    participant TokenConfig

    User->>AmountInput: Enter donation amount
    AmountInput->>AmountInput: Validate decimal places
    AmountInput->>DonationModal: Submit amount
    DonationModal->>TokenConfig: Check token decimals
    TokenConfig-->>DonationModal: Return decimal configuration
    DonationModal->>DonationModal: Convert and scale amount
    DonationModal->>User: Confirm donation
Loading

Poem

🐰 Decimal dance, tokens so bright,
Eight places now shine with delight!
From six to eight, we scale with grace,
Donations flow at a perfect pace.
CodeRabbit's magic, precise and neat,
Makes crypto math a whimsical treat! 🚀


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
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)
src/components/views/donate/Recurring/RecurringDonationModal/RecurringDonationModal.tsx (1)

245-261: Add a comment explaining the token conversion logic.

The code correctly handles the conversion of token amounts with 8 decimals to 18 decimals for super token compatibility. However, adding a comment would help explain why this conversion is necessary.

Consider adding a comment like:

+ // Convert token amounts to 18 decimals for super token compatibility.
+ // For tokens with 6 or 8 decimals, we first convert to a human-readable number
+ // by dividing by the token's decimals, then convert back to wei using 18 decimals.
  if (
    selectedRecurringToken.token.decimals === 6 ||
    selectedRecurringToken.token.decimals === 8
  ) {
src/components/views/donate/Recurring/RecurringDonationCard.tsx (1)

157-161: Document the scale factor calculation.

While the scale factors are correctly implemented, their purpose and calculation method should be documented for maintainability.

Consider adding a comment explaining the scale factors:

+ // Scale factors are used to adjust the flow rate calculations:
+ // - For 6 decimal tokens: 10000n (1e4) to handle the decimal difference (18 - 6 = 12, so 1e12/1e8 = 1e4)
+ // - For 8 decimal tokens: 100n (1e2) to handle the decimal difference (18 - 8 = 10, so 1e10/1e8 = 1e2)
+ // - For other tokens: 1n (no scaling needed as they typically have 18 decimals)
  const scaleFactor =
    selectedRecurringToken?.token.decimals === 6
      ? 10000n
      : selectedRecurringToken?.token.decimals === 8
        ? 100n
        : 1n;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a10b813 and 2965ed7.

📒 Files selected for processing (4)
  • src/components/AmountInput/AmountInput.tsx (2 hunks)
  • src/components/views/donate/Recurring/RecurringDonationCard.tsx (2 hunks)
  • src/components/views/donate/Recurring/RecurringDonationModal/RecurringDonationModal.tsx (1 hunks)
  • src/config/production.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (4)
src/components/AmountInput/AmountInput.tsx (2)

54-60: LGTM! The decimal place handling is well-implemented.

The logic correctly handles the display formatting for tokens with 8 decimals while maintaining backward compatibility for other tokens.


80-86: LGTM! Input validation aligns with display formatting.

The input validation logic is consistent with the display formatting, ensuring that users can't enter more decimal places than allowed for the token type.

src/components/views/donate/Recurring/RecurringDonationCard.tsx (1)

144-150: LGTM! Token amount reset is consistent.

The code correctly resets amounts when switching to tokens with 8 decimals, maintaining consistency with the existing behavior for 6 decimal tokens.

src/config/production.tsx (1)

641-655: LGTM! The cbBTC token configuration is complete.

The configuration correctly defines both the underlying cbBTC token with 8 decimals and its corresponding super token with 18 decimals. All required fields are properly set.

@kkatusic kkatusic merged commit 2965ed7 into develop Jan 20, 2025
3 checks passed
@kkatusic kkatusic deleted the feat/add_cbbtc_recurring branch January 20, 2025 19:23
@kkatusic kkatusic restored the feat/add_cbbtc_recurring branch January 21, 2025 10:22
@coderabbitai coderabbitai bot mentioned this pull request Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant