Преглед изворни кода

feat: 优化仓位关闭检测

lushdog@outlook.com пре 1 недеља
родитељ
комит
24c71ef927
1 измењених фајлова са 17 додато и 9 уклоњено
  1. 17 9
      src/app/my-lp/page.tsx

+ 17 - 9
src/app/my-lp/page.tsx

@@ -52,6 +52,7 @@ interface RecordInfo {
 	priceLower?: string
 	priceUpper?: string
 	isInRange?: boolean
+	isParentPositionClosed?: boolean
 	bonusInfo?: {
 		fromCreatorWallet: string
 		fromCreatorPositionStatus: number
@@ -97,12 +98,15 @@ function MyLPPageContent() {
 
 					let allCopyAmount = 0
 					let allCopys = 0
+					let isParentPositionClosed = false
 
 					if (bonusInfo?.fromCreatorPosition) {
-						const copyInfo = await fetch(
+						const copyInfo = await Promise.all([fetch(
 							`/api/my-lp/copyInfo?parentPositionAddress=${bonusInfo.fromCreatorPosition}&poolAddress=${pool.poolAddress}`
-						)
-						const copyInfoData = await copyInfo.json()
+						), fetch(
+							`/api/my-lp/detail?address=${bonusInfo.fromCreatorPosition}`
+						)])
+						const [copyInfoData, detailData] = await Promise.all(copyInfo.map(res => res.json()))
 						if (copyInfoData.retCode === 0 && copyInfoData.result) {
 							allCopys = copyInfoData.result.data.total
 							allCopyAmount = copyInfoData.result.data.records
@@ -113,9 +117,11 @@ function MyLPPageContent() {
 									0
 								)
 						}
+						isParentPositionClosed = detailData.result.data.status === 1
 					}
 					const newData = {
 						...data.result.data,
+						isParentPositionClosed,
 						allCopyAmount,
 						allCopys,
 					}
@@ -155,6 +161,8 @@ function MyLPPageContent() {
 		})
 
 		message.destroy()
+
+		return true
 	}
 
 	const fetchLPList = async (
@@ -178,7 +186,7 @@ function MyLPPageContent() {
 				setTotal(total)
 				setPoolMap(poolMap)
 				message.success(`查询成功,找到 ${data.result.data.total} 个 LP token`)
-				fetchLPDetail(positions)
+				await fetchLPDetail(positions)
 			} else {
 				message.error(data.retMsg || '查询失败')
 				setLpList([])
@@ -537,7 +545,7 @@ function MyLPPageContent() {
 						<span className="text-green-500 mr-2">新开</span>
 					)}
 					{record?.bonusInfo?.fromCreatorPosition ? (
-						record?.bonusInfo?.fromCreatorPositionStatus === 0 ? (
+						!record?.isParentPositionClosed ? (
 							<span className="text-green-500">上级未关仓</span>
 						) : (
 							<span className="text-red-500">上级已关仓</span>
@@ -606,7 +614,7 @@ function MyLPPageContent() {
 		}
 		message.loading({
 			key: 'closeAllPositionWithoutParent',
-			content: `正在一键关闭上级仓...${allPositions.length}个仓位`,
+			content: `正在一键关闭上级已关仓...${allPositions.length}个仓位`,
 			duration: 0,
 		})
 		try {
@@ -615,7 +623,7 @@ function MyLPPageContent() {
 				await handleClosePosition(position, true)
 				message.loading({
 					key: 'closeAllPositionWithoutParent',
-					content: `正在一键关闭上级仓... (${i + 1}/${allPositions.length})`,
+					content: `正在一键关闭上级已关仓... (${i + 1}/${allPositions.length})`,
 					duration: 0,
 				})
 			}
@@ -625,12 +633,12 @@ function MyLPPageContent() {
 			)
 			setLpList(newLpList)
 			message.success(
-				`一键关闭上级仓位成功,关闭了 ${allPositions.length} 个仓位`
+				`正在一键关闭上级已关仓仓位成功,关闭了 ${allPositions.length} 个仓位`
 			)
 		} catch (err: unknown) {
 			console.error('Error closing all positions without parent:', err)
 			message.error(
-				err instanceof Error ? err.message : '一键关闭上级仓位失败'
+				err instanceof Error ? err.message : '正在一键关闭上级已关仓仓位失败'
 			)
 		} finally {
 			message.destroy('closeAllPositionWithoutParent')