lushdog@outlook.com há 3 semanas atrás
pai
commit
7230aa389e
2 ficheiros alterados com 46 adições e 5 exclusões
  1. 2 2
      src/app/api/lp-copy/route.ts
  2. 44 3
      src/app/my-lp/page.tsx

+ 2 - 2
src/app/api/lp-copy/route.ts

@@ -236,8 +236,8 @@ export async function POST(request: NextRequest) {
 				poolInfo,
 			})
 
-			// 添加 2% slippage 作为 otherAmountMax(允许的最大值)
-			otherAmountMax = otherAmountNeeded.mul(new BN(10200)).div(new BN(10000))
+			// 添加 5% slippage 作为 otherAmountMax(允许的最大值)
+			otherAmountMax = otherAmountNeeded.mul(new BN(10500)).div(new BN(10000))
 		}
 
 		// 计算最终总价值(使用实际投入的金额,而不是加了 slippage 的 otherAmountMax)

+ 44 - 3
src/app/my-lp/page.tsx

@@ -60,7 +60,7 @@ function MyLPPageContent() {
 	const [loading, setLoading] = useState(false)
 	const [total, setTotal] = useState(0)
 	const [page, setPage] = useState(1)
-	const [pageSize, setPageSize] = useState(50)
+	const [pageSize] = useState(50)
 	const [poolMap, setPoolMap] = useState<Record<string, LPInfo>>({})
 
 	const fetchLPDetail = async (positions: RecordInfo[]) => {
@@ -159,13 +159,13 @@ function MyLPPageContent() {
 		}
 	}
 
-	const handleClosePosition = (record: RecordInfo) => {
+	const handleClosePosition = (record: RecordInfo): Promise<void> => {
 		message.loading({
 			key: 'closePosition',
 			content: '正在关仓...',
 			duration: 0,
 		})
-		fetch('/api/lp-index/lp-close', {
+		return fetch('/api/lp-index/lp-close', {
 			method: 'POST',
 			body: JSON.stringify({
 				nftMintAddress: record.nftMintAddress,
@@ -402,6 +402,39 @@ function MyLPPageContent() {
 			})
 	}
 
+	async function handleCloseAllPositionWithoutParent() {
+		const allPositions = lpList.filter(
+			(item) =>
+				item.bonusInfo?.fromCreatorPosition &&
+				item.bonusInfo?.fromCreatorPositionStatus !== 0
+		)
+		console.log(allPositions, 'allPositions')
+		if (allPositions.length === 0) {
+			message.info('没有需要关闭的仓位')
+			return
+		}
+		message.loading({
+			key: 'closeAllPositionWithoutParent',
+			content: `正在一键关闭无上级仓位...${allPositions.length}个仓位`,
+			duration: 0,
+		})
+		try {
+			for (const position of allPositions) {
+				await handleClosePosition(position)
+			}
+			message.success(
+				`一键关闭无上级仓位成功,关闭了 ${allPositions.length} 个仓位`
+			)
+		} catch (err: unknown) {
+			console.error('Error closing all positions without parent:', err)
+			message.error(
+				err instanceof Error ? err.message : '一键关闭无上级仓位失败'
+			)
+		} finally {
+			message.destroy('closeAllPositionWithoutParent')
+		}
+	}
+
 	useEffect(() => {
 		const userAddress = localStorage.getItem('userAddress')
 		if (userAddress) {
@@ -425,6 +458,13 @@ function MyLPPageContent() {
 						<Button onClick={() => fetchLPList(userAddress)} loading={loading}>
 							刷新
 						</Button>
+						<Button
+							type="primary"
+							onClick={() => handleCloseAllPositionWithoutParent()}
+							loading={loading}
+						>
+							一键关闭无上级仓位
+						</Button>
 					</div>
 				) : (
 					<Button type="primary" onClick={handleAddAddress}>
@@ -449,6 +489,7 @@ function MyLPPageContent() {
 							total: total,
 						}}
 						onChange={(pagination: TablePaginationConfig) => {
+							setPage(pagination.current || 1)
 							fetchLPList(userAddress, {
 								page: pagination.current || 1,
 								pageSize: pagination.pageSize || 50,