chore: 🔧 format seconds

This commit is contained in:
AP 2020-05-21 07:25:45 +02:00
parent 66a35fed92
commit b23f8c2299
2 changed files with 20 additions and 3 deletions

View file

@ -96,3 +96,20 @@ export const isLightningInvoice = (invoice: string): boolean => {
export const cleanLightningInvoice = invoice => {
return invoice.replace('LIGHTNING:', '').replace('lightning:', '');
};
export const formatSeconds = (seconds: number): string | null => {
if (!seconds || seconds === 0) {
return null;
}
const d = Math.floor(seconds / (3600 * 24));
const h = Math.floor((seconds % (3600 * 24)) / 3600);
const m = Math.floor((seconds % 3600) / 60);
const s = Math.floor(seconds % 60);
const dDisplay = d > 0 ? d + (d == 1 ? ' day, ' : ' days, ') : '';
const hDisplay = h > 0 ? h + (h == 1 ? ' hour, ' : ' hours, ') : '';
const mDisplay = m > 0 ? m + (m == 1 ? ' minute, ' : ' minutes, ') : '';
const sDisplay = s > 0 ? s + (s == 1 ? ' second' : ' seconds') : '';
return dDisplay + hDisplay + mDisplay + sDisplay;
};

View file

@ -2,7 +2,7 @@ import React, { useState } from 'react';
import ReactTooltip from 'react-tooltip';
import styled from 'styled-components';
import { ArrowDown, ArrowUp, EyeOff } from 'react-feather';
import { getPercent } from '../../../utils/helpers';
import { getPercent, formatSeconds } from '../../../utils/helpers';
import {
Progress,
ProgressBar,
@ -143,8 +143,8 @@ export const ChannelCard = ({
{renderLine('Is Static Remote Key:', is_static_remote_key)}
{renderLine('Local Reserve:', localReserve)}
{renderLine('Remote Reserve:', remoteReserve)}
{renderLine('Time Offline:', time_offline)}
{renderLine('Time Online:', time_online)}
{renderLine('Time Offline:', formatSeconds(time_offline))}
{renderLine('Time Online:', formatSeconds(time_online))}
{renderLine('Transaction Vout:', transaction_vout)}
{renderLine('Unsettled Balance:', unsettled_balance)}
<Sub4Title>Partner Node Info</Sub4Title>