fix: 修复交易统计和L2认证问题
- 修复交易统计数据计算逻辑(总订单数、已完成订单数、持仓数量) - 修复L2认证签名生成,支持URL-safe base64格式的secret - 添加标准HTTP请求头以匹配clob-client行为 - 移除数据库加密(私人应用,明文存储) - 添加自动获取API Key功能 - 优化持仓数量统计(包括正负仓位) - 添加EIP-712签名和L1认证支持 - 更新前端账户管理界面
This commit is contained in:
@@ -5,6 +5,7 @@ import Layout from './components/Layout'
|
||||
import AccountList from './pages/AccountList'
|
||||
import AccountImport from './pages/AccountImport'
|
||||
import AccountDetail from './pages/AccountDetail'
|
||||
import AccountEdit from './pages/AccountEdit'
|
||||
import LeaderList from './pages/LeaderList'
|
||||
import LeaderAdd from './pages/LeaderAdd'
|
||||
import ConfigPage from './pages/ConfigPage'
|
||||
@@ -21,6 +22,7 @@ function App() {
|
||||
<Route path="/accounts" element={<AccountList />} />
|
||||
<Route path="/accounts/import" element={<AccountImport />} />
|
||||
<Route path="/accounts/detail" element={<AccountDetail />} />
|
||||
<Route path="/accounts/edit" element={<AccountEdit />} />
|
||||
<Route path="/leaders" element={<LeaderList />} />
|
||||
<Route path="/leaders/add" element={<LeaderAdd />} />
|
||||
<Route path="/config" element={<ConfigPage />} />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useState } from 'react'
|
||||
import { useNavigate, useLocation } from 'react-router-dom'
|
||||
import { Layout as AntLayout, Menu, Drawer, Button } from 'antd'
|
||||
import { useMediaQuery } from 'react-responsive'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate, useSearchParams } from 'react-router-dom'
|
||||
import { Card, Descriptions, Button, Space, Tag, Spin, message, Typography, Divider } from 'antd'
|
||||
import { Card, Descriptions, Button, Space, Tag, Spin, message, Typography, Divider, Modal, Form, Input, Checkbox, Alert } from 'antd'
|
||||
import { ArrowLeftOutlined, ReloadOutlined, EditOutlined } from '@ant-design/icons'
|
||||
import { useAccountStore } from '../store/accountStore'
|
||||
import type { Account } from '../types'
|
||||
@@ -14,11 +14,14 @@ const AccountDetail: React.FC = () => {
|
||||
const isMobile = useMediaQuery({ maxWidth: 768 })
|
||||
const accountId = searchParams.get('id')
|
||||
|
||||
const { fetchAccountDetail, fetchAccountBalance } = useAccountStore()
|
||||
const { fetchAccountDetail, fetchAccountBalance, updateAccount } = useAccountStore()
|
||||
const [account, setAccount] = useState<Account | null>(null)
|
||||
const [balance, setBalance] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [balanceLoading, setBalanceLoading] = useState(false)
|
||||
const [editModalVisible, setEditModalVisible] = useState(false)
|
||||
const [editForm] = Form.useForm()
|
||||
const [editLoading, setEditLoading] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (accountId) {
|
||||
@@ -51,7 +54,7 @@ const AccountDetail: React.FC = () => {
|
||||
setBalanceLoading(true)
|
||||
try {
|
||||
const balanceData = await fetchAccountBalance(Number(accountId))
|
||||
setBalance(balanceData.balance || null)
|
||||
setBalance(balanceData.totalBalance || null)
|
||||
} catch (error: any) {
|
||||
console.error('获取余额失败:', error)
|
||||
// 余额查询失败不显示错误,只显示 "-"
|
||||
@@ -61,6 +64,46 @@ const AccountDetail: React.FC = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleEditSubmit = async (values: any) => {
|
||||
if (!account) return
|
||||
|
||||
setEditLoading(true)
|
||||
try {
|
||||
// 构建更新请求,空字符串转换为 undefined(不修改)
|
||||
const updateData: any = {
|
||||
accountId: account.id,
|
||||
accountName: values.accountName || undefined,
|
||||
isDefault: values.isDefault || false
|
||||
}
|
||||
|
||||
// 只有非空字符串才更新 API 凭证
|
||||
if (values.apiKey && values.apiKey.trim()) {
|
||||
updateData.apiKey = values.apiKey.trim()
|
||||
}
|
||||
if (values.apiSecret && values.apiSecret.trim()) {
|
||||
updateData.apiSecret = values.apiSecret.trim()
|
||||
}
|
||||
if (values.apiPassphrase && values.apiPassphrase.trim()) {
|
||||
updateData.apiPassphrase = values.apiPassphrase.trim()
|
||||
}
|
||||
|
||||
await updateAccount(updateData)
|
||||
|
||||
message.success('更新账户成功')
|
||||
setEditModalVisible(false)
|
||||
editForm.resetFields()
|
||||
|
||||
// 刷新账户详情
|
||||
if (accountId) {
|
||||
await loadAccountDetail()
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '更新账户失败')
|
||||
} finally {
|
||||
setEditLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div style={{ textAlign: 'center', padding: '50px' }}>
|
||||
@@ -113,7 +156,16 @@ const AccountDetail: React.FC = () => {
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<EditOutlined />}
|
||||
onClick={() => navigate(`/accounts/edit?id=${account.id}`)}
|
||||
onClick={() => {
|
||||
setEditModalVisible(true)
|
||||
editForm.setFieldsValue({
|
||||
accountName: account.accountName || '',
|
||||
apiKey: '', // 不显示实际值,留空表示不修改
|
||||
apiSecret: '', // 不显示实际值,留空表示不修改
|
||||
apiPassphrase: '', // 不显示实际值,留空表示不修改
|
||||
isDefault: account.isDefault || false
|
||||
})
|
||||
}}
|
||||
size={isMobile ? 'middle' : 'large'}
|
||||
block={isMobile}
|
||||
style={isMobile ? { minHeight: '44px' } : undefined}
|
||||
@@ -210,7 +262,9 @@ const AccountDetail: React.FC = () => {
|
||||
</Descriptions>
|
||||
</Card>
|
||||
|
||||
{account.totalOrders !== undefined || account.totalPnl !== undefined ? (
|
||||
{(account.totalOrders !== undefined || account.totalPnl !== undefined ||
|
||||
account.activeOrders !== undefined ||
|
||||
account.completedOrders !== undefined || account.positionCount !== undefined) ? (
|
||||
<>
|
||||
<Divider style={{ margin: isMobile ? '12px 0' : '16px 0' }} />
|
||||
<Card
|
||||
@@ -232,6 +286,21 @@ const AccountDetail: React.FC = () => {
|
||||
{account.totalOrders}
|
||||
</Descriptions.Item>
|
||||
)}
|
||||
{account.activeOrders !== undefined && (
|
||||
<Descriptions.Item label="活跃订单数">
|
||||
<Tag color={account.activeOrders > 0 ? 'orange' : 'default'}>{account.activeOrders}</Tag>
|
||||
</Descriptions.Item>
|
||||
)}
|
||||
{account.completedOrders !== undefined && (
|
||||
<Descriptions.Item label="已完成订单数">
|
||||
<Tag color="success">{account.completedOrders}</Tag>
|
||||
</Descriptions.Item>
|
||||
)}
|
||||
{account.positionCount !== undefined && (
|
||||
<Descriptions.Item label="持仓数量">
|
||||
<Tag color={account.positionCount > 0 ? 'blue' : 'default'}>{account.positionCount}</Tag>
|
||||
</Descriptions.Item>
|
||||
)}
|
||||
{account.totalPnl !== undefined && (
|
||||
<Descriptions.Item label="总盈亏">
|
||||
<span style={{
|
||||
@@ -246,6 +315,106 @@ const AccountDetail: React.FC = () => {
|
||||
</Card>
|
||||
</>
|
||||
) : null}
|
||||
|
||||
{/* 编辑账户 Modal */}
|
||||
<Modal
|
||||
title={account ? `编辑账户 - ${account.accountName || `账户 ${account.id}`}` : '编辑账户'}
|
||||
open={editModalVisible}
|
||||
onCancel={() => {
|
||||
setEditModalVisible(false)
|
||||
editForm.resetFields()
|
||||
}}
|
||||
footer={null}
|
||||
width={isMobile ? '95%' : 600}
|
||||
style={{ top: isMobile ? 20 : 50 }}
|
||||
destroyOnClose
|
||||
maskClosable
|
||||
closable
|
||||
>
|
||||
{account ? (
|
||||
<Form
|
||||
form={editForm}
|
||||
layout="vertical"
|
||||
onFinish={handleEditSubmit}
|
||||
size={isMobile ? 'middle' : 'large'}
|
||||
>
|
||||
<Alert
|
||||
message="编辑提示"
|
||||
description="API 凭证字段留空表示不修改。如需更新 API 凭证,请输入新值;如需保持原值不变,请留空。"
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: '24px' }}
|
||||
/>
|
||||
|
||||
<Form.Item
|
||||
label="账户名称"
|
||||
name="accountName"
|
||||
>
|
||||
<Input placeholder="账户名称(可选)" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="API Key"
|
||||
name="apiKey"
|
||||
help="留空表示不修改,输入新值将更新 API Key"
|
||||
>
|
||||
<Input.Password placeholder="留空表示不修改" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="API Secret"
|
||||
name="apiSecret"
|
||||
help="留空表示不修改,输入新值将更新 API Secret"
|
||||
>
|
||||
<Input.Password placeholder="留空表示不修改" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="API Passphrase"
|
||||
name="apiPassphrase"
|
||||
help="留空表示不修改,输入新值将更新 API Passphrase"
|
||||
>
|
||||
<Input.Password placeholder="留空表示不修改" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="isDefault"
|
||||
valuePropName="checked"
|
||||
>
|
||||
<Checkbox>设为默认账户</Checkbox>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item>
|
||||
<Space style={{ width: '100%', justifyContent: 'flex-end' }}>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setEditModalVisible(false)
|
||||
editForm.resetFields()
|
||||
}}
|
||||
size={isMobile ? 'middle' : 'large'}
|
||||
style={isMobile ? { minHeight: '44px' } : undefined}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
htmlType="submit"
|
||||
loading={editLoading}
|
||||
size={isMobile ? 'middle' : 'large'}
|
||||
style={isMobile ? { minHeight: '44px' } : undefined}
|
||||
>
|
||||
保存
|
||||
</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
) : (
|
||||
<div style={{ textAlign: 'center', padding: '20px' }}>
|
||||
<Spin size="large" />
|
||||
<div style={{ marginTop: '16px' }}>加载中...</div>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate, useSearchParams } from 'react-router-dom'
|
||||
import { Card, Form, Input, Button, message, Typography, Space, Alert, Checkbox } from 'antd'
|
||||
import { ArrowLeftOutlined } from '@ant-design/icons'
|
||||
import { useAccountStore } from '../store/accountStore'
|
||||
import { useMediaQuery } from 'react-responsive'
|
||||
|
||||
const { Title } = Typography
|
||||
|
||||
const AccountEdit: React.FC = () => {
|
||||
const navigate = useNavigate()
|
||||
const [searchParams] = useSearchParams()
|
||||
const isMobile = useMediaQuery({ maxWidth: 768 })
|
||||
const accountId = searchParams.get('id')
|
||||
|
||||
const { fetchAccountDetail, updateAccount, loading } = useAccountStore()
|
||||
const [form] = Form.useForm()
|
||||
const [account, setAccount] = useState<any>(null)
|
||||
const [loadingDetail, setLoadingDetail] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
if (accountId) {
|
||||
loadAccountDetail()
|
||||
} else {
|
||||
message.error('账户ID不能为空')
|
||||
navigate('/accounts')
|
||||
}
|
||||
}, [accountId])
|
||||
|
||||
const loadAccountDetail = async () => {
|
||||
if (!accountId) return
|
||||
|
||||
setLoadingDetail(true)
|
||||
try {
|
||||
const accountData = await fetchAccountDetail(Number(accountId))
|
||||
setAccount(accountData)
|
||||
|
||||
// 设置表单初始值
|
||||
form.setFieldsValue({
|
||||
accountName: accountData.accountName || '',
|
||||
isDefault: accountData.isDefault || false
|
||||
})
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '获取账户详情失败')
|
||||
navigate('/accounts')
|
||||
} finally {
|
||||
setLoadingDetail(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = async (values: any) => {
|
||||
if (!accountId) return
|
||||
|
||||
try {
|
||||
// 构建更新请求
|
||||
const updateData: any = {
|
||||
accountId: Number(accountId),
|
||||
accountName: values.accountName || undefined,
|
||||
isDefault: values.isDefault || false
|
||||
}
|
||||
|
||||
await updateAccount(updateData)
|
||||
|
||||
message.success('更新账户成功')
|
||||
navigate(`/accounts/detail?id=${accountId}`)
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '更新账户失败')
|
||||
}
|
||||
}
|
||||
|
||||
if (loadingDetail) {
|
||||
return (
|
||||
<div style={{ textAlign: 'center', padding: '50px' }}>
|
||||
<div>加载中...</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!account) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
padding: isMobile ? '0' : undefined,
|
||||
margin: isMobile ? '0 -8px' : undefined
|
||||
}}>
|
||||
<div style={{
|
||||
marginBottom: isMobile ? '12px' : '16px',
|
||||
padding: isMobile ? '0 8px' : '0'
|
||||
}}>
|
||||
<Button
|
||||
icon={<ArrowLeftOutlined />}
|
||||
onClick={() => navigate(`/accounts/detail?id=${accountId}`)}
|
||||
style={{ marginBottom: '16px' }}
|
||||
size={isMobile ? 'middle' : 'large'}
|
||||
>
|
||||
返回
|
||||
</Button>
|
||||
<Title level={isMobile ? 4 : 2} style={{ margin: 0, fontSize: isMobile ? '18px' : undefined }}>
|
||||
编辑账户
|
||||
</Title>
|
||||
</div>
|
||||
|
||||
<Card style={{
|
||||
margin: isMobile ? '0 -8px' : '0',
|
||||
borderRadius: isMobile ? '0' : undefined
|
||||
}}>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
onFinish={handleSubmit}
|
||||
size={isMobile ? 'middle' : 'large'}
|
||||
>
|
||||
<Form.Item
|
||||
label="账户名称"
|
||||
name="accountName"
|
||||
>
|
||||
<Input placeholder="账户名称(可选)" />
|
||||
</Form.Item>
|
||||
|
||||
<Alert
|
||||
message="API Key 管理"
|
||||
description="API Key 由系统自动管理,无需手动更新。如需重新获取 API Key,请删除并重新导入账户。"
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: '24px' }}
|
||||
/>
|
||||
|
||||
<Form.Item
|
||||
name="isDefault"
|
||||
valuePropName="checked"
|
||||
>
|
||||
<Checkbox>设为默认账户</Checkbox>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item>
|
||||
<Space>
|
||||
<Button
|
||||
type="primary"
|
||||
htmlType="submit"
|
||||
loading={loading}
|
||||
size={isMobile ? 'middle' : 'large'}
|
||||
style={isMobile ? { minHeight: '44px' } : undefined}
|
||||
>
|
||||
保存
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => navigate(`/accounts/detail?id=${accountId}`)}
|
||||
size={isMobile ? 'middle' : 'large'}
|
||||
style={isMobile ? { minHeight: '44px' } : undefined}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default AccountEdit
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
} from '../utils/ethers'
|
||||
import { useMediaQuery } from 'react-responsive'
|
||||
|
||||
const { Title, Text } = Typography
|
||||
const { Title } = Typography
|
||||
|
||||
type ImportType = 'privateKey' | 'mnemonic'
|
||||
|
||||
@@ -27,7 +27,7 @@ const AccountImport: React.FC = () => {
|
||||
const [addressError, setAddressError] = useState<string>('')
|
||||
|
||||
// 当私钥输入时,自动推导地址
|
||||
const handlePrivateKeyChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const handlePrivateKeyChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const privateKey = e.target.value.trim()
|
||||
if (!privateKey) {
|
||||
setDerivedAddress('')
|
||||
@@ -56,7 +56,7 @@ const AccountImport: React.FC = () => {
|
||||
}
|
||||
|
||||
// 当助记词输入时,自动推导地址
|
||||
const handleMnemonicChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const handleMnemonicChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const mnemonic = e.target.value.trim()
|
||||
if (!mnemonic) {
|
||||
setDerivedAddress('')
|
||||
@@ -136,9 +136,6 @@ const AccountImport: React.FC = () => {
|
||||
privateKey: privateKey,
|
||||
walletAddress: walletAddress,
|
||||
accountName: values.accountName,
|
||||
apiKey: values.apiKey,
|
||||
apiSecret: values.apiSecret,
|
||||
apiPassphrase: values.apiPassphrase,
|
||||
isDefault: values.isDefault || false
|
||||
})
|
||||
|
||||
@@ -165,7 +162,7 @@ const AccountImport: React.FC = () => {
|
||||
<Card>
|
||||
<Alert
|
||||
message="安全提示"
|
||||
description="私钥将加密存储在后端,请确保网络连接安全。建议使用 HTTPS 连接。"
|
||||
description="私钥将存储在后端数据库中,请确保数据库访问安全。建议使用 HTTPS 连接。"
|
||||
type="warning"
|
||||
showIcon
|
||||
style={{ marginBottom: '24px' }}
|
||||
@@ -305,29 +302,13 @@ const AccountImport: React.FC = () => {
|
||||
<Input placeholder="可选,用于标识账户" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="API Key"
|
||||
name="apiKey"
|
||||
help="Polymarket API Key(可选,用于 L2 API 认证)"
|
||||
>
|
||||
<Input.Password placeholder="可选,Polymarket API Key" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="API Secret"
|
||||
name="apiSecret"
|
||||
help="Polymarket API Secret(可选,用于 HMAC 签名)"
|
||||
>
|
||||
<Input.Password placeholder="可选,Polymarket API Secret" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="API Passphrase"
|
||||
name="apiPassphrase"
|
||||
help="Polymarket API Passphrase(可选,用于加密/解密密钥)"
|
||||
>
|
||||
<Input.Password placeholder="可选,Polymarket API Passphrase" />
|
||||
</Form.Item>
|
||||
<Alert
|
||||
message="API Key 自动获取"
|
||||
description="系统将自动从 Polymarket 获取或创建 API Key,无需手动输入。"
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: '24px' }}
|
||||
/>
|
||||
|
||||
<Form.Item
|
||||
name="isDefault"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { Card, Table, Button, Space, Tag, Popconfirm, message, Typography, Spin, Modal, Descriptions, Divider } from 'antd'
|
||||
import { PlusOutlined, StarOutlined, StarFilled, ReloadOutlined } from '@ant-design/icons'
|
||||
import { Card, Table, Button, Space, Tag, Popconfirm, message, Typography, Spin, Modal, Descriptions, Divider, Form, Input, Checkbox, Alert } from 'antd'
|
||||
import { PlusOutlined, StarOutlined, StarFilled, ReloadOutlined, EditOutlined } from '@ant-design/icons'
|
||||
import { useAccountStore } from '../store/accountStore'
|
||||
import type { Account } from '../types'
|
||||
import { useMediaQuery } from 'react-responsive'
|
||||
@@ -11,13 +11,17 @@ const { Title } = Typography
|
||||
const AccountList: React.FC = () => {
|
||||
const navigate = useNavigate()
|
||||
const isMobile = useMediaQuery({ maxWidth: 768 })
|
||||
const { accounts, loading, fetchAccounts, deleteAccount, setDefaultAccount, fetchAccountBalance, fetchAccountDetail } = useAccountStore()
|
||||
const { accounts, loading, fetchAccounts, deleteAccount, setDefaultAccount, fetchAccountBalance, fetchAccountDetail, updateAccount } = useAccountStore()
|
||||
const [balanceMap, setBalanceMap] = useState<Record<number, { total: string; available: string; position: string }>>({})
|
||||
const [balanceLoading, setBalanceLoading] = useState<Record<number, boolean>>({})
|
||||
const [detailModalVisible, setDetailModalVisible] = useState(false)
|
||||
const [detailAccount, setDetailAccount] = useState<Account | null>(null)
|
||||
const [detailBalance, setDetailBalance] = useState<{ total: string; available: string; position: string; positions: any[] } | null>(null)
|
||||
const [detailBalanceLoading, setDetailBalanceLoading] = useState(false)
|
||||
const [editModalVisible, setEditModalVisible] = useState(false)
|
||||
const [editAccount, setEditAccount] = useState<Account | null>(null)
|
||||
const [editForm] = Form.useForm()
|
||||
const [editLoading, setEditLoading] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
fetchAccounts()
|
||||
@@ -137,6 +141,75 @@ const AccountList: React.FC = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleShowEdit = async (account: Account) => {
|
||||
try {
|
||||
setEditModalVisible(true)
|
||||
setEditAccount(account)
|
||||
|
||||
// 加载账户详情并设置表单初始值
|
||||
const accountDetail = await fetchAccountDetail(account.id)
|
||||
setEditAccount(accountDetail)
|
||||
|
||||
editForm.setFieldsValue({
|
||||
accountName: accountDetail.accountName || '',
|
||||
apiKey: '', // 不显示实际值,留空表示不修改
|
||||
apiSecret: '', // 不显示实际值,留空表示不修改
|
||||
apiPassphrase: '', // 不显示实际值,留空表示不修改
|
||||
isDefault: accountDetail.isDefault || false
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.error('打开编辑失败:', error)
|
||||
message.error(error.message || '获取账户详情失败')
|
||||
setEditModalVisible(false)
|
||||
setEditAccount(null)
|
||||
}
|
||||
}
|
||||
|
||||
const handleEditSubmit = async (values: any) => {
|
||||
if (!editAccount) return
|
||||
|
||||
setEditLoading(true)
|
||||
try {
|
||||
// 构建更新请求,空字符串转换为 undefined(不修改)
|
||||
const updateData: any = {
|
||||
accountId: editAccount.id,
|
||||
accountName: values.accountName || undefined,
|
||||
isDefault: values.isDefault || false
|
||||
}
|
||||
|
||||
// 只有非空字符串才更新 API 凭证
|
||||
if (values.apiKey && values.apiKey.trim()) {
|
||||
updateData.apiKey = values.apiKey.trim()
|
||||
}
|
||||
if (values.apiSecret && values.apiSecret.trim()) {
|
||||
updateData.apiSecret = values.apiSecret.trim()
|
||||
}
|
||||
if (values.apiPassphrase && values.apiPassphrase.trim()) {
|
||||
updateData.apiPassphrase = values.apiPassphrase.trim()
|
||||
}
|
||||
|
||||
await updateAccount(updateData)
|
||||
|
||||
message.success('更新账户成功')
|
||||
setEditModalVisible(false)
|
||||
setEditAccount(null)
|
||||
editForm.resetFields()
|
||||
|
||||
// 刷新账户列表
|
||||
await fetchAccounts()
|
||||
|
||||
// 如果详情 Modal 打开着,也刷新详情
|
||||
if (detailModalVisible && detailAccount && detailAccount.id === editAccount.id) {
|
||||
const accountDetail = await fetchAccountDetail(editAccount.id)
|
||||
setDetailAccount(accountDetail)
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '更新账户失败')
|
||||
} finally {
|
||||
setEditLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: '账户名称',
|
||||
@@ -191,6 +264,17 @@ const AccountList: React.FC = () => {
|
||||
return balance && balance !== '-' && typeof balance === 'string' ? `${balance} USDC` : '-'
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '活跃订单',
|
||||
dataIndex: 'activeOrders',
|
||||
key: 'activeOrders',
|
||||
render: (_: any, record: Account) => {
|
||||
if (record.activeOrders !== undefined && record.activeOrders !== null) {
|
||||
return <Tag color={record.activeOrders > 0 ? 'orange' : 'default'}>{record.activeOrders}</Tag>
|
||||
}
|
||||
return <span style={{ color: '#999' }}>-</span>
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
@@ -203,6 +287,14 @@ const AccountList: React.FC = () => {
|
||||
>
|
||||
详情
|
||||
</Button>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
icon={<EditOutlined />}
|
||||
onClick={() => handleShowEdit(record)}
|
||||
>
|
||||
编辑
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这个账户吗?"
|
||||
description={
|
||||
@@ -281,6 +373,18 @@ const AccountList: React.FC = () => {
|
||||
可用: {balanceMap[record.id].available} USDC | 仓位: {balanceMap[record.id].position} USDC
|
||||
</div>
|
||||
)}
|
||||
{(record.activeOrders !== undefined && record.activeOrders !== null) && (
|
||||
<div style={{
|
||||
fontSize: '12px',
|
||||
color: '#666',
|
||||
marginTop: '4px',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: '8px'
|
||||
}}>
|
||||
活跃订单: <Tag color={record.activeOrders > 0 ? 'orange' : 'default'} style={{ margin: 0 }}>{record.activeOrders}</Tag>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -300,6 +404,15 @@ const AccountList: React.FC = () => {
|
||||
>
|
||||
查看详情
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
block
|
||||
icon={<EditOutlined />}
|
||||
onClick={() => handleShowEdit(record)}
|
||||
style={{ minHeight: '32px' }}
|
||||
>
|
||||
编辑
|
||||
</Button>
|
||||
{!record.isDefault && (
|
||||
<Button
|
||||
size="small"
|
||||
@@ -419,6 +532,20 @@ const AccountList: React.FC = () => {
|
||||
>
|
||||
刷新余额
|
||||
</Button>,
|
||||
<Button
|
||||
key="edit"
|
||||
type="primary"
|
||||
icon={<EditOutlined />}
|
||||
onClick={() => {
|
||||
if (detailAccount) {
|
||||
setDetailModalVisible(false)
|
||||
handleShowEdit(detailAccount)
|
||||
}
|
||||
}}
|
||||
disabled={!detailAccount}
|
||||
>
|
||||
编辑
|
||||
</Button>,
|
||||
<Button
|
||||
key="close"
|
||||
onClick={() => {
|
||||
@@ -532,7 +659,9 @@ const AccountList: React.FC = () => {
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
|
||||
{(detailAccount.totalOrders !== undefined || detailAccount.totalPnl !== undefined) && (
|
||||
{(detailAccount.totalOrders !== undefined || detailAccount.totalPnl !== undefined ||
|
||||
detailAccount.activeOrders !== undefined ||
|
||||
detailAccount.completedOrders !== undefined || detailAccount.positionCount !== undefined) && (
|
||||
<>
|
||||
<Divider />
|
||||
<Descriptions
|
||||
@@ -546,6 +675,21 @@ const AccountList: React.FC = () => {
|
||||
{detailAccount.totalOrders}
|
||||
</Descriptions.Item>
|
||||
)}
|
||||
{detailAccount.activeOrders !== undefined && (
|
||||
<Descriptions.Item label="活跃订单数">
|
||||
<Tag color={detailAccount.activeOrders > 0 ? 'orange' : 'default'}>{detailAccount.activeOrders}</Tag>
|
||||
</Descriptions.Item>
|
||||
)}
|
||||
{detailAccount.completedOrders !== undefined && (
|
||||
<Descriptions.Item label="已完成订单数">
|
||||
<Tag color="success">{detailAccount.completedOrders}</Tag>
|
||||
</Descriptions.Item>
|
||||
)}
|
||||
{detailAccount.positionCount !== undefined && (
|
||||
<Descriptions.Item label="持仓数量">
|
||||
<Tag color={detailAccount.positionCount > 0 ? 'blue' : 'default'}>{detailAccount.positionCount}</Tag>
|
||||
</Descriptions.Item>
|
||||
)}
|
||||
{detailAccount.totalPnl !== undefined && (
|
||||
<Descriptions.Item label="总盈亏">
|
||||
<span style={{
|
||||
@@ -567,6 +711,108 @@ const AccountList: React.FC = () => {
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
|
||||
{/* 编辑账户 Modal */}
|
||||
<Modal
|
||||
title={editAccount ? `编辑账户 - ${editAccount.accountName || `账户 ${editAccount.id}`}` : '编辑账户'}
|
||||
open={editModalVisible}
|
||||
onCancel={() => {
|
||||
setEditModalVisible(false)
|
||||
setEditAccount(null)
|
||||
editForm.resetFields()
|
||||
}}
|
||||
footer={null}
|
||||
width={isMobile ? '95%' : 600}
|
||||
style={{ top: isMobile ? 20 : 50 }}
|
||||
destroyOnClose
|
||||
maskClosable
|
||||
closable
|
||||
>
|
||||
{editAccount ? (
|
||||
<Form
|
||||
form={editForm}
|
||||
layout="vertical"
|
||||
onFinish={handleEditSubmit}
|
||||
size={isMobile ? 'middle' : 'large'}
|
||||
>
|
||||
<Alert
|
||||
message="编辑提示"
|
||||
description="API 凭证字段留空表示不修改。如需更新 API 凭证,请输入新值;如需保持原值不变,请留空。"
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: '24px' }}
|
||||
/>
|
||||
|
||||
<Form.Item
|
||||
label="账户名称"
|
||||
name="accountName"
|
||||
>
|
||||
<Input placeholder="账户名称(可选)" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="API Key"
|
||||
name="apiKey"
|
||||
help="留空表示不修改,输入新值将更新 API Key"
|
||||
>
|
||||
<Input.Password placeholder="留空表示不修改" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="API Secret"
|
||||
name="apiSecret"
|
||||
help="留空表示不修改,输入新值将更新 API Secret"
|
||||
>
|
||||
<Input.Password placeholder="留空表示不修改" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="API Passphrase"
|
||||
name="apiPassphrase"
|
||||
help="留空表示不修改,输入新值将更新 API Passphrase"
|
||||
>
|
||||
<Input.Password placeholder="留空表示不修改" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="isDefault"
|
||||
valuePropName="checked"
|
||||
>
|
||||
<Checkbox>设为默认账户</Checkbox>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item>
|
||||
<Space style={{ width: '100%', justifyContent: 'flex-end' }}>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setEditModalVisible(false)
|
||||
setEditAccount(null)
|
||||
editForm.resetFields()
|
||||
}}
|
||||
size={isMobile ? 'middle' : 'large'}
|
||||
style={isMobile ? { minHeight: '44px' } : undefined}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
htmlType="submit"
|
||||
loading={editLoading}
|
||||
size={isMobile ? 'middle' : 'large'}
|
||||
style={isMobile ? { minHeight: '44px' } : undefined}
|
||||
>
|
||||
保存
|
||||
</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
) : (
|
||||
<div style={{ textAlign: 'center', padding: '20px' }}>
|
||||
<Spin size="large" />
|
||||
<div style={{ marginTop: '16px' }}>加载中...</div>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Card, Form, Input, Button, Switch, Radio, InputNumber, message, Typography, Space } from 'antd'
|
||||
import { Card, Form, Button, Switch, Radio, InputNumber, message, Typography } from 'antd'
|
||||
import { SaveOutlined } from '@ant-design/icons'
|
||||
import { apiService } from '../services/api'
|
||||
import type { CopyTradingConfig } from '../types'
|
||||
@@ -11,7 +11,7 @@ const ConfigPage: React.FC = () => {
|
||||
const isMobile = useMediaQuery({ maxWidth: 768 })
|
||||
const [form] = Form.useForm()
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [config, setConfig] = useState<CopyTradingConfig | null>(null)
|
||||
const [, setConfig] = useState<CopyTradingConfig | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
fetchConfig()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { Card, Form, Input, Button, Select, Switch, message, Typography } from 'antd'
|
||||
import { Card, Form, Input, Button, Select, Switch, message, Typography, Space } from 'antd'
|
||||
import { ArrowLeftOutlined } from '@ant-design/icons'
|
||||
import { apiService } from '../services/api'
|
||||
import { useAccountStore } from '../store/accountStore'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Card, Table, Tag, Space, message } from 'antd'
|
||||
import { Card, Table, Tag, message } from 'antd'
|
||||
import { apiService } from '../services/api'
|
||||
import type { CopyOrder } from '../types'
|
||||
import { useMediaQuery } from 'react-responsive'
|
||||
|
||||
@@ -3,10 +3,8 @@ import { Card, Row, Col, Statistic, message } from 'antd'
|
||||
import { ArrowUpOutlined, ArrowDownOutlined } from '@ant-design/icons'
|
||||
import { apiService } from '../services/api'
|
||||
import type { Statistics as StatisticsType } from '../types'
|
||||
import { useMediaQuery } from 'react-responsive'
|
||||
|
||||
const Statistics: React.FC = () => {
|
||||
const isMobile = useMediaQuery({ maxWidth: 768 })
|
||||
const [stats, setStats] = useState<StatisticsType | null>(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ export interface Account {
|
||||
balance?: string
|
||||
totalOrders?: number
|
||||
totalPnl?: string
|
||||
activeOrders?: number
|
||||
completedOrders?: number
|
||||
positionCount?: number
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,9 +41,6 @@ export interface AccountImportRequest {
|
||||
privateKey: string
|
||||
walletAddress: string
|
||||
accountName?: string
|
||||
apiKey?: string
|
||||
apiSecret?: string
|
||||
apiPassphrase?: string
|
||||
isDefault?: boolean
|
||||
}
|
||||
|
||||
@@ -50,9 +50,6 @@ export interface AccountImportRequest {
|
||||
export interface AccountUpdateRequest {
|
||||
accountId: number
|
||||
accountName?: string
|
||||
apiKey?: string
|
||||
apiSecret?: string
|
||||
apiPassphrase?: string
|
||||
isDefault?: boolean
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user