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

optimize: swap UI in send confirm OK-34238 #6316

Merged
merged 6 commits into from
Dec 6, 2024
Merged

Conversation

weatherstar
Copy link
Contributor

@weatherstar weatherstar commented Dec 6, 2024

Summary by CodeRabbit

  • 新特性
    • 添加了用于处理内部交换和质押的功能。
    • 引入了新的组件 TxActionSwapInfoSwapServiceFeeOverview,用于显示交易和服务费用信息。
    • 增加了对交易中网络ID的支持,提升了交易的详细信息。
  • 错误修复
    • 改进了多个方法的错误处理,确保更好的用户反馈和交易可靠性。
  • 文档
    • 新增了翻译条目,扩展了本地化功能。
  • 常量
    • 添加了默认服务费用常量 swapServiceFeeDefault

Copy link

codesandbox bot commented Dec 6, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@weatherstar weatherstar enabled auto-merge (squash) December 6, 2024 10:21
Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

Walkthrough

本次更改涉及多个文件,主要集中在 VaultBaseVault 类的修改。新增了处理内部交换和质押的功能,更新了传输资产的相关方法,增强了错误处理。还引入了新的 React 组件 TxActionSwapInfoSwapServiceFeeOverview,用于展示交易信息和服务费用。此外,更新了多个类型定义以支持新的网络标识和滑点属性,改善了代码的灵活性和可读性。

Changes

文件路径 更改摘要
packages/kit-bg/src/vaults/base/VaultBase.ts 新增 buildInternalSwapActionbuildInternalStakingAction 方法;更新 buildTxTransferAssetAction 方法以包含 networkId;改进 getAccount 方法的错误处理;更新多个方法以支持自定义网络。
packages/kit-bg/src/vaults/impls/btc/Vault.ts 更新 buildDecodedTx 方法以包含 networkId;改进 buildDecodedPsbtTx 方法的错误处理;为多个方法添加返回类型。
packages/kit-bg/src/vaults/impls/kaspa/Vault.ts 更新 buildDecodedTxbuildEncodedTx 方法以包含 networkId 和错误处理;增强 updateUnsignedTx 方法的验证逻辑。
packages/kit/src/components/TxAction/TxActionSwapInfo.tsx 新增 TxActionSwapInfo 组件,展示交换交易的详细信息。
packages/kit/src/components/TxAction/TxActionTransfer.tsx 更新 TxActionTransferDetailView 函数以条件渲染 TxActionSwapInfo 组件;改进网络信息的显示逻辑。
packages/kit/src/views/AssetDetails/pages/HistoryDetails/components/TxDetailsInfoItem/index.tsx 新增 compactAll 属性以增强布局灵活性。
packages/kit/src/views/Swap/components/SwapProviderInfoItem.tsx 移除旧的费用信息组件,新增 SwapServiceFeeOverview 组件;更新导出声明。
packages/kit/src/views/Swap/components/SwapServiceFeeOverview.tsx 新增 SwapServiceFeeOverview 组件,展示交换操作的服务费用概览。
packages/shared/src/locale/enum/translations.ts 新增多个翻译条目以扩展本地化能力。
packages/shared/types/swap/SwapProvider.constants.ts 新增 swapServiceFeeDefault 常量,表示默认服务费用。
packages/shared/types/swap/types.ts IFetchQuoteResult 接口新增 slippage 属性。
packages/shared/types/tx.ts IDecodedTxTransferInfo 类型新增 networkId 属性。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant VaultBase
    participant VaultBtc
    participant VaultKaspa
    participant TxActionSwapInfo
    participant SwapServiceFeeOverview

    User->>VaultBase: 发起交换请求
    VaultBase->>VaultBtc: 构建解码交易
    VaultBtc->>VaultBase: 返回解码交易
    VaultBase->>User: 返回交易详情

    User->>TxActionSwapInfo: 查看交换信息
    TxActionSwapInfo->>User: 展示交换详情

    User->>SwapServiceFeeOverview: 查看服务费用
    SwapServiceFeeOverview->>User: 展示费用概览
Loading

🪧 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 or 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
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: 5

🧹 Outside diff range comments (2)
packages/kit-bg/src/vaults/impls/kaspa/Vault.ts (1)

Line range hint 284-295: 重复的错误处理

在 '_collectUTXOsInfoByApi' 方法中,'try' 块中抛出了错误,'catch' 块中又抛出了相同的错误。这可能导致堆栈信息丢失,建议只在 'catch' 块中处理错误。

packages/kit/src/components/TxAction/TxActionTransfer.tsx (1)

Line range hint 755-773: 条件判断可简化

第755到773行,对 'networkInfo' 的处理,可以将条件判断合并,减少嵌套,提升代码简洁性。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 12164f5 and e113a92.

⛔ Files ignored due to path filters (20)
  • packages/shared/src/locale/json/bn.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/de.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/en.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/en_US.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/es.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/fr_FR.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/hi_IN.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/id.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/it_IT.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/ja_JP.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/ko_KR.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/pt.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/pt_BR.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/ru.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/th_TH.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/uk_UA.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/vi.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/zh_CN.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/zh_HK.json is excluded by !packages/shared/src/locale/json/*.json
  • packages/shared/src/locale/json/zh_TW.json is excluded by !packages/shared/src/locale/json/*.json
📒 Files selected for processing (12)
  • packages/kit-bg/src/vaults/base/VaultBase.ts (3 hunks)
  • packages/kit-bg/src/vaults/impls/btc/Vault.ts (2 hunks)
  • packages/kit-bg/src/vaults/impls/kaspa/Vault.ts (2 hunks)
  • packages/kit/src/components/TxAction/TxActionSwapInfo.tsx (1 hunks)
  • packages/kit/src/components/TxAction/TxActionTransfer.tsx (6 hunks)
  • packages/kit/src/views/AssetDetails/pages/HistoryDetails/components/TxDetailsInfoItem/index.tsx (3 hunks)
  • packages/kit/src/views/Swap/components/SwapProviderInfoItem.tsx (3 hunks)
  • packages/kit/src/views/Swap/components/SwapServiceFeeOverview.tsx (1 hunks)
  • packages/shared/src/locale/enum/translations.ts (2 hunks)
  • packages/shared/types/swap/SwapProvider.constants.ts (1 hunks)
  • packages/shared/types/swap/types.ts (1 hunks)
  • packages/shared/types/tx.ts (1 hunks)
🔇 Additional comments (14)
packages/kit/src/components/TxAction/TxActionTransfer.tsx (1)

Line range hint 583-606: 检查 'networkId' 的有效性

第583到606行,使用 'swapInfo.sender.accountInfo.networkId',需要确保该值存在,避免可能的空引用错误。

packages/kit-bg/src/vaults/base/VaultBase.ts (1)

Line range hint 962-974: 确保 'networkId' 的正确性

第962和974行,向 'transfers' 数组中的对象添加了 'networkId' 属性,需验证该属性是否正确设置,防止后续操作出错。

packages/kit/src/views/Swap/components/SwapProviderInfoItem.tsx (3)

17-17: 新增 SwapServiceFeeOverview 组件导入

引入新组件优化了费用展示逻辑,使代码更加模块化。


50-50: 使用 SwapServiceFeeOverview 替换原有费用显示逻辑

简化了费用展示方式,提高了代码可维护性。


55-57: 优化组件导出方式

使用 memo 包装组件并显式导出,有助于性能优化。

packages/kit/src/views/AssetDetails/pages/HistoryDetails/components/TxDetailsInfoItem/index.tsx (2)

28-28: 新增 compactAll 布局控制属性

通过新增的 compactAll 属性,提供了更灵活的布局控制选项。

Also applies to: 38-38


57-59: 实现 compactAll 布局逻辑

合理实现了 compactAll 的布局控制,保持了与现有 compact 属性的一致性。

packages/shared/types/tx.ts (1)

161-161: 扩展交易信息类型定义

在 IDecodedTxTransferInfo 接口中添加 networkId 字段,增强了多网络场景下的交易支持。建议验证所有使用此接口的地方是否需要更新。

packages/shared/types/swap/types.ts (1)

269-269: 代码变更看起来不错!

IFetchQuoteResult 接口添加可选的 slippage 属性能更好地支持滑点功能。

packages/kit-bg/src/vaults/impls/btc/Vault.ts (2)

254-254: 代码变更正确!

为发送代币添加 networkId 属性有助于跨链交易的追踪。


266-266: 代码变更合理!

为接收代币添加 networkId 属性完善了跨链交易的网络信息。

packages/shared/types/swap/SwapProvider.constants.ts (1)

16-17: 常量定义合适!

添加 swapServiceFeeDefault 常量统一了默认交换服务费用的设置,值为 0.3 是合理的。

packages/shared/src/locale/enum/translations.ts (2)

1451-1451: 命名规范符合要求!

provider_cow_route 的命名遵循了现有的命名模式,并且正确放置在provider相关配置区域。


1928-1929: 交换提示文案已完整添加!

批量交换和单笔交换的提示文案都已添加,保持了命名一致性。

让我们验证是否所有swap相关的翻译都已完整:

✅ Verification successful

交换相关的翻译已完整添加且保持一致!

搜索结果显示所有交换相关的翻译都已完整添加到各个语言文件中,包括:

  • 批量交换提示 (batch_swap_tip)
  • 单笔交换提示 (single_swap_tip)
  • 交换汇率 (rate)
  • 报价相关提示 (quotes)

所有翻译保持了命名和格式的一致性。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索所有swap相关的翻译key
rg "swap.*tip" 

Length of output: 73637


Script:

#!/bin/bash
# Search for all swap-related translation keys in the codebase
rg "swap.*tip|swap.*quote|swap.*rate" 

Length of output: 94535

@weatherstar weatherstar merged commit d8729c7 into x Dec 6, 2024
8 checks passed
@weatherstar weatherstar deleted the feat/swap-confirm branch December 6, 2024 10:56
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