diff --git a/apps/block_scout_web/assets/js/app.js b/apps/block_scout_web/assets/js/app.js index f10e3d696d..0893b8b4ae 100644 --- a/apps/block_scout_web/assets/js/app.js +++ b/apps/block_scout_web/assets/js/app.js @@ -23,6 +23,7 @@ import './locale' import './pages/address' import './pages/address/coin_balances' import './pages/address/transactions' +import './pages/address/logs' import './pages/address/validations' import './pages/address/internal_transactions' import './pages/blocks' diff --git a/apps/block_scout_web/assets/js/pages/address/logs.js b/apps/block_scout_web/assets/js/pages/address/logs.js new file mode 100644 index 0000000000..ddfe3e9bfc --- /dev/null +++ b/apps/block_scout_web/assets/js/pages/address/logs.js @@ -0,0 +1,64 @@ +import $ from 'jquery' +import _ from 'lodash' +import URI from 'urijs' +import humps from 'humps' +import { subscribeChannel } from '../../socket' +import { connectElements } from '../../lib/redux_helpers.js' +import { createAsyncLoadStore } from '../../lib/async_listing_load' + +export const initialState = { + addressHash: null +} + +export function reducer (state, action) { + switch (action.type) { + case 'PAGE_LOAD': + case 'ELEMENTS_LOAD': { + return Object.assign({}, state, _.omit(action, 'type')) + } + default: + return state + } +} + +const elements = { + '[data-search-field]' : { + render ($el, state) { + $el + } + }, + '[data-search-button]' : { + render ($el, state) { + $el + } + } +} + +if ($('[data-page="address-logs"]').length) { + console.log('iffff') + const store = createAsyncLoadStore(reducer, initialState, 'dataset.identifierHash') + const addressHash = $('[data-page="address-details"]')[0].dataset.pageAddressHash + const $element = $('[data-async-listing]') + + + connectElements({ store, elements }) + + store.dispatch({ + type: 'PAGE_LOAD', + addressHash: addressHash}) + + function loadSearchItems () { + var topic = $('[data-search-field]').val(); + var path = "/search_logs?topic=" + topic + "&address_id=" + store.getState().addressHash + store.dispatch({type: 'START_REQUEST'}) + $.getJSON(path, {type: 'JSON'}) + .done(response => store.dispatch(Object.assign({type: 'ITEMS_FETCHED'}, humps.camelizeKeys(response)))) + .fail(() => store.dispatch({type: 'REQUEST_ERROR'})) + .always(() => store.dispatch({type: 'FINISH_REQUEST'})) + } + + + $element.on('click', '[data-search-button]', (event) => { + loadSearchItems() + }) +} diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/_logs.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/_logs.html.eex new file mode 100644 index 0000000000..66f75362c3 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/_logs.html.eex @@ -0,0 +1,54 @@ +
+
+
<%= gettext "Transaction" %>
+
+

+ <%= link( + @log.transaction, + to: transaction_path(@conn, :show, @log.transaction), + "data-test": "log_address_link", + "data-address-hash": @log.transaction + ) %> +

+
+
<%= gettext "Topics" %>
+
+
+ <%= unless is_nil(@log.first_topic) do %> +
+ [0] + <%= @log.first_topic %> +
+ <% end %> + <%= unless is_nil(@log.second_topic) do %> +
+ [1] + <%= @log.second_topic %> +
+ <% end %> + <%= unless is_nil(@log.third_topic) do %> +
+ [2] + <%= @log.third_topic %> +
+ <% end %> + <%= unless is_nil(@log.fourth_topic) do %> +
+ [3] + <%= @log.fourth_topic %> +
+ <% end %> +
+
+
+ <%= gettext "Data" %> +
+
+ <%= unless is_nil(@log.data) do %> +
+ <%= @log.data %> +
+ <% end %> +
+
+
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex index 22f446924f..f873465372 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex @@ -1,82 +1,33 @@
<%= render BlockScoutWeb.AddressView, "overview.html", assigns %> +
<%= render BlockScoutWeb.AddressView, "_tabs.html", assigns %> -
- +

<%= gettext "Logs" %>

- <%= if @next_page_url do %> - <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", cur_page_number: "1", show_pagination_limit: true, next_page_path: @next_page_url %> - <% end %> + id='search-text-input' /> + + + <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> - <%= if !@next_page_url do %> - <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", cur_page_number: "1", show_pagination_limit: true %> - <% end %> + - <%= if Enum.count(@logs) > 0 do %> - <%= for log <- @logs do %> -
-
-
<%= gettext "Transaction" %>
-
-

- <%= link( - log.transaction, - to: transaction_path(@conn, :show, log.transaction), - "data-test": "log_address_link", - "data-address-hash": log.transaction - ) %> -

-
-
<%= gettext "Topics" %>
-
-
- <%= unless is_nil(log.first_topic) do %> -
- [0] - <%= log.first_topic %> -
- <% end %> - <%= unless is_nil(log.second_topic) do %> -
- [1] - <%= log.second_topic %> -
- <% end %> - <%= unless is_nil(log.third_topic) do %> -
- [2] - <%= log.third_topic %> -
- <% end %> - <%= unless is_nil(log.fourth_topic) do %> -
- [3] - <%= log.fourth_topic %> -
- <% end %> -
-
-
- <%= gettext "Data" %> -
-
- <%= unless is_nil(log.data) do %> -
- <%= log.data %> -
- <% end %> -
-
+
+
+ <%= gettext "There are no logs for this address." %>
- <% end %> - <% else %> -
- <%= gettext "There are no logs for this address." %> -
- <% end %> +
+ +
+ + <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> +
+
+