From 73f141c56b5d11ce1f179aec70a2e5d60c17ca8d Mon Sep 17 00:00:00 2001 From: Samuel Manzanera Date: Thu, 11 Jan 2024 16:19:44 +0100 Subject: [PATCH] =?UTF-8?q?fix=20=F0=9F=90=9B=20(explorer):=20Use=20memory?= =?UTF-8?q?=20values=20for=20Oracle's=20explorer=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before the page loads Oracle's data from transaction itself and decoded it, while it could be retrieved directly from the memory tables. --- .../explorer/live/chains/oracle_chain_live.ex | 31 +++---------------- .../live/chains/oracle_chain_live.html.heex | 3 +- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/lib/archethic_web/explorer/live/chains/oracle_chain_live.ex b/lib/archethic_web/explorer/live/chains/oracle_chain_live.ex index f0a157594..86100a12d 100644 --- a/lib/archethic_web/explorer/live/chains/oracle_chain_live.ex +++ b/lib/archethic_web/explorer/live/chains/oracle_chain_live.ex @@ -16,7 +16,6 @@ defmodule ArchethicWeb.Explorer.OracleChainLive do alias Archethic.TransactionChain.Transaction alias Archethic.TransactionChain.Transaction.ValidationStamp alias Archethic.TransactionChain.Transaction.ValidationStamp.LedgerOperations - alias Archethic.TransactionChain.TransactionData alias ArchethicWeb.Explorer.Components.TransactionsList def mount(_params, _session, socket) do @@ -26,23 +25,8 @@ defmodule ArchethicWeb.Explorer.OracleChainLive do end next_summary_date = OracleChain.next_summary_date(DateTime.utc_now()) - next_first_oracle_address = Crypto.derive_oracle_address(next_summary_date, 0) - - {last_oracle_data, update_time} = - case TransactionChain.get_last_transaction(next_first_oracle_address, - data: [:content], - validation_stamp: [:timestamp] - ) do - {:ok, - %Transaction{ - data: %TransactionData{content: content}, - validation_stamp: %ValidationStamp{timestamp: timestamp} - }} -> - {Jason.decode!(content), timestamp} - - {:error, :transaction_not_exists} -> - {%{}, nil} - end + + uco_prices = OracleChain.get_uco_price(DateTime.utc_now()) oracle_dates = case get_oracle_dates() |> Enum.to_list() do @@ -55,8 +39,7 @@ defmodule ArchethicWeb.Explorer.OracleChainLive do new_assign = socket - |> assign(:last_oracle_data, last_oracle_data) - |> assign(:update_time, update_time || next_summary_date) + |> assign(:last_oracle_data, %{uco: uco_prices}) |> assign(:dates, oracle_dates) |> assign(:current_date_page, 1) |> assign(:transactions, list_transactions_by_date(next_summary_date)) @@ -104,15 +87,11 @@ defmodule ArchethicWeb.Explorer.OracleChainLive do {:new_transaction, address, :oracle, timestamp}, socket = %{assigns: assigns = %{current_date_page: current_page}} ) do - {:ok, %Transaction{data: %TransactionData{content: content}}} = - TransactionChain.get_transaction(address, data: [:content]) - - last_oracle_data = Jason.decode!(content) + uco_prices = OracleChain.get_uco_price(timestamp) new_assign = socket - |> assign(:last_oracle_data, last_oracle_data) - |> assign(:update_time, timestamp) + |> assign(:last_oracle_data, %{uco: uco_prices}) if current_page == 1 do # Only update the transaction listed when you are on the first page diff --git a/lib/archethic_web/explorer/live/chains/oracle_chain_live.html.heex b/lib/archethic_web/explorer/live/chains/oracle_chain_live.html.heex index 169eaabea..8344cfaf5 100644 --- a/lib/archethic_web/explorer/live/chains/oracle_chain_live.html.heex +++ b/lib/archethic_web/explorer/live/chains/oracle_chain_live.html.heex @@ -9,7 +9,7 @@ <%= if Enum.empty?(@last_oracle_data) do %> N/A <% else %> - <%= get_in(@last_oracle_data, ["uco", "usd"]) %> $ + <%= get_in(@last_oracle_data, [:uco, :usd]) %> $ <% end %> @@ -26,4 +26,3 @@ socket={@socket} uco_price_now={@uco_price_now} /> -
Last changes from <%= format_date(@update_time) %>