-
Notifications
You must be signed in to change notification settings - Fork 379
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-33669: Add order data to staking #6159
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
Walkthrough此次更改主要涉及多个文件,新增了与“赚取订单”相关的功能。 Changes
🪧 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: 16
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (9)
packages/kit-bg/src/dbs/simple/base/SimpleDb.ts
(2 hunks)packages/kit-bg/src/dbs/simple/base/SimpleDbProxy.ts
(2 hunks)packages/kit-bg/src/dbs/simple/entity/SimpleDbEntityEarnOrders.ts
(1 hunks)packages/kit-bg/src/services/ServiceHistory.ts
(3 hunks)packages/kit-bg/src/services/ServiceStaking.ts
(7 hunks)packages/kit-bg/src/vaults/base/VaultBase.ts
(2 hunks)packages/kit/src/views/Staking/hooks/useUniversalHooks.ts
(8 hunks)packages/shared/types/history.ts
(2 hunks)packages/shared/types/staking.ts
(2 hunks)
🔇 Additional comments (15)
packages/kit-bg/src/dbs/simple/base/SimpleDb.ts (2)
16-16
: 导入语句格式正确
新增的 SimpleDbEntityEarnOrders
导入语句遵循了文件现有的导入规范,位置排序恰当。
77-78
: earnOrders 属性初始化符合规范
earnOrders
属性的声明和初始化与文件中其他数据库实体保持一致,维护了良好的代码风格。
packages/shared/types/history.ts (2)
6-6
: 导入声明清晰明确!
新增的 EDecodedTxStatus
类型导入与现有的事务相关类型放在一起,结构合理。
230-235
: 接口定义结构完整!
IChangedPendingTxInfo
接口设计合理,包含了追踪待处理交易状态变化所需的必要字段:
- accountId 和 networkId 用于定位具体账户
- txId 用于标识具体交易
- status 用于表示交易状态
这些字段能够有效支持赚取订单功能中的交易状态跟踪。
packages/kit-bg/src/dbs/simple/base/SimpleDbProxy.ts (2)
20-20
: 导入语句格式正确
新增的 SimpleDbEntityEarnOrders 类型导入遵循了现有的导入模式,并保持了正确的字母顺序排序。
164-166
: earnOrders 属性实现规范
新增的 earnOrders 属性:
- 使用了标准的 _createProxyService 方法初始化
- 类型声明正确
- 与其他属性保持一致的实现方式
- 在 earn 属性后保持了正确的字母顺序
packages/shared/types/staking.ts (3)
26-26
: 新增 orderId 字段符合预期!
在 IStakingInfo
接口中添加可选的 orderId
字段,与 PR 目标保持一致。
150-153
: 类型定义清晰简洁!
IStakeTx
联合类型的定义清晰明了,包含了所有必要的交易类型。
156-159
: 响应类型结构合理!
新增的 IStakeTxResponse
类型设计合理:
- 包含交易信息
tx
- 包含订单ID
orderId
- 结构简单清晰
这个设计很好地支持了订单相关功能的集成。
packages/kit/src/views/Staking/hooks/useUniversalHooks.ts (2)
19-28
: 新增的 createStakeInfoWithOrderId 函数实现合理
函数实现简洁明了,通过扩展运算符保留了原有属性,同时添加了 orderId。这种实现方式既保证了类型安全,又避免了直接修改原对象。
99-99
: useUniversalStake 中的改动需要验证
新增的 orderId 处理逻辑看起来合理,但需要确保:
- stakeTx.orderId 是否始终存在
- 上游组件是否正确处理了包含 orderId 的 stakingInfo
Also applies to: 112-127
✅ Verification successful
Let me search for more specific patterns to understand the stakeTx and orderId handling.
需要进一步验证 orderId 的处理逻辑
根据现有代码分析,我们看到:
- stakeTx.orderId 被用于多个场景(质押、解质押、领取收益)
- 上游组件通过 navigationToSendConfirm 接收 stakingInfo
但我们仍需要验证关键接口定义。
orderId 处理逻辑已得到验证
基于代码分析,我们可以确认:
- stakeTx.orderId 在质押、解质押和领取收益的所有场景中都被正确传递
- navigationToSendConfirm 正确接收并处理包含 orderId 的 stakingInfo
- 整个流程保持了数据一致性,从交易构建到确认页面
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 检查 stakeTx.orderId 的生成逻辑
ast-grep --pattern 'buildStakeTransaction($$$) {
$$$
return {
$$$
orderId: $_,
$$$
}
}'
Length of output: 107
Script:
#!/bin/bash
# Search for stakeTx related code patterns
rg -A 5 "stakeTx" packages/kit/src/views/Staking/hooks/useUniversalHooks.ts
# Search for orderId usage in the staking related files
rg "orderId" packages/kit/src/views/Staking/
Length of output: 2661
Script:
#!/bin/bash
# Search for stake transaction building logic
ast-grep --pattern 'const stakeTx = $_($$$)'
# Search for staking info type definitions
rg -A 5 "interface.*StakingInfo|type.*StakingInfo" packages/kit/src/views/Staking/
Length of output: 131
Script:
#!/bin/bash
# Search for IStakeTxResponse interface definition
rg -A 10 "interface IStakeTxResponse" packages/kit/src/
# Search for buildStakeTransaction implementation
rg -A 10 "buildStakeTransaction.*\{" packages/kit/src/
# Search for stakingInfo type usage in navigation
rg -A 5 "navigationToSendConfirm.*stakingInfo" packages/kit/src/
Length of output: 1115
Script:
#!/bin/bash
# 搜索 serviceStaking 相关接口定义
rg -A 10 "class.*ServiceStaking" packages/kit/src/
# 搜索 stakingInfo 相关类型定义
rg -A 10 "type.*StakingInfo|interface.*StakingInfo" packages/kit/src/background/services/
# 搜索 navigationToSendConfirm 的实现
rg -A 10 "navigationToSendConfirm.*=.*" packages/kit/src/
Length of output: 7085
packages/kit-bg/src/services/ServiceHistory.ts (1)
290-305
: 代码实现清晰简洁!
新增的状态变更跟踪逻辑实现得很好,变量命名清晰,代码结构合理。
packages/kit-bg/src/vaults/base/VaultBase.ts (1)
79-79
: 导入语句更新已确认
导入语句已正确更新为使用新的 IStakeTx
类型。
packages/kit-bg/src/services/ServiceStaking.ts (2)
17-20
: 新增类型导入
添加了必要的类型导入,保持了代码的类型安全性。
Also applies to: 42-47, 54-57
828-828
: 方法 buildEarnTx
参数类型更改
buildEarnTx
方法的参数 tx
类型从 IStakeTxResponse
更改为 IStakeTx
。请确保所有调用此方法的代码已更新,以匹配新的参数类型,防止类型不匹配导致的错误。
运行以下脚本以验证方法的使用情况:
✅ Verification successful
Let me gather more information about the types and their usage.
参数类型变更是安全的
从代码分析结果来看,所有调用 buildEarnTx
的地方都是通过 stakeTx.tx
传参,而 stakeTx
的类型 IStakeTxResponse
中的 tx
属性就是 IStakeTx
类型。因此这个类型变更是向后兼容的,不会导致类型不匹配问题。
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 描述:检查所有对 `buildEarnTx` 方法的调用,确保参数类型已更新。
# 使用 ripgrep 搜索 `buildEarnTx` 的调用,并显示上下文
rg -A 3 -B 1 'buildEarnTx\('
Length of output: 1677
Script:
#!/bin/bash
# 检查 IStakeTx 和 IStakeTxResponse 类型的定义和使用
ast-grep --pattern 'interface IStakeTx {
$$$
}'
ast-grep --pattern 'interface IStakeTxResponse {
$$$
}'
# 检查 stakeTx.tx 的类型和使用
rg -A 5 'stakeTx.*tx'
Length of output: 1576
Script:
#!/bin/bash
# 检查 stakeTx 变量的类型定义
rg -B 5 -A 1 'const stakeTx'
# 检查 tx 属性的类型定义
ast-grep --pattern 'type $_ = {
tx: $_
$$$
}'
# 搜索可能的类型导入
rg 'import.*IStakeTx|import.*IStakeTxResponse'
Length of output: 2760
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: 7
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (6)
packages/kit-bg/src/services/ServiceHistory.ts
(3 hunks)packages/kit-bg/src/services/ServiceStaking.ts
(8 hunks)packages/kit/src/views/DAppConnection/hooks/useRiskDetection.ts
(2 hunks)packages/shared/src/logger/scopes/discovery/scenes/dapp.ts
(2 hunks)packages/shared/src/logger/scopes/staking/index.ts
(1 hunks)packages/shared/src/logger/scopes/staking/scenes/order.ts
(1 hunks)
🔇 Additional comments (10)
packages/shared/src/logger/scopes/staking/index.ts (2)
4-4
: 导入语句看起来不错!
导入语句遵循了与 PageScene
相同的模式,保持了代码的一致性。
12-12
: 很好的实现!
order
场景的添加方式与现有的 page
场景保持一致,使用了相同的 createScene
工厂方法。这种一致性有助于代码的可维护性。
packages/shared/src/logger/scopes/staking/scenes/order.ts (1)
1-7
: 导入路径验证
导入看起来结构清晰,但建议验证这些导入路径的正确性。
✅ Verification successful
导入路径验证完成,一切正常 ✅
导入路径已确认存在且正确:
@onekeyhq/kit-bg/src/dbs/simple/entity/SimpleDbEntityEarnOrders
@onekeyhq/shared/types/tx
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 验证导入路径是否存在
fd --type f "SimpleDbEntityEarnOrders.ts$" packages/kit-bg/src/dbs/simple/entity/
fd --type f "tx.ts$" packages/shared/types/
Length of output: 223
packages/shared/src/logger/scopes/discovery/scenes/dapp.ts (1)
1-1
: 导入声明看起来不错!
导入语句清晰明确,并且仅引入所需的类型。
packages/kit/src/views/DAppConnection/hooks/useRiskDetection.ts (1)
6-6
: 导入 defaultLogger 符合预期!
从共享模块导入 logger 是正确的做法,有助于保持日志记录的一致性。
packages/kit-bg/src/services/ServiceStaking.ts (1)
914-973
: 代码逻辑清晰,方法实现正确
新增的 addEarnOrder
、updateEarnOrder
和 updateEarnOrderStatusToServer
方法逻辑正确,实现合理。
packages/kit-bg/src/services/ServiceHistory.ts (4)
18-18
: 新类型 IChangedPendingTxInfo 导入正确
引入了新的类型 IChangedPendingTxInfo
,用于跟踪状态已改变的待处理交易。
290-290
: 初始化 changedPendingTxInfos 数组
成功初始化了用于收集状态变化的待处理交易信息的数组。
297-305
: 正确收集已确认的交易信息
在找到已确认的交易后,正确地将其信息添加到 changedPendingTxInfos
数组中,逻辑清晰。
309-314
: 重复的建议:添加错误处理逻辑
之前的评论仍然适用,建议为异步操作添加错误处理,以捕获和处理可能的异常。
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (1)
packages/kit-bg/src/vaults/base/VaultBase.ts
(2 hunks)
🔇 Additional comments (1)
packages/kit-bg/src/vaults/base/VaultBase.ts (1)
79-79
: 验证类型更改在代码库中的影响
需要确保 IStakeTx 类型的变更与其他文件保持一致。
✅ Verification successful
类型变更已经得到正确处理
通过代码分析可以确认:
IStakeTx
是一个联合类型,在packages/shared/types/staking.ts
中定义- 所有使用
IStakeTx
的实现都已经正确处理了类型关系:- BTC Vault 使用
IStakeTxBtcBabylon
- Cosmos Vault 使用
IStakeTxCosmosAmino
- 基础 VaultBase 提供了默认实现
- BTC Vault 使用
类型系统保持一致,无需额外修改。
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 检查 IStakeTx 的使用情况
rg "IStakeTx" -A 3
# 检查可能受影响的质押相关文件
rg "buildStakeEncodedTx" -A 3
Length of output: 8523
buildStakeEncodedTx(params: IStakeTx): Promise<IEncodedTx> { | ||
return Promise.resolve(params as IEncodedTx); | ||
} |
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.
建议改进 buildStakeEncodedTx 方法的实现
当前实现存在以下问题:
- 直接将输入参数转换为 IEncodedTx 类型,缺少必要的验证
- 没有错误处理机制
建议按如下方式重构:
- buildStakeEncodedTx(params: IStakeTx): Promise<IEncodedTx> {
- return Promise.resolve(params as IEncodedTx);
- }
+ buildStakeEncodedTx(params: IStakeTx): Promise<IEncodedTx> {
+ if (!params.amount || !params.contractAddress) {
+ throw new Error('无效的质押交易参数');
+ }
+ const encodedTx: IEncodedTx = {
+ ...params,
+ type: 'stake',
+ };
+ return Promise.resolve(encodedTx);
+ }
📝 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.
buildStakeEncodedTx(params: IStakeTx): Promise<IEncodedTx> { | |
return Promise.resolve(params as IEncodedTx); | |
} | |
buildStakeEncodedTx(params: IStakeTx): Promise<IEncodedTx> { | |
if (!params.amount || !params.contractAddress) { | |
throw new Error('无效的质押交易参数'); | |
} | |
const encodedTx: IEncodedTx = { | |
...params, | |
type: 'stake', | |
}; | |
return Promise.resolve(encodedTx); | |
} |
Summary by CodeRabbit
新功能
earnOrders
属性,增强了数据库和代理服务的功能。SimpleDbEntityEarnOrders
类,提供管理赚取订单的接口和方法。dappRiskDetect
方法,增强风险检测功能。StakingScope
中添加了order
属性,扩展了场景管理能力。OrderScene
类,提供订单管理的公共方法。文档