|
|
@ -18,12 +18,14 @@ export const initialState = { |
|
|
|
beyondPageOne: null, |
|
|
|
beyondPageOne: null, |
|
|
|
channelDisconnected: false, |
|
|
|
channelDisconnected: false, |
|
|
|
filter: null, |
|
|
|
filter: null, |
|
|
|
|
|
|
|
newBlock: null, |
|
|
|
newInternalTransactions: [], |
|
|
|
newInternalTransactions: [], |
|
|
|
newPendingTransactions: [], |
|
|
|
newPendingTransactions: [], |
|
|
|
newTransactions: [], |
|
|
|
newTransactions: [], |
|
|
|
newTransactionHashes: [], |
|
|
|
newTransactionHashes: [], |
|
|
|
newPendingTransactionHashesBatch: [], |
|
|
|
newPendingTransactionHashesBatch: [], |
|
|
|
transactionCount: null |
|
|
|
transactionCount: null, |
|
|
|
|
|
|
|
validationCount: null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function reducer (state = initialState, action) { |
|
|
|
export function reducer (state = initialState, action) { |
|
|
@ -33,7 +35,8 @@ export function reducer (state = initialState, action) { |
|
|
|
addressHash: action.addressHash, |
|
|
|
addressHash: action.addressHash, |
|
|
|
beyondPageOne: action.beyondPageOne, |
|
|
|
beyondPageOne: action.beyondPageOne, |
|
|
|
filter: action.filter, |
|
|
|
filter: action.filter, |
|
|
|
transactionCount: numeral(action.transactionCount).value() |
|
|
|
transactionCount: numeral(action.transactionCount).value(), |
|
|
|
|
|
|
|
validationCount: action.transactionCount ? numeral(action.transactionCount).value() : null |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
case 'CHANNEL_DISCONNECTED': { |
|
|
|
case 'CHANNEL_DISCONNECTED': { |
|
|
@ -44,9 +47,15 @@ export function reducer (state = initialState, action) { |
|
|
|
batchCountAccumulator: 0 |
|
|
|
batchCountAccumulator: 0 |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
case 'RECEIVED_UPDATED_BALANCE': { |
|
|
|
case 'RECEIVED_NEW_BLOCK': { |
|
|
|
|
|
|
|
if (state.channelDisconnected) return state |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const validationCount = state.validationCount + 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (state.beyondPageOne) return Object.assign({}, state, { validationCount }) |
|
|
|
return Object.assign({}, state, { |
|
|
|
return Object.assign({}, state, { |
|
|
|
balance: action.msg.balance |
|
|
|
newBlock: action.msg.blockHtml, |
|
|
|
|
|
|
|
validationCount |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
case 'RECEIVED_NEW_INTERNAL_TRANSACTION_BATCH': { |
|
|
|
case 'RECEIVED_NEW_INTERNAL_TRANSACTION_BATCH': { |
|
|
@ -133,12 +142,9 @@ export function reducer (state = initialState, action) { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
case 'RECEIVED_NEW_BLOCK': { |
|
|
|
case 'RECEIVED_UPDATED_BALANCE': { |
|
|
|
if (state.channelDisconnected || state.beyondPageOne) return state |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Object.assign({}, state, { |
|
|
|
return Object.assign({}, state, { |
|
|
|
newBlock: action.msg.blockHtml, |
|
|
|
balance: action.msg.balance |
|
|
|
minerHash: action.msg.blockMinerHash |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
default: |
|
|
|
default: |
|
|
@ -158,32 +164,31 @@ if ($addressDetailsPage.length) { |
|
|
|
addressHash, |
|
|
|
addressHash, |
|
|
|
beyondPageOne: !!blockNumber, |
|
|
|
beyondPageOne: !!blockNumber, |
|
|
|
filter, |
|
|
|
filter, |
|
|
|
transactionCount: $('[data-selector="transaction-count"]').text() |
|
|
|
transactionCount: $('[data-selector="transaction-count"]').text(), |
|
|
|
|
|
|
|
validationCount: $('[data-selector="validation-count"]') ? $('[data-selector="validation-count"]').text() : null |
|
|
|
}) |
|
|
|
}) |
|
|
|
addressChannel.join() |
|
|
|
addressChannel.join() |
|
|
|
addressChannel.onError(() => store.dispatch({ type: 'CHANNEL_DISCONNECTED' })) |
|
|
|
addressChannel.onError(() => store.dispatch({ type: 'CHANNEL_DISCONNECTED' })) |
|
|
|
addressChannel.on('balance', (msg) => store.dispatch({ type: 'RECEIVED_UPDATED_BALANCE', msg })) |
|
|
|
addressChannel.on('balance', (msg) => store.dispatch({ type: 'RECEIVED_UPDATED_BALANCE', msg })) |
|
|
|
if (!state.beyondPageOne) { |
|
|
|
addressChannel.on('transaction', batchChannel((msgs) => |
|
|
|
const blocksChannel = socket.channel(`blocks:new_block`, {}) |
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_TRANSACTION_BATCH', msgs }) |
|
|
|
blocksChannel.join() |
|
|
|
)) |
|
|
|
blocksChannel.onError(() => store.dispatch({ type: 'CHANNEL_DISCONNECTED' })) |
|
|
|
|
|
|
|
blocksChannel.on('new_block', (msg) => { |
|
|
|
|
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_BLOCK', msg: humps.camelizeKeys(msg) }) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
addressChannel.on('transaction', batchChannel((msgs) => |
|
|
|
|
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_TRANSACTION_BATCH', msgs }) |
|
|
|
|
|
|
|
)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addressChannel.on('internal_transaction', batchChannel((msgs) => |
|
|
|
addressChannel.on('internal_transaction', batchChannel((msgs) => |
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_INTERNAL_TRANSACTION_BATCH', msgs }) |
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_INTERNAL_TRANSACTION_BATCH', msgs }) |
|
|
|
)) |
|
|
|
)) |
|
|
|
addressChannel.on('pending_transaction', batchChannel((msgs) => |
|
|
|
addressChannel.on('pending_transaction', batchChannel((msgs) => |
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_PENDING_TRANSACTION_BATCH', msgs }) |
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_PENDING_TRANSACTION_BATCH', msgs }) |
|
|
|
)) |
|
|
|
)) |
|
|
|
addressChannel.on('transaction', batchChannel((msgs) => |
|
|
|
addressChannel.on('transaction', batchChannel((msgs) => |
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_TRANSACTION_BATCH', msgs }) |
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_TRANSACTION_BATCH', msgs }) |
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
const blocksChannel = socket.channel(`blocks:${addressHash}`, {}) |
|
|
|
|
|
|
|
blocksChannel.join() |
|
|
|
|
|
|
|
blocksChannel.onError(() => store.dispatch({ type: 'CHANNEL_DISCONNECTED' })) |
|
|
|
|
|
|
|
blocksChannel.on('new_block', (msg) => { |
|
|
|
|
|
|
|
store.dispatch({ type: 'RECEIVED_NEW_BLOCK', msg: humps.camelizeKeys(msg) }) |
|
|
|
|
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
render (state, oldState) { |
|
|
|
render (state, oldState) { |
|
|
|
const $balance = $('[data-selector="balance-card"]') |
|
|
|
const $balance = $('[data-selector="balance-card"]') |
|
|
@ -198,6 +203,7 @@ if ($addressDetailsPage.length) { |
|
|
|
const $pendingTransactionsList = $('[data-selector="pending-transactions-list"]') |
|
|
|
const $pendingTransactionsList = $('[data-selector="pending-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"]') |
|
|
|
|
|
|
|
const $validationCount = $('[data-selector="validation-count"]') |
|
|
|
const $validationsList = $('[data-selector="validations-list"]') |
|
|
|
const $validationsList = $('[data-selector="validations-list"]') |
|
|
|
|
|
|
|
|
|
|
|
if ($emptyInternalTransactionsList.length && state.newInternalTransactions.length) window.location.reload() |
|
|
|
if ($emptyInternalTransactionsList.length && state.newInternalTransactions.length) window.location.reload() |
|
|
@ -209,6 +215,7 @@ if ($addressDetailsPage.length) { |
|
|
|
updateAllCalculatedUsdValues() |
|
|
|
updateAllCalculatedUsdValues() |
|
|
|
} |
|
|
|
} |
|
|
|
if (oldState.transactionCount !== state.transactionCount) $transactionCount.empty().append(numeral(state.transactionCount).format()) |
|
|
|
if (oldState.transactionCount !== state.transactionCount) $transactionCount.empty().append(numeral(state.transactionCount).format()) |
|
|
|
|
|
|
|
if (oldState.validationCount !== state.validationCount) $validationCount.empty().append(numeral(state.validationCount).format()) |
|
|
|
if (state.batchCountAccumulator) { |
|
|
|
if (state.batchCountAccumulator) { |
|
|
|
$channelBatching.show() |
|
|
|
$channelBatching.show() |
|
|
|
$channelBatchingCount[0].innerHTML = numeral(state.batchCountAccumulator).format() |
|
|
|
$channelBatchingCount[0].innerHTML = numeral(state.batchCountAccumulator).format() |
|
|
@ -241,14 +248,9 @@ if ($addressDetailsPage.length) { |
|
|
|
prependWithClingBottom($transactionsList, state.newTransactions.slice(oldState.newTransactions.length).reverse().join('')) |
|
|
|
prependWithClingBottom($transactionsList, state.newTransactions.slice(oldState.newTransactions.length).reverse().join('')) |
|
|
|
updateAllAges() |
|
|
|
updateAllAges() |
|
|
|
} |
|
|
|
} |
|
|
|
if (oldState.newBlock !== state.newBlock && state.minerHash === state.addressHash) { |
|
|
|
if (oldState.newBlock !== state.newBlock) { |
|
|
|
const len = $validationsList.children().length |
|
|
|
prependWithClingBottom($validationsList, state.newBlock) |
|
|
|
$validationsList |
|
|
|
updateAllAges() |
|
|
|
.children() |
|
|
|
|
|
|
|
.slice(len - 1, len) |
|
|
|
|
|
|
|
.remove() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$validationsList.prepend(state.newBlock) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|