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

chore(trading): move useTradingInfo hook to @suite-common/trading #17450

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

jbazant
Copy link
Contributor

@jbazant jbazant commented Mar 6, 2025

Description

Refactor useTradingInfo to suite-common.

@jbazant jbazant added the no-project This label is used to specify that PR doesn't need to be added to a project label Mar 6, 2025
@jbazant jbazant requested a review from adderpositive March 6, 2025 14:36
Copy link

coderabbitai bot commented Mar 6, 2025

Walkthrough

The changes refactor the source of the useTradingInfo hook and related trading modules across the codebase. Import statements in components, hooks, forms, views, and tests are updated to use @suite-common/trading instead of local paths. Multiple files have had redundant or duplicate imports removed, and tests now mock the updated module. In addition to consolidating hook imports, several trading-related types and interfaces have been revised: outdated declarations have been removed or consolidated, and new properties and types have been introduced to better define trading options. Updates in the suite-common/trading package include modifications to package dependencies (adding @trezor/address-validator and react-redux), changes to Redux typings with an extended dispatch interface for thunk actions, new exports for hooks, and TypeScript configuration adjustments to include new reference paths.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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)
suite-common/trading/src/types.ts (1)

119-133: Well-designed interface for the relocated hook

This comprehensive interface aligns perfectly with the PR objective of moving the useTradingInfo hook to @suite-common/trading. The methods provide all the necessary transformations for working with crypto IDs and building selection options.

One suggestion would be to rename this to TradingInfoHookProps or similar to clearly indicate it represents a hook's return value.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5057a4f and 4beb965.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (4)
  • packages/suite/src/types/trading/trading.ts (3 hunks)
  • suite-common/trading/package.json (1 hunks)
  • suite-common/trading/src/hooks/useTradingInfo.ts (3 hunks)
  • suite-common/trading/src/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • suite-common/trading/src/hooks/useTradingInfo.ts
  • packages/suite/src/types/trading/trading.ts
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: PR-check / node-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: PR-check / node-override init-api-flaky
  • GitHub Check: PR-check / web-override init-api-flaky
  • GitHub Check: PR-check / web-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: build-deploy
  • GitHub Check: build-deploy
  • GitHub Check: EAS Update
  • GitHub Check: transport-e2e-test
  • GitHub Check: build-web
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: prepare_android_test_app
  • GitHub Check: test
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: Socket Security: Pull Request Alerts
🔇 Additional comments (5)
suite-common/trading/package.json (2)

19-19: Addition of @trezor/address-validator Dependency

The inclusion of "@trezor/address-validator": "workspace:*" in the dependencies is appropriate for consolidating trading-related validations within the module. Ensure that its usage is documented and covered by tests in the module where it's utilized.


26-26: Addition of react-redux Dependency

Adding "react-redux": "8.0.7" supports the Redux integrations needed by hooks such as useTradingInfo. Verify that this version is compatible with the other parts of your codebase and that no conflicts arise within the larger monorepo.

suite-common/trading/src/types.ts (3)

103-105: Good addition of discriminator property and contextual fields

Adding the type: 'currency' discriminator property is a good practice for union types. The optional balance and networkName properties will improve the UI display capabilities of crypto assets.


108-113: Well-structured group interface with appropriate discriminator

This interface provides a clear way to represent asset groups in selection components with all the necessary metadata. The discriminator pattern with type: 'group' works well with the existing TradingCryptoSelectItemProps.


115-117: Good union type implementation

Creating this union type allows for proper typing of components that need to handle both individual crypto assets and group headers, improving type safety when working with hierarchical data structures.

Copy link

github-actions bot commented Mar 6, 2025

🚀 Expo preview is ready!

  • Project → trezor-suite-preview
  • Platforms → android, ios
  • Scheme → trezorsuitelite
  • Runtime Version → 26
  • More info

Learn more about 𝝠 Expo Github Action

@jbazant
Copy link
Contributor Author

jbazant commented Mar 6, 2025

/rebase

Copy link

github-actions bot commented Mar 6, 2025

@trezor-ci trezor-ci force-pushed the refactor-useTradingInfo-to-suite-common branch from 4beb965 to 4501684 Compare March 6, 2025 16:13
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)
suite-common/trading/src/types.ts (1)

119-133: Consider adding JSDoc comments to the interface methods

The TradingInfoProps interface is well-structured and comprehensive, defining all the functionality required for the useTradingInfo hook that's being moved in this PR. However, adding JSDoc comments to document the purpose and behavior of each method would improve maintainability.

Example:

 export interface TradingInfoProps {
+    /**
+     * Returns the platform name for a given crypto ID
+     * @param cryptoId - The crypto ID to look up
+     * @returns The platform name or undefined if not found
+     */
     cryptoIdToPlatformName: (cryptoId: CryptoId) => string | undefined;
     // Add similar comments for other methods...
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4beb965 and 4501684.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (34)
  • packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/TradingTermsModal.tsx (1 hunks)
  • packages/suite/src/hooks/wallet/trading/form/common/useTradingFormActions.ts (1 hunks)
  • packages/suite/src/hooks/wallet/trading/form/useTradingBuyForm.tsx (1 hunks)
  • packages/suite/src/hooks/wallet/trading/form/useTradingBuyFormDefaultValues.tsx (1 hunks)
  • packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts (1 hunks)
  • packages/suite/src/hooks/wallet/trading/form/useTradingExchangeFormDefaultValues.ts (1 hunks)
  • packages/suite/src/hooks/wallet/trading/form/useTradingSellForm.ts (1 hunks)
  • packages/suite/src/types/trading/trading.ts (3 hunks)
  • packages/suite/src/types/trading/tradingForm.ts (1 hunks)
  • packages/suite/src/utils/wallet/trading/__tests__/buyUtils.test.ts (1 hunks)
  • packages/suite/src/utils/wallet/trading/__tests__/exchangeUtils.test.ts (2 hunks)
  • packages/suite/src/utils/wallet/trading/__tests__/sellUtils.test.ts (2 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingAddressOptions.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingCryptoAmount.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingFeaturedOffers/TradingFeaturedOffersAmounts.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingForm/TradingFormInput/TradingFormInputCryptoSelect.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingForm/TradingFormInput/TradingFormInputFiatCrypto/TradingFormInputCryptoAmount.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingForm/TradingFormInput/TradingFormInputFiatCrypto/TradingFormInputFiatCrypto.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingForm/TradingFormOffer.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingForm/TradingFormOfferCryptoAmount.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingInfo/TradingInfoHeader.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingOfferExchange/TradingOfferExchangeSendApproval.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingOfferExchange/TradingOfferExchangeSendSwap.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerify.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerifyOptions.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerifyOptionsItem.tsx (1 hunks)
  • packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionAmounts.tsx (1 hunks)
  • suite-common/trading/package.json (1 hunks)
  • suite-common/trading/redux.d.ts (1 hunks)
  • suite-common/trading/src/hooks/useTradingInfo.ts (3 hunks)
  • suite-common/trading/src/index.ts (1 hunks)
  • suite-common/trading/src/thunks/buy/__tests__/handleRequestThunk.test.ts (1 hunks)
  • suite-common/trading/src/types.ts (1 hunks)
  • suite-common/trading/tsconfig.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (33)
  • suite-common/trading/tsconfig.json
  • packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/TradingTermsModal.tsx
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerifyOptionsItem.tsx
  • suite-common/trading/src/thunks/buy/tests/handleRequestThunk.test.ts
  • packages/suite/src/hooks/wallet/trading/form/useTradingExchangeFormDefaultValues.ts
  • suite-common/trading/src/index.ts
  • packages/suite/src/views/wallet/trading/common/TradingForm/TradingFormOfferCryptoAmount.tsx
  • packages/suite/src/views/wallet/trading/common/TradingCryptoAmount.tsx
  • packages/suite/src/views/wallet/trading/common/TradingForm/TradingFormInput/TradingFormInputCryptoSelect.tsx
  • suite-common/trading/redux.d.ts
  • packages/suite/src/views/wallet/trading/common/TradingForm/TradingFormInput/TradingFormInputFiatCrypto/TradingFormInputCryptoAmount.tsx
  • packages/suite/src/hooks/wallet/trading/form/common/useTradingFormActions.ts
  • packages/suite/src/views/wallet/trading/common/TradingForm/TradingFormOffer.tsx
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingOfferExchange/TradingOfferExchangeSendApproval.tsx
  • suite-common/trading/package.json
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerifyOptions.tsx
  • suite-common/trading/src/hooks/useTradingInfo.ts
  • packages/suite/src/hooks/wallet/trading/form/useTradingBuyFormDefaultValues.tsx
  • packages/suite/src/types/trading/tradingForm.ts
  • packages/suite/src/utils/wallet/trading/tests/exchangeUtils.test.ts
  • packages/suite/src/views/wallet/trading/common/TradingForm/TradingFormInput/TradingFormInputFiatCrypto/TradingFormInputFiatCrypto.tsx
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingVerify/TradingVerify.tsx
  • packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts
  • packages/suite/src/views/wallet/trading/common/TradingTransactions/TradingTransaction/TradingTransactionAmounts.tsx
  • packages/suite/src/views/wallet/trading/common/TradingFeaturedOffers/TradingFeaturedOffersAmounts.tsx
  • packages/suite/src/hooks/wallet/trading/form/useTradingSellForm.ts
  • packages/suite/src/hooks/wallet/trading/form/useTradingBuyForm.tsx
  • packages/suite/src/utils/wallet/trading/tests/sellUtils.test.ts
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingInfo/TradingInfoHeader.tsx
  • packages/suite/src/views/wallet/trading/common/TradingSelectedOffer/TradingOfferExchange/TradingOfferExchangeSendSwap.tsx
  • packages/suite/src/views/wallet/trading/common/TradingAddressOptions.tsx
  • packages/suite/src/types/trading/trading.ts
  • packages/suite/src/utils/wallet/trading/tests/buyUtils.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: PR-check / node-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: PR-check / node-override init-api-flaky
  • GitHub Check: PR-check / web-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: PR-check / web-override init-api-flaky
  • GitHub Check: build-deploy
  • GitHub Check: build-deploy
  • GitHub Check: EAS Update
  • GitHub Check: prepare_android_test_app
  • GitHub Check: build-web
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: transport-e2e-test
  • GitHub Check: test
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: Socket Security: Pull Request Alerts
🔇 Additional comments (3)
suite-common/trading/src/types.ts (3)

103-105: Type discriminator addition looks good

Adding the type: 'currency' discriminator field to TradingCryptoSelectItemProps enables proper type narrowing when used in the union type with TradingSelectAssetOptionGroupProps. The optional balance and networkName properties enhance the type with useful information for UI rendering.


108-113: Clear interface definition for option groups

The TradingSelectAssetOptionGroupProps interface is well-defined with a clear discriminator (type: 'group') to distinguish it from individual crypto items in the union type.


115-117: Good use of discriminated union

This union type properly combines the two option types (items and groups) with discriminating type fields, making it easy to use type narrowing in components that consume these types.

@jbazant jbazant merged commit c0197c1 into develop Mar 7, 2025
73 checks passed
@jbazant jbazant deleted the refactor-useTradingInfo-to-suite-common branch March 7, 2025 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-project This label is used to specify that PR doesn't need to be added to a project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants