|
|
@@ -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,
|