Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 10c3732

Browse files
TimeTilAvailable for force closed channels: Throw error on NaN input and move field down.
1 parent e57143d commit 10c3732

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/helper.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,12 @@ export const generateArc = (x, y, radius, startAngle, endAngle) => {
329329
* @return {string} The amount of time the blocks is equivalent to.
330330
*/
331331
export const getTimeTilAvailable = numBlocks => {
332-
const days = Math.floor(numBlocks / (24 * 6));
333-
const hours = Math.floor((numBlocks % (24 * 6)) / 6);
332+
let num = Number(numBlocks);
333+
if (isNaN(num)) {
334+
throw new Error('Invalid input!');
335+
}
336+
const days = Math.floor(num / (24 * 6));
337+
const hours = Math.floor((num % (24 * 6)) / 6);
334338
const daysString = days === 1 ? 'day' : 'days';
335339
const hoursString = hours === 1 ? 'hour' : 'hours';
336340
return `${days} ${daysString} and ${hours} ${hoursString}`;

src/view/channel-detail.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ const ChannelDetailView = ({ store, nav }) => (
4242
{store.selectedChannel.closingTxId}
4343
</DetailField>
4444
) : null}
45-
{store.selectedChannel.timeTilAvailable ? (
46-
<DetailField name="Time Til Available">
47-
{store.selectedChannel.timeTilAvailable}
48-
</DetailField>
49-
) : null}
5045
<DetailField name="Remote Node Public Key">
5146
{store.selectedChannel.remotePubkey}
5247
</DetailField>
5348
<DetailField name="Status">
5449
{store.selectedChannel.statusLabel}
5550
</DetailField>
51+
{store.selectedChannel.timeTilAvailable ? (
52+
<DetailField name="Time Til Available">
53+
{store.selectedChannel.timeTilAvailable}
54+
</DetailField>
55+
) : null}
5656
<DetailField name="Capacity">
5757
{store.selectedChannel.capacityLabel} {store.unitLabel}
5858
</DetailField>

test/unit/helper.spec.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,12 @@ describe('Helpers Unit Tests', () => {
825825
expect(time, 'to equal', '3 days and 5 hours');
826826
});
827827

828-
it('should show NaN for undefined', () => {
829-
const time = helpers.getTimeTilAvailable(undefined);
830-
expect(time, 'to equal', 'NaN days and NaN hours');
828+
it('should error on undefined', () => {
829+
expect(
830+
helpers.getTimeTilAvailable.bind(undefined),
831+
'to throw',
832+
/Invalid/
833+
);
831834
});
832835

833836
it('should work for 1 day and 1 hour', () => {

0 commit comments

Comments
 (0)