Skip to content

Commit

Permalink
rename and simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
shamsartem committed Feb 12, 2025
1 parent dea9043 commit 75fe5e8
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions packages/cli/package/src/commands/provider/deal-exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
} from "../../lib/const.js";
import {
getContracts,
getSignerAddress,
multicallRead,
populateTx,
signBatch,
Expand Down Expand Up @@ -54,7 +53,6 @@ export default class DealExit extends BaseCommand<typeof DealExit> {
async run(): Promise<void> {
const { flags } = await initCli(this, await this.parse(DealExit));
const { contracts } = await getContracts();
const signerAddress = await getSignerAddress();

const dealIds =
// flags.all
Expand All @@ -78,7 +76,7 @@ export default class DealExit extends BaseCommand<typeof DealExit> {
}

// 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 {
Expand All @@ -96,37 +94,28 @@ export default class DealExit extends BaseCommand<typeof DealExit> {
ReturnType<ReturnType<Contracts["getDeal"]>["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);
}),
],
});
Expand Down

0 comments on commit 75fe5e8

Please sign in to comment.