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

Commit a187372

Browse files
Change formatTimeToMaturity to be a helper method.
1 parent 572d329 commit a187372

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/action/channel.js

Lines changed: 2 additions & 8 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 } from '../helper';
6+
import { toSatoshis, poll, formatTimeTilMaturity } 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: this._formatTimeTilMaturity(pfcc.blocksTilMaturity),
163+
timeTilAvailable: formatTimeTilMaturity(pfcc.blocksTilMaturity),
164164
status: 'pending-force-closing',
165165
}));
166166
const wccs = response.waitingCloseChannels.map(wcc => ({
@@ -347,12 +347,6 @@ class ChannelAction {
347347
const channel = pc.find(c => c.channelPoint === channelPoint);
348348
if (channel) pc.splice(pc.indexOf(channel));
349349
}
350-
351-
_formatTimeTilMaturity(numBlocks) {
352-
const days = Math.floor(numBlocks / (24 * 6));
353-
const hours = Math.floor((numBlocks % (24 * 6)) / 6);
354-
return `${days} days and ${hours} hours`;
355-
}
356350
}
357351

358352
export default ChannelAction;

src/helper.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,15 @@ export const generateArc = (x, y, radius, startAngle, endAngle) => {
321321
'Z',
322322
].join(' ');
323323
};
324+
325+
/**
326+
* Convert a number of blocks to an amount of time in the format "X days and Y
327+
* hours" assuming 10 minutes per block.
328+
* @param {number} numBlocks The number of blocks to convert.
329+
* @return {string} The amount of time the blocks is equivalent to.
330+
*/
331+
export const formatTimeTilMaturity = numBlocks => {
332+
const days = Math.floor(numBlocks / (24 * 6));
333+
const hours = Math.floor((numBlocks % (24 * 6)) / 6);
334+
return `${days} days and ${hours} hours`;
335+
};

test/unit/helper.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,4 +817,12 @@ describe('Helpers Unit Tests', () => {
817817
);
818818
});
819819
});
820+
821+
describe('formatTimeTilMaturity()', () => {
822+
it('should format blocks to human-readable time', () => {
823+
const numBlocks = 463;
824+
const time = helpers.formatTimeTilMaturity(numBlocks);
825+
expect(time, 'to equal', '3 days and 5 hours');
826+
});
827+
});
820828
});

0 commit comments

Comments
 (0)