|
|
@ -11,7 +11,9 @@ const BATCH_THRESHOLD = 10 |
|
|
|
|
|
|
|
|
|
|
|
export const initialState = { |
|
|
|
export const initialState = { |
|
|
|
batchCountAccumulator: 0, |
|
|
|
batchCountAccumulator: 0, |
|
|
|
|
|
|
|
beyondPageOne: null, |
|
|
|
blockNumber: null, |
|
|
|
blockNumber: null, |
|
|
|
|
|
|
|
channelDisconnected: false, |
|
|
|
confirmations: null, |
|
|
|
confirmations: null, |
|
|
|
newTransactions: [] |
|
|
|
newTransactions: [] |
|
|
|
} |
|
|
|
} |
|
|
@ -20,9 +22,18 @@ export function reducer (state = initialState, action) { |
|
|
|
switch (action.type) { |
|
|
|
switch (action.type) { |
|
|
|
case 'PAGE_LOAD': { |
|
|
|
case 'PAGE_LOAD': { |
|
|
|
return Object.assign({}, state, { |
|
|
|
return Object.assign({}, state, { |
|
|
|
|
|
|
|
beyondPageOne: !!action.index, |
|
|
|
blockNumber: parseInt(action.blockNumber, 10) |
|
|
|
blockNumber: parseInt(action.blockNumber, 10) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
case 'CHANNEL_DISCONNECTED': { |
|
|
|
|
|
|
|
if (state.beyondPageOne) return state |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Object.assign({}, state, { |
|
|
|
|
|
|
|
channelDisconnected: true, |
|
|
|
|
|
|
|
batchCountAccumulator: 0 |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
case 'RECEIVED_NEW_BLOCK': { |
|
|
|
case 'RECEIVED_NEW_BLOCK': { |
|
|
|
if ((action.msg.blockNumber - state.blockNumber) > state.confirmations) { |
|
|
|
if ((action.msg.blockNumber - state.blockNumber) > state.confirmations) { |
|
|
|
return Object.assign({}, state, { |
|
|
|
return Object.assign({}, state, { |
|
|
@ -31,7 +42,8 @@ export function reducer (state = initialState, action) { |
|
|
|
} else return state |
|
|
|
} else return state |
|
|
|
} |
|
|
|
} |
|
|
|
case 'RECEIVED_NEW_TRANSACTION_BATCH': { |
|
|
|
case 'RECEIVED_NEW_TRANSACTION_BATCH': { |
|
|
|
debugger |
|
|
|
if (state.channelDisconnected || state.beyondPageOne) return state |
|
|
|
|
|
|
|
|
|
|
|
if (!state.batchCountAccumulator && action.msgs.length < BATCH_THRESHOLD) { |
|
|
|
if (!state.batchCountAccumulator && action.msgs.length < BATCH_THRESHOLD) { |
|
|
|
return Object.assign({}, state, { |
|
|
|
return Object.assign({}, state, { |
|
|
|
newTransactions: [ |
|
|
|
newTransactions: [ |
|
|
@ -68,10 +80,14 @@ router.when('/transactions/:transactionHash').then(({ locale }) => initRedux(red |
|
|
|
} |
|
|
|
} |
|
|
|
})) |
|
|
|
})) |
|
|
|
|
|
|
|
|
|
|
|
router.when('/transactions', { exactPathMatch: true }).then(({ locale }) => initRedux(reducer, { |
|
|
|
router.when('/transactions', { exactPathMatch: true }).then((params) => initRedux(reducer, { |
|
|
|
main (store) { |
|
|
|
main (store) { |
|
|
|
|
|
|
|
const { locale, index } = params |
|
|
|
const transactionsChannel = socket.channel(`transactions:new_transaction`) |
|
|
|
const transactionsChannel = socket.channel(`transactions:new_transaction`) |
|
|
|
|
|
|
|
numeral.locale(locale) |
|
|
|
|
|
|
|
store.dispatch({ type: 'PAGE_LOAD', index }) |
|
|
|
transactionsChannel.join() |
|
|
|
transactionsChannel.join() |
|
|
|
|
|
|
|
transactionsChannel.onError(() => store.dispatch({ type: 'CHANNEL_DISCONNECTED' })) |
|
|
|
transactionsChannel.on('new_transaction', batchChannel((msgs) => |
|
|
|
transactionsChannel.on('new_transaction', batchChannel((msgs) => |
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_TRANSACTION_BATCH', msgs: humps.camelizeKeys(msgs) })) |
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_TRANSACTION_BATCH', msgs: humps.camelizeKeys(msgs) })) |
|
|
|
) |
|
|
|
) |
|
|
@ -79,8 +95,10 @@ router.when('/transactions', { exactPathMatch: true }).then(({ locale }) => init |
|
|
|
render (state, oldState) { |
|
|
|
render (state, oldState) { |
|
|
|
const $channelBatching = $('[data-selector="channel-batching-message"]') |
|
|
|
const $channelBatching = $('[data-selector="channel-batching-message"]') |
|
|
|
const $channelBatchingCount = $('[data-selector="channel-batching-count"]') |
|
|
|
const $channelBatchingCount = $('[data-selector="channel-batching-count"]') |
|
|
|
|
|
|
|
const $channelDisconnected = $('[data-selector="channel-disconnected-message"]') |
|
|
|
const $transactionsList = $('[data-selector="transactions-list"]') |
|
|
|
const $transactionsList = $('[data-selector="transactions-list"]') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (state.channelDisconnected) $channelDisconnected.show() |
|
|
|
if (state.batchCountAccumulator) { |
|
|
|
if (state.batchCountAccumulator) { |
|
|
|
$channelBatching.show() |
|
|
|
$channelBatching.show() |
|
|
|
$channelBatchingCount[0].innerHTML = numeral(state.batchCountAccumulator).format() |
|
|
|
$channelBatchingCount[0].innerHTML = numeral(state.batchCountAccumulator).format() |
|
|
|