|
|
|
@ -1,5 +1,7 @@ |
|
|
|
|
import $ from 'jquery' |
|
|
|
|
import humps from 'humps' |
|
|
|
|
import numeral from 'numeral' |
|
|
|
|
import 'numeral/locales' |
|
|
|
|
import router from '../router' |
|
|
|
|
import socket from '../socket' |
|
|
|
|
import { updateAllAges } from '../lib/from_now' |
|
|
|
@ -26,7 +28,7 @@ export function reducer (state = initialState, action) { |
|
|
|
|
return Object.assign({}, state, { |
|
|
|
|
newTransactions: [ |
|
|
|
|
...state.newTransactions, |
|
|
|
|
...humps.camelizeKeys(action.msgs).map(({homepageTransactionHtml}) => homepageTransactionHtml) |
|
|
|
|
...action.msgs.map(({homepageTransactionHtml}) => homepageTransactionHtml) |
|
|
|
|
] |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
@ -40,20 +42,23 @@ export function reducer (state = initialState, action) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
router.when('', { exactPathMatch: true }).then(() => initRedux(reducer, { |
|
|
|
|
router.when('', { exactPathMatch: true }).then(({ locale }) => initRedux(reducer, { |
|
|
|
|
main (store) { |
|
|
|
|
const blocksChannel = socket.channel(`blocks:new_block`) |
|
|
|
|
numeral.locale(locale) |
|
|
|
|
blocksChannel.join() |
|
|
|
|
blocksChannel.on('new_block', msg => store.dispatch({ type: 'RECEIVED_NEW_BLOCK', msg })) |
|
|
|
|
|
|
|
|
|
const transactionsChannel = socket.channel(`transactions:new_transaction`) |
|
|
|
|
transactionsChannel.join() |
|
|
|
|
transactionsChannel.on('new_transaction', batchChannel((msgs) => |
|
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_TRANSACTION_BATCH', msgs })) |
|
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_TRANSACTION_BATCH', msgs: humps.camelizeKeys(msgs) })) |
|
|
|
|
) |
|
|
|
|
}, |
|
|
|
|
render (state, oldState) { |
|
|
|
|
const $blockList = $('[data-selector="chain-block-list"]') |
|
|
|
|
const $channelBatching = $('[data-selector="channel-batching-message"]') |
|
|
|
|
const $channelBatchingCount = $('[data-selector="channel-batching-count"]') |
|
|
|
|
const $transactionsList = $('[data-selector="transactions-list"]') |
|
|
|
|
|
|
|
|
|
if (oldState.newBlock !== state.newBlock) { |
|
|
|
@ -61,6 +66,12 @@ router.when('', { exactPathMatch: true }).then(() => initRedux(reducer, { |
|
|
|
|
$blockList.prepend(state.newBlock) |
|
|
|
|
updateAllAges() |
|
|
|
|
} |
|
|
|
|
if (state.batchCountAccumulator) { |
|
|
|
|
$channelBatching.show() |
|
|
|
|
$channelBatchingCount[0].innerHTML = numeral(state.batchCountAccumulator).format() |
|
|
|
|
} else { |
|
|
|
|
$channelBatching.hide() |
|
|
|
|
} |
|
|
|
|
if (oldState.newTransactions !== state.newTransactions) { |
|
|
|
|
const newTransactionsToInsert = state.newTransactions.slice(oldState.newTransactions.length) |
|
|
|
|
$transactionsList |
|
|
|
|