From 4b910ff87b17ff41d7641283e0d01871a516dcf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Mon, 24 Jan 2022 16:30:55 +0000 Subject: [PATCH] fix: return values for validation function --- lib/blockchain/install.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/blockchain/install.js b/lib/blockchain/install.js index 02b60fdd..f7a21cb0 100644 --- a/lib/blockchain/install.js +++ b/lib/blockchain/install.js @@ -119,17 +119,14 @@ function getBlockchainSyncStatus (cryptoList) { return settingsLoader.loadLatest() .then(settings => { + const installedButNotConfigured = [] const blockchainStatuses = _.reduce((acc, value) => { const processStatus = common.es(`sudo supervisorctl status ${value.code} | awk '{ print $2 }'`).trim() return wallet.checkBlockchainStatus(settings, value.cryptoCode) - .then(res => { - console.log('res', res) - return _.includes(value.cryptoCode, _.keys(installedCryptos) ? ({ ...acc, [value.cryptoCode]: res }) : ({ ...acc })) - }) - .catch(err => { - console.log('err', err) + .then(res => _.includes(value.cryptoCode, _.keys(installedCryptos) ? ({ ...acc, [value.cryptoCode]: res }) : ({ ...acc }))) + .catch(() => { if (processStatus === 'RUNNING') { - console.log(`Detected ${value.cryptoCode} installed on this machine, but couldn't establish a connection. Is this plugin configured via admin?`) + installedButNotConfigured.push(value.cryptoCode) return { ...acc, [value.cryptoCode]: 'syncing' } } return { ...acc } @@ -139,7 +136,7 @@ function getBlockchainSyncStatus (cryptoList) { cryptoList ) - return blockchainStatuses + return { blockchainStatuses, installedButNotConfigured } }) } @@ -165,11 +162,20 @@ function run () { name: 'crypto', message: 'Which cryptocurrencies would you like to install?\nTo prevent server resource overloading, only TWO coins should be syncing simultaneously.\nMore coins can be installed after this process is over.', choices, - validate: (a) => { + validate: (answers) => { + if (_.size(answers) > 2) return `Please insert a maximum of two coins to install.` return getBlockchainSyncStatus(cryptos) - .then(chains => { - const result = _.reduce((acc, value) => ({ ...acc, [value]: _.isNil(acc[value]) ? 1 : acc[value] + 1 }), {}, _.values(chains)) - return result.syncing > 0 || _.size(a) > 0 && _.size(a) <= 2 + .then(({ blockchainStatuses, installedButNotConfigured }) => { + if (!_.isEmpty(installedButNotConfigured)) { + return `Detected ${_.join(' and ', installedButNotConfigured)} installed on this machine, but couldn't establish connection. ${_.size(installedButNotConfigured) === 1 ? `Is this plugin` : `Are these plugins`} configured via admin?` + } + + const result = _.reduce((acc, value) => ({ ...acc, [value]: _.isNil(acc[value]) ? 1 : acc[value] + 1 }), {}, _.values(blockchainStatuses)) + if (result.syncing > 2) { + return `There are currently more than 2 blockchains in their initial synchronization. Please try again later.` + } + + return true }) } })