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 fiatCode = localeConfig.fiatCurrency
|
||||
const cryptoCodes = localeConfig.cryptoCurrencies
|
||||
const timezone = millisecondsToMinutes(getTimezoneOffset(localeConfig.timezone))
|
||||
|
||||
const tickerPromises = cryptoCodes.map(c => ticker.getRates(settings, fiatCode, c))
|
||||
const balancePromises = cryptoCodes.map(c => fiatBalance(fiatCode, c))
|
||||
const testnetPromises = cryptoCodes.map(c => wallet.cryptoNetwork(settings, c))
|
||||
const pingPromise = recordPing(deviceTime, machineVersion, machineModel)
|
||||
const currentConfigVersionPromise = fetchCurrentConfigVersion()
|
||||
const currentAvailablePromoCodes = loyalty.getNumberOfAvailablePromoCodes()
|
||||
const networkPromises = cryptoCodes.map(c => wallet.cryptoNetwork(settings, c))
|
||||
const supportsBatchingPromise = cryptoCodes.map(c => wallet.supportsBatching(settings, c))
|
||||
|
||||
const promises = [
|
||||
return Promise.all([
|
||||
buildAvailableCassettes(),
|
||||
pingPromise,
|
||||
currentConfigVersionPromise,
|
||||
timezone
|
||||
].concat(
|
||||
supportsBatchingPromise,
|
||||
tickerPromises,
|
||||
balancePromises,
|
||||
testnetPromises,
|
||||
currentAvailablePromoCodes
|
||||
)
|
||||
recordPing(deviceTime, machineVersion, machineModel),
|
||||
fetchCurrentConfigVersion(),
|
||||
millisecondsToMinutes(getTimezoneOffset(localeConfig.timezone)),
|
||||
loyalty.getNumberOfAvailablePromoCodes(),
|
||||
Promise.all(supportsBatchingPromise),
|
||||
Promise.all(tickerPromises),
|
||||
Promise.all(balancePromises),
|
||||
Promise.all(networkPromises)
|
||||
])
|
||||
.then(([
|
||||
cassettes,
|
||||
_pingRes,
|
||||
configVersion,
|
||||
timezone,
|
||||
numberOfAvailablePromoCodes,
|
||||
batchableCoins,
|
||||
tickers,
|
||||
balances,
|
||||
networks
|
||||
]) => {
|
||||
const coinsWithoutRate = _.flow(
|
||||
_.zip(cryptoCodes),
|
||||
_.map(mapCoinSettings)
|
||||
)(networks)
|
||||
|
||||
return Promise.all(promises)
|
||||
.then(arr => {
|
||||
const cassettes = arr[0]
|
||||
const configVersion = arr[2]
|
||||
const tz = arr[3]
|
||||
const cryptoCodesCount = cryptoCodes.length
|
||||
const batchableCoinsRes = arr.slice(4, cryptoCodesCount + 4)
|
||||
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
|
||||
const coins = _.flow(
|
||||
_.map(it => ({ batchable: it })),
|
||||
_.zipWith(
|
||||
_.assign,
|
||||
_.zipWith(_.assign, coinsWithoutRate, tickers)
|
||||
)
|
||||
)(batchableCoins)
|
||||
|
||||
return {
|
||||
cassettes,
|
||||
rates: buildRates(tickers),
|
||||
balances: buildBalances(balances),
|
||||
coins: _.zipWith(_.assign, _.zipWith(_.assign, coinsWithoutRate, tickers), batchableCoins),
|
||||
coins,
|
||||
configVersion,
|
||||
areThereAvailablePromoCodes,
|
||||
timezone: tz
|
||||
areThereAvailablePromoCodes: numberOfAvailablePromoCodes > 0,
|
||||
timezone
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue