From e7ace9cae65ecfee65527de599ed1b1890be2578 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 29 May 2019 10:20:11 +0300 Subject: [PATCH] fix credo --- .../assets/js/pages/address/logs.js | 18 ++++++------- apps/explorer/lib/explorer/chain.ex | 27 +++++++++---------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/apps/block_scout_web/assets/js/pages/address/logs.js b/apps/block_scout_web/assets/js/pages/address/logs.js index 6cbced717e..a9ad5104c3 100644 --- a/apps/block_scout_web/assets/js/pages/address/logs.js +++ b/apps/block_scout_web/assets/js/pages/address/logs.js @@ -13,15 +13,15 @@ export const initialState = { export function reducer (state, action) { switch (action.type) { - case 'PAGE_LOAD': - case 'ELEMENTS_LOAD': { - return Object.assign({}, state, _.omit(action, 'type')) - } - case 'START_SEARCH': { - return Object.assign({}, state, {pagesStack: [], isSearch: true}) - } - default: - return state + case 'PAGE_LOAD': + case 'ELEMENTS_LOAD': { + return Object.assign({}, state, _.omit(action, 'type')) + } + case 'START_SEARCH': { + return Object.assign({}, state, {pagesStack: [], isSearch: true}) + } + default: + return state } } diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index a52965a92b..d2b88ba722 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -280,7 +280,7 @@ defmodule Explorer.Chain do |> Enum.take(paging_options.page_size) end - @spec address_to_logs(Address.t(), [Keyword.t()]) :: [ + @spec address_to_logs(Address.t(), Keyword.t()) :: [ Log.t() ] def address_to_logs( @@ -291,7 +291,6 @@ defmodule Explorer.Chain do paging_options = Keyword.get(options, :paging_options) || %PagingOptions{page_size: 50} {block_number, transaction_index, log_index} = paging_options.key || {BlockNumberCache.max_number(), 0, 0} - topic = Keyword.get(options, :topic) base_query = from(log in Log, @@ -308,22 +307,22 @@ defmodule Explorer.Chain do select: log ) - query = - if topic do - from(log in base_query, - where: - log.first_topic == ^topic or log.second_topic == ^topic or log.third_topic == ^topic or - log.fourth_topic == ^topic - ) - else - base_query - end - - query + base_query + |> filter_topic(options) |> Repo.all() |> Enum.take(paging_options.page_size) end + defp filter_topic(base_query, topic: topic) do + from(log in base_query, + where: + log.first_topic == ^topic or log.second_topic == ^topic or log.third_topic == ^topic or + log.fourth_topic == ^topic + ) + end + + defp filter_topic(base_query, _), do: base_query + @doc """ Finds all `t:Explorer.Chain.Transaction.t/0`s given the address_hash and the token contract address hash.