-
Notifications
You must be signed in to change notification settings - Fork 20
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: evm gas refund #1211
feat: evm gas refund #1211
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
6 Skipped Deployments
|
WalkthroughThis pull request implements EVM gas refund logic across multiple components and services. The changes introduce a new Changes
Sequence DiagramsequenceDiagram
participant User
participant TxDetailsPage
participant EVMService
participant FeeCalculator
User->>TxDetailsPage: View Transaction Details
TxDetailsPage->>EVMService: Fetch EVM Params
EVMService-->>TxDetailsPage: Return Params with gasRefundRatio
TxDetailsPage->>FeeCalculator: Compute Fee with gasRefundRatio
FeeCalculator-->>TxDetailsPage: Calculate Adjusted Fee
TxDetailsPage->>User: Display Transaction Details with Gas Refund
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
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: 1
🧹 Nitpick comments (7)
src/lib/pages/tx-details/components/TxInfo.tsx (1)
76-80
: Consider adding a tooltip to explain gas refund.The gas refund percentage display could benefit from a tooltip explaining how it affects the final transaction fee.
{gasRefundRatio && ( - <LabelText label="Gas Refund Percentage"> + <LabelText + label="Gas Refund Percentage" + tooltip="Percentage of unused gas that will be refunded, reducing the final transaction fee" + > {`${formatPrettyPercent(gasRefundRatio, 2, true)}`} </LabelText> )}src/lib/pages/tx-details/components/TxInfoMobile.tsx (1)
85-89
: Consider adding a tooltip to explain gas refund (mobile).For consistency with the desktop version, consider adding a tooltip here as well.
{gasRefundRatio && ( - <LabelText flex={1} label="Gas Refund Percentage"> + <LabelText + flex={1} + label="Gas Refund Percentage" + tooltip="Percentage of unused gas that will be refunded, reducing the final transaction fee" + > {`${formatPrettyPercent(gasRefundRatio, 2, true)}`} </LabelText> )}src/lib/pages/evm-tx-details/data.ts (1)
54-56
: Ensure safe type conversion for gasRefundRatio.The fallback to 0 using type assertion might hide potential type issues. Consider using a more explicit conversion.
- const gasRefundRatio = - evmParams?.params.gasRefundRatio ?? (0 as Ratio<number>); + const gasRefundRatio: Ratio<number> = + evmParams?.params.gasRefundRatio ?? 0;src/lib/services/evm/index.ts (1)
30-33
: Consider using a custom error type for EVM-related errors.Instead of using generic Error, create a custom error type for better error handling and type safety.
+class EvmError extends Error { + constructor(hook: string) { + super(`EVM is not enabled (${hook})`); + this.name = 'EvmError'; + } +} - if (!evm.enabled) throw new Error("EVM is not enabled (useEvmParams)"); + if (!evm.enabled) throw new EvmError("useEvmParams");src/lib/pages/evm-tx-details/components/EvmTxGasReceipt.tsx (1)
25-41
: Consider adding aria-labels for better accessibility.The grid layout should have appropriate ARIA attributes for screen readers.
- <SimpleGrid columns={{ base: 2, md: 1 }} gap={4}> + <SimpleGrid + columns={{ base: 2, md: 1 }} + gap={4} + role="group" + aria-label="Transaction gas details">src/lib/pages/tx-details/index.tsx (1)
77-83
: Consider memoizing child components for better performance.The gas refund ratio prop updates might cause unnecessary re-renders.
+const MemoizedTxInfoMobile = memo(TxInfoMobile); +const MemoizedTxInfo = memo(TxInfo); - <TxInfoMobile txData={data} gasRefundRatio={gasRefundRatio} /> + <MemoizedTxInfoMobile txData={data} gasRefundRatio={gasRefundRatio} /> - <TxInfo txData={data} gasRefundRatio={gasRefundRatio} /> + <MemoizedTxInfo txData={data} gasRefundRatio={gasRefundRatio} />CHANGELOG.md (1)
42-42
: Consider adding more details about the EVM gas refund feature.While the entry correctly follows the changelog format, it would be helpful to provide more context about:
- The purpose and benefits of the gas refund feature
- Any configuration options or requirements
- Impact on existing functionality
Consider expanding the entry like this:
-[#1211](https://github.com/alleslabs/celatone-frontend/pull/1211) Implement evm gas refund logic +[#1211](https://github.com/alleslabs/celatone-frontend/pull/1211) Implement EVM gas refund logic - Adds support for calculating and displaying gas refund percentages in transaction details, introduces gasRefundRatio property across components, and enhances the UI to show refund information
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
CHANGELOG.md
(1 hunks)src/lib/pages/evm-tx-details/components/EvmTxGasReceipt.tsx
(2 hunks)src/lib/pages/evm-tx-details/data.ts
(5 hunks)src/lib/pages/tx-details/components/TxInfo.tsx
(4 hunks)src/lib/pages/tx-details/components/TxInfoMobile.tsx
(4 hunks)src/lib/pages/tx-details/index.tsx
(4 hunks)src/lib/services/evm/index.ts
(1 hunks)src/lib/services/types/evm/params.ts
(2 hunks)src/lib/utils/fee.ts
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (javascript)
🔇 Additional comments (9)
src/lib/services/types/evm/params.ts (1)
13-13
: LGTM! Clean addition of gas refund ratio parameter.The implementation follows the schema's naming convention and ensures type safety using
zRatio
with number coercion.src/lib/pages/tx-details/components/TxInfo.tsx (1)
20-20
: LGTM! Clean implementation of gas refund display.The changes correctly integrate the gas refund calculation and display:
- Props interface is properly typed
- Fee calculation uses the new
computeCosmosFee
function- Gas refund percentage is conditionally rendered
Also applies to: 32-52
src/lib/pages/tx-details/components/TxInfoMobile.tsx (1)
19-19
: LGTM! Mobile implementation matches desktop version.The changes correctly mirror the desktop implementation:
- Props interface is properly typed
- Fee calculation uses the new
computeCosmosFee
functionAlso applies to: 33-53
src/lib/pages/evm-tx-details/data.ts (2)
73-75
: LGTM: Transaction fee calculation using actual gas amount.The implementation correctly uses the adjusted gas amount (after refund) for calculating the transaction fee.
68-71
: Verify gas refund calculation for edge cases.The gas refund calculation needs additional validation:
- Ensure gasRefund doesn't exceed the total gas used
- Handle potential negative values
✅ Verification successful
Gas refund calculation is properly implemented and handles edge cases
The implementation is safe because:
- Gas refund is limited to unused gas only
- Refund ratio is controlled by chain parameters
- Default value of 0 ensures graceful handling when parameters are unavailable
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any existing gas refund validation logic rg -A 5 "gasRefund" --type ts --type tsxLength of output: 68
Script:
#!/bin/bash # Search for gas refund related logic with correct file type rg -t ts "gasRefund" -B 5 -A 5 # Search specifically for gasRefundRatio to understand how it's defined rg -t ts "gasRefundRatio" -B 2 -A 2Length of output: 21769
src/lib/services/evm/index.ts (1)
Line range hint
35-41
: LGTM: Query configuration for EVM params.The query configuration is well-optimized with appropriate caching settings:
- Infinity stale time for static params
- No refetch on window focus
- No retry on mount
src/lib/pages/evm-tx-details/components/EvmTxGasReceipt.tsx (1)
38-40
: Verify the precision of gas refund percentage formatting.The format precision of 2 decimal places might not be sufficient for all cases.
✅ Verification successful
Gas refund percentage formatting precision is appropriate
The current 2 decimal place precision is consistent with other gas-related metrics in the codebase and provides sufficient accuracy for gas refund representation. The implementation includes proper handling of edge cases, including very small percentages.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for other percentage formatting instances rg "formatPrettyPercent.*" --type ts --type tsxLength of output: 77
Script:
#!/bin/bash # Search for formatPrettyPercent usage with correct file types echo "=== Searching in .ts files ===" rg "formatPrettyPercent" --type ts echo -e "\n=== Searching in .tsx files ===" rg "formatPrettyPercent" -g "*.tsx" echo -e "\n=== Looking for function implementation ===" ast-grep --pattern 'function formatPrettyPercent($_) { $$$ }' echo -e "\n=== Looking for const implementation ===" ast-grep --pattern 'const formatPrettyPercent = $_'Length of output: 16742
src/lib/pages/tx-details/index.tsx (1)
56-61
: LGTM: Comprehensive loading state handling.The loading state correctly accounts for all async operations:
- Redirect checking
- Data loading
- Related EVM transaction fetching
- EVM params fetching
CHANGELOG.md (1)
Line range hint
1-41
: LGTM! Well-structured changelog header.The header section properly follows the Keep a Changelog format, providing clear guidelines for:
- Changelog principles and usage
- Types of changes categorization
- Version and section linking requirements
Summary by CodeRabbit
New Features
Improvements
Technical Updates