Skip to content

fix(transfer): 修复确认转账按钮无响应和交易历史不加载 - #103

Merged
Gaubee merged 9 commits into
mainfrom
fix/transfer-confirm-callback
Dec 23, 2025
Merged

Gaubee merged 9 commits into
mainfrom
fix/transfer-confirm-callback

Conversation

@Gaubee

@Gaubee Gaubee commented Dec 23, 2025 •

Copy link
Copy Markdown
Contributor

问题根因

没有仔细研究 legacy wallet-base SDK。原始 WalletFetch 在响应处理中自动解包 { success, result } 结构:

// WalletFetch._handleResThen()
const d = 'result' in data ? data.result : data;
return d;

所以原始代码可以直接 const { trs } = await _fetch.post<{ trs: [...] }>()。而我们直接用 fetch(),需要手动解包。

修复内容

Bug 1: 确认转账按钮无响应

pendingCallback 在调用前被清除。修复:先保存引用。

Bug 2: 交易历史不加载

result.trs → result.result.trs

Bug 3: 区块高度/手续费获取失败

chain-service.ts 中所有 API 响应解析都错误:data.data.xxx → json.result.xxx

教训

  1. 开发前必须研究原始 SDK 的封装逻辑
  2. e2e 测试只截图不验证流程是无效的

…firmJob

The pendingCallback was being cleared before it was called, causing
the confirm button to do nothing. Fixed by saving the reference first.

Bug: clicking 'confirm transfer' button had no effect
API returns { success, result: { trs: [...] } } but code was reading
result.trs (undefined) instead of result.result.trs.

This caused transaction history to always be empty.
@Gaubee Gaubee changed the title fix(transfer): 修复确认转账按钮无响应 fix(transfer): 修复确认转账按钮无响应和交易历史不加载 Dec 23, 2025
All BioForest APIs return { success: boolean, result: T } format.
Fixed parsing in:
- chain-service.ts: getBlockHeight, getGasPrice, healthCheck
- transaction-service.ts: getTransactionHistory (lastblock call)

Root cause: Did not study legacy wallet-base SDK which auto-unwraps
the { success, result } wrapper in WalletFetch._handleResThen()
…tus, getTransaction API parsing

All methods were incorrectly parsing { data: {...} } instead of { success, result: {...} }
- Add bioforest-api.test.ts with 19 tests covering all API methods
- Mock fetch to verify { success, result } response format parsing
- Test ChainService: getBlockHeight, getGasPrice, healthCheck
- Test TransactionService: getTransactionHistory, getTransactionStatus, getTransaction, broadcastTransaction
- Test AssetService: getNativeBalance, getTokenBalances
- Fix getGasPrice to return default on success=false instead of throwing
- Add 'BioForest 转账完整流程验证' test suite
- Test verifies: form fill -> confirm sheet -> password input
- Fix mock transactions format (add height, correct structure)
- Add data-testid to PasswordConfirmJob and TransferConfirmJob
- Update bioforest-mock.ts to match real API response format
核心修复:
- TransferConfirmJob: 保存 callback 引用后再清除,避免 null 调用
- transaction-service: 修复 API 响应解析 (result.result.xxx)
- chain-service: 修复 healthCheck/getBlockHeight/getGasPrice 解析
- transaction-service: 使用 SDK 计算真实最小手续费

测试新增:
- bioforest-full-flow.spec.ts: 完整钱包导入+转账流程 e2e 测试
- bioforest-api.test.ts: 19 个 API 解析单元测试 (已在之前提交)
- .env.example + .gitignore: 支持本地测试密钥配置

测试结果:
- 单元测试: 19/19 通过
- E2E 测试: bioforest-transfer 19/19 通过
- E2E 测试: bioforest-full-flow 4/13 通过 (9 个需要状态共享改进)
@Gaubee
Gaubee merged commit efa0d5b into main Dec 23, 2025
5 checks passed
@Gaubee
Gaubee deleted the fix/transfer-confirm-callback branch January 4, 2026 07:23
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.

1 participant