Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
fix(storage): makes periodsSinceLastPayout 0 if not positive (#384)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Uhlíř <adam@uhlir.dev>
  • Loading branch information
itofarina and AuHau authored Nov 13, 2020
1 parent 05533b8 commit c98ea78
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/services/storage/models/agreement.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ export default class Agreement extends Model {
// Date.now = ms
// this.lastPayout.getTime = ms
// this.billingPeriod = seconds ==> * 1000
const periods = new BigNumber(Date.now() - this.lastPayout.getTime()).div(this.billingPeriod.times(1000))
const timePassedMs = Date.now() - this.lastPayout.getTime()

if (timePassedMs < 0) {
// We cannot fully rely on blockchain time, as it can be a little bit ahead of real time
return new BigNumber(0)
}

const periods = new BigNumber(timePassedMs).div(this.billingPeriod.times(1000))
return floor
? bnFloor(periods)
: periods
Expand Down

0 comments on commit c98ea78

Please sign in to comment.