refactor: no more array slicing in pollQueries()
This commit is contained in:
parent
d2b78ea93d
commit
af0029581e
1 changed files with 36 additions and 33 deletions
|
|
@ -230,52 +230,55 @@ function plugins (settings, deviceId) {
|
||||||
const localeConfig = configManager.getLocale(deviceId, settings.config)
|
const localeConfig = configManager.getLocale(deviceId, settings.config)
|
||||||
const fiatCode = localeConfig.fiatCurrency
|
const fiatCode = localeConfig.fiatCurrency
|
||||||
const cryptoCodes = localeConfig.cryptoCurrencies
|
const cryptoCodes = localeConfig.cryptoCurrencies
|
||||||
const timezone = millisecondsToMinutes(getTimezoneOffset(localeConfig.timezone))
|
|
||||||
|
|
||||||
const tickerPromises = cryptoCodes.map(c => ticker.getRates(settings, fiatCode, c))
|
const tickerPromises = cryptoCodes.map(c => ticker.getRates(settings, fiatCode, c))
|
||||||
const balancePromises = cryptoCodes.map(c => fiatBalance(fiatCode, c))
|
const balancePromises = cryptoCodes.map(c => fiatBalance(fiatCode, c))
|
||||||
const testnetPromises = cryptoCodes.map(c => wallet.cryptoNetwork(settings, c))
|
const networkPromises = cryptoCodes.map(c => wallet.cryptoNetwork(settings, c))
|
||||||
const pingPromise = recordPing(deviceTime, machineVersion, machineModel)
|
|
||||||
const currentConfigVersionPromise = fetchCurrentConfigVersion()
|
|
||||||
const currentAvailablePromoCodes = loyalty.getNumberOfAvailablePromoCodes()
|
|
||||||
const supportsBatchingPromise = cryptoCodes.map(c => wallet.supportsBatching(settings, c))
|
const supportsBatchingPromise = cryptoCodes.map(c => wallet.supportsBatching(settings, c))
|
||||||
|
|
||||||
const promises = [
|
return Promise.all([
|
||||||
buildAvailableCassettes(),
|
buildAvailableCassettes(),
|
||||||
pingPromise,
|
recordPing(deviceTime, machineVersion, machineModel),
|
||||||
currentConfigVersionPromise,
|
fetchCurrentConfigVersion(),
|
||||||
timezone
|
millisecondsToMinutes(getTimezoneOffset(localeConfig.timezone)),
|
||||||
].concat(
|
loyalty.getNumberOfAvailablePromoCodes(),
|
||||||
supportsBatchingPromise,
|
Promise.all(supportsBatchingPromise),
|
||||||
tickerPromises,
|
Promise.all(tickerPromises),
|
||||||
balancePromises,
|
Promise.all(balancePromises),
|
||||||
testnetPromises,
|
Promise.all(networkPromises)
|
||||||
currentAvailablePromoCodes
|
])
|
||||||
)
|
.then(([
|
||||||
|
cassettes,
|
||||||
|
_pingRes,
|
||||||
|
configVersion,
|
||||||
|
timezone,
|
||||||
|
numberOfAvailablePromoCodes,
|
||||||
|
batchableCoins,
|
||||||
|
tickers,
|
||||||
|
balances,
|
||||||
|
networks
|
||||||
|
]) => {
|
||||||
|
const coinsWithoutRate = _.flow(
|
||||||
|
_.zip(cryptoCodes),
|
||||||
|
_.map(mapCoinSettings)
|
||||||
|
)(networks)
|
||||||
|
|
||||||
return Promise.all(promises)
|
const coins = _.flow(
|
||||||
.then(arr => {
|
_.map(it => ({ batchable: it })),
|
||||||
const cassettes = arr[0]
|
_.zipWith(
|
||||||
const configVersion = arr[2]
|
_.assign,
|
||||||
const tz = arr[3]
|
_.zipWith(_.assign, coinsWithoutRate, tickers)
|
||||||
const cryptoCodesCount = cryptoCodes.length
|
)
|
||||||
const batchableCoinsRes = arr.slice(4, cryptoCodesCount + 4)
|
)(batchableCoins)
|
||||||
const batchableCoins = batchableCoinsRes.map(it => ({ batchable: it }))
|
|
||||||
const tickers = arr.slice(cryptoCodesCount + 4, 2 * cryptoCodesCount + 4)
|
|
||||||
const balances = arr.slice(2 * cryptoCodesCount + 4, 3 * cryptoCodesCount + 4)
|
|
||||||
const testNets = arr.slice(3 * cryptoCodesCount + 4, arr.length - 1)
|
|
||||||
const coinParams = _.zip(cryptoCodes, testNets)
|
|
||||||
const coinsWithoutRate = _.map(mapCoinSettings, coinParams)
|
|
||||||
const areThereAvailablePromoCodes = arr[arr.length - 1] > 0
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cassettes,
|
cassettes,
|
||||||
rates: buildRates(tickers),
|
rates: buildRates(tickers),
|
||||||
balances: buildBalances(balances),
|
balances: buildBalances(balances),
|
||||||
coins: _.zipWith(_.assign, _.zipWith(_.assign, coinsWithoutRate, tickers), batchableCoins),
|
coins,
|
||||||
configVersion,
|
configVersion,
|
||||||
areThereAvailablePromoCodes,
|
areThereAvailablePromoCodes: numberOfAvailablePromoCodes > 0,
|
||||||
timezone: tz
|
timezone
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue