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

98 lines
2.3 KiB

5 years ago
import $ from 'jquery'
import omit from 'lodash.omit'
5 years ago
import humps from 'humps'
import { createStore, connectElements } from '../lib/redux_helpers.js'
import { createAsyncLoadStore } from '../lib/async_listing_load'
import '../app'
import {
openQrModal
} from '../lib/modals'
export const initialState = {
5 years ago
channelDisconnected: false,
transferCount: null,
tokenHolderCount: null
}
5 years ago
export function reducer (state = initialState, action) {
switch (action.type) {
5 years ago
case 'PAGE_LOAD':
case 'ELEMENTS_LOAD': {
return Object.assign({}, state, omit(action, 'type'))
}
5 years ago
case 'COUNTERS_FETCHED': {
return Object.assign({}, state, {
5 years ago
transferCount: action.transferCount,
tokenHolderCount: action.tokenHolderCount
})
}
default:
5 years ago
return state
}
}
const elements = {
'[data-page="counters"]': {
5 years ago
render ($el, state) {
if (state.counters) {
5 years ago
return $el
}
5 years ago
return $el
}
},
'[token-transfer-count]': {
5 years ago
render ($el, state) {
if (state.transferCount) {
$el.empty().text(state.transferCount + ' Transfers')
5 years ago
return $el.show()
}
}
},
5 years ago
'[token-holder-count]': {
render ($el, state) {
if (state.tokenHolderCount) {
$el.empty().text(state.tokenHolderCount + ' Addresses')
5 years ago
return $el.show()
}
}
5 years ago
}
}
5 years ago
function loadCounters (store) {
const $element = $('[data-async-counters]')
const path = $element.data() && $element.data().asyncCounters
5 years ago
function fetchCounters () {
5 years ago
store.dispatch({ type: 'START_REQUEST' })
$.getJSON(path)
5 years ago
.done(response => store.dispatch(Object.assign({ type: 'COUNTERS_FETCHED' }, humps.camelizeKeys(response))))
.fail(() => store.dispatch({ type: 'REQUEST_ERROR' }))
.always(() => store.dispatch({ type: 'FINISH_REQUEST' }))
}
fetchCounters()
}
5 years ago
const $tokenPage = $('[token-page]')
if ($tokenPage.length) {
updateCounters()
}
function updateCounters () {
5 years ago
const store = createStore(reducer)
connectElements({ store, elements })
loadCounters(store)
}
if ($('[data-page="token-holders-list"]').length) {
window.onbeforeunload = () => {
window.loading = true
}
createAsyncLoadStore(reducer, initialState, null)
}
$('.btn-qr-icon').click(_event => {
openQrModal()
})