|
@@ -659,6 +659,42 @@ function MyLPPageContent() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ async function handleClosePositionOutOfRange() {
|
|
|
|
|
+ // 只关闭 xxx/USDC 或者 xxx/USDT 的仓位, 因为 这些仓位的isInRange是正确的, 其他仓位的isInRange是错误的
|
|
|
|
|
+ const outOfRangePositions = lpList.filter((item) => {
|
|
|
|
|
+ const poolInfo = getPoolInfo(item.poolAddress)
|
|
|
|
|
+ return (poolInfo.lpToken.toLowerCase().endsWith('usdc') || poolInfo.lpToken.toLowerCase().endsWith('usdt')) && !item.isInRange
|
|
|
|
|
+ })
|
|
|
|
|
+ if (outOfRangePositions.length === 0) {
|
|
|
|
|
+ message.info('没有需要关闭的仓位')
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ message.loading({
|
|
|
|
|
+ key: 'closePositionOutOfRange',
|
|
|
|
|
+ content: `正在关闭出区间仓位...${outOfRangePositions.length}个仓位`,
|
|
|
|
|
+ duration: 0,
|
|
|
|
|
+ })
|
|
|
|
|
+ try {
|
|
|
|
|
+ for (let i = 0; i < outOfRangePositions.length; i++) {
|
|
|
|
|
+ const position = outOfRangePositions[i]
|
|
|
|
|
+ await handleClosePosition(position, true)
|
|
|
|
|
+ message.loading({
|
|
|
|
|
+ key: 'closePositionOutOfRange',
|
|
|
|
|
+ content: `正在关闭出区间仓位... (${i + 1}/${outOfRangePositions.length})`,
|
|
|
|
|
+ duration: 0,
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ const newLpList = lpList.filter(
|
|
|
|
|
+ (item) => !outOfRangePositions.some((p) => p.nftMintAddress === item.nftMintAddress)
|
|
|
|
|
+ )
|
|
|
|
|
+ setLpList(newLpList)
|
|
|
|
|
+ message.success(`关闭出区间仓位成功,关闭了 ${outOfRangePositions.length} 个仓位`)
|
|
|
|
|
+ } catch (err: unknown) {
|
|
|
|
|
+ console.error('Error closing positions out of range:', err)
|
|
|
|
|
+ message.error(err instanceof Error ? err.message : '关闭出区间仓位失败')
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
async function handleBatchClosePosition() {
|
|
async function handleBatchClosePosition() {
|
|
|
if (selectedRowKeys.length === 0) {
|
|
if (selectedRowKeys.length === 0) {
|
|
|
message.info('请先选择要关闭的仓位')
|
|
message.info('请先选择要关闭的仓位')
|
|
@@ -768,6 +804,13 @@ function MyLPPageContent() {
|
|
|
>
|
|
>
|
|
|
一键关闭上级已关仓
|
|
一键关闭上级已关仓
|
|
|
</Button>
|
|
</Button>
|
|
|
|
|
+ <Button
|
|
|
|
|
+ type="primary"
|
|
|
|
|
+ onClick={() => handleClosePositionOutOfRange()}
|
|
|
|
|
+ loading={loading}
|
|
|
|
|
+ >
|
|
|
|
|
+ 关闭出区间
|
|
|
|
|
+ </Button>
|
|
|
{selectedRowKeys.length > 0 && (
|
|
{selectedRowKeys.length > 0 && (
|
|
|
<Button
|
|
<Button
|
|
|
type="primary"
|
|
type="primary"
|