Skip to content

Commit

Permalink
LNDHub: fix display of expiry time
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Sep 6, 2023
1 parent 3c3b817 commit 2216ddc
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions models/Invoice.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { observable, computed } from 'mobx';
import BigNumber from 'bignumber.js';

import BaseModel from './BaseModel';
import Base64Utils from './../utils/Base64Utils';
Expand Down Expand Up @@ -223,10 +224,16 @@ export default class Invoice extends BaseModel {
}

@computed public get expirationDate(): Date | string {
if (this.expiry || this.expire_time) {
const expiration = this.expiry || this.expire_time;
if (expiration == '0') return localeString('models.Invoice.never');
return `${expiration} ${localeString('models.Invoice.seconds')}`;
const expiry = this.expiry || this.expire_time;

// handle LNDHub
if (expiry && new BigNumber(expiry).gte(1600000000)) {
return DateTimeUtils.listFormattedDate(expiry);
}

if (expiry) {
if (expiry == '0') return localeString('models.Invoice.never');
return `${expiry} ${localeString('models.Invoice.seconds')}`;
}

return this.expires_at
Expand All @@ -235,10 +242,16 @@ export default class Invoice extends BaseModel {
}

@computed public get isExpired(): boolean {
if (this.expiry) {
const expiry = this.expiry || this.expire_time;

if (expiry && new BigNumber(expiry).gte(1600000000)) {
return new Date().getTime() / 1000 > DateTimeUtils.listFormattedDate(expiry);
}

if (expiry) {
return (
new Date().getTime() / 1000 >
Number(this.creation_date) + Number(this.expiry)
Number(this.creation_date) + Number(expiry)
);
}

Expand Down

0 comments on commit 2216ddc

Please sign in to comment.