feat: 添加交易历史、错误提示和打包优化
1. 交易历史记录功能 - 新增 useTransactionHistory hook 管理交易记录 - 新增 TransactionHistory 组件显示历史 - 交易记录保存到 localStorage 2. 错误处理和用户提示 - 新增 Toast 通知组件 - 交易提交/成功/失败时显示提示 - 解析并显示友好的错误信息 3. 打包优化 - 配置代码分割 (manualChunks) - 分离 react/web3/walletconnect/i18n - 提高 chunk 大小警告阈值 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
33
frontend/src/context/TransactionContext.tsx
Normal file
33
frontend/src/context/TransactionContext.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import { createContext, useContext } from 'react'
|
||||
import type { ReactNode } from 'react'
|
||||
import { useTransactionHistory } from '../hooks/useTransactionHistory'
|
||||
import type { TransactionRecord, TransactionType } from '../hooks/useTransactionHistory'
|
||||
|
||||
interface TransactionContextType {
|
||||
transactions: TransactionRecord[]
|
||||
addTransaction: (tx: Omit<TransactionRecord, 'id' | 'timestamp'>) => string
|
||||
updateTransaction: (id: string, updates: Partial<TransactionRecord>) => void
|
||||
clearHistory: () => void
|
||||
}
|
||||
|
||||
const TransactionContext = createContext<TransactionContextType | null>(null)
|
||||
|
||||
export function TransactionProvider({ children }: { children: ReactNode }) {
|
||||
const history = useTransactionHistory()
|
||||
|
||||
return (
|
||||
<TransactionContext.Provider value={history}>
|
||||
{children}
|
||||
</TransactionContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export function useTransactions() {
|
||||
const context = useContext(TransactionContext)
|
||||
if (!context) {
|
||||
throw new Error('useTransactions must be used within TransactionProvider')
|
||||
}
|
||||
return context
|
||||
}
|
||||
|
||||
export type { TransactionType, TransactionRecord }
|
||||
Reference in New Issue
Block a user