mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-07 03:07:56 +08:00
1e0da2ee39
## Problem Users entering private keys with "0x" prefix failed validation incorrectly: **Scenario:** - User inputs: `0x1234...` (34 characters including "0x") - Expected part1 length: 32 characters - **Bug**: Code checks `part1.length < 32` → `34 < 32` → ❌ FALSE → "Key too long" error - **Actual**: Should normalize to `1234...` (32 chars) → ✅ Valid **Impact:** - Users cannot paste keys from wallets (most include "0x") - Confusing UX - valid keys rejected - Forces manual "0x" removal ## Root Cause **File**: `web/src/components/TwoStageKeyModal.tsx` **Lines 77-84** (handleStage1Next): ```typescript // ❌ Bug: Checks length before normalizing if (part1.length < expectedPart1Length) { // Fails for "0x..." inputs } ``` **Lines 132-143** (handleStage2Complete): ```typescript // ❌ Bug: Same issue if (part2.length < expectedPart2Length) { // Fails for "0x..." inputs } // ❌ Bug: Concatenates without normalizing part1 const fullKey = part1 + part2 // May have double "0x" ``` ## Solution ### Fix 1: Normalize before validation **Lines 77-79**: ```typescript // ✅ Normalize first, then validate const normalized1 = part1.startsWith('0x') ? part1.slice(2) : part1 if (normalized1.length < expectedPart1Length) { // Now correctly handles both "0x..." and "1234..." } ``` **Lines 134-136**: ```typescript // ✅ Same for part2 const normalized2 = part2.startsWith('0x') ? part2.slice(2) : part2 if (normalized2.length < expectedPart2Length) { // ... } ``` ### Fix 2: Normalize before concatenation **Lines 145-147**: ```typescript // ✅ Remove "0x" from both parts before concatenating const normalized1 = part1.startsWith('0x') ? part1.slice(2) : part1 const fullKey = normalized1 + normalized2 // Result: Always 64 characters without "0x" ``` ## Testing **Manual Test Cases:** | Input Type | Part 1 | Part 2 | Before | After | |------------|--------|--------|--------|-------| | **No prefix** | `1234...` (32) | `5678...` (32) | ✅ Pass | ✅ Pass | | **With prefix** | `0x1234...` (34) | `0x5678...` (34) | ❌ Fail | ✅ Pass | | **Mixed** | `0x1234...` (34) | `5678...` (32) | ❌ Fail | ✅ Pass | | **Both prefixed** | `0x1234...` (34) | `0x5678...` (34) | ❌ Fail | ✅ Pass | **Validation consistency:** - Before: `validatePrivateKeyFormat` normalizes, but input checks don't ❌ - After: Both normalize the same way ✅ ## Impact - ✅ Users can paste keys directly from wallets - ✅ Supports both `0x1234...` and `1234...` formats - ✅ Consistent with `validatePrivateKeyFormat` logic - ✅ Better UX - no manual "0x" removal needed **Files changed**: 1 frontend file - web/src/components/TwoStageKeyModal.tsx (+6 lines, -2 lines) Co-authored-by: the-dev-z <the-dev-z@users.noreply.github.com> Co-authored-by: tinkle-community <tinklefund@gmail.com>
NOFX Web Dashboard
基于 Vite + React + TypeScript 的AI自动交易监控面板
技术栈
- React 18 - UI框架
- TypeScript - 类型安全
- Vite - 构建工具
- Tailwind CSS - 样式框架
- SWR - 数据获取和缓存
- Zustand - 状态管理
- Recharts - 图表库
安装依赖
npm install
运行开发服务器
npm run dev
构建生产版本
npm run build
功能特性
实时监控
- 系统状态 - 运行状态、AI提供商、周期数
- 账户信息 - 净值、可用余额、总盈亏、保证金使用率
- 持仓列表 - 实时价格、盈亏、杠杆、强平价
- 决策日志 - 完整的AI思维链(可展开)、决策动作、执行结果
AI思维链分析
每个决策记录都包含完整的AI思考过程:
- 第一步:现有持仓分析(技术指标、盈亏评估)
- 第二步:账户风险评估(保证金使用率、可用余额)
- 第三步:新机会评估(候选币种筛选、技术形态分析)
- 第四步:最终决策总结(平仓/开仓/持有决策)
点击 "💭 AI思维链分析" 即可展开查看完整分析过程!
自动刷新
- 系统状态、账户、持仓:每5秒刷新
- 决策日志、统计:每10秒刷新
API集成
前端通过Vite代理访问后端API(http://localhost:8080)
API端点:
GET /api/status- 系统状态GET /api/account- 账户信息GET /api/positions- 持仓列表GET /api/decisions- 决策日志(最近30条)GET /api/decisions/latest- 最新决策(最近5条)GET /api/statistics- 统计信息
项目结构
web/
├── src/
│ ├── components/ # React组件(待扩展)
│ ├── lib/
│ │ └── api.ts # API调用函数
│ ├── store/ # Zustand状态管理(待扩展)
│ ├── types/
│ │ └── index.ts # TypeScript类型定义
│ ├── App.tsx # 主应用组件
│ ├── main.tsx # 入口文件
│ └── index.css # 全局样式
├── index.html # HTML模板
├── vite.config.ts # Vite配置
├── tailwind.config.js # Tailwind配置
├── tsconfig.json # TypeScript配置
└── package.json # 依赖配置
注意事项
- 确保后端API服务已启动(默认端口8080)
- Node.js版本要求:>= 18.0.0
- 网络连接:需要访问Binance API
开发计划
- 添加图表展示(账户净值走势、盈亏曲线)
- 添加决策详情页面(完整的CoT分析)
- 添加手动交易控制
- 添加参数配置页面
- 添加通知和告警系统