mac
2 days ago
6 changed files with 418 additions and 4 deletions
-
28src/api/index.ts
-
4src/pages/chat/group-list/index.tsx
-
180src/pages/coin/default-list.tsx
-
180src/pages/coin/token-list.tsx
-
2src/pages/login/index.tsx
-
28src/route/routes.ts
@ -0,0 +1,180 @@ |
|||
import api from "@/api" |
|||
import MyTable from "@/components/MyTable" |
|||
import { Button, Drawer, Form, Input, notification, Popconfirm } from "antd" |
|||
import React, { useRef, useState } from "react" |
|||
|
|||
const chaindNames = { |
|||
1: 'Ethereum Mainnet', |
|||
56: 'BNB Smart Chain Mainnet', |
|||
42161: 'Arbitrum One', |
|||
10: 'OP Mainnet', |
|||
97: 'BSC Testnet', |
|||
11155111: 'Ethereum Sepolia', |
|||
11155420: 'Optimism Sepolia Testnet Archival', |
|||
421614: 'Arbitrum Sepolia Testnet Archival', |
|||
} |
|||
|
|||
const TokenList = () => { |
|||
|
|||
const [visible, setVisible] = useState(false) |
|||
const operateType = useRef('' as 'c' | 'u') |
|||
const [form] = Form.useForm() |
|||
const tableRef = useRef(null) |
|||
const currentItem = useRef({} as any) |
|||
|
|||
const columns = [ |
|||
{ |
|||
title: '地址', |
|||
dataIndex: 'address', |
|||
width: 300 |
|||
}, |
|||
{ |
|||
title: '币种名称', |
|||
dataIndex: 'name', |
|||
width: 200 |
|||
}, |
|||
{ |
|||
title: '币种符号', |
|||
dataIndex: 'symbol', |
|||
width: 200 |
|||
}, |
|||
{ |
|||
title: 'chainId', |
|||
dataIndex: 'chain_id', |
|||
width: 200, |
|||
render: (id) => <div>{id} ({chaindNames[id]})</div> |
|||
}, |
|||
{ |
|||
title: '精度', |
|||
dataIndex: 'decimals', |
|||
}, |
|||
{ |
|||
title: '操作', |
|||
dataIndex: '', |
|||
fixed: 'right', |
|||
width: 150, |
|||
render: (row) => ( |
|||
<div style={{ display: 'flex' }}> |
|||
<div style={{ fontSize: 12, color: '#1890ff', marginLeft: 15, textWrap: 'nowrap', cursor: 'pointer' }} onClick={() => { |
|||
operateType.current = 'u'; |
|||
form.setFieldsValue(row) |
|||
currentItem.current = row |
|||
setVisible(true) |
|||
}}>修改</div> |
|||
<Popconfirm title="确认删除?" onConfirm={() => delToken(row)}> |
|||
<div style={{ fontSize: 12, color: '#1890ff', marginLeft: 15, textWrap: 'nowrap', cursor: 'pointer' }}>删除</div> |
|||
</Popconfirm> |
|||
</div> |
|||
) |
|||
}, |
|||
] |
|||
|
|||
const delToken = async (item) => { |
|||
try { |
|||
const res: any = await api.delete_buzzDefaultTokens({ id: item.id }) |
|||
if (res.code === 0) { |
|||
notification.success({ |
|||
message: '删除成功' |
|||
}); |
|||
tableRef.current.update() |
|||
} |
|||
} catch (error) { |
|||
|
|||
} |
|||
} |
|||
|
|||
const changeToken = async (values) => { |
|||
let params = { ...values } |
|||
Object.keys(params).map(key => { |
|||
params[key] = typeof params[key] == 'string' ? params[key].trim() : params[key] |
|||
}) |
|||
const res: any = await api.update_buzzDefaultTokens({ |
|||
...params, |
|||
chain_id: Number(params.chain_id), |
|||
id: currentItem.current.id |
|||
}) |
|||
if (res.code === 0) { |
|||
tableRef.current.update() |
|||
notification.success({ |
|||
message: '修改成功' |
|||
}) |
|||
} |
|||
} |
|||
|
|||
const createToken = async (values) => { |
|||
let params = { ...values } |
|||
Object.keys(params).map(key => { |
|||
params[key] = params[key].trim() |
|||
}) |
|||
const res: any = await api.create_buzzDefaultTokens({ |
|||
...params, |
|||
chain_id: Number(params.chain_id) |
|||
}) |
|||
if (res.code === 0) { |
|||
tableRef.current.update() |
|||
notification.success({ |
|||
message: '创建成功' |
|||
}) |
|||
} |
|||
} |
|||
|
|||
const onFinish = (values) => { |
|||
close() |
|||
if (operateType.current === 'c') { |
|||
createToken(values) |
|||
} else { |
|||
changeToken(values) |
|||
} |
|||
} |
|||
|
|||
const close = () => { |
|||
setVisible(false) |
|||
form.resetFields() |
|||
} |
|||
|
|||
return ( |
|||
<> |
|||
<MyTable |
|||
ref={tableRef} |
|||
header={ |
|||
<div style={{ display: 'flex', justifyContent: 'flex-end', marginBottom: 15 }}> |
|||
<Button type="primary" onClick={() => { |
|||
operateType.current = 'c' |
|||
setVisible(true) |
|||
}}>添加币种</Button> |
|||
</div> |
|||
} |
|||
apiFun={api.get_buzzDefaultTokens} |
|||
columns={columns} |
|||
rowKey="id" |
|||
/> |
|||
{visible && ( |
|||
<Drawer visible={visible} onClose={close} width={500} title={operateType.current === 'c' ? '创建币种' : '修改币种'}> |
|||
<Form layout="vertical" form={form} onFinish={onFinish}> |
|||
<Form.Item label="chainID" name="chain_id" rules={[{ required: true, message: '请输入' }]}> |
|||
<Input /> |
|||
</Form.Item> |
|||
<Form.Item label="币种地址" name="address" rules={[{ required: true, message: '请输入' }]}> |
|||
<Input /> |
|||
</Form.Item> |
|||
<Form.Item label="币种名称" name="name" rules={[{ required: true, message: '请输入' }]}> |
|||
<Input /> |
|||
</Form.Item> |
|||
<Form.Item label="币种符号" name="symbol" rules={[{ required: true, message: '请输入' }]}> |
|||
<Input /> |
|||
</Form.Item> |
|||
<Form.Item label="币种精度" name="decimals" rules={[{ required: true, message: '请输入' }]}> |
|||
<Input /> |
|||
</Form.Item> |
|||
<Form.Item > |
|||
<Button type="primary" htmlType="submit">确认</Button> |
|||
</Form.Item> |
|||
</Form> |
|||
</Drawer> |
|||
) |
|||
} |
|||
</> |
|||
) |
|||
} |
|||
|
|||
export default TokenList |
@ -0,0 +1,180 @@ |
|||
import api from "@/api" |
|||
import MyTable from "@/components/MyTable" |
|||
import { Button, Drawer, Form, Input, notification, Popconfirm } from "antd" |
|||
import React, { useRef, useState } from "react" |
|||
|
|||
const chaindNames = { |
|||
1: 'Ethereum Mainnet', |
|||
56: 'BNB Smart Chain Mainnet', |
|||
42161: 'Arbitrum One', |
|||
10: 'OP Mainnet', |
|||
97: 'BSC Testnet', |
|||
11155111: 'Ethereum Sepolia', |
|||
11155420: 'Optimism Sepolia Testnet Archival', |
|||
421614: 'Arbitrum Sepolia Testnet Archival', |
|||
} |
|||
|
|||
const TokenList = () => { |
|||
|
|||
const [visible, setVisible] = useState(false) |
|||
const operateType = useRef('' as 'c' | 'u') |
|||
const [form] = Form.useForm() |
|||
const tableRef = useRef(null) |
|||
const currentItem = useRef({} as any) |
|||
|
|||
const columns = [ |
|||
{ |
|||
title: '地址', |
|||
dataIndex: 'address', |
|||
width: 300 |
|||
}, |
|||
{ |
|||
title: '币种名称', |
|||
dataIndex: 'name', |
|||
width: 200 |
|||
}, |
|||
{ |
|||
title: '币种符号', |
|||
dataIndex: 'symbol', |
|||
width: 200 |
|||
}, |
|||
{ |
|||
title: 'chainId', |
|||
dataIndex: 'chain_id', |
|||
width: 200, |
|||
render: (id) => <div>{id} ({chaindNames[id]})</div> |
|||
}, |
|||
{ |
|||
title: '精度', |
|||
dataIndex: 'decimals', |
|||
}, |
|||
{ |
|||
title: '操作', |
|||
dataIndex: '', |
|||
fixed: 'right', |
|||
width: 150, |
|||
render: (row) => ( |
|||
<div style={{ display: 'flex' }}> |
|||
<div style={{ fontSize: 12, color: '#1890ff', marginLeft: 15, textWrap: 'nowrap', cursor: 'pointer' }} onClick={() => { |
|||
operateType.current = 'u'; |
|||
form.setFieldsValue(row) |
|||
currentItem.current = row |
|||
setVisible(true) |
|||
}}>修改</div> |
|||
<Popconfirm title="确认删除?" onConfirm={() => delToken(row)}> |
|||
<div style={{ fontSize: 12, color: '#1890ff', marginLeft: 15, textWrap: 'nowrap', cursor: 'pointer' }}>删除</div> |
|||
</Popconfirm> |
|||
</div> |
|||
) |
|||
}, |
|||
] |
|||
|
|||
const delToken = async (item) => { |
|||
try { |
|||
const res: any = await api.delete_buzzTokens({ id: item.id }) |
|||
if (res.code === 0) { |
|||
notification.success({ |
|||
message: '删除成功' |
|||
}); |
|||
tableRef.current.update() |
|||
} |
|||
} catch (error) { |
|||
|
|||
} |
|||
} |
|||
|
|||
const changeToken = async (values) => { |
|||
let params = { ...values } |
|||
Object.keys(params).map(key => { |
|||
params[key] = typeof params[key] == 'string' ? params[key].trim() : params[key] |
|||
}) |
|||
const res: any = await api.update_buzzTokens({ |
|||
...params, |
|||
chain_id: Number(params.chain_id), |
|||
id: currentItem.current.id |
|||
}) |
|||
if (res.code === 0) { |
|||
tableRef.current.update() |
|||
notification.success({ |
|||
message: '修改成功' |
|||
}) |
|||
} |
|||
} |
|||
|
|||
const createToken = async (values) => { |
|||
let params = { ...values } |
|||
Object.keys(params).map(key => { |
|||
params[key] = params[key].trim() |
|||
}) |
|||
const res: any = await api.create_buzzTokens({ |
|||
...params, |
|||
chain_id: Number(params.chain_id) |
|||
}) |
|||
if (res.code === 0) { |
|||
tableRef.current.update() |
|||
notification.success({ |
|||
message: '创建成功' |
|||
}) |
|||
} |
|||
} |
|||
|
|||
const onFinish = (values) => { |
|||
close() |
|||
if (operateType.current === 'c') { |
|||
createToken(values) |
|||
} else { |
|||
changeToken(values) |
|||
} |
|||
} |
|||
|
|||
const close = () => { |
|||
setVisible(false) |
|||
form.resetFields() |
|||
} |
|||
|
|||
return ( |
|||
<> |
|||
<MyTable |
|||
ref={tableRef} |
|||
header={ |
|||
<div style={{ display: 'flex', justifyContent: 'flex-end', marginBottom: 15 }}> |
|||
<Button type="primary" onClick={() => { |
|||
operateType.current = 'c' |
|||
setVisible(true) |
|||
}}>添加币种</Button> |
|||
</div> |
|||
} |
|||
apiFun={api.get_buzzTokens} |
|||
columns={columns} |
|||
rowKey="id" |
|||
/> |
|||
{visible && ( |
|||
<Drawer visible={visible} onClose={close} width={500} title={operateType.current === 'c' ? '创建币种' : '修改币种'}> |
|||
<Form layout="vertical" form={form} onFinish={onFinish}> |
|||
<Form.Item label="chainID" name="chain_id" rules={[{ required: true, message: '请输入' }]}> |
|||
<Input /> |
|||
</Form.Item> |
|||
<Form.Item label="币种地址" name="address" rules={[{ required: true, message: '请输入' }]}> |
|||
<Input /> |
|||
</Form.Item> |
|||
<Form.Item label="币种名称" name="name" rules={[{ required: true, message: '请输入' }]}> |
|||
<Input /> |
|||
</Form.Item> |
|||
<Form.Item label="币种符号" name="symbol" rules={[{ required: true, message: '请输入' }]}> |
|||
<Input /> |
|||
</Form.Item> |
|||
<Form.Item label="币种精度" name="decimals" rules={[{ required: true, message: '请输入' }]}> |
|||
<Input /> |
|||
</Form.Item> |
|||
<Form.Item > |
|||
<Button type="primary" htmlType="submit">确认</Button> |
|||
</Form.Item> |
|||
</Form> |
|||
</Drawer> |
|||
) |
|||
} |
|||
</> |
|||
) |
|||
} |
|||
|
|||
export default TokenList |
Write
Preview
Loading…
Cancel
Save
Reference in new issue