Skip to content

Commit

Permalink
fix: filter out balances without day.
Browse files Browse the repository at this point in the history
  • Loading branch information
DenSmolonski committed Jul 4, 2024
1 parent 4837261 commit 49edf1b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
4 changes: 3 additions & 1 deletion apps/indexer/lib/indexer/block/realtime/fetcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,12 @@ defmodule Indexer.Block.Realtime.Fetcher do
block_timestamp_map = CoinBalance.block_timestamp_map(params_list, json_rpc_named_arguments)

importable_balances_daily_params =
Enum.map(params_list, fn param ->
params_list
|> Enum.map(fn param ->
day = Map.get(block_timestamp_map, "#{param.block_number}")
(day && Map.put(param, :day, day)) || param
end)
|> Enum.filter(fn param -> Map.has_key?(param, :day) end)

{:ok,
%{
Expand Down
12 changes: 0 additions & 12 deletions apps/indexer/lib/indexer/fetcher/coin_balance_daily_updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,12 @@ defmodule Indexer.Fetcher.CoinBalanceDailyUpdater do
{:noreply, Enum.reduce(daily_balances_params, state, &put_new_param/2)}
end

# Clause to handle params without a :day key
defp put_new_param(%{day: nil} = param, acc) do
IO.inspect(param)
acc
end

defp put_new_param(%{day: day, address_hash: address_hash, value: value} = param, acc) do
Map.update(acc, {address_hash, day}, param, fn %{value: old_value} = old_param ->
if is_nil(old_value) or value > old_value, do: param, else: old_param
end)
end

# Default clause to catch all other cases
defp put_new_param(param, acc) do
IO.inspect(param, label: "Unhandled param structure")
acc
end

@impl true
def handle_info(:update, state) when state == %{} do
schedule_next_update()
Expand Down

0 comments on commit 49edf1b

Please sign in to comment.