fix: promise resolving in reducer function
This commit is contained in:
parent
fc5a13fcf3
commit
92efea080e
1 changed files with 21 additions and 16 deletions
|
|
@ -122,23 +122,25 @@ function getBlockchainSyncStatus (cryptoList) {
|
||||||
const installedButNotConfigured = []
|
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 acc.then(a => {
|
||||||
.then(res => _.includes(value.cryptoCode, _.keys(installedCryptos) ? ({ ...acc, [value.cryptoCode]: res }) : ({ ...acc })))
|
return wallet.checkBlockchainStatus(settings, value.cryptoCode)
|
||||||
.catch(() => {
|
.then(res => _.includes(value.cryptoCode, _.keys(installedCryptos)) ? Promise.resolve({ ...a, [value.cryptoCode]: res }) : Promise.resolve({ ...a }))
|
||||||
console.log('processStatus', processStatus)
|
.catch(() => {
|
||||||
if (processStatus === 'RUNNING') {
|
if (processStatus === 'RUNNING') {
|
||||||
installedButNotConfigured.push(value.cryptoCode)
|
installedButNotConfigured.push(value.cryptoCode)
|
||||||
return { ...acc, [value.cryptoCode]: 'syncing' }
|
return Promise.resolve({ ...a, [value.cryptoCode]: 'syncing' })
|
||||||
}
|
}
|
||||||
return { ...acc }
|
return Promise.resolve({ ...a })
|
||||||
})
|
})
|
||||||
|
})
|
||||||
},
|
},
|
||||||
{},
|
Promise.resolve({}),
|
||||||
cryptoList
|
cryptoList
|
||||||
)
|
)
|
||||||
|
|
||||||
return { blockchainStatuses, installedButNotConfigured }
|
return Promise.all([blockchainStatuses, installedButNotConfigured])
|
||||||
})
|
})
|
||||||
|
.then(([blockchainStatuses, installedButNotConfigured]) => ({ blockchainStatuses, installedButNotConfigured }))
|
||||||
}
|
}
|
||||||
|
|
||||||
function run () {
|
function run () {
|
||||||
|
|
@ -163,10 +165,14 @@ function run () {
|
||||||
return getBlockchainSyncStatus(cryptos)
|
return getBlockchainSyncStatus(cryptos)
|
||||||
.then(({ blockchainStatuses, installedButNotConfigured }) => {
|
.then(({ blockchainStatuses, installedButNotConfigured }) => {
|
||||||
if (!_.isEmpty(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}
|
logger.warn(`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))
|
const result = _.reduce((acc, value) => ({ ...acc, [value]: _.isNil(acc[value]) ? 1 : acc[value] + 1 }), {}, _.values(blockchainStatuses))
|
||||||
|
if (_.size(answers) + result.syncing > 2) {
|
||||||
|
return { message: `Installing these coins would pass the 2 parallel blockchain synchronization limit. Please try again with fewer coins or try again later.`, isValid: false }
|
||||||
|
}
|
||||||
|
|
||||||
if (result.syncing > 2) {
|
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: `There are currently more than 2 blockchains in their initial synchronization. Please try again later.`, isValid: false }
|
||||||
}
|
}
|
||||||
|
|
@ -183,12 +189,11 @@ function run () {
|
||||||
})
|
})
|
||||||
|
|
||||||
inquirer.prompt(questions)
|
inquirer.prompt(questions)
|
||||||
.then(answers => Promise.all([validateAnswers(answers), answers]))
|
.then(answers => Promise.all([validateAnswers(answers.crypto), answers]))
|
||||||
.then(([res, answers]) => {
|
.then(([res, answers]) => {
|
||||||
console.log('res', res)
|
|
||||||
if (res.isValid) {
|
if (res.isValid) {
|
||||||
return processCryptos(answers.crypto)
|
return processCryptos(answers.crypto)
|
||||||
}
|
}
|
||||||
console.log(res.message)
|
logger.error(res.message)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue