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

64 lines
1.7 KiB

import $ from 'jquery'
import omit from 'lodash/omit'
import humps from 'humps'
import socket from '../../socket'
import { connectElements } from '../../lib/redux_helpers.js'
import { createAsyncLoadStore } from '../../lib/async_listing_load.js'
export const initialState = {
addressHash: null,
channelDisconnected: false
}
export function reducer (state = initialState, action) {
switch (action.type) {
case 'PAGE_LOAD':
case 'ELEMENTS_LOAD': {
return Object.assign({}, state, omit(action, 'type'))
}
case 'CHANNEL_DISCONNECTED': {
return Object.assign({}, state, { channelDisconnected: true })
}
case 'RECEIVED_NEW_BLOCK': {
if (state.channelDisconnected) return state
if (state.beyondPageOne) return state
return Object.assign({}, state, {
items: [
action.blockHtml,
...state.items
]
})
}
default:
return state
}
}
const elements = {
'[data-selector="channel-disconnected-message"]': {
render ($el, state) {
if (state.channelDisconnected) $el.show()
}
}
}
if ($('[data-page="blocks-validated"]').length) {
const store = createAsyncLoadStore(reducer, initialState, 'dataset.blockNumber')
connectElements({ store, elements })
const addressHash = $('[data-page="address-details"]')[0].dataset.pageAddressHash
store.dispatch({
type: 'PAGE_LOAD',
addressHash
})
const blocksChannel = socket.channel(`blocks:${addressHash}`, {})
blocksChannel.join()
blocksChannel.onError(() => store.dispatch({
type: 'CHANNEL_DISCONNECTED'
}))
blocksChannel.on('new_block', (msg) => store.dispatch({
type: 'RECEIVED_NEW_BLOCK',
blockHtml: humps.camelizeKeys(msg).blockHtml
}))
}