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/sending nft fee calc #581

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Conversation

gamalielhere
Copy link
Contributor

@gamalielhere gamalielhere commented Dec 20, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced balance validation in the transaction component to ensure users have sufficient funds for both the transaction amount and fees.
    • Updated error messaging for insufficient funds during transactions.
  • Bug Fixes

    • Improved validation logic for input amounts in the transaction component to prevent negative values.
  • Chores

    • Minor formatting adjustments for code consistency.

Copy link

coderabbitai bot commented Dec 20, 2024

Walkthrough

The pull request introduces consistent changes across multiple Ethereum network configuration files, specifically modifying the activityHandler property. The changes involve importing wrapActivityHandler from a new module and wrapping existing promise-based activity handlers that resolve to empty arrays. Additionally, the send-transaction component's index.vue file has been updated with enhanced balance and transaction validation logic, focusing on improving user feedback and input checks for transaction amounts and fees.

Changes

File Change Summary
packages/extension/src/providers/ethereum/networks/arb-nova.ts Added wrapActivityHandler import, modified activityHandler to use wrapped promise
packages/extension/src/providers/ethereum/networks/bsc.ts Replaced EtherscanActivity with empty array promise in activityHandler
packages/extension/src/providers/ethereum/networks/holesky.ts Added wrapActivityHandler import, wrapped existing empty array promise
packages/extension/src/providers/ethereum/networks/op-bnb.ts Added wrapActivityHandler import, modified activityHandler
packages/extension/src/providers/ethereum/networks/palm.ts Added wrapActivityHandler import, wrapped empty array promise
packages/extension/src/providers/ethereum/ui/send-transaction/index.vue Enhanced balance and transaction validation logic, added gas fee checks, refined error messaging

Possibly related PRs

Suggested reviewers

  • kvhnuke
  • NickKelly1

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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.

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

github-actions bot commented Dec 20, 2024

💼 Build Files
chrome: enkrypt-chrome-9002ec63.zip
firefox: enkrypt-firefox-9002ec63.zip

💉 Virus total analysis
chrome: 9002ec63
firefox: 9002ec63

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

🧹 Nitpick comments (3)
packages/extension/src/providers/ethereum/networks/arb-nova.ts (1)

Line range hint 4-24: Consider documenting the relationship between activity handlers and fee calculations.

While the implementation of wrapActivityHandler is consistent across all network configurations, the connection between these changes and NFT fee calculations (mentioned in the PR title) isn't immediately clear. Consider:

  1. Adding comments explaining how these changes relate to fee calculations
  2. Documenting any assumptions about the activity handler's role in fee processing
  3. Including test cases that verify the integration between these components

Would you like help drafting documentation or test cases to clarify these relationships?

packages/extension/src/providers/ethereum/ui/send-transaction/index.vue (2)

228-238: Consider adding a pre-validation step

While the validation logic is correct, consider adding a pre-validation step before attempting transactions to provide early feedback to users.

+const canCoverFees = computed(() => {
+  return !toBN(
+    toBase(
+      gasCostValues.value[selectedFee.value].nativeValue,
+      props.network.decimals,
+    ),
+  ).gt(toBN(nativeBalance.value));
+});

+watch(canCoverFees, (newVal) => {
+  if (!newVal) {
+    // Disable send button or show warning
+  }
+});

Also applies to: 577-578


228-238: Consider implementing fee estimation caching

The current implementation recalculates fees on every input change. Consider implementing a caching mechanism for fee estimates to improve performance and reduce RPC calls.

  1. Cache fee estimates with a reasonable TTL (e.g., 30 seconds)
  2. Only recalculate when:
    • The selected fee type changes
    • The TTL expires
    • The transaction parameters significantly change

Also applies to: 577-578

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eec3ed6 and 9002ec6.

📒 Files selected for processing (6)
  • packages/extension/src/providers/ethereum/networks/arb-nova.ts (2 hunks)
  • packages/extension/src/providers/ethereum/networks/bsc.ts (1 hunks)
  • packages/extension/src/providers/ethereum/networks/holesky.ts (2 hunks)
  • packages/extension/src/providers/ethereum/networks/op-bnb.ts (2 hunks)
  • packages/extension/src/providers/ethereum/networks/palm.ts (2 hunks)
  • packages/extension/src/providers/ethereum/ui/send-transaction/index.vue (2 hunks)
🔇 Additional comments (8)
packages/extension/src/providers/ethereum/networks/holesky.ts (2)

4-4: LGTM: Import addition is consistent with other network configurations.

The import statement follows the project's convention using the @/ alias path.


18-18: Verify the wrapper's impact on activity handling.

While the change maintains the same underlying behavior (returning an empty array), we should verify that wrapActivityHandler properly handles promise resolution.

✅ Verification successful

The wrapper properly handles promise resolution for activity handling

The wrapActivityHandler implementation correctly handles promise resolution and caching:

  • It properly awaits the promise returned by the wrapped handler using await
  • It handles both empty and populated activity states
  • It implements caching with proper TTL (5 minutes) and cache invalidation
  • The empty array promise in the Holesky network is handled appropriately within this wrapper
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for wrapActivityHandler implementation and usage patterns
ast-grep --pattern 'export default function wrapActivityHandler($_) {
  $$$
}'

Length of output: 80


Script:

#!/bin/bash
# Let's try searching for wrapActivityHandler with ripgrep to find its implementation
rg "wrapActivityHandler" -A 5

Length of output: 65711


Script:

#!/bin/bash
# Let's search for the implementation of wrapActivityHandler in the libs directory
rg -g "*.ts" "export.*wrapActivityHandler" -A 10 packages/extension/src/libs/

Length of output: 79


Script:

#!/bin/bash
# Let's try finding the file containing wrapActivityHandler implementation
fd "wrap-activity-handler.ts" packages/extension/src/

Length of output: 121


Script:

#!/bin/bash
# Let's examine the implementation of wrapActivityHandler
cat packages/extension/src/libs/activity-state/wrap-activity-handler.ts

Length of output: 1216

packages/extension/src/providers/ethereum/networks/op-bnb.ts (1)

6-6: Verify integration with NFT handler.

Given that this is a production network with NFT support, we should verify that wrapActivityHandler properly integrates with the existing shNFTHandler for NFT-related activities.

Also applies to: 24-24

✅ Verification successful

NFT handler integration is properly implemented

The verification shows that the integration is correct and safe:

  1. The shNFTHandler from simplehash.ts explicitly supports opBNB network (listed as OpBNB in supportedNetworks)
  2. The wrapActivityHandler is a generic wrapper that adds caching functionality and works independently of the NFT handler
  3. Both handlers are properly initialized in op-bnb.ts and don't interfere with each other's operation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for interactions between NFT handler and activity handler
rg -A 5 "shNFTHandler.*wrapActivityHandler|wrapActivityHandler.*shNFTHandler"

# Check NFT handler implementation
ast-grep --pattern 'const shNFTHandler = {
  $$$
}'

Length of output: 133


Script:

#!/bin/bash
# Let's first check the file content to understand the NFT handler usage
cat packages/extension/src/providers/ethereum/networks/op-bnb.ts

# Also search for NFT handler patterns across the codebase
rg -A 5 "NFTHandler"

# Look for activity handler wrapping patterns
ast-grep --pattern 'wrapActivityHandler($$$)'

Length of output: 50398


Script:

#!/bin/bash
# Let's check the implementation of the NFT handler and activity handler wrapper
cat packages/extension/src/libs/nft-handlers/simplehash.ts
cat packages/extension/src/libs/activity-state/wrap-activity-handler.ts

Length of output: 5210

packages/extension/src/providers/ethereum/networks/arb-nova.ts (1)

6-6: Consistent implementation across network configurations.

The changes follow the same pattern as other network configurations, which is good for maintainability. However, given this PR's focus on NFT fee calculations, we should verify the broader impact.

Consider adding integration tests to verify the interaction between wrapped activity handlers and fee calculations across different networks.

Also applies to: 24-24

packages/extension/src/providers/ethereum/networks/palm.ts (1)

5-5: Verify if empty activity handler is intentional

The activity handler is now returning an empty array. While this implementation is consistent with other network files, please verify if this is intentional as it might affect activity tracking for the Palm network.

Also applies to: 24-24

✅ Verification successful

Empty activity handler is intentional for Palm network

The empty activity handler implementation is intentional and consistent with several other EVM networks in the codebase. Multiple networks like BSC, Holesky, Arbitrum Nova, Klaytn, and others also use wrapActivityHandler(() => Promise.resolve([])). This pattern is used when a network doesn't have a specific activity tracking implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if other network configurations use similar empty activity handlers
rg -A 1 "activityHandler.*wrapActivityHandler" 

Length of output: 17630

packages/extension/src/providers/ethereum/networks/bsc.ts (1)

26-26: ⚠️ Potential issue

Consider impact of removing EtherscanActivity

The change removes actual activity tracking via EtherscanActivity in favor of an empty array. This is a significant change that could affect transaction history visibility.

packages/extension/src/providers/ethereum/ui/send-transaction/index.vue (2)

228-238: Improved fee validation logic

Good addition of native balance check for transaction fees. This prevents transactions from failing due to insufficient funds for gas fees.


577-578: Enhanced input validation

Good addition of BigNumber validation to prevent NaN values and ensure numeric inputs are valid.

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.

1 participant