feat: 优化金库交易和LP流动池功能
主要更新: - 金库交易动态读取: 从合约动态获取所有金库地址和名称 - 边界值测试优化: 修复 buy_exceed_hardcap 计算逻辑和错误处理 - 新增 ErrorBoundary 组件: 全局错误边界处理 - vite 配置优化: 添加 optimizeDeps 解决动态导入问题 - 交易历史和连接按钮改进 技术改进: - 使用 useReadContract/useReadContracts 批量读取合约数据 - 改进 parseError 函数处理 ccip 模块加载失败 - 添加测试状态管理 (isTestRunning, testTypeRef) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
export type TransactionType = 'mint' | 'burn' | 'buy' | 'sell' | 'approve' | 'create_vault' | 'update_price' | 'test'
|
||||
export type TransactionType = 'mint' | 'burn' | 'buy' | 'sell' | 'approve' | 'create_vault' | 'update_price' | 'test' | 'addLiquidity' | 'removeLiquidity' | 'swap'
|
||||
|
||||
export interface TransactionRecord {
|
||||
id: string
|
||||
@@ -25,10 +25,31 @@ export function useTransactionHistory() {
|
||||
try {
|
||||
const stored = localStorage.getItem(STORAGE_KEY)
|
||||
if (stored) {
|
||||
setTransactions(JSON.parse(stored))
|
||||
const parsed = JSON.parse(stored)
|
||||
// 过滤并修复损坏的记录
|
||||
const valid = Array.isArray(parsed)
|
||||
? parsed
|
||||
.filter((tx: any) => tx && typeof tx === 'object' && tx.id && typeof tx.id === 'string')
|
||||
.map((tx: any) => ({
|
||||
...tx,
|
||||
// 确保所有字段都是正确类型
|
||||
id: String(tx.id),
|
||||
type: String(tx.type || 'test'),
|
||||
hash: (typeof tx.hash === 'string' && tx.hash.startsWith('0x')) ? tx.hash : '',
|
||||
timestamp: Number(tx.timestamp) || Date.now(),
|
||||
status: ['pending', 'success', 'failed'].includes(tx.status) ? tx.status : 'failed',
|
||||
amount: tx.amount ? String(tx.amount) : undefined,
|
||||
token: tx.token ? String(tx.token) : undefined,
|
||||
vault: tx.vault ? String(tx.vault) : undefined,
|
||||
error: tx.error ? (typeof tx.error === 'string' ? tx.error : JSON.stringify(tx.error)) : undefined,
|
||||
}))
|
||||
: []
|
||||
setTransactions(valid)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to load transaction history:', e)
|
||||
// 清除损坏的数据
|
||||
localStorage.removeItem(STORAGE_KEY)
|
||||
}
|
||||
}, [])
|
||||
|
||||
@@ -44,7 +65,13 @@ export function useTransactionHistory() {
|
||||
// 添加新交易
|
||||
const addTransaction = (tx: Omit<TransactionRecord, 'id' | 'timestamp'>) => {
|
||||
const newTx: TransactionRecord = {
|
||||
...tx,
|
||||
type: tx.type,
|
||||
hash: (typeof tx.hash === 'string' && tx.hash.startsWith('0x')) ? tx.hash : '',
|
||||
status: tx.status,
|
||||
amount: tx.amount ? String(tx.amount) : undefined,
|
||||
token: tx.token ? String(tx.token) : undefined,
|
||||
vault: tx.vault ? String(tx.vault) : undefined,
|
||||
error: tx.error ? (typeof tx.error === 'string' ? tx.error : JSON.stringify(tx.error)) : undefined,
|
||||
id: `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
||||
timestamp: Date.now(),
|
||||
}
|
||||
@@ -58,6 +85,14 @@ export function useTransactionHistory() {
|
||||
|
||||
// 更新交易状态
|
||||
const updateTransaction = (id: string, updates: Partial<TransactionRecord>) => {
|
||||
// 确保 hash 是字符串
|
||||
if (updates.hash && typeof updates.hash !== 'string') {
|
||||
updates.hash = ''
|
||||
}
|
||||
// 确保 error 是字符串
|
||||
if (updates.error && typeof updates.error !== 'string') {
|
||||
updates.error = JSON.stringify(updates.error)
|
||||
}
|
||||
setTransactions(prev => {
|
||||
const updated = prev.map(tx =>
|
||||
tx.id === id ? { ...tx, ...updates } : tx
|
||||
|
||||
Reference in New Issue
Block a user