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

85 lines
2.2 KiB

import $ from 'jquery'
import _ from 'lodash'
import URI from 'urijs'
import humps from 'humps'
import { subscribeChannel } from '../../socket'
import { connectElements } from '../../lib/redux_helpers.js'
import { createAsyncLoadStore } from '../../lib/async_listing_load'
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'))
}
case 'START_SEARCH': {
return Object.assign({}, state, {pagesStack: [], isSearch: true})
}
default:
return state
6 years ago
}
}
const elements = {
'[data-search-field]': {
6 years ago
render ($el, state) {
$el
}
},
'[data-search-button]': {
6 years ago
render ($el, state) {
$el
}
},
'[data-cancel-search-button]': {
6 years ago
render ($el, state) {
if (!state.isSearch) {
return $el.hide()
}
6 years ago
return $el.show()
}
6 years ago
}
}
if ($('[data-page="address-logs"]').length) {
6 years ago
const store = createAsyncLoadStore(reducer, initialState, 'dataset.identifierHash')
const addressHash = $('[data-page="address-details"]')[0].dataset.pageAddressHash
const $element = $('[data-async-listing]')
6 years ago
connectElements({ store, elements })
6 years ago
store.dispatch({
type: 'PAGE_LOAD',
addressHash: addressHash})
6 years ago
function loadSearchItems () {
var topic = $('[data-search-field]').val();
var path = "/search_logs?topic=" + topic + "&address_id=" + store.getState().addressHash
store.dispatch({type: 'START_REQUEST'})
$.getJSON(path, {type: 'JSON'})
.done(response => store.dispatch(Object.assign({type: 'ITEMS_FETCHED'}, humps.camelizeKeys(response))))
.fail(() => store.dispatch({type: 'REQUEST_ERROR'}))
.always(() => store.dispatch({type: 'FINISH_REQUEST'}))
}
6 years ago
$element.on('click', '[data-search-button]', (event) => {
store.dispatch({
type: 'START_SEARCH',
addressHash: addressHash})
loadSearchItems()
})
6 years ago
$element.on('click', '[data-cancel-search-button]', (event) => {
console.log('click')
window.location.replace(window.location.href.split('?')[0])
})
}