lushdog@outlook.com 3 недель назад
Родитель
Сommit
5a20e8a792
3 измененных файлов с 68 добавлено и 3 удалено
  1. 29 0
      src/app/api/my-lp/mintList/route.ts
  2. 3 1
      src/app/api/my-lp/route.ts
  3. 36 2
      src/app/my-lp/page.tsx

+ 29 - 0
src/app/api/my-lp/mintList/route.ts

@@ -0,0 +1,29 @@
+import { NextResponse } from 'next/server'
+
+export async function GET() {
+	try {
+		const response = await fetch(
+			'https://api2.byreal.io/byreal/api/dex/v2/mint/list?page=1&pageSize=200&sort=desc',
+			{
+				method: 'GET',
+				headers: {
+					accept: 'application/json',
+				},
+			}
+		)
+		if (!response.ok) {
+			return NextResponse.json(
+				{ retCode: response.status, retMsg: '外部 API 请求失败' },
+				{ status: response.status }
+			)
+		}
+		const data = await response.json()
+		return NextResponse.json(data.result.data)
+	} catch (error) {
+		console.error('API Route Error:', error)
+		return NextResponse.json(
+			{ retCode: 500, retMsg: '服务器内部错误' },
+			{ status: 500 }
+		)
+	}
+}

+ 3 - 1
src/app/api/my-lp/route.ts

@@ -6,9 +6,11 @@ export async function GET(request: NextRequest) {
 		const page = searchParams.get('page') || '1'
 		const pageSize = searchParams.get('pageSize') || '500'
 		const address = searchParams.get('userAddress')
+		const status = searchParams.get('status') || '0'
+		const tokenAddress = searchParams.get('tokenAddress') || ''
 
 		const response = await fetch(
-			`https://api2.byreal.io/byreal/api/dex/v2/position/list?userAddress=${address}&page=${page}&pageSize=${pageSize}&status=0`,
+			`https://api2.byreal.io/byreal/api/dex/v2/position/list?userAddress=${address}&page=${page}&pageSize=${pageSize}&tokenAddress=${tokenAddress}&status=${status}`,
 			{
 				method: 'GET',
 				headers: {

+ 36 - 2
src/app/my-lp/page.tsx

@@ -12,12 +12,14 @@ import {
 	Typography,
 	Tag,
 	InputNumber,
+	Select,
 } from 'antd'
 import type { ColumnsType, TablePaginationConfig } from 'antd/es/table'
 import dayjs from 'dayjs'
 import pLimit from 'p-limit'
 
 interface MintInfo {
+	mint: string
 	symbol: string
 	decimals: number
 	logoURI: string
@@ -71,6 +73,9 @@ function MyLPPageContent() {
 	const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([])
 	const [batchClosing, setBatchClosing] = useState(false)
 	const inputNumberRef = useRef<React.ComponentRef<typeof InputNumber>>(null)
+	const [mintList, setMintList] = useState<MintInfo[]>([])
+	const [tokenAddress, setTokenAddress] = useState<string>('')
+
 	const fetchLPDetail = async (positions: RecordInfo[]) => {
 		message.loading(`正在查询当前页面仓位详细信息,请稍等...`)
 
@@ -147,7 +152,8 @@ function MyLPPageContent() {
 
 	const fetchLPList = async (
 		adddr: string,
-		pagination?: { page: number; pageSize: number }
+		pagination?: { page: number; pageSize: number },
+		tokenAddress?: string
 	) => {
 		if (!adddr) return
 		const newPage = pagination?.page || page
@@ -155,7 +161,7 @@ function MyLPPageContent() {
 		setLoading(true)
 		try {
 			const response = await fetch(
-				`/api/my-lp?userAddress=${encodeURIComponent(adddr)}&page=${newPage}&pageSize=${newPageSize}`
+				`/api/my-lp?userAddress=${encodeURIComponent(adddr)}&tokenAddress=${tokenAddress || ''}&page=${newPage}&pageSize=${newPageSize}&status=0`
 			)
 			const data = await response.json()
 			const { positions, total, poolMap } = data.result?.data
@@ -257,6 +263,14 @@ function MyLPPageContent() {
 			})
 	}
 
+	function fetchMintList() {
+		fetch('/api/my-lp/mintList')
+			.then((res) => res.json())
+			.then((data) => {
+				setMintList(data.records as MintInfo[])
+			})
+	}
+
 	function handleAddPosition(record: RecordInfo) {
 		message.loading({
 			key: 'addPosition',
@@ -659,14 +673,34 @@ function MyLPPageContent() {
 		} else {
 			fetchAddress()
 		}
+		fetchMintList()
 		// eslint-disable-next-line react-hooks/exhaustive-deps
 	}, [])
 
+	function onMintChange(value: string) {
+		setTokenAddress(value)
+		fetchLPList(userAddress, { page: 1, pageSize: 50 }, value)
+	}
+
 	return (
 		<main style={{ padding: '24px' }}>
 			<div className="mb-4">
 				{userAddress ? (
 					<div className="flex items-center gap-2 mb-4">
+						<Select
+							value={tokenAddress}
+							placeholder="选择 LP Token"
+							style={{ width: 200 }}
+							allowClear
+							showSearch
+							options={mintList.map((mint) => ({
+								label: mint.symbol,
+								value: mint.address,
+							}))}
+							onChange={(value) => {
+								onMintChange(value)
+							}}
+						/>
 						<p className="text-lg font-bold">你的地址: {userAddress}</p>
 						<Button type="primary" onClick={handleAddressChange}>
 							更换地址