|
|
@ -14,6 +14,7 @@ export const initialState = { |
|
|
|
beyondPageOne: null, |
|
|
|
beyondPageOne: null, |
|
|
|
channelDisconnected: false, |
|
|
|
channelDisconnected: false, |
|
|
|
filter: null, |
|
|
|
filter: null, |
|
|
|
|
|
|
|
newInternalTransactions: [], |
|
|
|
newTransactions: [], |
|
|
|
newTransactions: [], |
|
|
|
balance: null, |
|
|
|
balance: null, |
|
|
|
transactionCount: null |
|
|
|
transactionCount: null |
|
|
@ -42,6 +43,29 @@ export function reducer (state = initialState, action) { |
|
|
|
balance: action.msg.balance |
|
|
|
balance: action.msg.balance |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
case 'RECEIVED_NEW_INTERNAL_TRANSACTION_BATCH': { |
|
|
|
|
|
|
|
if (state.channelDisconnected || state.beyondPageOne) return state |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const incomingInternalTransactions = humps.camelizeKeys(action.msgs) |
|
|
|
|
|
|
|
.filter(({toAddressHash, fromAddressHash}) => ( |
|
|
|
|
|
|
|
!state.filter || |
|
|
|
|
|
|
|
(state.filter === 'to' && toAddressHash === state.addressHash) || |
|
|
|
|
|
|
|
(state.filter === 'from' && fromAddressHash === state.addressHash) |
|
|
|
|
|
|
|
)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!state.batchCountAccumulator && action.msgs.length < BATCH_THRESHOLD) { |
|
|
|
|
|
|
|
return Object.assign({}, state, { |
|
|
|
|
|
|
|
newInternalTransactions: [ |
|
|
|
|
|
|
|
...state.newInternalTransactions, |
|
|
|
|
|
|
|
...incomingInternalTransactions.map(({internalTransactionHtml}) => internalTransactionHtml) |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return Object.assign({}, state, { |
|
|
|
|
|
|
|
batchCountAccumulator: state.batchCountAccumulator + action.msgs.length |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
case 'RECEIVED_NEW_TRANSACTION_BATCH': { |
|
|
|
case 'RECEIVED_NEW_TRANSACTION_BATCH': { |
|
|
|
if (state.channelDisconnected || state.beyondPageOne) return state |
|
|
|
if (state.channelDisconnected || state.beyondPageOne) return state |
|
|
|
|
|
|
|
|
|
|
@ -75,26 +99,38 @@ export function reducer (state = initialState, action) { |
|
|
|
router.when('/address/:addressHash').then((params) => initRedux(reducer, { |
|
|
|
router.when('/address/:addressHash').then((params) => initRedux(reducer, { |
|
|
|
main (store) { |
|
|
|
main (store) { |
|
|
|
const { addressHash, blockNumber } = params |
|
|
|
const { addressHash, blockNumber } = params |
|
|
|
const channel = socket.channel(`addresses:${addressHash}`, {}) |
|
|
|
const addressChannel = socket.channel(`addresses:${addressHash}`, {}) |
|
|
|
store.dispatch({ |
|
|
|
store.dispatch({ |
|
|
|
type: 'PAGE_LOAD', |
|
|
|
type: 'PAGE_LOAD', |
|
|
|
params, |
|
|
|
params, |
|
|
|
transactionCount: $('[data-selector="transaction-count"]').text() |
|
|
|
transactionCount: $('[data-selector="transaction-count"]').text() |
|
|
|
}) |
|
|
|
}) |
|
|
|
channel.join() |
|
|
|
addressChannel.join() |
|
|
|
channel.onError(() => store.dispatch({ type: 'CHANNEL_DISCONNECTED' })) |
|
|
|
addressChannel.onError(() => store.dispatch({ type: 'CHANNEL_DISCONNECTED' })) |
|
|
|
channel.on('balance', (msg) => store.dispatch({ type: 'RECEIVED_UPDATED_BALANCE', msg })) |
|
|
|
addressChannel.on('balance', (msg) => store.dispatch({ type: 'RECEIVED_UPDATED_BALANCE', msg })) |
|
|
|
if (!blockNumber) channel.on('transaction', batchChannel((msgs) => store.dispatch({ type: 'RECEIVED_NEW_TRANSACTION_BATCH', msgs }))) |
|
|
|
if (!blockNumber) { |
|
|
|
|
|
|
|
addressChannel.on('transaction', batchChannel((msgs) => |
|
|
|
|
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_TRANSACTION_BATCH', msgs }) |
|
|
|
|
|
|
|
)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!blockNumber) { |
|
|
|
|
|
|
|
addressChannel.on('internal_transaction', batchChannel((msgs) => |
|
|
|
|
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_INTERNAL_TRANSACTION_BATCH', msgs }) |
|
|
|
|
|
|
|
)) |
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
render (state, oldState) { |
|
|
|
render (state, oldState) { |
|
|
|
|
|
|
|
const $balance = $('[data-selector="balance-card"]') |
|
|
|
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 $channelDisconnected = $('[data-selector="channel-disconnected-message"]') |
|
|
|
|
|
|
|
const $emptyInternalTransactionsList = $('[data-selector="empty-internal-transactions-list"]') |
|
|
|
const $emptyTransactionsList = $('[data-selector="empty-transactions-list"]') |
|
|
|
const $emptyTransactionsList = $('[data-selector="empty-transactions-list"]') |
|
|
|
const $balance = $('[data-selector="balance-card"]') |
|
|
|
const $internalTransactionsList = $('[data-selector="internal-transactions-list"]') |
|
|
|
const $transactionCount = $('[data-selector="transaction-count"]') |
|
|
|
const $transactionCount = $('[data-selector="transaction-count"]') |
|
|
|
const $transactionsList = $('[data-selector="transactions-list"]') |
|
|
|
const $transactionsList = $('[data-selector="transactions-list"]') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($emptyInternalTransactionsList.length && state.newInternalTransactions.length) window.location.reload() |
|
|
|
if ($emptyTransactionsList.length && state.newTransactions.length) window.location.reload() |
|
|
|
if ($emptyTransactionsList.length && state.newTransactions.length) window.location.reload() |
|
|
|
if (state.channelDisconnected) $channelDisconnected.show() |
|
|
|
if (state.channelDisconnected) $channelDisconnected.show() |
|
|
|
if (oldState.balance !== state.balance) $balance.empty().append(state.balance) |
|
|
|
if (oldState.balance !== state.balance) $balance.empty().append(state.balance) |
|
|
@ -105,6 +141,9 @@ router.when('/address/:addressHash').then((params) => initRedux(reducer, { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$channelBatching.hide() |
|
|
|
$channelBatching.hide() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (oldState.newInternalTransactions !== state.newInternalTransactions && $internalTransactionsList.length) { |
|
|
|
|
|
|
|
$internalTransactionsList.prepend(state.newInternalTransactions.slice(oldState.newInternalTransactions.length).reverse().join('')) |
|
|
|
|
|
|
|
} |
|
|
|
if (oldState.newTransactions !== state.newTransactions && $transactionsList.length) { |
|
|
|
if (oldState.newTransactions !== state.newTransactions && $transactionsList.length) { |
|
|
|
$transactionsList.prepend(state.newTransactions.slice(oldState.newTransactions.length).reverse().join('')) |
|
|
|
$transactionsList.prepend(state.newTransactions.slice(oldState.newTransactions.length).reverse().join('')) |
|
|
|
updateAllAges() |
|
|
|
updateAllAges() |
|
|
|