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()
.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
})
}
})