From 626f37374f6c5860c4c8cfe9c22e6a1ca8ad476a Mon Sep 17 00:00:00 2001 From: Sophia Date: Fri, 13 Sep 2024 13:29:20 -0400 Subject: [PATCH] Fix collecting orders on epoch closure (#2451) --- .../src/components/LiquidityEpochSection.tsx | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/centrifuge-app/src/components/LiquidityEpochSection.tsx b/centrifuge-app/src/components/LiquidityEpochSection.tsx index 29f8b03744..eb0cd05875 100644 --- a/centrifuge-app/src/components/LiquidityEpochSection.tsx +++ b/centrifuge-app/src/components/LiquidityEpochSection.tsx @@ -78,30 +78,29 @@ function EpochStatusOngoing({ pool }: { pool: Pool }) { const { execute: closeEpochTx, isLoading: loadingClose } = useCentrifugeTransaction( 'Start order execution', - (cent) => (args: [poolId: string, batchSolution: boolean, collect: boolean], options) => - !args[2] - ? cent.pools.closeEpoch([args[0], args[1]], options) - : cent.pools.closeEpoch([args[0], args[1]], { batch: true }).pipe( - switchMap((closeTx) => { - const tx = api.tx.utility.batchAll( - [ - ...closeTx.method.args[0], - orders?.length - ? api.tx.utility.batch( - orders - .slice(0, MAX_COLLECT) - .map((order) => - api.tx.investments[ - order.type === 'invest' ? 'collectInvestmentsFor' : 'collectRedemptionsFor' - ](order.accountId, [pool.id, order.trancheId]) - ) + (cent) => (args: [poolId: string, collect: boolean], options) => + cent.pools.closeEpoch([args[0], false], { batch: true }).pipe( + switchMap((closeTx) => { + const tx = api.tx.utility.batchAll( + [ + ...closeTx.method.args[0], + orders?.length + ? api.tx.utility.batch( + orders + .slice(0, MAX_COLLECT) + .map((order) => + api.tx.investments[order.type === 'invest' ? 'collectInvestmentsFor' : 'collectRedemptionsFor']( + order.accountId, + [pool.id, order.trancheId] + ) ) - : null, - ].filter(Boolean) - ) - return cent.wrapSignAndSend(api, tx, options) - }) - ), + ) + : null, + ].filter(Boolean) + ) + return cent.wrapSignAndSend(api, tx, options) + }) + ), { onSuccess: () => { console.log('Started order execution successfully') @@ -112,7 +111,7 @@ function EpochStatusOngoing({ pool }: { pool: Pool }) { const closeEpoch = async () => { if (!pool) return // const batchCloseAndSolution = ordersLocked && !ordersFullyExecutable // also collect the first MAX_COLLECT open orders when orders are fully executable - closeEpochTx([pool.id, false, ordersFullyExecutable], { + closeEpochTx([pool.id, ordersFullyExecutable], { account, forceProxyType: ['Borrow', 'Invest'], })