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/logs.js

106 lines
2.5 KiB

import $ from 'jquery'
import omit from 'lodash.omit'
import { connectElements } from '../../lib/redux_helpers.js'
import { createAsyncLoadStore, loadPage } from '../../lib/async_listing_load'
import '../address'
// @ts-ignore
import { utils } from 'web3'
export const initialState = {
6 years ago
addressHash: null,
isSearch: false
}
export function reducer (state, action) {
6 years ago
switch (action.type) {
6 years ago
case 'PAGE_LOAD':
case 'ELEMENTS_LOAD': {
return Object.assign({}, state, omit(action, 'type'))
6 years ago
}
case 'START_SEARCH': {
5 years ago
return Object.assign({}, state, { pagesStack: [], isSearch: true })
6 years ago
}
default:
return state
6 years ago
}
}
const elements = {
'[data-search-field]': {
6 years ago
render ($el, state) {
return $el
6 years ago
}
},
'[data-search-button]': {
6 years ago
render ($el, state) {
return $el
6 years ago
}
},
'[data-cancel-search-button]': {
6 years ago
render ($el, state) {
if (!state.isSearch) {
return $el.hide()
}
return $el.show()
}
},
'[data-search]': {
render ($el, state) {
if (state.emptyResponse && !state.isSearch) {
return $el.hide()
}
6 years ago
return $el.show()
}
6 years ago
}
}
if ($('[data-page="address-logs"]').length) {
let timer
const waitTime = 500
const store = createAsyncLoadStore(reducer, initialState, 'dataset.identifierLog')
6 years ago
const addressHash = $('[data-page="address-details"]')[0].dataset.pageAddressHash
const $element = $('[data-async-listing]')
6 years ago
connectElements({ store, elements })
const searchFunc = (_event) => {
6 years ago
store.dispatch({
type: 'START_SEARCH',
addressHash
5 years ago
})
4 years ago
const topic = $('[data-search-field]').val()
const addressHashPlain = store.getState().addressHash
const addressHashChecksum = addressHashPlain && utils.toChecksumAddress(addressHashPlain)
2 years ago
const path = `/search-logs?topic=${topic}&address_id=${addressHashChecksum}`
loadPage(store, path)
}
store.dispatch({
type: 'PAGE_LOAD',
addressHash
6 years ago
})
$element.on('click', '[data-search-button]', searchFunc)
4 years ago
$element.on('click', '[data-cancel-search-button]', (_event) => {
$('[data-search-field]').val('')
loadPage(store, window.location.pathname)
})
$element.on('input keyup', '[data-search-field]', (event) => {
if (event.type === 'input') {
clearTimeout(timer)
timer = setTimeout(() => {
searchFunc(event)
}, waitTime)
}
if (event.type === 'keyup' && event.keyCode === 13) {
clearTimeout(timer)
searchFunc(event)
}
6 years ago
})
}