Эх сурвалжийг харах

refactor(my-lp): 优化代码结构,提取公共计算逻辑并改进仓位来源显示

- 提取 getParentPositionData 辅助函数,减少重复代码
- 上级 fee 和 fee/tvl 列添加单日数据展示
- 仓位来源列改用图标显示,更直观区分新开/复制及上级状态
lushdog@outlook.com 3 долоо хоног өмнө
parent
commit
5675262629
1 өөрчлөгдсөн 76 нэмэгдсэн , 65 устгасан
  1. 76 65
      src/app/my-lp/page.tsx

+ 76 - 65
src/app/my-lp/page.tsx

@@ -21,6 +21,8 @@ import {
 	CloseCircleOutlined,
 	PlusCircleOutlined,
 	AimOutlined,
+	CopyOutlined,
+	CheckCircleOutlined,
 } from '@ant-design/icons'
 import type { ColumnsType, TablePaginationConfig } from 'antd/es/table'
 import dayjs from 'dayjs'
@@ -412,6 +414,29 @@ function MyLPPageContent() {
 		else return 'red'
 	}
 
+	function getParentPositionData(record: RecordInfo) {
+		const claimed =
+			Number(record.parentPositionInfo?.totalClaimedFeeAndReward) || 0
+		const unclaimed =
+			Number(record.parentPositionInfo?.totalUnClaimedFeeAndReward) || 0
+		const parentFee = claimed + unclaimed
+		const parentDeposit = Number(record.parentPositionInfo?.totalDeposit) || 0
+		const parentWithdraw = Number(record.parentPositionInfo?.totalWithdraw) || 0
+		const parentAmount = parentDeposit - parentWithdraw
+		const openTime = record.openTime || 0
+		const now = Date.now()
+		const days = (now - openTime) / (24 * 60 * 60 * 1000) || 1
+		const totalCopyAmount = Number(record.allCopyAmount) || 0
+		const liquidityUsd = Number(record.liquidityUsd) || 0
+		return {
+			parentFee,
+			parentAmount,
+			days,
+			totalCopyAmount,
+			liquidityUsd,
+		}
+	}
+
 	function formatPositionAgeMs(
 		ms: number | undefined,
 		openTime?: number
@@ -625,7 +650,7 @@ function MyLPPageContent() {
 		{
 			title: (
 				<span>
-					1U ROI{' '}
+					1UROI{' '}
 					<Tooltip title="当前状态下,假设一开始复制金额为 1U 可获得的奖励">
 						<span style={{ cursor: 'help' }}>❓</span>
 					</Tooltip>
@@ -633,12 +658,7 @@ function MyLPPageContent() {
 			),
 			key: 'oneURoi',
 			render: (_text: string, record: RecordInfo) => {
-				const claimed =
-					Number(record.parentPositionInfo?.totalClaimedFeeAndReward) || 0
-				const unclaimed =
-					Number(record.parentPositionInfo?.totalUnClaimedFeeAndReward) || 0
-				const parentFee = claimed + unclaimed
-				const totalCopyAmount = Number(record.allCopyAmount) || 0
+				const { parentFee, totalCopyAmount } = getParentPositionData(record)
 				const oneURoi =
 					totalCopyAmount > 0 ? (parentFee * 0.05) / totalCopyAmount : 0
 				return (
@@ -651,7 +671,7 @@ function MyLPPageContent() {
 		{
 			title: (
 				<span>
-					1U/Day 回报{' '}
+					1U日ROI{' '}
 					<Tooltip title="复制金额为 1U 时,每天可获得的奖励">
 						<span style={{ cursor: 'help' }}>❓</span>
 					</Tooltip>
@@ -659,15 +679,8 @@ function MyLPPageContent() {
 			),
 			key: 'oneUPerDayRoi',
 			render: (_text: string, record: RecordInfo) => {
-				const claimed =
-					Number(record.parentPositionInfo?.totalClaimedFeeAndReward) || 0
-				const unclaimed =
-					Number(record.parentPositionInfo?.totalUnClaimedFeeAndReward) || 0
-				const parentFee = claimed + unclaimed
-				const totalCopyAmount = Number(record.allCopyAmount) || 0
-				const openTime = record.openTime || 0
-				const now = Date.now()
-				const days = (now - openTime) / (24 * 60 * 60 * 1000) || 1
+				const { parentFee, days, totalCopyAmount } =
+					getParentPositionData(record)
 				const oneUPerDayRoi =
 					days > 0 && totalCopyAmount > 0
 						? (parentFee * 0.05) / days / totalCopyAmount
@@ -690,16 +703,8 @@ function MyLPPageContent() {
 			),
 			key: 'currentRoi',
 			render: (_text: string, record: RecordInfo) => {
-				const claimed =
-					Number(record.parentPositionInfo?.totalClaimedFeeAndReward) || 0
-				const unclaimed =
-					Number(record.parentPositionInfo?.totalUnClaimedFeeAndReward) || 0
-				const parentFee = claimed + unclaimed
-				const liquidityUsd = Number(record.liquidityUsd) || 0
-				const totalCopyAmount = Number(record.allCopyAmount) || 0
-				const openTime = record.openTime || 0
-				const now = Date.now()
-				const days = (now - openTime) / (24 * 60 * 60 * 1000) || 1
+				const { parentFee, days, totalCopyAmount, liquidityUsd } =
+					getParentPositionData(record)
 				const currentRoi =
 					days > 0 && totalCopyAmount > 0
 						? (((parentFee * 0.05) / days) * liquidityUsd) / totalCopyAmount
@@ -727,11 +732,7 @@ function MyLPPageContent() {
 			dataIndex: 'parentLiquidityUsd',
 			key: 'parentLiquidityUsd',
 			render: (_text: string, record: RecordInfo) => {
-				const parentDeposit =
-					Number(record.parentPositionInfo?.totalDeposit) || 0
-				const parentWithdraw =
-					Number(record.parentPositionInfo?.totalWithdraw) || 0
-				const parentAmount = parentDeposit - parentWithdraw
+				const { parentAmount } = getParentPositionData(record)
 				const displayAmount = parentAmount < 0 ? 0.01 : parentAmount
 				return (
 					<span className="font-mono text-sm text-purple-500">
@@ -744,14 +745,14 @@ function MyLPPageContent() {
 			title: '上级 fee',
 			key: 'parentFee',
 			render: (_text: string, record: RecordInfo) => {
-				const claimed =
-					Number(record.parentPositionInfo?.totalClaimedFeeAndReward) || 0
-				const unclaimed =
-					Number(record.parentPositionInfo?.totalUnClaimedFeeAndReward) || 0
-				const parentFee = claimed + unclaimed
+				const { parentFee, days } = getParentPositionData(record)
+				const dailyFee = parentFee / days
 				return (
 					<span className="font-mono text-sm text-orange-500">
 						${parentFee.toFixed(2)}
+						<span className="text-xs text-gray-500">
+							(${dailyFee.toFixed(2)}/日)
+						</span>
 					</span>
 				)
 			},
@@ -760,20 +761,15 @@ function MyLPPageContent() {
 			title: '上级 fee/tvl',
 			key: 'parentFeeRatio',
 			render: (_text: string, record: RecordInfo) => {
-				const claimed =
-					Number(record.parentPositionInfo?.totalClaimedFeeAndReward) || 0
-				const unclaimed =
-					Number(record.parentPositionInfo?.totalUnClaimedFeeAndReward) || 0
-				const parentFee = claimed + unclaimed
-				const parentDeposit =
-					Number(record.parentPositionInfo?.totalDeposit) || 0
-				const parentWithdraw =
-					Number(record.parentPositionInfo?.totalWithdraw) || 0
-				const parentAmount = parentDeposit - parentWithdraw
+				const { parentFee, parentAmount, days } = getParentPositionData(record)
 				const ratio = parentAmount > 0 ? (parentFee / parentAmount) * 100 : 0
+				const dailyRatio = ratio / days
 				return (
 					<span className="font-mono text-sm text-blue-500">
 						{ratio.toFixed(2)}%
+						<span className="text-xs text-gray-500">
+							({dailyRatio.toFixed(2)}%/日)
+						</span>
 					</span>
 				)
 			},
@@ -934,27 +930,42 @@ function MyLPPageContent() {
 		{
 			title: '仓位来源',
 			dataIndex: 'bonusInfo',
-			width: 140,
+			width: 80,
 			fixed: 'right',
 			key: 'bonusInfoSource',
-			render: (text: string, record: RecordInfo) => (
-				<span className="font-mono text-sm">
-					{record?.bonusInfo?.fromCreatorPosition ? (
-						<span className="text-blue-500 mr-2">复制</span>
-					) : (
-						<span className="text-green-500 mr-2">新开</span>
-					)}
-					{record?.bonusInfo?.fromCreatorPosition ? (
-						record?.isParentPositionClosed ? (
-							<span className="text-red-500">上级已关仓</span>
+			render: (_text: string, record: RecordInfo) => {
+				const isCopy = !!record?.bonusInfo?.fromCreatorPosition
+				const isParentClosed = record?.isParentPositionClosed
+				if (!isCopy) {
+					return (
+						<Tooltip title="新开仓位">
+							<PlusCircleOutlined
+								style={{ fontSize: '20px', color: '#52c41a' }}
+							/>
+						</Tooltip>
+					)
+				}
+				return (
+					<div className="flex items-center gap-2">
+						<Tooltip title="复制仓位">
+							<CopyOutlined style={{ fontSize: '18px', color: '#1890ff' }} />
+						</Tooltip>
+						{isParentClosed ? (
+							<Tooltip title="上级已关仓">
+								<CloseCircleOutlined
+									style={{ fontSize: '18px', color: '#ff4d4f' }}
+								/>
+							</Tooltip>
 						) : (
-							<span className="text-green-500">上级未关仓</span>
-						)
-					) : (
-						''
-					)}
-				</span>
-			),
+							<Tooltip title="上级未关仓">
+								<CheckCircleOutlined
+									style={{ fontSize: '18px', color: '#52c41a' }}
+								/>
+							</Tooltip>
+						)}
+					</div>
+				)
+			},
 		},
 		{
 			title: '操作',