@@ -94,47 +94,49 @@ export default class DealExit extends BaseCommand<typeof DealExit> {
9494 } ) ,
9595 ) ) as Awaited < ReturnType < ReturnType < Contracts [ "getDeal" ] > [ "getWorkers" ] > > [ ] ;
9696
97- const workers = dealIds . flatMap ( ( id , i ) => {
97+ const dealWorkers = dealIds . map ( ( id , i ) => {
9898 const deal = contracts . getDeal ( id ) ;
9999 const workers = workersFromRPC [ i ] ;
100100
101- if ( workers === undefined ) {
101+ return {
102+ dealId : id ,
103+ workers : ( workers ?? [ ] )
104+ . filter ( ( worker ) => {
105+ return worker . provider . toLowerCase ( ) === signerAddress ;
106+ } )
107+ . map ( ( worker ) => {
108+ return { worker, deal } ;
109+ } ) ,
110+ } ;
111+ } ) ;
112+
113+ for ( const { dealId, workers } of dealWorkers ) {
114+ const [ firstWorker , ...restWorkers ] = workers ;
115+
116+ if ( firstWorker === undefined ) {
102117 commandObj . warn (
103- `Was not able to get workers for deal ${ id } from chain. Skipping... ` ,
118+ `No workers found for address ${ signerAddress } and deal id: ${ dealId } ` ,
104119 ) ;
105120
106- return [ ] ;
121+ continue ;
107122 }
108123
109- return workers
110- . filter ( ( worker ) => {
111- return worker . provider . toLowerCase ( ) === signerAddress ;
112- } )
113- . map ( ( worker ) => {
114- return { worker, deal } ;
115- } ) ;
116- } ) ;
117-
118- const [ firstWorker , ...restWorkers ] = workers ;
119-
120- if ( firstWorker === undefined ) {
121- return commandObj . error (
122- `No workers found for address ${ signerAddress } and deal ids: ${ dealIds . join ( ", " ) } ` ,
124+ await signBatch (
125+ `Remove the following workers from deal ${ dealId } :\n\n${ workers
126+ . map ( ( { worker : { onchainId } } ) => {
127+ return onchainId ;
128+ } )
129+ . join ( "\n" ) } `,
130+ [
131+ populateTx (
132+ firstWorker . deal . removeWorker ,
133+ firstWorker . worker . onchainId ,
134+ ) ,
135+ ...restWorkers . map ( ( { deal, worker : { onchainId } } ) => {
136+ return populateTx ( deal . removeWorker , onchainId ) ;
137+ } ) ,
138+ ] ,
123139 ) ;
124140 }
125-
126- await signBatch (
127- `Remove the following workers from deals:\n\n${ workers
128- . map ( ( { worker : { onchainId } } ) => {
129- return onchainId ;
130- } )
131- . join ( "\n" ) } `,
132- [
133- populateTx ( firstWorker . deal . removeWorker , firstWorker . worker . onchainId ) ,
134- ...restWorkers . map ( ( { deal, worker : { onchainId } } ) => {
135- return populateTx ( deal . removeWorker , onchainId ) ;
136- } ) ,
137- ] ,
138- ) ;
139141 }
140142}
0 commit comments