fix: block ZEC and XMR from being installed simultaneously

fix: improve error message and organize some code
This commit is contained in:
Sérgio Salgado 2022-08-12 16:19:38 +01:00
parent bd1ed64890
commit c7880d07de

View file

@ -138,19 +138,34 @@ function getBlockchainSyncStatus (cryptoList) {
}) })
} }
function isInstalled (crypto) {
if (crypto.cryptoCode === 'XMR') return true
return isInstalledSoftware(crypto) && isInstalledVolume(crypto)
}
function isDisabled (crypto) {
switch (crypto.cryptoCode) {
case 'ETH':
return 'Use admin\'s Infura plugin'
case 'ZEC':
return isInstalled(crypto) && 'Installed' || isInstalled(_.find(it => it.code === 'monero', cryptos)) && 'Insufficient resources. Contact support.'
case 'XMR':
return isInstalled(crypto) && 'Installed' || isInstalled(_.find(it => it.code === 'zcash', cryptos)) && 'Insufficient resources. Contact support.'
default:
return isInstalled(crypto) && 'Installed'
}
}
function run () { function run () {
const choices = _.flow([ const choices = _.flow([
_.filter(c => c.type !== 'erc-20'), _.filter(c => c.type !== 'erc-20'),
_.map(c => { _.map(c => {
const checked = isInstalledSoftware(c) && isInstalledVolume(c)
const name = c.code === 'ethereum' ? 'Ethereum and/or USDT' : c.display const name = c.code === 'ethereum' ? 'Ethereum and/or USDT' : c.display
return { return {
name, name,
value: c.code, value: c.code,
checked, checked: isInstalled(c),
disabled: c.cryptoCode === 'ETH' disabled: isDisabled(c)
? 'Use admin\'s Infura plugin'
: checked && 'Installed'
} }
}), }),
])(cryptos) ])(cryptos)
@ -159,6 +174,15 @@ function run () {
const validateAnswers = async (answers) => { const validateAnswers = async (answers) => {
if (_.size(answers) > 2) return { message: `Please insert a maximum of two coins to install.`, isValid: false } if (_.size(answers) > 2) return { message: `Please insert a maximum of two coins to install.`, isValid: false }
if (
_.isEmpty(_.difference(['monero', 'zcash'], answers)) ||
(_.includes('monero', answers) && isInstalled(_.find(it => it.code === 'zcash', cryptos))) ||
(_.includes('zcash', answers) && isInstalled(_.find(it => it.code === 'monero', cryptos)))
) {
return { message: `Zcash and Monero installations are temporarily mutually exclusive, given the space needed for their blockchains. Contact support for more information.`, isValid: false }
}
return getBlockchainSyncStatus(cryptos) return getBlockchainSyncStatus(cryptos)
.then(blockchainStatuses => { .then(blockchainStatuses => {
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))