feat: blockchain status checking no longer dependent on plugin status

This commit is contained in:
Sérgio Salgado 2022-02-24 20:57:12 +00:00
parent 3c33695b9d
commit f23f31e4d9
4 changed files with 23 additions and 27 deletions

View file

@ -118,32 +118,24 @@ function plugin (crypto) {
}
function getBlockchainSyncStatus (cryptoList) {
const installedCryptos = _.reduce((acc, value) => ({ ...acc, [value.cryptoCode]: isInstalledSoftware(value) && isInstalledVolume(value) }), {}, 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 acc.then(a => {
return wallet.checkBlockchainStatus(settings, value.cryptoCode)
.then(res => _.includes(value.cryptoCode, _.keys(installedCryptos)) ? Promise.resolve({ ...a, [value.cryptoCode]: res }) : Promise.resolve({ ...a }))
.catch(() => {
if (processStatus === 'RUNNING') {
installedButNotConfigured.push(value.cryptoCode)
return Promise.resolve({ ...a, [value.cryptoCode]: 'syncing' })
}
return Promise.resolve({ ...a })
})
if (processStatus === 'RUNNING') {
return wallet.checkBlockchainStatus(settings, value.cryptoCode)
.then(res => Promise.resolve({ ...a, [value.cryptoCode]: res }))
}
return Promise.resolve({ ...a })
})
},
Promise.resolve({}),
cryptoList
)
return Promise.all([blockchainStatuses, installedButNotConfigured])
return blockchainStatuses
})
.then(([blockchainStatuses, installedButNotConfigured]) => ({ blockchainStatuses, installedButNotConfigured }))
}
function run () {
@ -166,11 +158,7 @@ function run () {
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)) {
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?`)
}
.then(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 }