-
Notifications
You must be signed in to change notification settings - Fork 392
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/ext dapp account bug #6412
Fix/ext dapp account bug #6412
Conversation
(cherry picked from commit d8f050db1b3457ca0e273430abe880be0c1753c2)
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
总览代码变更概述这次代码变更涉及多个文件,主要集中在账户选择器、事件总线和调试工具等模块。变更包括优化账户同步逻辑、改进事件处理机制、调整网络选择策略,以及增强调试输出格式。 变更详情代码变更
新增文件
序列图对于账户选择器的变更,可以生成以下序列图: sequenceDiagram
participant User
participant AccountSelector
participant EventBus
participant NetworkSelector
User->>AccountSelector: 选择场景
AccountSelector->>EventBus: 触发账户选择事件
EventBus->>NetworkSelector: 同步网络信息
NetworkSelector-->>AccountSelector: 返回网络配置
AccountSelector->>User: 更新选中账户
这个序列图展示了新的账户选择流程,突出了场景、事件总线和网络选择器之间的交互。 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 10
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (10)
packages/kit-bg/src/dbs/simple/entity/SimpleDbEntityAccountSelector.ts
(2 hunks)packages/kit-bg/src/providers/ProviderApiEthereum.ts
(1 hunks)packages/kit/src/components/AccountSelector/AccountSelectorEffects.tsx
(1 hunks)packages/kit/src/components/AccountSelector/hooks/useAutoSelectNetwork.tsx
(2 hunks)packages/kit/src/states/jotai/contexts/accountSelector/actions.tsx
(9 hunks)packages/kit/src/views/DAppConnection/components/DAppAccountList/DAppAccountListItem.tsx
(1 hunks)packages/kit/src/views/DAppConnection/dappTest.html
(1 hunks)packages/kit/src/views/DAppConnection/hooks/useHandleAccountChanged.ts
(3 hunks)packages/shared/src/eventBus/appEventBus.ts
(2 hunks)packages/shared/src/utils/debug/debugUtils.ts
(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/shared/src/eventBus/appEventBus.ts
[error] 333-333: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
🔇 Additional comments (21)
packages/kit/src/views/DAppConnection/hooks/useHandleAccountChanged.ts (4)
3-4
: 导入节流方法,替代原本的防抖。依赖看起来正常。
45-48
: 用 ref 追踪最新状态。逻辑清晰,写法简洁。
Line range hint 50-71
: 节流回调的设置合理。避免频繁调用,性能更好。
73-77
: 在依赖更新时调用节流函数,流程简洁明了。
packages/shared/src/utils/debug/debugUtils.ts (1)
22-27
: 使用 console.groupCollapsed 展开日志。可读性提升,排查更方便。
packages/kit/src/components/AccountSelector/hooks/useAutoSelectNetwork.tsx (6)
4-5
: 新增 networkUtils 和 EAccountSelectorSceneName,方便网络逻辑处理。
9-9
: 引入 sceneInfo,获取更多场景信息。
17-18
: 分离 selectedAccount,提取 networkId,便于后续判断。
25-26
: 通过 sceneInfo 获取 sceneName、sceneUrl,增强可读性。
60-67
: 发现场景为 discover 且是 AllNetwork 时清空网络 ID,避免混淆。
83-91
: 依赖中包含 sceneName,确保场景改动能及时触发逻辑更新。
packages/kit-bg/src/dbs/simple/entity/SimpleDbEntityAccountSelector.ts (2)
1-2
: 通过 cloneDeep 避免共享引用,减少不必要的对象污染。
149-149
: 返回深拷贝,外部修改不会影响原对象。安全性更高。
packages/kit/src/components/AccountSelector/AccountSelectorEffects.tsx (2)
233-261
: 新增函数逻辑检查无误
此函数根据特定条件更新账号,并避免通过 eventEmitDisabled: true
造成循环触发事件。逻辑简洁可读,测试时需留意远程事件标记。
266-274
: 事件监听与清理配置正确
注册与移除事件均有调用,确保组件卸载时正常清理。不易出现事件泄漏问题。
packages/shared/src/eventBus/appEventBus.ts (1)
385-393
: 设置远程事件标记逻辑合理
此处对 payload.$$isRemoteEvent
的设定能区分本地事件与远程事件,但仍需留意空值判断,避免不必要的属性更新。
packages/kit/src/states/jotai/contexts/accountSelector/actions.tsx (5)
57-57
: 网络工具导入可接受
networkUtils
在后续代码中用于网络判断逻辑,符合需求。
299-303
: 新增方法获取场景信息
getCurrentSceneInfo
对获取场景数据有益,后续可考虑更多场景兼容性。
316-316
: 使用场景信息以快速判定
此处通过 sceneInfo 优化判断和后续逻辑分支,让代码更具可读性。
365-371
: 按场景自动修正推导类型
基于全局来源更新 deriveType,确保网络兼容一致。逻辑紧凑易读。
Line range hint 1396-1430
: 场景同步函数扩展
syncFromScene
新增 withNetworkSync
可灵活控制网络同步。处理细节简洁,避免强制同步带来潜在的意外切换。
Summary by CodeRabbit
新功能
dappTest.html
。syncSceneData
函数,以增强账户选择逻辑。AccountSelectorActions
中添加了getCurrentSceneInfo
方法。bug修复
文档
改进