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(trading): fixed swap inputs validation and styling #17066

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

Conversation

TomasBoda
Copy link
Contributor

@TomasBoda TomasBoda commented Feb 18, 2025

Description

  • the receive address input and the extra field inputs are displayed only after the user selects whether to create a new account or to use an account that isn't in Suite
  • the receive address input shows errors only after the user has interacted with it
  • the extra field inputs (memo, destination tag, ...) have better styling for readability

Related Issue

Resolve #16954
Resolve #17071

Screenshots:

Screen.Recording.2025-02-18.at.10.49.37.mov

@TomasBoda TomasBoda added the bug Something isn't working as expected label Feb 18, 2025
@TomasBoda TomasBoda self-assigned this Feb 18, 2025
Copy link

coderabbitai bot commented Feb 18, 2025

Walkthrough

This pull request introduces modifications to the trading module across several files. In the useTradingVerifyAccount.tsx file, a useEffect hook has been removed, which stops the automatic triggering of form validation when the methods object changes. In the TradingVerify.tsx file, changes include adjustments to the layout spacing between Column components, improved conditional rendering for the address input field, and enhanced validation logic for both the address and extra field inputs. Additionally, a new component, TradingVerifyDestinationTag, has been introduced to encapsulate the extra field input, and the button enabling logic for the "continue transaction" button has been modified to prevent submission with an empty address. The Switch.tsx file also saw a change in the CSS styling for the hover state of the Container component. New declarations were made for the TradingVerifyDestinationTag component and the TradingVerifyDestinationTagProps interface.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f0aeab and c1d56e8.

📒 Files selected for processing (2)
  • packages/suite/src/views/wallet/trading/common/ConfirmedOnTrezor.tsx (2 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerify.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerify.tsx
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=other, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=passphrase, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: build-web
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: build-web
  • GitHub Check: Setup and Cache Dependencies
🔇 Additional comments (2)
packages/suite/src/views/wallet/trading/common/ConfirmedOnTrezor.tsx (2)

8-8: LGTM!

The import is correctly placed with other design system imports and follows the project's module organization.


22-22: LGTM! Good use of design system tokens.

The addition of border-radius using theme tokens ensures visual consistency across the application while improving the component's styling.


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.

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

@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 (1)
packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerify.tsx (1)

239-239: Consider relying on form validation for empty address check.

The additional address === '' check is redundant since the address field is already marked as required in the form validation (line 67). The form.formState.isValid check should be sufficient.

-            isDisabled={!form.formState.isValid || address === '' || callInProgress}
+            isDisabled={!form.formState.isValid || callInProgress}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92df98c and d3aee4a.

📒 Files selected for processing (2)
  • packages/suite/src/hooks/wallet/trading/form/useTradingVerifyAccount.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerify.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=other, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=passphrase, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: build-web
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: build-web
🔇 Additional comments (4)
packages/suite/src/hooks/wallet/trading/form/useTradingVerifyAccount.tsx (1)

75-77: LGTM! The validation mode change improves user experience.

Changing the form validation mode from 'onChange' to 'onTouched' aligns with the PR objectives and improves UX by showing validation errors only after user interaction.

Please verify that this change:

  1. Doesn't affect fields that might need immediate validation
  2. Works correctly with the form validation trigger on mount (line 160)
  3. Maintains expected behavior with shouldValidate flags in setValue calls (lines 125, 127)
packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerify.tsx (3)

128-128: LGTM! Improved spacing for better readability.

The increased gap between Column components enhances the visual hierarchy and readability of the form.


147-174: LGTM! Enhanced address input validation UX.

The changes improve the user experience by:

  1. Only showing the address input after account selection
  2. Displaying error messages only after the user has interacted with the field

181-181: LGTM! Consistent rendering behavior for extra fields.

The extra field input now follows the same pattern as the address input, only showing after account selection.

@tomasklim
Copy link
Member

This is extremely confusing, can we hide memo when buying to your own acc? @adderpositive
Screenshot 2025-02-18 at 11 00 05

@tomasklim
Copy link
Member

This is how our send form now looks like for Ripple
Screenshot 2025-02-18 at 11 06 22

I am thinking that we should replicate it here with by default disabled Add Memo/Destination tag and probably without i or with different text.

What do you think @jirih-stsh?

@jirih-stsh
Copy link

I am thinking that we should replicate it here with by default disabled Add Memo/Destination tag and probably without i or with different text.

What do you think @jirih-stsh?

@tomasklim Yeah I agree. Lets copy the Ui from send, but keep the toggle disabled. Just be aware that currently in send, if you disable the toggle it will inject a warning banner instead bellow the input. Not sure if that will good look in swap.

@tomasklim
Copy link
Member

tomasklim commented Feb 18, 2025

Let's do it without banner and without i. What is this? can cover it

@adderpositive
Copy link
Contributor

This is extremely confusing, can we hide memo when buying to your own acc? @adderpositive Screenshot 2025-02-18 at 11 00 05

I don't know. Will there still be a possibility to fill the memo?

@TomasBoda TomasBoda requested a review from a team as a code owner February 18, 2025 11:45
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 (1)
packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerifyDestinationTag.tsx (1)

41-43: Add aria-label for better accessibility.

The guide button should have an aria-label to improve accessibility for screen readers.

-                <Button variant="tertiary" type="button" size="tiny" onClick={handleOpenGuide}>
+                <Button 
+                    variant="tertiary" 
+                    type="button" 
+                    size="tiny" 
+                    onClick={handleOpenGuide}
+                    aria-label="Learn more about destination tag"
+                >
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57a2300 and 17005ad.

📒 Files selected for processing (3)
  • packages/components/src/components/form/Switch/Switch.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerify.tsx (4 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerifyDestinationTag.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerify.tsx
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=other, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=passphrase, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: build-web
  • GitHub Check: build-web
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
🔇 Additional comments (4)
packages/components/src/components/form/Switch/Switch.tsx (1)

66-70: LGTM! Improved hover state selector specificity.

The change from :hover to &:hover is a good practice in styled-components as it makes the hover state more specific to the component and prevents unintended effects on nested elements.

packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerifyDestinationTag.tsx (3)

1-13: LGTM! Clean interface design with proper type safety.

The imports are well-organized and the interface is clearly defined with appropriate types.


15-22: LGTM! Implementation aligns with requirements.

The component correctly initializes with the toggle disabled by default, as requested in the PR discussion.


33-49: LGTM! Clean layout with proper conditional rendering.

The layout is well-structured and the conditional rendering of the input component is implemented correctly. The use of a tertiary button for the guide link provides a good balance between accessibility and visual cleanliness.

@TomasBoda
Copy link
Contributor Author

TomasBoda commented Feb 18, 2025

Let's do it without banner and without i. What is this? can cover it

@tomasklim Done

Screen.Recording.2025-02-18.at.12.53.14.mov

@TomasBoda
Copy link
Contributor Author

I also fixed #17071 as discussed with @jvaclavik

@tomasklim
Copy link
Member

/rebase

Copy link

@trezor-ci trezor-ci force-pushed the fix/trading-swap-inputs branch from 17005ad to 8f0aeab Compare February 18, 2025 12:25
Copy link
Member

@tomasklim tomasklim left a comment

Choose a reason for hiding this comment

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

It should not be under
Screenshot 2025-02-18 at 13 33 31

@TomasBoda
Copy link
Contributor Author

It should not be under Screenshot 2025-02-18 at 13 33 31

done

@TomasBoda TomasBoda requested a review from tomasklim February 18, 2025 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove hover background color change in the toggle component circle Trading - memo is not nice
4 participants