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/explorer_web/assets/js/pages/address.js

58 lines
2.1 KiB

import $ from 'jquery'
import humps from 'humps'
import socket from '../socket'
import router from '../router'
import { batchChannel } from '../utils'
const BATCH_THRESHOLD = 10
router.when('/addresses/:addressHash').then(({ addressHash, blockNumber, filter }) => {
const channel = socket.channel(`addresses:${addressHash}`, {})
const $channelDisconnected = $('[data-selector="channel-disconnected-message"]')
const $channelBatching = $('[data-selector="channel-batching-message"]')
channel.join()
.receive('ok', resp => { console.log('Joined successfully', `addresses:${addressHash}`, resp) })
.receive('error', resp => { console.log('Unable to join', `addresses:${addressHash}`, resp) })
channel.onError(() => {
$channelDisconnected.show()
$channelBatching.hide()
})
if (!blockNumber) {
const $emptyTransactionsList = $('[data-selector="empty-transactions-list"]')
if ($emptyTransactionsList.length) {
channel.on('transaction', () => {
window.location.reload()
})
}
const $transactionsList = $('[data-selector="transactions-list"]')
const $channelBatchingCount = $('[data-selector="channel-batching-count"]')
let batchCountAccumulator = 0
if ($transactionsList.length) {
channel.on('transaction', batchChannel((msgs) => {
if ($channelDisconnected.is(':visible')) {
return
}
if (msgs.length > BATCH_THRESHOLD || batchCountAccumulator > 0) {
$channelBatching.show()
batchCountAccumulator += msgs.length
$channelBatchingCount[0].innerHTML = batchCountAccumulator
} else {
const transactionsHtml = humps.camelizeKeys(msgs)
.filter(({toAddressHash, fromAddressHash}) => (
!filter ||
(filter === 'to' && toAddressHash === addressHash) ||
(filter === 'from' && fromAddressHash === addressHash)
))
.map(({transactionHtml}) => transactionHtml)
.reverse()
.join('')
$transactionsList.prepend(transactionsHtml)
}
}))
}
}
})