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

Hotfix/add modal swap #991

Merged
merged 2 commits into from
Oct 8, 2024
Merged

Hotfix/add modal swap #991

merged 2 commits into from
Oct 8, 2024

Conversation

quangdz1704
Copy link
Contributor

@quangdz1704 quangdz1704 commented Oct 8, 2024

Hotfix/add modal swap

Summary by CodeRabbit

  • New Features
    • Introduced a warning modal for high-impact swaps, enhancing user awareness before transaction finalization.
  • Styling Updates
    • Improved mobile responsiveness and visual hierarchy of the SwapWarningModal.
  • Bug Fixes
    • Updated button types for better clarity and functionality in mobile and standard views.

@quangdz1704 quangdz1704 self-assigned this Oct 8, 2024
Copy link

coderabbitai bot commented Oct 8, 2024

Walkthrough

The pull request includes updates to the package.json file, specifically upgrading the @sentry/react dependency from version ^7.47.1 to 7.99.0, with this version also specified in the resolutions section. Additionally, the SwapWarningModal component has been modified in its styling and functionality, enhancing responsiveness for mobile devices and integrating a modal warning for high-impact swaps in the Swap component.

Changes

File Change Summary
package.json Updated @sentry/react from ^7.47.1 to 7.99.0 in dependencies and resolutions.
src/pages/UniversalSwap/Component/SwapWarningModal/index.module.scss Adjusted styles for .desc, .impact, and .button classes to improve mobile responsiveness.
src/pages/UniversalSwap/Component/SwapWarningModal/index.tsx Changed cancel button type from 'secondary-sm' to 'third-sm' for mobile and standard modes.
src/pages/UniversalSwap/Swap/index.tsx Added SwapWarningModal import, initialized openSwapWarning state, and updated swap submission logic to include a warning modal for high-impact swaps.

Possibly related PRs

Suggested reviewers

  • haunv3
  • trungbach
  • vuonghuuhung

🐰 In a world of swaps and code so bright,
A modal now warns before the final bite.
With styles that dance on mobile screens,
Our app now flows like a dream, it seems!
Dependencies updated, all in a row,
Hopping along, watch our features grow! 🌟


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

sonarcloud bot commented Oct 8, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@quangdz1704 quangdz1704 merged commit eead3df into main Oct 8, 2024
4 of 5 checks passed
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: 1

🧹 Outside diff range and nitpick comments (3)
src/pages/UniversalSwap/Component/SwapWarningModal/index.tsx (1)

Line range hint 1-1: Consider using CSS media queries for responsive design

The component currently uses isMobile() from '@walletconnect/browser-utils' to determine the device type. While this works, it might not be the most reliable or flexible approach for responsive design.

Consider using CSS media queries or a more robust responsive design approach:

  1. Use CSS media queries in your styles to handle different screen sizes.
  2. If you need to adjust behavior in React, you could use a custom hook that listens to window resize events and provides the current breakpoint.

This approach would allow for more granular control over the component's appearance and behavior across different screen sizes, not just mobile vs. desktop.

Example of a custom hook for responsive design:

import { useState, useEffect } from 'react';

const useResponsive = () => {
  const [isMobile, setIsMobile] = useState(window.innerWidth < 768);

  useEffect(() => {
    const handleResize = () => {
      setIsMobile(window.innerWidth < 768);
    };

    window.addEventListener('resize', handleResize);
    return () => window.removeEventListener('resize', handleResize);
  }, []);

  return { isMobile };
};

You could then use this hook in your component:

const SwapWarningModal = ({ open, onClose, onConfirm, impact }: SwapWarningModalProps) => {
  const { isMobile } = useResponsive();
  // ... rest of the component
}

This approach would make the component more adaptable to different screen sizes and easier to maintain in the long run.

Also applies to: 16-16

src/pages/UniversalSwap/Swap/index.tsx (2)

Line range hint 604-604: Fix typo in function name

The function name caculateImpactWarning contains a typo. It should be calculateImpactWarning.

Apply this change:

-function caculateImpactWarning() {
+function calculateImpactWarning() {

833-836: Improved safety check for high-impact swaps

The addition of a check for high-impact swaps before proceeding with the transaction is a good safety measure. It prevents users from accidentally executing swaps with significant price impacts.

Consider extracting the magic number 10 into a named constant for better readability and maintainability.

Apply this change at the top of the file:

const HIGH_IMPACT_THRESHOLD = 10;

Then update the condition:

-if (impactWarning > 10) return setOpenSwapWarning(true);
+if (impactWarning > HIGH_IMPACT_THRESHOLD) return setOpenSwapWarning(true);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between aebebff and cb1fa3a.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (4)
  • package.json (2 hunks)
  • src/pages/UniversalSwap/Component/SwapWarningModal/index.module.scss (2 hunks)
  • src/pages/UniversalSwap/Component/SwapWarningModal/index.tsx (2 hunks)
  • src/pages/UniversalSwap/Swap/index.tsx (5 hunks)
🧰 Additional context used
🔇 Additional comments (10)
src/pages/UniversalSwap/Component/SwapWarningModal/index.tsx (1)

24-24: LGTM! Consider verifying the visual impact of the button type change.

The change from 'secondary' to 'third' button type for the cancel action is appropriate and aligns with common UI practices. This modification will likely affect the styling and emphasis of the cancel button in both mobile and desktop views.

To ensure the change doesn't negatively impact the user experience, please verify the visual appearance of the cancel button in both mobile and desktop views. You may want to check:

  1. The button's visibility and contrast against the background.
  2. The visual hierarchy between the cancel and confirm buttons.
  3. Consistency with other modals or dialogs in the application.
src/pages/UniversalSwap/Component/SwapWarningModal/index.module.scss (4)

116-120: LGTM: Improved readability and mobile responsiveness

The addition of line-height: 150% enhances text readability, while the font size reduction to 12px for mobile devices improves the responsive design. These changes are well-considered and should positively impact the user experience.


123-126: LGTM: Enhanced visual hierarchy

Changing the font weight to 600 for the .impact class improves the visual hierarchy, making important information more prominent. The added empty line enhances code readability. These are small but valuable improvements.


144-146: LGTM: Improved button styling and consistency

Setting a fixed height of 44px for buttons ensures consistency across devices. The added padding (6px vertical, 10px horizontal) improves the button's appearance and increases the touch target size, enhancing usability, especially on touch devices.


137-140: LGTM: Improved mobile layout, verify button order

The reduced gap and reversed column direction for buttons on small mobile devices are good improvements for space utilization and accessibility. The primary action button will likely be more accessible at the bottom of the screen on mobile devices.

Please verify that the new button order (bottom-to-top on mobile) aligns with the intended user flow and doesn't cause confusion. Run the following script to check for any related comments or documentation:

package.json (2)

133-133: LGTM: Consistent version resolution for @sentry/react

Adding @sentry/react to the resolutions field with the same version as in dependencies is a good practice. This ensures that all nested dependencies will use this specific version, preventing potential conflicts.


28-28: Verify compatibility with the updated @sentry/react version

The @sentry/react package has been updated from ^7.47.1 to 7.99.0, which is a significant version jump. While this update likely includes bug fixes and new features, it may also introduce breaking changes.

Please ensure that:

  1. The application is compatible with this new version.
  2. All Sentry-related functionality is thoroughly tested.
  3. The changelog for @sentry/react between versions 7.47.1 and 7.99.0 has been reviewed for any breaking changes or deprecations.

Run the following script to check for any Sentry-related warnings or errors after the update:

✅ Verification successful

@sentry/react has been successfully updated to version 7.99.0 without any build warnings or errors.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for Sentry-related issues after the update

# Test: Search for Sentry imports and usages
echo "Searching for Sentry imports and usages:"
rg --type typescript --type javascript -i 'sentry'

# Test: Check build logs for Sentry-related warnings
echo "Checking build logs for Sentry-related warnings:"
yarn build 2>&1 | rg -i 'sentry|warning|error'

Length of output: 327


Script:

#!/bin/bash
# Description: Check for Sentry-related issues after the update

# Test: Search for Sentry imports and usages using correct file types
echo "Searching for Sentry imports and usages:"
rg --type ts --type tsx --type js --type jsx -i 'sentry'

# Test: Check build logs for Sentry-related warnings
echo "Checking build logs for Sentry-related warnings:"
yarn build 2>&1 | rg -i 'sentry|warning|error'

Length of output: 326


Script:

#!/bin/bash
# Description: Check for Sentry-related issues after the update

# Test: Search for Sentry imports and usages across all relevant files
echo "Searching for Sentry imports and usages:"
rg -i 'sentry'

# Test: Check build logs for Sentry-related warnings
echo "Checking build logs for Sentry-related warnings:"
yarn build 2>&1 | rg -i 'sentry|warning|error'

Length of output: 6813

src/pages/UniversalSwap/Swap/index.tsx (3)

87-87: Uncommented SwapWarningModal import

The SwapWarningModal import has been uncommented. This suggests that a new feature for warning users about high-impact swaps is being implemented.


128-128: New state for swap warning modal

A new state variable openSwapWarning has been added. This state is likely used to control the visibility of the SwapWarningModal, enhancing the user experience by providing warnings for high-impact swaps.


Line range hint 959-968: SwapWarningModal successfully integrated

The SwapWarningModal has been successfully integrated into the component. It uses the appropriate state for visibility control and includes necessary props for handling user interactions. This addition enhances the user experience by providing clear warnings for high-impact swaps.

@quangdz1704 quangdz1704 deleted the hotfix/add_modal_swap branch October 8, 2024 10:48
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.

3 participants