fix: return values for validation function

This commit is contained in:
Sérgio Salgado 2022-01-24 16:30:55 +00:00
parent 9411b2ea69
commit 4b910ff87b

View file

@ -119,17 +119,14 @@ function getBlockchainSyncStatus (cryptoList) {
return settingsLoader.loadLatest() return settingsLoader.loadLatest()
.then(settings => { .then(settings => {
const installedButNotConfigured = []
const blockchainStatuses = _.reduce((acc, value) => { const blockchainStatuses = _.reduce((acc, value) => {
const processStatus = common.es(`sudo supervisorctl status ${value.code} | awk '{ print $2 }'`).trim() const processStatus = common.es(`sudo supervisorctl status ${value.code} | awk '{ print $2 }'`).trim()
return wallet.checkBlockchainStatus(settings, value.cryptoCode) return wallet.checkBlockchainStatus(settings, value.cryptoCode)
.then(res => { .then(res => _.includes(value.cryptoCode, _.keys(installedCryptos) ? ({ ...acc, [value.cryptoCode]: res }) : ({ ...acc })))
console.log('res', res) .catch(() => {
return _.includes(value.cryptoCode, _.keys(installedCryptos) ? ({ ...acc, [value.cryptoCode]: res }) : ({ ...acc }))
})
.catch(err => {
console.log('err', err)
if (processStatus === 'RUNNING') { 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, [value.cryptoCode]: 'syncing' }
} }
return { ...acc } return { ...acc }
@ -139,7 +136,7 @@ function getBlockchainSyncStatus (cryptoList) {
cryptoList cryptoList
) )
return blockchainStatuses return { blockchainStatuses, installedButNotConfigured }
}) })
} }
@ -165,11 +162,20 @@ function run () {
name: 'crypto', 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.', 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, choices,
validate: (a) => { validate: (answers) => {
if (_.size(answers) > 2) return `Please insert a maximum of two coins to install.`
return getBlockchainSyncStatus(cryptos) return getBlockchainSyncStatus(cryptos)
.then(chains => { .then(({ blockchainStatuses, installedButNotConfigured }) => {
const result = _.reduce((acc, value) => ({ ...acc, [value]: _.isNil(acc[value]) ? 1 : acc[value] + 1 }), {}, _.values(chains)) if (!_.isEmpty(installedButNotConfigured)) {
return result.syncing > 0 || _.size(a) > 0 && _.size(a) <= 2 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
}) })
} }
}) })