diff --git a/lib/blockchain/install.js b/lib/blockchain/install.js index f7a21cb0..4ba0f059 100644 --- a/lib/blockchain/install.js +++ b/lib/blockchain/install.js @@ -125,6 +125,7 @@ function getBlockchainSyncStatus (cryptoList) { return wallet.checkBlockchainStatus(settings, value.cryptoCode) .then(res => _.includes(value.cryptoCode, _.keys(installedCryptos) ? ({ ...acc, [value.cryptoCode]: res }) : ({ ...acc }))) .catch(() => { + console.log('processStatus', processStatus) if (processStatus === 'RUNNING') { installedButNotConfigured.push(value.cryptoCode) return { ...acc, [value.cryptoCode]: 'syncing' } @@ -157,29 +158,37 @@ function run () { 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({ type: 'checkbox', 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: (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 - }) - } + choices }) 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) + }) }