|
@@ -1,32 +1,40 @@
|
|
|
'use client'
|
|
'use client'
|
|
|
|
|
|
|
|
import { useEffect, useState } from 'react'
|
|
import { useEffect, useState } from 'react'
|
|
|
-import { Button, Modal, Input, Table, message, Spin } from 'antd'
|
|
|
|
|
|
|
+import { Button, Modal, Input, Table, message, Spin, Image } from 'antd'
|
|
|
import type { ColumnsType } from 'antd/es/table'
|
|
import type { ColumnsType } from 'antd/es/table'
|
|
|
|
|
|
|
|
-interface LPInfo {
|
|
|
|
|
- mint: string
|
|
|
|
|
- amount: string
|
|
|
|
|
- uiAmount: number
|
|
|
|
|
|
|
+interface MintInfo {
|
|
|
|
|
+ symbol: string
|
|
|
decimals: number
|
|
decimals: number
|
|
|
|
|
+ logoURI: string
|
|
|
|
|
+ price: string
|
|
|
|
|
+ address: string
|
|
|
|
|
+}
|
|
|
|
|
+interface LPInfo {
|
|
|
|
|
+ mintA: MintInfo
|
|
|
|
|
+ mintB: MintInfo
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-interface LPResponse {
|
|
|
|
|
- code: number
|
|
|
|
|
- message: string
|
|
|
|
|
- data?: {
|
|
|
|
|
- address: string
|
|
|
|
|
- lpList: LPInfo[]
|
|
|
|
|
- total: number
|
|
|
|
|
- }
|
|
|
|
|
|
|
+interface RecordInfo {
|
|
|
|
|
+ poolAddress: string
|
|
|
|
|
+ nftMintAddress: string
|
|
|
|
|
+ PriceRange: string
|
|
|
|
|
+ Token: string
|
|
|
|
|
+ TokenA: number
|
|
|
|
|
+ TokenB: number
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export default function MyLPPage() {
|
|
export default function MyLPPage() {
|
|
|
const [userAddress, setUserAddress] = useState<string>('')
|
|
const [userAddress, setUserAddress] = useState<string>('')
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false)
|
|
const [isModalOpen, setIsModalOpen] = useState(false)
|
|
|
const [inputValue, setInputValue] = useState<string>('')
|
|
const [inputValue, setInputValue] = useState<string>('')
|
|
|
- const [lpList, setLpList] = useState<LPInfo[]>([])
|
|
|
|
|
|
|
+ const [lpList, setLpList] = useState<RecordInfo[]>([])
|
|
|
const [loading, setLoading] = useState(false)
|
|
const [loading, setLoading] = useState(false)
|
|
|
|
|
+ const [total, setTotal] = useState(0)
|
|
|
|
|
+ const [page, setPage] = useState(1)
|
|
|
|
|
+ const [pageSize, setPageSize] = useState(10)
|
|
|
|
|
+ const [poolMap, setPoolMap] = useState<Record<string, LPInfo>>({})
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
const userAddress = localStorage.getItem('userAddress')
|
|
const userAddress = localStorage.getItem('userAddress')
|
|
@@ -35,27 +43,24 @@ export default function MyLPPage() {
|
|
|
}
|
|
}
|
|
|
}, [])
|
|
}, [])
|
|
|
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- if (userAddress) {
|
|
|
|
|
- fetchLPList()
|
|
|
|
|
- }
|
|
|
|
|
- }, [userAddress])
|
|
|
|
|
-
|
|
|
|
|
const fetchLPList = async () => {
|
|
const fetchLPList = async () => {
|
|
|
if (!userAddress) return
|
|
if (!userAddress) return
|
|
|
|
|
|
|
|
setLoading(true)
|
|
setLoading(true)
|
|
|
try {
|
|
try {
|
|
|
const response = await fetch(
|
|
const response = await fetch(
|
|
|
- `/api/my-lp?address=${encodeURIComponent(userAddress)}`
|
|
|
|
|
|
|
+ `/api/my-lp?userAddress=${encodeURIComponent(userAddress)}&page=${page}&pageSize=${pageSize}`
|
|
|
)
|
|
)
|
|
|
- const data: LPResponse = await response.json()
|
|
|
|
|
-
|
|
|
|
|
- if (data.code === 200 && data.data) {
|
|
|
|
|
- setLpList(data.data.lpList)
|
|
|
|
|
- message.success(`查询成功,找到 ${data.data.total} 个 LP token`)
|
|
|
|
|
|
|
+ const data = await response.json()
|
|
|
|
|
+ console.log(data, 'data')
|
|
|
|
|
+ const { positions, total, poolMap } = data.result?.data
|
|
|
|
|
+ if (data.retCode === 0 && data.result) {
|
|
|
|
|
+ setLpList(positions as RecordInfo[])
|
|
|
|
|
+ setTotal(total)
|
|
|
|
|
+ setPoolMap(poolMap)
|
|
|
|
|
+ message.success(`查询成功,找到 ${data.result.data.total} 个 LP token`)
|
|
|
} else {
|
|
} else {
|
|
|
- message.error(data.message || '查询失败')
|
|
|
|
|
|
|
+ message.error(data.retMsg || '查询失败')
|
|
|
setLpList([])
|
|
setLpList([])
|
|
|
}
|
|
}
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
@@ -88,13 +93,61 @@ export default function MyLPPage() {
|
|
|
setInputValue('')
|
|
setInputValue('')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const columns: ColumnsType<LPInfo> = [
|
|
|
|
|
|
|
+ function getPoolInfo(poolAddress: string) {
|
|
|
|
|
+ const poolInfo = poolMap[poolAddress]
|
|
|
|
|
+ if (!poolInfo) {
|
|
|
|
|
+ return {
|
|
|
|
|
+ lpToken: '',
|
|
|
|
|
+ logoURI: [],
|
|
|
|
|
+ price: [],
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ const tokenA = poolInfo.mintA.symbol
|
|
|
|
|
+ const tokenB = poolInfo.mintB.symbol
|
|
|
|
|
+ return {
|
|
|
|
|
+ lpToken: `${tokenA}/${tokenB}`,
|
|
|
|
|
+ logoURI: [poolInfo.mintA.logoURI, poolInfo.mintB.logoURI],
|
|
|
|
|
+ price: [poolInfo.mintA.price, poolInfo.mintB.price],
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const columns: ColumnsType<RecordInfo> = [
|
|
|
|
|
+ {
|
|
|
|
|
+ title: 'LP Token',
|
|
|
|
|
+ dataIndex: 'lpToken',
|
|
|
|
|
+ key: 'lpToken',
|
|
|
|
|
+ render: (text: string, record: RecordInfo) => (
|
|
|
|
|
+ <div className="flex items-center gap-2">
|
|
|
|
|
+ <span className="inline-flex items-center">
|
|
|
|
|
+ <Image
|
|
|
|
|
+ src={getPoolInfo(record.poolAddress).logoURI[0]}
|
|
|
|
|
+ alt="logo"
|
|
|
|
|
+ width={20}
|
|
|
|
|
+ height={20}
|
|
|
|
|
+ style={{ borderRadius: '50%', marginLeft: 8 }}
|
|
|
|
|
+ />
|
|
|
|
|
+ <Image
|
|
|
|
|
+ src={getPoolInfo(record.poolAddress).logoURI[1]}
|
|
|
|
|
+ alt="logo"
|
|
|
|
|
+ width={20}
|
|
|
|
|
+ height={20}
|
|
|
|
|
+ style={{ borderRadius: '50%' }}
|
|
|
|
|
+ />
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <span className="font-mono text-sm">
|
|
|
|
|
+ {getPoolInfo(record.poolAddress).lpToken}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ),
|
|
|
|
|
+ },
|
|
|
{
|
|
{
|
|
|
title: 'NFT Token Address',
|
|
title: 'NFT Token Address',
|
|
|
- dataIndex: 'nftMint',
|
|
|
|
|
- key: 'nftMint',
|
|
|
|
|
|
|
+ dataIndex: 'nftMintAddress',
|
|
|
|
|
+ key: 'nftMintAddress',
|
|
|
render: (text: string) => (
|
|
render: (text: string) => (
|
|
|
- <span className="font-mono text-sm">{text}</span>
|
|
|
|
|
|
|
+ <span className="font-mono text-sm">
|
|
|
|
|
+ {text.slice(0, 6)}...{text.slice(-4)}
|
|
|
|
|
+ </span>
|
|
|
),
|
|
),
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
@@ -144,11 +197,17 @@ export default function MyLPPage() {
|
|
|
<Table
|
|
<Table
|
|
|
columns={columns}
|
|
columns={columns}
|
|
|
dataSource={lpList}
|
|
dataSource={lpList}
|
|
|
- rowKey="nftMint"
|
|
|
|
|
|
|
+ rowKey="nftMintAddress"
|
|
|
pagination={{
|
|
pagination={{
|
|
|
- pageSize: 10,
|
|
|
|
|
|
|
+ pageSize: pageSize,
|
|
|
showSizeChanger: true,
|
|
showSizeChanger: true,
|
|
|
showTotal: (total) => `共 ${total} 条记录`,
|
|
showTotal: (total) => `共 ${total} 条记录`,
|
|
|
|
|
+ total: total,
|
|
|
|
|
+ }}
|
|
|
|
|
+ onChange={(pagination) => {
|
|
|
|
|
+ setPage(pagination.current || 1)
|
|
|
|
|
+ setPageSize(pagination.pageSize || 10)
|
|
|
|
|
+ fetchLPList()
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
|
</Spin>
|
|
</Spin>
|