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

Commit e57143d

Browse files
Refactor force close Time Til Available and add add'l tests.
1 parent a187372 commit e57143d

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

src/action/channel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* call the corresponding GRPC apis for channel management.
44
*/
55

6-
import { toSatoshis, poll, formatTimeTilMaturity } from '../helper';
6+
import { toSatoshis, poll, getTimeTilAvailable } from '../helper';
77
import * as log from './log';
88

99
class ChannelAction {
@@ -160,7 +160,7 @@ class ChannelAction {
160160
limboBalance: pfcc.limboBalance,
161161
maturityHeight: pfcc.maturityHeight,
162162
blocksTilMaturity: pfcc.blocksTilMaturity,
163-
timeTilAvailable: formatTimeTilMaturity(pfcc.blocksTilMaturity),
163+
timeTilAvailable: getTimeTilAvailable(pfcc.blocksTilMaturity),
164164
status: 'pending-force-closing',
165165
}));
166166
const wccs = response.waitingCloseChannels.map(wcc => ({

src/helper.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,10 @@ export const generateArc = (x, y, radius, startAngle, endAngle) => {
328328
* @param {number} numBlocks The number of blocks to convert.
329329
* @return {string} The amount of time the blocks is equivalent to.
330330
*/
331-
export const formatTimeTilMaturity = numBlocks => {
331+
export const getTimeTilAvailable = numBlocks => {
332332
const days = Math.floor(numBlocks / (24 * 6));
333333
const hours = Math.floor((numBlocks % (24 * 6)) / 6);
334-
return `${days} days and ${hours} hours`;
334+
const daysString = days === 1 ? 'day' : 'days';
335+
const hoursString = hours === 1 ? 'hour' : 'hours';
336+
return `${days} ${daysString} and ${hours} ${hoursString}`;
335337
};

src/view/channel-detail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const ChannelDetailView = ({ store, nav }) => (
4242
{store.selectedChannel.closingTxId}
4343
</DetailField>
4444
) : null}
45-
{store.selectedChannel.blocksTilMaturity ? (
45+
{store.selectedChannel.timeTilAvailable ? (
4646
<DetailField name="Time Til Available">
4747
{store.selectedChannel.timeTilAvailable}
4848
</DetailField>

test/unit/helper.spec.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,11 +818,28 @@ describe('Helpers Unit Tests', () => {
818818
});
819819
});
820820

821-
describe('formatTimeTilMaturity()', () => {
821+
describe('getTimeTilAvailable()', () => {
822822
it('should format blocks to human-readable time', () => {
823823
const numBlocks = 463;
824-
const time = helpers.formatTimeTilMaturity(numBlocks);
824+
const time = helpers.getTimeTilAvailable(numBlocks);
825825
expect(time, 'to equal', '3 days and 5 hours');
826826
});
827+
828+
it('should show NaN for undefined', () => {
829+
const time = helpers.getTimeTilAvailable(undefined);
830+
expect(time, 'to equal', 'NaN days and NaN hours');
831+
});
832+
833+
it('should work for 1 day and 1 hour', () => {
834+
const numBlocks = 150;
835+
const time = helpers.getTimeTilAvailable(numBlocks);
836+
expect(time, 'to equal', '1 day and 1 hour');
837+
});
838+
839+
it('should work for 0', () => {
840+
const numBlocks = 0;
841+
const time = helpers.getTimeTilAvailable(numBlocks);
842+
expect(time, 'to equal', '0 days and 0 hours');
843+
});
827844
});
828845
});

0 commit comments

Comments
 (0)