From 4d1eec40052a0908d023af40123a9a87d07be02e Mon Sep 17 00:00:00 2001 From: nicolau Date: Tue, 17 Dec 2024 07:57:33 -0300 Subject: [PATCH 1/2] fix: explorer inactive operators bug --- explorer/lib/explorer/models/operators.ex | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/explorer/lib/explorer/models/operators.ex b/explorer/lib/explorer/models/operators.ex index 570372390e..9054f4fb40 100644 --- a/explorer/lib/explorer/models/operators.ex +++ b/explorer/lib/explorer/models/operators.ex @@ -68,16 +68,20 @@ defmodule Operators do get_operators() |> Enum.map(fn operator -> + total_stake_eth = operator.total_stake |> EthConverter.wei_to_eth(2) + + {_, total_stake_usd} = + operator.total_stake |> EthConverter.wei_to_usd(0) + case operator.is_active do false -> - Map.from_struct(operator) |> Map.put(:weight, 0) + Map.from_struct(operator) + |> Map.put(:weight, 0) + |> Map.put(:total_stake_eth, total_stake_eth) + |> Map.put(:total_stake_usd, total_stake_usd) true -> weight = Decimal.div(operator.total_stake, total_stake) - total_stake_eth = operator.total_stake |> EthConverter.wei_to_eth(2) - - {_, total_stake_usd} = - operator.total_stake |> EthConverter.wei_to_usd(0) Map.from_struct(operator) |> Map.put(:total_stake_eth, total_stake_eth) From c0ce128dfa5fc3b52d605907d73aae6b94e540ae Mon Sep 17 00:00:00 2001 From: nicolau Date: Tue, 17 Dec 2024 08:37:35 -0300 Subject: [PATCH 2/2] refactor: calculate stake when is_active only --- explorer/lib/explorer/models/operators.ex | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/explorer/lib/explorer/models/operators.ex b/explorer/lib/explorer/models/operators.ex index 9054f4fb40..cd4688db71 100644 --- a/explorer/lib/explorer/models/operators.ex +++ b/explorer/lib/explorer/models/operators.ex @@ -68,20 +68,19 @@ defmodule Operators do get_operators() |> Enum.map(fn operator -> - total_stake_eth = operator.total_stake |> EthConverter.wei_to_eth(2) - - {_, total_stake_usd} = - operator.total_stake |> EthConverter.wei_to_usd(0) - case operator.is_active do false -> Map.from_struct(operator) |> Map.put(:weight, 0) - |> Map.put(:total_stake_eth, total_stake_eth) - |> Map.put(:total_stake_usd, total_stake_usd) + |> Map.put(:total_stake_eth, 0) + |> Map.put(:total_stake_usd, 0) true -> weight = Decimal.div(operator.total_stake, total_stake) + total_stake_eth = operator.total_stake |> EthConverter.wei_to_eth(2) + + {_, total_stake_usd} = + operator.total_stake |> EthConverter.wei_to_usd(0) Map.from_struct(operator) |> Map.put(:total_stake_eth, total_stake_eth)