@@ -105,9 +105,14 @@ export default function AssetsSection({ pool }: { pool: Pool }) {
105105 }
106106 )
107107
108- let [ liquidityAdminAccount ] = useSuitableAccounts ( { poolId : pool . id , poolRole : [ 'LiquidityAdmin' ] } )
109108 const [ update , setUpdate ] = useState ( false )
110109 const isTinlakePool = pool . id . startsWith ( '0x' )
110+ const [ liquidityAdminAccount ] = useSuitableAccounts ( { poolId : pool . id , poolRole : [ 'LiquidityAdmin' ] } )
111+ const [ account ] = useSuitableAccounts ( {
112+ poolId : pool . id ,
113+ proxyType : [ 'Borrow' , 'Invest' ] ,
114+ poolRole : [ 'LiquidityAdmin' , 'PoolAdmin' ] ,
115+ } )
111116
112117 // Needs to update when selecting a new pool
113118 useEffect ( ( ) => {
@@ -155,6 +160,39 @@ export default function AssetsSection({ pool }: { pool: Pool }) {
155160 return acc
156161 } , { } ) || { }
157162
163+ const { execute : closeEpochTx , isLoading : loadingClose } = useCentrifugeTransaction (
164+ 'Start order execution' ,
165+ ( cent ) => ( args : [ poolId : string , collect : boolean ] , options ) =>
166+ cent . pools . closeEpoch ( [ args [ 0 ] , false ] , { batch : true } ) . pipe (
167+ switchMap ( ( closeTx ) => {
168+ const tx = api . tx . utility . batchAll (
169+ [
170+ ...closeTx . method . args [ 0 ] ,
171+ orders ?. length
172+ ? api . tx . utility . batch (
173+ orders
174+ . slice ( 0 , MAX_COLLECT )
175+ . map ( ( order ) =>
176+ api . tx . investments [ order . type === 'invest' ? 'collectInvestmentsFor' : 'collectRedemptionsFor' ] (
177+ order . accountId ,
178+ [ pool . id , order . trancheId ]
179+ )
180+ )
181+ )
182+ : null ,
183+ ] . filter ( Boolean )
184+ )
185+ return cent . wrapSignAndSend ( api , tx , options )
186+ } )
187+ ) ,
188+ {
189+ onSuccess : ( ) => {
190+ setUpdate ( false )
191+ queryClient . invalidateQueries ( [ 'loans' , pool . id ] )
192+ } ,
193+ }
194+ )
195+
158196 const { execute, isLoading : isUpdating } = useCentrifugeTransaction (
159197 'Update NAV' ,
160198 ( cent ) => ( args : [ values : TransactionLoanData [ ] ] , options ) => {
@@ -305,8 +343,10 @@ export default function AssetsSection({ pool }: { pool: Pool }) {
305343 } ,
306344 {
307345 onSuccess : ( ) => {
308- setUpdate ( false )
309- queryClient . invalidateQueries ( [ 'loans' , pool . id ] )
346+ closeEpochTx ( [ pool . id , ordersFullyExecutable ] , {
347+ account,
348+ forceProxyType : [ 'Borrow' , 'Invest' ] ,
349+ } )
310350 } ,
311351 }
312352 )
@@ -500,7 +540,7 @@ export default function AssetsSection({ pool }: { pool: Pool }) {
500540 < Button
501541 small
502542 style = { { width : '170px' } }
503- disabled = { ! form . dirty || isUpdating }
543+ disabled = { ! form . dirty || isUpdating || loadingClose }
504544 onClick = { ( ) => form . submitForm ( ) }
505545 >
506546 Update NAV
0 commit comments