From 4ca96a9910d8d24ec846b78a0cfc234f80e357ed Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Mon, 13 Aug 2018 22:23:19 +0200 Subject: [PATCH] fix(neutrino): handle numbers and strings --- app/lib/lnd/neutrino.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/lib/lnd/neutrino.js b/app/lib/lnd/neutrino.js index ea96aecf..fb5caced 100644 --- a/app/lib/lnd/neutrino.js +++ b/app/lib/lnd/neutrino.js @@ -196,12 +196,12 @@ class Neutrino extends EventEmitter { if (height) { this.setState(CHAIN_SYNC_IN_PROGRESS) - this.setLndBlockHeight(Number(height)) + this.setLndBlockHeight(height) } if (cfilter) { this.setState(CHAIN_SYNC_IN_PROGRESS) - this.setLndCfilterHeight(Number(cfilter)) + this.setLndCfilterHeight(cfilter) } // Lnd syncing has completed. @@ -248,10 +248,11 @@ class Neutrino extends EventEmitter { * Set the current block height and emit an event to notify others if it has changed. * @param {String|Number} height Block height */ - setCurrentBlockHeight(height: number) { - const changed = Neutrino.incrementIfHigher(this, 'currentBlockHeight', height) + setCurrentBlockHeight(height: number | string) { + const heightAsNumber = Number(height) + const changed = Neutrino.incrementIfHigher(this, 'currentBlockHeight', heightAsNumber) if (changed) { - this.emit(GOT_CURRENT_BLOCK_HEIGHT, height) + this.emit(GOT_CURRENT_BLOCK_HEIGHT, heightAsNumber) } } @@ -259,11 +260,12 @@ class Neutrino extends EventEmitter { * Set the lnd block height and emit an event to notify others if it has changed. * @param {String|Number} height Block height */ - setLndBlockHeight(height: number) { - const changed = Neutrino.incrementIfHigher(this, 'lndBlockHeight', height) + setLndBlockHeight(height: number | string) { + const heightAsNumber = Number(height) + const changed = Neutrino.incrementIfHigher(this, 'lndBlockHeight', heightAsNumber) if (changed) { - this.emit(GOT_LND_BLOCK_HEIGHT, height) - this.setCurrentBlockHeight(height) + this.emit(GOT_LND_BLOCK_HEIGHT, heightAsNumber) + this.setCurrentBlockHeight(heightAsNumber) } } @@ -271,7 +273,7 @@ class Neutrino extends EventEmitter { * Set the lnd cfilter height and emit an event to notify others if it has changed. * @param {String|Number} height Block height */ - setLndCfilterHeight(height: number) { + setLndCfilterHeight(height: number | string) { const heightAsNumber = Number(height) this.lndCfilterHeight = heightAsNumber this.emit(GOT_LND_CFILTER_HEIGHT, heightAsNumber)