Skip to content

Conversation

@Gaubee
Copy link
Contributor

@Gaubee Gaubee commented Dec 29, 2025

概述

实现锻造(Forge)小程序的完整后端 API 集成,将现有 Demo UI 连接到 COT Recharge API 后端。

主要变更

API 层

  • src/api/types.ts - COT Recharge API 完整类型定义
  • src/api/config.ts - API 端点配置
  • src/api/client.ts - HTTP 客户端封装
  • src/api/recharge.ts - 充值 API 服务
  • src/api/helpers.ts - 消息编码辅助函数

React Hooks

  • useRechargeConfig - 获取并解析锻造选项配置
  • useForge - 多步骤锻造流程(外链签名 → 内链签名 → 提交)
  • useContractPool - 获取池统计信息
  • useRechargeRecords - 获取交易记录

UI 集成

  • 重写 App.tsx 使用真实 API 数据
  • 完整 i18n 国际化支持(4种语言)
  • 动态代币选择器
  • 多步骤处理状态显示

测试覆盖

  • 单元测试: hooks 和 API helpers 的完整测试
  • Storybook 测试: App.stories.tsx 包含交互式测试
  • E2E 测试: 9 个完整的用户流程测试用例

待确认事项

以下参数需要与后端确认:

  • API Base URL (当前默认: https://api.eth-metaverse.com)
  • signTransData 格式要求 (0x 前缀? hex/base64?)
  • publicKey 编码格式 (hex/base58?)
  • 签名算法和消息格式验证
  • 时间戳容差窗口

测试

cd miniapps/forge
pnpm typecheck  # 类型检查
pnpm test:run   # 单元测试
pnpm e2e        # E2E 测试

相关研究

详见 .chat/research-miniapp-锻造-backend.md

- Add API types for COT Recharge (types.ts)
- Add API client and service layer (client.ts, recharge.ts)
- Add helper functions for message encoding (helpers.ts)
- Create React hooks:
  - useRechargeConfig: fetch and parse forge options
  - useForge: handle forge flow (sign external tx, sign internal msg, submit)
  - useContractPool: fetch pool statistics
  - useRechargeRecords: fetch transaction records
- Update App.tsx to use real API:
  - Load config from backend on mount
  - Support dynamic token selection from config
  - Show processing steps during forge
  - Display order ID on success
- Update tests to mock API calls
- Remove unused imports (ExternalChainName, motion, React)
- Use self-closing tags for empty div elements
- Add vite-env.d.ts for ImportMeta.env types
- Update i18n translations for forge functionality
- Fix i18n tests for new translation keys
- Add useTranslation hook
- Replace hardcoded Chinese strings with t() calls
- Add getChainName helper using translations
- Initialize i18n in tests
Unit tests:
- useRechargeConfig hook (config fetching, parsing, error handling)
- useForge hook (forge flow, step transitions, error states)
- API helpers (encoding functions, message creation)

Storybook tests:
- App.stories.tsx with interactive play functions
- ConnectStep, SwapStep, TokenPicker, LoadingState, ErrorState stories

E2E tests:
- Updated ui.spec.ts with 9 comprehensive test cases
- Full forge flow, error handling, navigation, token selection
- Updated i18n helpers for forge-specific text patterns
@Gaubee Gaubee force-pushed the feat/forge-backend branch from 171f94d to 729b9b2 Compare December 29, 2025 14:56
- Fixed mock API URL pattern to match actual endpoint (/recharge/support)
- Updated all story play functions to wait for button to be enabled
- Button is disabled until forgeOptions loads, causing CI failures
@Gaubee Gaubee force-pushed the feat/forge-backend branch from 729b9b2 to e9d86d8 Compare December 29, 2025 14:57
@Gaubee Gaubee merged commit f1b7463 into main Dec 29, 2025
5 checks passed
@Gaubee Gaubee deleted the feat/forge-backend branch December 29, 2025 14:59
Gaubee added a commit that referenced this pull request Dec 30, 2025
P0 高风险修复:
- Teleport: signTransData 改用 signedTx.data(RLP encoded rawTx)而非 signature
- Forge: 添加 bio_getPublicKey API 框架(含回退机制)

P1 中风险修复:
- Forge E2E mock: 使用正确的 endpoint 路径 /cot/recharge/support 和 /cot/recharge/V2
- Forge API config: 改为 fail-fast 策略,未配置 VITE_COT_API_BASE_URL 时报错

P2 改进:
- Teleport types.ts: 添加 @bnqkl 包使用说明注释

详细变更:
- packages/bio-sdk: 添加 bio_getPublicKey 方法定义
- src/services/ecosystem: 添加 handleGetPublicKey handler(待完整实现)
- miniapps/forge: useForge 调用 bio_getPublicKey,失败时回退到 address
- miniapps/forge: 更新测试以包含新的 API 调用
- miniapps/teleport: 修正 signTransData 数据源并添加说明注释
Gaubee added a commit that referenced this pull request Dec 30, 2025
* fix(miniapps): 修复 PR #142/#143 review 发现的问题

P0 高风险修复:
- Teleport: signTransData 改用 signedTx.data(RLP encoded rawTx)而非 signature
- Forge: 添加 bio_getPublicKey API 框架(含回退机制)

P1 中风险修复:
- Forge E2E mock: 使用正确的 endpoint 路径 /cot/recharge/support 和 /cot/recharge/V2
- Forge API config: 改为 fail-fast 策略,未配置 VITE_COT_API_BASE_URL 时报错

P2 改进:
- Teleport types.ts: 添加 @bnqkl 包使用说明注释

详细变更:
- packages/bio-sdk: 添加 bio_getPublicKey 方法定义
- src/services/ecosystem: 添加 handleGetPublicKey handler(待完整实现)
- miniapps/forge: useForge 调用 bio_getPublicKey,失败时回退到 address
- miniapps/forge: 更新测试以包含新的 API 调用
- miniapps/teleport: 修正 signTransData 数据源并添加说明注释

* feat(bio-sdk): bio_signMessage 返回 { signature, publicKey }

- SignatureAuthService.handleMessageSign 返回 SignatureResult
- SigningConfirmJob 发送 signature + publicKey
- bio_signMessage/bio_signTypedData 返回新格式
- useForge 直接使用 signResult.publicKey(hex 格式)
- 移除 bio_getPublicKey 回退逻辑(不再需要)

publicKey 为 hex 编码的 32 字节公钥(BioForest Ed25519)

* fix(miniapps): E2E 测试修复 + i18n 初始化

- forge: 添加 i18n 导入到 main.tsx
- forge: 修复 E2E mock (fetch 拦截 + 选择器优化)
- forge: 添加 E2E 测试用 API base URL
- teleport: 修复 E2E mock (使用 addInitScript)
- teleport: 优化资产选择器和确认页面选择器

E2E 测试结果:
- Forge: 9/9 通过
- Teleport: 8/8 通过
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.

2 participants