From 75fe5e8371e382fdca43854ea5405d17d2be9dfd Mon Sep 17 00:00:00 2001 From: Artsiom Shamsutdzinau Date: Wed, 12 Feb 2025 11:48:56 +0100 Subject: [PATCH] rename and simplify --- .../src/commands/provider/deal-exit.ts | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/packages/cli/package/src/commands/provider/deal-exit.ts b/packages/cli/package/src/commands/provider/deal-exit.ts index ed1ca91bb..1be87546e 100644 --- a/packages/cli/package/src/commands/provider/deal-exit.ts +++ b/packages/cli/package/src/commands/provider/deal-exit.ts @@ -26,7 +26,6 @@ import { } from "../../lib/const.js"; import { getContracts, - getSignerAddress, multicallRead, populateTx, signBatch, @@ -54,7 +53,6 @@ export default class DealExit extends BaseCommand { async run(): Promise { const { flags } = await initCli(this, await this.parse(DealExit)); const { contracts } = await getContracts(); - const signerAddress = await getSignerAddress(); const dealIds = // flags.all @@ -78,7 +76,7 @@ export default class DealExit extends BaseCommand { } // eslint-disable-next-line @typescript-eslint/consistent-type-assertions - const workersFromRPC = (await multicallRead( + const workerIdsFromRPC = (await multicallRead( dealIds.map((id): MulticallReadItem => { const deal = contracts.getDeal(id); return { @@ -96,37 +94,28 @@ export default class DealExit extends BaseCommand { ReturnType["getWorkerIds"]> >[]; - const dealWorkers = dealIds.map((id, i) => { - const deal = contracts.getDeal(id); - const workers = workersFromRPC[i]; - - return { - dealId: id, - workers: (workers ?? []).map((worker) => { - return { worker, deal }; - }), - }; + const dealWorkerIds = dealIds.map((dealId, i) => { + const deal = contracts.getDeal(dealId); + const workerIds = workerIdsFromRPC[i] ?? []; + return { dealId, deal, workerIds }; }); - for (const { dealId, workers } of dealWorkers) { - const [firstWorker, ...restWorkers] = workers; - - if (firstWorker === undefined) { - commandObj.warn( - `No workers found for address ${signerAddress} and deal id: ${dealId}`, - ); + for (const { dealId, deal, workerIds } of dealWorkerIds) { + const [firstWorkerId, ...restWorkerIds] = workerIds; + if (firstWorkerId === undefined) { + commandObj.warn(`No workers found for deal id: ${dealId}`); continue; } await signBatch({ - title: `Remove the following workers from deal ${dealId}:\n\n${workers.join( + title: `Remove the following workers from deal ${dealId}:\n\n${workerIds.join( "\n", )}`, populatedTxs: [ - populateTx(firstWorker.deal.removeWorker, firstWorker.worker), - ...restWorkers.map(({ deal, worker }) => { - return populateTx(deal.removeWorker, worker); + populateTx(deal.removeWorker, firstWorkerId), + ...restWorkerIds.map((workerId) => { + return populateTx(deal.removeWorker, workerId); }), ], });