-
-
Notifications
You must be signed in to change notification settings - Fork 33
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 estimated timer #4950
Add estimated timer #4950
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe pull request introduces configuration and handling changes for tokens with varying decimal precisions, specifically focusing on tokens like Coinbase Wrapped BTC with 8 decimal places. The modifications span multiple files, including sitemap generation configuration, amount input handling, recurring donation components, and production token configuration. The changes aim to enhance the system's flexibility in processing different token types with more precise decimal handling. Changes
Possibly related issues
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 (5)
src/components/AmountInput/AmountInput.tsx (2)
54-60
: Consider using an object map for decimal precision.The current implementation uses a ternary operator to determine
maxDecimals
. As more token types with different decimal precisions are added, this approach might become harder to maintain.Consider using an object map for better maintainability:
-const maxDecimals = decimals === 8 ? 8 : decimals / 3; +const DECIMAL_PRECISION: { [key: number]: number } = { + 8: 8, + 18: 6, + 6: 2, +}; +const maxDecimals = DECIMAL_PRECISION[decimals] || decimals / 3;
80-86
: Improve decimal validation logic.The current implementation has separate conditions for 8 decimals and other cases. This could be simplified using the same
maxDecimals
variable that was calculated earlier.Consider using the
maxDecimals
variable for validation:-// Allow more decimals if token has 8 decimals -if (decimals === 8) { - if (_decimals?.length > 8) return; // Limit to 8 decimals -} else { - if (_decimals?.length > decimals / 3) return; // Limit to 6 or 2 decimals for other tokens -} +const maxDecimals = decimals === 8 ? 8 : decimals / 3; +if (_decimals?.length > maxDecimals) return;src/components/views/donate/Recurring/RecurringDonationModal/RecurringDonationModal.tsx (1)
245-261
: Consider extracting token conversion logic.The token conversion logic is complex and could benefit from being extracted into a separate helper function. This would improve readability and make it easier to test.
Consider creating a helper function:
const convertTokenAmount = ( amount: bigint, decimals: number, targetDecimals: number = 18 ): bigint => { if (decimals === 6 || decimals === 8) { const divisor = BigInt(10 ** decimals); const currentAmount = Number(amount) / Number(divisor); return ethers.utils.parseUnits(currentAmount.toFixed(8), targetDecimals).toBigInt(); } return amount; };Then use it in the code:
-if (selectedRecurringToken.token.decimals === 6 || selectedRecurringToken.token.decimals === 8) { - const divisor = BigInt(10 ** selectedRecurringToken.token.decimals); - const currentAmount = Number(amount) / Number(divisor); - newAmount = ethers.utils.parseUnits(currentAmount.toFixed(8), 18).toBigInt(); - - const currentPerMonth = Number(perMonthAmount) / Number(divisor); - newPerMonthAmount = ethers.utils.parseUnits(currentPerMonth.toFixed(8), 18).toBigInt(); -} +newAmount = convertTokenAmount(amount, selectedRecurringToken.token.decimals); +newPerMonthAmount = convertTokenAmount(perMonthAmount, selectedRecurringToken.token.decimals);src/components/views/donate/Recurring/RecurringDonationCard.tsx (2)
144-150
: Consider using a constant for supported decimals.The condition for resetting amounts could be more maintainable by using a constant for supported decimal places.
Consider using a constant:
+const SUPPORTED_DECIMALS = [6, 8]; + -if (selectedRecurringToken.token.decimals === 6 || selectedRecurringToken.token.decimals === 8) { +if (SUPPORTED_DECIMALS.includes(selectedRecurringToken.token.decimals)) { setAmount(0n); setPerMonthAmount(0n); }
157-161
: Consider using an object map for scale factors.The scale factor calculation uses nested ternary operators which can be hard to read and maintain.
Consider using an object map:
+const SCALE_FACTORS: { [key: number]: bigint } = { + 6: 10000n, + 8: 100n, +}; + -const scaleFactor = selectedRecurringToken?.token.decimals === 6 - ? 10000n - : selectedRecurringToken?.token.decimals === 8 - ? 100n - : 1n; +const scaleFactor = SCALE_FACTORS[selectedRecurringToken?.token.decimals || 0] || 1n;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
pages/api/generate-sitemap.ts
(1 hunks)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)
✅ Files skipped from review due to trivial changes (1)
- pages/api/generate-sitemap.ts
🔇 Additional comments (1)
src/config/production.tsx (1)
641-655
: LGTM! Token configuration is well-structured.The configuration for "Coinbase Wrapped BTC" is complete with all necessary properties:
- Correct decimal places (8 for underlying token, 18 for super token)
- Proper token addresses
- Appropriate coingeckoId for price tracking
Summary by CodeRabbit
Release Notes
New Features
Improvements
Configuration