Co-authored-by: Stamates <stamates@hotmail.com>
pull/916/head
jimmay5469 6 years ago committed by Stamates
parent 1814f3ee76
commit 88ab1172bc
  1. 4
      apps/block_scout_web/assets/js/lib/currency.js
  2. 16
      apps/block_scout_web/assets/js/lib/indexing.js

@ -34,10 +34,8 @@ function tryUpdateCalculatedUsdValues (el, usdExchangeRate = el.dataset.usdExcha
const formattedUsd = formatUsdValue(usd) const formattedUsd = formatUsdValue(usd)
if (formattedUsd !== el.innerHTML) el.innerHTML = formattedUsd if (formattedUsd !== el.innerHTML) el.innerHTML = formattedUsd
} }
let currentUsdExchangeRate
export function updateAllCalculatedUsdValues (usdExchangeRate) { export function updateAllCalculatedUsdValues (usdExchangeRate) {
currentUsdExchangeRate = usdExchangeRate $('[data-usd-exchange-rate]').each((i, el) => tryUpdateCalculatedUsdValues(el, usdExchangeRate))
$('[data-usd-exchange-rate]').each((i, el) => tryUpdateCalculatedUsdValues(el, currentUsdExchangeRate))
} }
updateAllCalculatedUsdValues() updateAllCalculatedUsdValues()

@ -1,29 +1,25 @@
import $ from 'jquery' import $ from 'jquery'
import _ from 'lodash'
import humps from 'humps' import humps from 'humps'
import numeral from 'numeral' import numeral from 'numeral'
import socket from '../socket' import socket from '../socket'
function tryUpdateIndexedStatus (el, indexedRatio = el.dataset.indexedRatio, indexingFinished = false) { function tryUpdateIndexedStatus (el, indexedRatio = el.dataset.indexedRatio, indexingFinished = false) {
if (indexingFinished) return $("[data-selector='indexed-status']").remove() if (indexingFinished) return $("[data-selector='indexed-status']").remove()
const blocksPercentComplete = numeral(indexedRatio).format('0%')
let indexedText let indexedText
if (parseInt(indexedRatio) === 1.0) { if (blocksPercentComplete === '100%') {
indexedText = window.localized['Indexing Tokens'] indexedText = window.localized['Indexing Tokens']
} else { } else {
indexedText = `${numeral(indexedRatio).format('0%')} ${window.localized['Blocks Indexed']}` indexedText = `${blocksPercentComplete} ${window.localized['Blocks Indexed']}`
} }
if (indexedText !== el.innerHTML) el.innerHTML = indexedText if (indexedText !== el.innerHTML) el.innerHTML = indexedText
} }
let currentIndexedRatio export function updateIndexStatus (msg = {}) {
let indexingFinished $('[data-indexed-ratio]').each((i, el) => tryUpdateIndexedStatus(el, msg.ratio, msg.finished))
export function updateIndexStatus (msg) {
currentIndexedRatio = _.get(msg, 'ratio')
indexingFinished = _.get(msg, 'finished')
$('[data-indexed-ratio]').each((i, el) => tryUpdateIndexedStatus(el, currentIndexedRatio, indexingFinished))
} }
updateIndexStatus() updateIndexStatus()
export const indexingChannel = socket.channel(`blocks:indexing`) const indexingChannel = socket.channel(`blocks:indexing`)
indexingChannel.join() indexingChannel.join()
indexingChannel.on('index_status', (msg) => updateIndexStatus(humps.camelizeKeys(msg))) indexingChannel.on('index_status', (msg) => updateIndexStatus(humps.camelizeKeys(msg)))

Loading…
Cancel
Save