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

[TASK-6919] Show slippage fee on request pay #526

Merged
merged 4 commits into from
Nov 19, 2024

Conversation

jjramirezn
Copy link
Contributor

Get the slippage fee used from the sdk and show it cost in dollars on request pay

The sdk version must be bumped after deploying to main peanutprotocol/peanut-sdk#166

Copy link

vercel bot commented Nov 14, 2024

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

Name Status Preview Comments Updated (UTC)
peanut-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 19, 2024 1:27pm

Copy link
Contributor

coderabbitai bot commented Nov 14, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request includes updates to the package.json file, specifically incrementing the version of the @squirrel-labs/peanut-sdk dependency from ^0.5.8 to ^0.5.10. Additionally, modifications in the Initial.view.tsx file introduce new state variables for slippage calculations and cross-chain transaction handling, updating the component's logic to accommodate these changes.

Changes

File Change Summary
package.json Updated @squirrel-labs/peanut-sdk version from ^0.5.8 to ^0.5.10.
src/components/Request/Pay/Views/Initial.view.tsx Added state variables for slippagePercentage and xChainUnsignedTxs; updated logic for transaction handling and estimation.

Possibly related PRs

Suggested reviewers

  • panosfilianos
  • Hugo0

Warning

Rate limit exceeded

@jjramirezn has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 8 minutes and 59 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 88597a0 and 3a651e8.


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

Copy link
Contributor

@Hugo0 Hugo0 left a comment

Choose a reason for hiding this comment

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

lgtm, dependent on SDK release

@Hugo0 Hugo0 marked this pull request as ready for review November 19, 2024 12:46
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 and nitpick comments (3)
package.json (1)

26-26: Consider SDK update timing

The PR objectives indicate that the SDK version should be updated following the deployment to the main branch. Consider whether this update should be in a separate PR that's merged after the main deployment.

src/components/Request/Pay/Views/Initial.view.tsx (2)

143-153: Remove console logging statements

Production code should not contain console logging statements. Consider using a proper logging system if debugging information needs to be preserved.

-                console.log('slippage', slippagePercentage)
-                console.dir(txData)

424-439: Consider adding loading state for slippage calculation

The slippage cost display is well-implemented and consistent with the existing UI. However, consider adding a loading state similar to the network cost display to improve user experience during calculation.

-                        {null !== calculatedSlippage && (
+                        {calculatedSlippage === null ? (
+                            <div className="flex w-full flex-row items-center justify-between gap-1 px-2 text-h8 text-gray-1">
+                                <div className="flex w-max flex-row items-center justify-center gap-1">
+                                    <Icon name={'money-out'} className="h-4 fill-gray-1" />
+                                    <label className="font-bold">Slippage cost</label>
+                                </div>
+                                <div className="h-2 w-16 animate-colorPulse rounded bg-slate-700"></div>
+                            </div>
+                        ) : calculatedSlippage && (
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 195c4a7 and 88597a0.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/components/Request/Pay/Views/Initial.view.tsx (5 hunks)
🔇 Additional comments (5)
package.json (1)

26-26: ⚠️ Potential issue

Update SDK version to 0.5.10 and include lock file changes

The SDK version needs to be updated to ^0.5.10 due to a recent hotfix. Additionally, the pnpm-lock.json file must be updated to reflect this change.

Apply this diff:

-        "@squirrel-labs/peanut-sdk": "^0.5.9",
+        "@squirrel-labs/peanut-sdk": "^0.5.10",

Then run:

pnpm install

to update the lock file.

src/components/Request/Pay/Views/Initial.view.tsx (4)

93-96: LGTM: Well-structured state management for slippage handling

The new state variables are properly typed and initialized, following React's best practices.


102-106: LGTM: Efficient slippage calculation with proper null handling

The calculation is correctly memoized and handles undefined states appropriately. The result is properly formatted for currency display.


187-188: LGTM: Proper state cleanup on token/chain changes

The slippage states are appropriately reset when the user changes the token or chain, preventing stale data from being displayed.


308-316: LGTM: Safe transaction handling with proper checks

The code properly checks for the existence of cross-chain transactions before proceeding and correctly integrates with the transaction submission flow.

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 and nitpick comments (2)
src/components/Request/Pay/Views/Initial.view.tsx (2)

102-106: Consider using a more precise numeric handling approach

While the current implementation is functional, consider using a decimal handling library like decimal.js or bignumber.js for more precise financial calculations to avoid potential floating-point precision issues.

 const calculatedSlippage = useMemo(() => {
     if (!selectedTokenData?.price || !slippagePercentage) return null
-    return ((slippagePercentage / 100) * selectedTokenData.price * Number(estimatedFromValue)).toFixed(2)
+    return new BigNumber(slippagePercentage)
+      .div(100)
+      .times(selectedTokenData.price)
+      .times(estimatedFromValue)
+      .toFixed(2)
 }, [slippagePercentage, selectedTokenData, estimatedFromValue])

306-314: Consider enhancing error feedback for cross-chain transactions

While the implementation is correct, consider providing more specific error messages when xChainUnsignedTxs is undefined to improve the user experience.

-                if (!xChainUnsignedTxs) return
+                if (!xChainUnsignedTxs) {
+                    throw new Error('Cross-chain transaction data is not available. Please try again.')
+                }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 88597a0 and 3a651e8.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/components/Request/Pay/Views/Initial.view.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🔇 Additional comments (4)
src/components/Request/Pay/Views/Initial.view.tsx (4)

93-96: LGTM: Well-structured state management for slippage handling

The new state variables are properly typed and initialized, following React's best practices.


143-151: LGTM: Robust transaction preparation with proper error handling

The transaction preparation logic properly handles both success and error cases, ensuring state consistency by resetting values when needed.

Also applies to: 158-159


185-186: LGTM: Clean state reset on token/chain changes

Appropriate reset of slippage-related states when the token or chain selection changes, preventing stale data issues.


422-437: LGTM: Well-implemented slippage cost display

The UI implementation for slippage cost follows the existing design patterns and provides clear information to users through tooltips.

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.

2 participants