Skip to content

Commit

Permalink
add time count down for links ( campaigns publication ) (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
hichri-louay authored Sep 26, 2023
1 parent 9d88757 commit a30b195
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -636,13 +636,13 @@
</span>
<span
class="btn-apply-text text-orange"
*ngIf="harvestAvailable === true"
*ngIf="harvestAvailable === true "
>
<img class="" src="/assets/Images/campagne/hourglass.svg" style="margin-top:-4px;" />
<span> {{ 'wait_harvest' | translate }}</span>


<span> {{ harvestAvailableIn }} </span>
<span> {{ this.prom.campaign.remuneration === 'publication' ? countHarvestDownTimerForPublication(): harvestAvailableIn }} </span>
</span>
</button>
<!-- link indisponible-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ export class FarmPostCardComponent implements OnInit {
[atLastOneChecked(), requiredDescription()]
);
}
countHarvestDownTimerForPublication() {
// Provided end date in UNIX timestamp format (e.g., 1698192000)
const endDateTimestamp = this.prom.campaign.endDate * 1000; // Convert to milliseconds

// Current date
const currentDate = Date.now();

// Calculate the time difference in milliseconds
const timeDifference = endDateTimestamp - currentDate;

// Calculate days, hours, and minutes
const days = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeDifference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeDifference % (1000 * 60 * 60)) / (1000 * 60));
if(days === 0 && hours === 0 && minutes === 0) {
this.harvestAvailable = false;
} else this.harvestAvailable = true;
return `${days}d ${hours}h ${minutes}min`;
}
private countDownTimer(): void {
const timestampAcceptedDate: number = this.prom.acceptedDate * 1000;

Expand Down Expand Up @@ -142,11 +161,12 @@ export class FarmPostCardComponent implements OnInit {
)
.subscribe((prom: any) => {
this.prom = new Participation(prom);

this.countHarvestDownTimerForPublication();
});
let currencyName = this.prom.campaign.currency;
this.intervalId = setInterval(() => {
this.countDownTimer();

}, 1000);
if (currencyName === 'SATTBEP20') currencyName = 'SATT';

Expand Down

0 comments on commit a30b195

Please sign in to comment.