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-34496: Confirm passphrase use enter key #6397

Merged
merged 3 commits into from
Dec 23, 2024
Merged

Conversation

originalix
Copy link
Contributor

@originalix originalix commented Dec 23, 2024

Summary by CodeRabbit

  • 新功能

    • 引入异步方法以增强令牌元数据合并功能。
    • EnterPhase 组件中添加表单提交和键盘支持功能。
    • 改进 SearchModal 组件中的搜索项logo URL构建方式。
  • Bug 修复

    • 修复了表单提交时的错误提示逻辑。
  • 文档

    • 更新了相关函数和组件的声明以反映新的实现。

Copy link

codesandbox bot commented Dec 23, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link
Contributor

coderabbitai bot commented Dec 23, 2024

概述

代码变更总览

工作流程

此次代码变更主要涉及四个文件,重点是改进令牌管理、硬件交互和搜索功能的异步处理。主要变更包括在 ServiceToken 中添加异步方法、优化 Hardware 组件的表单提交逻辑、更新令牌管理钩子以支持异步元数据合并,以及简化搜索模态框中的图标 URL 生成。

变更详情

文件路径 变更摘要
packages/kit-bg/src/services/ServiceToken.ts 新增异步 mergeTokenMetadataWithCustomData 方法,将令牌元数据合并方法改为支持异步操作
packages/kit/src/components/Hardware/Hardware.tsx 添加表单提交和键盘事件处理函数,改进用户交互体验
packages/kit/src/views/AssetList/hooks/useTokenManagement.ts 更新令牌处理逻辑,使用异步方法合并令牌元数据
packages/kit/src/views/Discovery/pages/SearchModal/index.tsx 简化搜索项目徽标 URL 生成,直接使用静态 URL

序列图

对于 ServiceToken 的变更,我们可以展示异步令牌元数据合并的流程:

sequenceDiagram
    participant Client
    participant ServiceToken
    participant CustomTokens
    
    Client->>ServiceToken: mergeTokenMetadataWithCustomData()
    ServiceToken->>CustomTokens: 获取自定义令牌
    CustomTokens-->>ServiceToken: 返回自定义令牌
    ServiceToken->>ServiceToken: 合并令牌元数据
    ServiceToken-->>Client: 返回合并后的令牌
Loading

这个序列图展示了新的异步令牌元数据合并方法的工作原理,突出了客户端、服务和自定义令牌之间的交互。

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 23, 2024 07:38
@originalix originalix merged commit 99e4617 into x Dec 23, 2024
7 of 8 checks passed
@originalix originalix deleted the fix/passphrase-enter branch December 23, 2024 07:47
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: 11

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 44126d6 and 617cfc0.

📒 Files selected for processing (4)
  • packages/kit-bg/src/services/ServiceToken.ts (5 hunks)
  • packages/kit/src/components/Hardware/Hardware.tsx (3 hunks)
  • packages/kit/src/views/AssetList/hooks/useTokenManagement.ts (1 hunks)
  • packages/kit/src/views/Discovery/pages/SearchModal/index.tsx (1 hunks)
🔇 Additional comments (2)
packages/kit/src/components/Hardware/Hardware.tsx (2)

379-388: 事件卸载完善
组件卸载时能正确移除监听器,做法合理,不需额外改动。


483-483: 逻辑统一
将点击确认的逻辑统一到 handleSubmit,有助于维护与调试。

Comment on lines +42 to +50
const allTokens = await Promise.all(
[...tokenList.tokens, ...customTokens].map((token) =>
backgroundApiProxy.serviceToken.mergeTokenMetadataWithCustomData({
token,
customTokens,
networkId,
}),
),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

添加错误处理
这里使用了 Promise.all(),如果其中任意一个 Promise 被拒绝,会阻塞整个流程。建议在外层添加 try/catch 或分块执行,防止单点错误导致全部失败。

- const allTokens = await Promise.all([...]);
+ let allTokens = [];
+ try {
+   allTokens = await Promise.all([...]);
+ } catch (error) {
+   // 在这里记录并安全处理错误
+ }

Committable suggestion skipped: line range outside the PR's diff.

await backgroundApiProxy.serviceDiscovery.buildWebsiteIconUrl(
'https://google.com',
);
const logo = 'https://uni.onekey-asset.com/static/logo/google.png';
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

避免硬编码 URL
建议将该 logo 地址配置化或集中管理,后续维护更灵活。

@@ -21,6 +21,7 @@ import {
useMedia,
} from '@onekeyhq/components';
import { ETranslations } from '@onekeyhq/shared/src/locale';
import platformEnv from '@onekeyhq/shared/src/platformEnv';
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

确认导入用途
如果只在浏览器环境使用,可考虑按需加载,避免在其它平台上额外增大包体。

Comment on lines +353 to +369
const handleSubmit = form.handleSubmit(async () => {
const values = form.getValues();
if (
!isSingleInput &&
(values.passphrase || '') !== (values.confirmPassphrase || '')
) {
Toast.error({
title: intl.formatMessage({
id: ETranslations.feedback_passphrase_not_matched,
}),
});
return;
}
const passphrase = values.passphrase || '';
onConfirm({ passphrase, save: true });
});

Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

检查空字符串
当 passphrase 为空时,最好给用户额外提示,以免误操作。

Comment on lines +370 to +378
const handleKeyPress = useCallback(
async (event: KeyboardEvent) => {
if (event.key === 'Enter') {
void handleSubmit();
}
},
[handleSubmit],
);

Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

留意回车事件
如果用户想换行而不小心触发回车提交,可能带来操作困扰。可区分或提醒。

@@ -207,7 +207,7 @@

resp.data.data.riskTokens.data = resp.data.data.riskTokens.data.map(
(token) => ({
...this.mergeTokenMetadataWithCustomData({
...this.mergeTokenMetadataWithCustomDataSync({
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

重复调用
这一段再次调用相同逻辑,封装可提高代码可维护性。

@@ -220,7 +220,7 @@

resp.data.data.smallBalanceTokens.data =
resp.data.data.smallBalanceTokens.data.map((token) => ({
...this.mergeTokenMetadataWithCustomData({
...this.mergeTokenMetadataWithCustomDataSync({
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

减少重复
这里也重复了相似逻辑,建议统一抽离成公共方法。

return Promise.resolve(this.mergeTokenMetadataWithCustomDataSync(params));
}

private mergeTokenMetadataWithCustomDataSync<T extends IToken>({
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

可扩展性建议
仅校验 token.symbol 和 token.name,如果有更多字段要合并或覆盖,建议在此一并处理。

@@ -521,7 +530,7 @@
networkId,
});

tokenInfo = this.mergeTokenMetadataWithCustomData({
tokenInfo = this.mergeTokenMetadataWithCustomDataSync({
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

复用逻辑
此处与 fetchAccountTokens 里的逻辑类似,建议共用合并方法,减少重复。

Comment on lines +290 to +298
@backgroundMethod()
async mergeTokenMetadataWithCustomData<T extends IToken>(params: {
token: T;
customTokens: IAccountToken[];
networkId: string;
}): Promise<T> {
return Promise.resolve(this.mergeTokenMetadataWithCustomDataSync(params));
}

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

直接使用 async/await
无需手动调用 Promise.resolve(),可直接返回结果,简化代码结构。

async mergeTokenMetadataWithCustomData<T extends IToken>(params: {
  token: T;
  customTokens: IAccountToken[];
  networkId: string;
}): Promise<T> {
-  return Promise.resolve(this.mergeTokenMetadataWithCustomDataSync(params));
+  return this.mergeTokenMetadataWithCustomDataSync(params);
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@backgroundMethod()
async mergeTokenMetadataWithCustomData<T extends IToken>(params: {
token: T;
customTokens: IAccountToken[];
networkId: string;
}): Promise<T> {
return Promise.resolve(this.mergeTokenMetadataWithCustomDataSync(params));
}
@backgroundMethod()
async mergeTokenMetadataWithCustomData<T extends IToken>(params: {
token: T;
customTokens: IAccountToken[];
networkId: string;
}): Promise<T> {
return this.mergeTokenMetadataWithCustomDataSync(params);
}

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