@ -0,0 +1,87 @@ |
|||||||
|
import $ from 'jquery' |
||||||
|
import omit from 'lodash/omit' |
||||||
|
import humps from 'humps' |
||||||
|
import { createStore, connectElements } from '../lib/redux_helpers.js' |
||||||
|
|
||||||
|
export const initialState = { |
||||||
|
channelDisconnected: false, |
||||||
|
transferCount: null, |
||||||
|
tokenHolderCount: null |
||||||
|
} |
||||||
|
|
||||||
|
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': { |
||||||
|
if (state.beyondPageOne) return state |
||||||
|
|
||||||
|
return Object.assign({}, state, { |
||||||
|
channelDisconnected: true |
||||||
|
}) |
||||||
|
} |
||||||
|
case 'COUNTERS_FETCHED': { |
||||||
|
return Object.assign({}, state, { |
||||||
|
transferCount: action.transferCount, |
||||||
|
tokenHolderCount: action.tokenHolderCount |
||||||
|
}) |
||||||
|
} |
||||||
|
default: |
||||||
|
return state |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
const elements = { |
||||||
|
'[data-page="counters"]': { |
||||||
|
render ($el, state) { |
||||||
|
if (state.counters) { |
||||||
|
return $el |
||||||
|
} |
||||||
|
return $el |
||||||
|
} |
||||||
|
}, |
||||||
|
'[token-transfer-count]': { |
||||||
|
render ($el, state) { |
||||||
|
if (state.transferCount) { |
||||||
|
$el.text(state.transferCount + ' Transfers') |
||||||
|
return $el.show() |
||||||
|
} else { |
||||||
|
return $el.hide() |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
'[token-holder-count]': { |
||||||
|
render ($el, state) { |
||||||
|
if (state.tokenHolderCount) { |
||||||
|
$el.text(state.tokenHolderCount + ' Addresses') |
||||||
|
return $el.show() |
||||||
|
} else { |
||||||
|
return $el.hide() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function loadCounters (store) { |
||||||
|
const $element = $('[data-async-counters]') |
||||||
|
const path = $element.data().asyncCounters |
||||||
|
function fetchCounters () { |
||||||
|
store.dispatch({type: 'START_REQUEST'}) |
||||||
|
$.getJSON(path) |
||||||
|
.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() |
||||||
|
} |
||||||
|
|
||||||
|
const $tokenPage = $('[token-page]') |
||||||
|
|
||||||
|
if ($tokenPage.length) { |
||||||
|
const store = createStore(reducer) |
||||||
|
connectElements({ store, elements }) |
||||||
|
loadCounters(store) |
||||||
|
} |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 808 B After Width: | Height: | Size: 532 B |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 9.6 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 562 B |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 305 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 569 B |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 796 B |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 952 B After Width: | Height: | Size: 888 B |
Before Width: | Height: | Size: 186 B After Width: | Height: | Size: 184 B |
Before Width: | Height: | Size: 245 B After Width: | Height: | Size: 243 B |
Before Width: | Height: | Size: 415 B After Width: | Height: | Size: 412 B |
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 2.9 KiB |