Skip to content

Commit

Permalink
LSPS7: adds months to expiry display
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Jan 13, 2025
1 parent 04f89b6 commit 3d2d2d0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 14 deletions.
3 changes: 3 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,10 @@
"time.minutes": "Minutes",
"time.hours": "Hours",
"time.days": "Days",
"time.day": "Day",
"time.weeks": "Weeks",
"time.months": "Months",
"time.month": "Month",
"time.10min": "10 min",
"time.1H": "1H",
"time.1D": "1D",
Expand Down
15 changes: 11 additions & 4 deletions utils/DateTimeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@ class DateTimeUtils {
return `${time} | ${monthAndDay}${year}`;
};

blocksToDaysRounded = (blocks: number) => {
// 1440 minutes in a day
// 144 blocks in a day w/ 10 min blocks
blocksToMonthsAndDays = (blocks: number) => {
const blocksPerDay = 144;
return Math.round(blocks / blocksPerDay);
const daysPerMonth = 30;

// Calculate total days
const totalDays = Math.round(blocks / blocksPerDay);

// Calculate months and remaining days
const months = Math.floor(totalDays / daysPerMonth);
const days = totalDays % daysPerMonth;

return { months, days };
};
}

Expand Down
56 changes: 46 additions & 10 deletions views/Channels/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ interface ChannelState {
channel: Channel;
renewalInfo: {
expiresInBlocks?: number;
expiresInDays?: number;
expiresMonths?: number;
expiresDays?: number;
maxExtensionInBlocks?: number;
};
}
Expand Down Expand Up @@ -121,9 +122,12 @@ export default class ChannelView extends React.Component<
.toNumber();
}

let expiresInDays;
let expiresMonths, expiresDays;
if (expiresInBlocks) {
expiresInDays = DateTimeUtils.blocksToDaysRounded(expiresInBlocks);
const { months, days } =
DateTimeUtils.blocksToMonthsAndDays(expiresInBlocks);
expiresMonths = months;
expiresDays = days;
}

let maxExtensionInBlocks;
Expand All @@ -140,7 +144,8 @@ export default class ChannelView extends React.Component<
channel,
renewalInfo: {
expiresInBlocks,
expiresInDays,
expiresDays,
expiresMonths,
maxExtensionInBlocks
}
};
Expand Down Expand Up @@ -488,13 +493,44 @@ export default class ChannelView extends React.Component<
}}
>{`${numberWithCommas(
renewalInfo.expiresInBlocks
)} ${localeString('general.blocks')} ${
renewalInfo.expiresInDays
? `(${numberWithCommas(
renewalInfo.expiresInDays
)} ${localeString(
'general.blocks'
)}\n ~${
renewalInfo.expiresMonths
? `${numberWithCommas(
Math.abs(
renewalInfo.expiresMonths
)
)} ${localeString(
'time.days'
).toLowerCase()})`
new BigNumber(
Math.abs(
renewalInfo.expiresMonths
)
).gt(1)
? 'time.months'
: 'time.month'
).toLowerCase()}`
: ''
}${
renewalInfo.expiresMonths &&
renewalInfo.expiresDays
? ', '
: ''
}${
renewalInfo.expiresDays
? `${numberWithCommas(
Math.abs(
renewalInfo.expiresDays
)
)} ${localeString(
new BigNumber(
Math.abs(
renewalInfo.expiresDays
)
).gt(1)
? 'time.days'
: 'time.day'
).toLowerCase()}`
: ''
}`}</Text>
</View>
Expand Down

0 comments on commit 3d2d2d0

Please sign in to comment.