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

OK-34478: Support transfer custom token without symbol #6388

Merged
merged 5 commits into from
Dec 21, 2024
Merged

Conversation

originalix
Copy link
Contributor

@originalix originalix commented Dec 21, 2024

Summary by CodeRabbit

  • 新功能

    • 增强了代币数据的获取和处理,支持自定义代币数据的集成。
    • 在添加自定义代币的过程中,符号输入字段的可编辑性得到了动态管理。
    • 新增了两个翻译条目,以支持用户身份验证和代币管理功能。
  • 更新

    • 更新了安全RPC方法列表,新增了eth_feeHistory方法。
  • 错误修复

    • 改进了符号输入字段的验证规则和错误处理逻辑。

Copy link

codesandbox bot commented Dec 21, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link
Contributor

coderabbitai bot commented Dec 21, 2024

概述

代码变更总览

这个拉取请求包含了多个文件的修改,主要涉及服务令牌处理、添加自定义令牌流程、本地化翻译和 RPC 缓存方法。变更旨在改进令牌管理和用户交互体验。

变更

文件路径 变更摘要
packages/kit-bg/src/services/ServiceToken.ts 新增 mergeTokenMetadataWithCustomData 私有方法,更新 fetchAccountTokens 方法签名和内部逻辑
packages/kit/src/views/AssetList/hooks/useAddToken.ts 添加 isSymbolEditable 状态和相关函数,增强令牌添加流程
packages/kit/src/views/AssetList/pages/AddCustomTokenModal.tsx 引入动态符号可编辑性控制
packages/shared/src/locale/enum/translations.ts 新增两个本地化翻译枚举项
packages/shared/src/rpcCache/constants.ts EVM_SAFE_RPC_METHODS 中添加 'eth_feeHistory' 方法

详细变更

ServiceToken 服务

新增 mergeTokenMetadataWithCustomData 私有方法,用于增强令牌数据处理。该方法检查并合并自定义令牌信息,改进了令牌获取和处理的灵活性。fetchAccountTokens 方法签名也被更新,支持更多可选参数。

添加自定义令牌流程

useAddTokenAddCustomTokenModal 中引入 isSymbolEditable 状态,允许动态控制令牌符号字段的可编辑性。这提供了更灵活的用户输入体验。

本地化和 RPC 方法

  • 新增两个本地化翻译枚举项:auth_new_passcode_same_as_oldmanage_token_token_required
  • EVM_SAFE_RPC_METHODS 中添加 'eth_feeHistory' 方法,扩展了安全 RPC 方法列表

这些变更整体上提升了应用的令牌管理、用户交互和系统灵活性。

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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

@originalix originalix enabled auto-merge (squash) December 21, 2024 01:37
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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4d5fb98 and f828c63.

⛔ 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 (5)
  • packages/kit-bg/src/services/ServiceToken.ts (3 hunks)
  • packages/kit/src/views/AssetList/hooks/useAddToken.ts (6 hunks)
  • packages/kit/src/views/AssetList/pages/AddCustomTokenModal.tsx (4 hunks)
  • packages/shared/src/locale/enum/translations.ts (2 hunks)
  • packages/shared/src/rpcCache/constants.ts (1 hunks)
🔇 Additional comments (6)
packages/shared/src/rpcCache/constants.ts (1)

77-77: 新增的 RPC 方法符合安全标准!

新增的 eth_feeHistory 方法是一个只读方法,用于获取历史 gas 费用数据,适合添加到安全 RPC 方法列表中。

packages/kit/src/views/AssetList/hooks/useAddToken.ts (2)

57-57: 状态管理实现清晰!

新增的 isSymbolEditable 状态变量及其 setter 函数实现了对代币符号编辑权限的灵活控制。

Also applies to: 89-90


160-166: 代币符号处理逻辑合理!

代码根据搜索结果动态设置符号的可编辑状态:

  • 当获取到有效符号时禁用编辑
  • 当符号为空时启用编辑,允许用户输入

这种实现方式既保证了数据准确性,又提供了良好的用户体验。

packages/kit/src/views/AssetList/pages/AddCustomTokenModal.tsx (1)

355-364: 表单验证规则优化合理!

根据 isSymbolEditable 状态动态设置验证规则:

  • 当符号可编辑时要求必填
  • 当符号不可编辑时移除验证

这种实现方式避免了不必要的验证提示。

packages/kit-bg/src/services/ServiceToken.ts (1)

290-314: 代码实现清晰且逻辑合理!

新增的 mergeTokenWithCustomData 方法实现了 token 数据的优雅合并,并在 fetchAccountTokens 中得到了一致的应用。代码结构良好,类型定义完整。

Also applies to: 198-227

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

91-91: 翻译键添加规范!

新增的两个翻译键:

  • auth_new_passcode_same_as_old
  • manage_token_token_required

遵循了现有的命名规范和点号表示法模式。

Also applies to: 1281-1281

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f828c63 and e5e240b.

📒 Files selected for processing (1)
  • packages/kit-bg/src/services/ServiceToken.ts (5 hunks)
🔇 Additional comments (4)
packages/kit-bg/src/services/ServiceToken.ts (4)

198-202: 合并自定义元数据的用法不错
这里在 map() 内部调用 mergeTokenMetadataWithCustomData,逻辑清晰,确保在获取到 tokens 后第一时间合并额外信息,避免出现空 symbol 或 name。


210-214: 保持一致性地合并自定义信息
riskTokens 的处理方式与前面 tokens 相同,实现始终如一的合并逻辑。这对后续维护很友好。


490-502: 在 getToken 中对 localToken 使用合并策略
如果本地 token 缺失 symbol 或 name,就从自定义 tokens 中补齐,逻辑正确。若后续还有更多 info 字段需要补全,也可沿用此方法。


515-529: 在 fetchTokensDetails 之后再次合并元数据
fetchTokensDetails 返回的 tokenInfo 同样进行补齐,保证获取到的 token 始终包含完整信息。做法一致性强、可维护性好。

packages/kit-bg/src/services/ServiceToken.ts Show resolved Hide resolved
packages/kit-bg/src/services/ServiceToken.ts Show resolved Hide resolved
@originalix originalix merged commit 3a326f1 into x Dec 21, 2024
8 checks passed
@originalix originalix deleted the feat/empty-symbol branch December 21, 2024 05:28
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