pull/1030/head
jimmay5469 6 years ago
parent 95ef4b9718
commit d844185c18
  1. 21
      apps/block_scout_web/assets/js/pages/address.js
  2. 12
      apps/block_scout_web/assets/js/utils.js
  3. 27
      apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex
  4. 3
      apps/block_scout_web/lib/block_scout_web/templates/address_transaction/index.html.eex

@ -27,6 +27,7 @@ export const initialState = {
internalTransactionsBatch: [], internalTransactionsBatch: [],
validatedBlocks: [], validatedBlocks: [],
loadingNextPage: false,
nextPage: null, nextPage: null,
beyondPageOne: null beyondPageOne: null
@ -148,8 +149,14 @@ export function reducer (state = initialState, action) {
balance: action.msg.balance balance: action.msg.balance
}) })
} }
case 'LOADING_NEXT_PAGE': {
return Object.assign({}, state, {
loadingNextPage: true
})
}
case 'NEXT_TRANSACTIONS_PAGE': { case 'NEXT_TRANSACTIONS_PAGE': {
return Object.assign({}, state, { return Object.assign({}, state, {
loadingNextPage: false,
nextPage: action.msg.nextPage, nextPage: action.msg.nextPage,
transactions: [ transactions: [
...state.transactions, ...state.transactions,
@ -196,7 +203,7 @@ if ($addressDetailsPage.length) {
blockHtml: el.outerHTML blockHtml: el.outerHTML
})).toArray(), })).toArray(),
nextPage: $('[data-selector="next-page-button"]').length ? `${$('[data-selector="next-page-button"]').hide().attr("href")}&type=JSON` : null, nextPage: $('[data-selector="next-page-button"]').length ? `${$('[data-selector="next-page-button"]').hide().attr('href')}&type=JSON` : null,
beyondPageOne: !!blockNumber beyondPageOne: !!blockNumber
}) })
@ -219,14 +226,22 @@ if ($addressDetailsPage.length) {
blocksChannel.on('new_block', (msg) => store.dispatch({ type: 'RECEIVED_NEW_BLOCK', msg: humps.camelizeKeys(msg) })) blocksChannel.on('new_block', (msg) => store.dispatch({ type: 'RECEIVED_NEW_BLOCK', msg: humps.camelizeKeys(msg) }))
$('[data-selector="transactions-list"]').length && atBottom(function loadMoreTransactions () { $('[data-selector="transactions-list"]').length && atBottom(function loadMoreTransactions () {
$.get(store.getState().nextPage).done(msg => { const nextPage = store.getState().nextPage
if (nextPage) {
store.dispatch({ type: 'LOADING_NEXT_PAGE' })
$.get(nextPage).done(msg => {
store.dispatch({ type: 'NEXT_TRANSACTIONS_PAGE', msg: humps.camelizeKeys(msg) }) store.dispatch({ type: 'NEXT_TRANSACTIONS_PAGE', msg: humps.camelizeKeys(msg) })
setTimeout(() => atBottom(loadMoreTransactions), 1000)
}) })
}
}) })
}, },
render (state, oldState) { render (state, oldState) {
if (state.channelDisconnected) $('[data-selector="channel-disconnected-message"]').show() if (state.channelDisconnected) $('[data-selector="channel-disconnected-message"]').show()
if (state.loadingNextPage) {
$('[data-selector="loading-next-page"]').show()
} else {
$('[data-selector="loading-next-page"]').hide()
}
if (oldState.balance !== state.balance) { if (oldState.balance !== state.balance) {
$('[data-selector="balance-card"]').empty().append(state.balance) $('[data-selector="balance-card"]').empty().append(state.balance)

@ -116,6 +116,7 @@ function smarterSlideUp ($el, { complete = _.noop } = {}) {
} }
export function listMorph (container, newElements, { key, horizontal }) { export function listMorph (container, newElements, { key, horizontal }) {
if (!container) return
const oldElements = $(container).children().get() const oldElements = $(container).children().get()
let currentList = _.map(oldElements, (el) => ({ id: _.get(el, key), el })) let currentList = _.map(oldElements, (el) => ({ id: _.get(el, key), el }))
const newList = _.map(newElements, (el) => ({ id: _.get(el, key), el })) const newList = _.map(newElements, (el) => ({ id: _.get(el, key), el }))
@ -151,12 +152,13 @@ export function listMorph (container, newElements, { key, horizontal }) {
} }
export function atBottom (callback) { export function atBottom (callback) {
$(window).on("scroll", function infiniteScrollChecker () { function infiniteScrollChecker () {
var scrollHeight = $(document).height(); var scrollHeight = $(document).height()
var scrollPosition = $(window).height() + $(window).scrollTop(); var scrollPosition = $(window).height() + $(window).scrollTop()
if ((scrollHeight - scrollPosition) / scrollHeight === 0) { if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
$(window).off("scroll", infiniteScrollChecker)
callback() callback()
} }
}); }
infiniteScrollChecker()
$(window).on('scroll', infiniteScrollChecker)
} }

@ -33,13 +33,29 @@ defmodule BlockScoutWeb.AddressTransactionController do
transactions_plus_one = Chain.address_to_transactions(address, full_options) transactions_plus_one = Chain.address_to_transactions(address, full_options)
{transactions, next_page} = split_list_by_page(transactions_plus_one) {transactions, next_page} = split_list_by_page(transactions_plus_one)
next_page =
case next_page_params(next_page, transactions, params) do
nil ->
nil
next_page_params ->
address_transaction_path(
conn,
:index,
address,
next_page_params
)
end
json( json(
conn, conn,
%{ %{
transactions: Enum.map(transactions, fn transaction -> transactions:
Enum.map(transactions, fn transaction ->
%{ %{
transaction_hash: Hash.to_string(transaction.hash), transaction_hash: Hash.to_string(transaction.hash),
transaction_html: View.render_to_string( transaction_html:
View.render_to_string(
TransactionView, TransactionView,
"_tile.html", "_tile.html",
current_address: address, current_address: address,
@ -47,12 +63,7 @@ defmodule BlockScoutWeb.AddressTransactionController do
) )
} }
end), end),
next_page: address_transaction_path( next_page: next_page
conn,
:index,
address,
next_page_params(next_page, transactions, params)
)
} }
) )
else else

@ -74,6 +74,9 @@
<%= render(BlockScoutWeb.TransactionView, "_tile.html", current_address: @address, transaction: transaction) %> <%= render(BlockScoutWeb.TransactionView, "_tile.html", current_address: @address, transaction: transaction) %>
<% end %> <% end %>
</span> </span>
<div data-selector="loading-next-page" style="display: none;">
<%= gettext("Loading") %>...
</div>
<% else %> <% else %>
<div class="tile tile-muted text-center"> <div class="tile tile-muted text-center">
<span data-selector="empty-transactions-list"><%= gettext "There are no transactions for this address." %></span> <span data-selector="empty-transactions-list"><%= gettext "There are no transactions for this address." %></span>

Loading…
Cancel
Save