Blockchain explorer for Ethereum based network and a tool for inspecting and analyzing EVM based blockchains.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
blockscout/apps/block_scout_web/assets/js/lib/indexing.js

26 lines
975 B

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