fix: workaround inquirer validation not working properly
This commit is contained in:
parent
4b910ff87b
commit
fc5a13fcf3
1 changed files with 27 additions and 18 deletions
|
|
@ -125,6 +125,7 @@ function getBlockchainSyncStatus (cryptoList) {
|
||||||
return wallet.checkBlockchainStatus(settings, value.cryptoCode)
|
return wallet.checkBlockchainStatus(settings, value.cryptoCode)
|
||||||
.then(res => _.includes(value.cryptoCode, _.keys(installedCryptos) ? ({ ...acc, [value.cryptoCode]: res }) : ({ ...acc })))
|
.then(res => _.includes(value.cryptoCode, _.keys(installedCryptos) ? ({ ...acc, [value.cryptoCode]: res }) : ({ ...acc })))
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
console.log('processStatus', processStatus)
|
||||||
if (processStatus === 'RUNNING') {
|
if (processStatus === 'RUNNING') {
|
||||||
installedButNotConfigured.push(value.cryptoCode)
|
installedButNotConfigured.push(value.cryptoCode)
|
||||||
return { ...acc, [value.cryptoCode]: 'syncing' }
|
return { ...acc, [value.cryptoCode]: 'syncing' }
|
||||||
|
|
@ -157,29 +158,37 @@ function run () {
|
||||||
|
|
||||||
const questions = []
|
const questions = []
|
||||||
|
|
||||||
|
const validateAnswers = async (answers) => {
|
||||||
|
if (_.size(answers) > 2) return { message: `Please insert a maximum of two coins to install.`, isValid: false }
|
||||||
|
return getBlockchainSyncStatus(cryptos)
|
||||||
|
.then(({ blockchainStatuses, installedButNotConfigured }) => {
|
||||||
|
if (!_.isEmpty(installedButNotConfigured)) {
|
||||||
|
return { message: `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?`, isValid: false}
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = _.reduce((acc, value) => ({ ...acc, [value]: _.isNil(acc[value]) ? 1 : acc[value] + 1 }), {}, _.values(blockchainStatuses))
|
||||||
|
if (result.syncing > 2) {
|
||||||
|
return { message: `There are currently more than 2 blockchains in their initial synchronization. Please try again later.`, isValid: false }
|
||||||
|
}
|
||||||
|
|
||||||
|
return { message: null, isValid: true }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
questions.push({
|
questions.push({
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
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: (answers) => {
|
|
||||||
if (_.size(answers) > 2) return `Please insert a maximum of two coins to install.`
|
|
||||||
return getBlockchainSyncStatus(cryptos)
|
|
||||||
.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
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
inquirer.prompt(questions)
|
inquirer.prompt(questions)
|
||||||
.then(answers => processCryptos(answers.crypto))
|
.then(answers => Promise.all([validateAnswers(answers), answers]))
|
||||||
|
.then(([res, answers]) => {
|
||||||
|
console.log('res', res)
|
||||||
|
if (res.isValid) {
|
||||||
|
return processCryptos(answers.crypto)
|
||||||
|
}
|
||||||
|
console.log(res.message)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue