Skip to content

Commit

Permalink
Merge pull request #28 from golemfactory/beta
Browse files Browse the repository at this point in the history
Beta -> Master
  • Loading branch information
SewerynKras authored Mar 7, 2024
2 parents 5daeae4 + 822c80b commit a609441
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class TaskService {
let networkNode: NetworkNode | undefined;

try {
this.startAcceptingAgreementPayments(agreement);
activity = await this.getOrCreateActivity(agreement);
task.start(activity, networkNode);
this.events.emit("taskStarted", task.getDetails());
Expand Down Expand Up @@ -148,14 +149,19 @@ export class TaskService {
this.activities.delete(activity.agreement.id);
}

private startAcceptingAgreementPayments(agreement: Agreement) {
const agreementAlreadyAccepted = this.activities.has(agreement.id);
if (agreementAlreadyAccepted) return;
this.paymentService.acceptPayments(agreement);
}

private async getOrCreateActivity(agreement: Agreement) {
const previous = this.activities.get(agreement.id);
if (previous) {
return previous;
} else {
const activity = await Activity.create(agreement, this.yagnaApi, this.options);
this.activities.set(agreement.id, activity);
this.paymentService.acceptPayments(agreement);
return activity;
}
}
Expand Down

0 comments on commit a609441

Please sign in to comment.