Skip to content

Commit

Permalink
Use alpine.js to avoid backend calls for the transaction viewer (#78)
Browse files Browse the repository at this point in the history
* added alpinejs code in the template

* removed handle_event functions

* cleaned up unused code
  • Loading branch information
ambareesha7 committed Sep 21, 2021
1 parent 3bd600d commit 9594b35
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 116 deletions.
34 changes: 2 additions & 32 deletions lib/archethic_web/live/transaction_details_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ defmodule ArchEthicWeb.TransactionDetailsLive do
alias ArchEthic.PubSub

alias ArchEthic.TransactionChain.Transaction
alias ArchEthic.TransactionChain.TransactionData

alias ArchEthicWeb.ExplorerView

Expand All @@ -18,11 +17,7 @@ defmodule ArchEthicWeb.TransactionDetailsLive do
assign(socket, %{
exists: false,
previous_address: nil,
transaction: nil,
hide_content: true,
tab_panel: "tx",
data_section: "code",
operation_section: "transaction_movements"
transaction: nil
})}
end

Expand All @@ -41,30 +36,6 @@ defmodule ArchEthicWeb.TransactionDetailsLive do
end
end

def handle_event("switch_tab", %{"tab_panel" => tab_panel}, socket) do
{:noreply, assign(socket, :tab_panel, tab_panel)}
end

def handle_event("switch_data", %{"data_section" => data_section}, socket) do
{:noreply, assign(socket, :data_section, data_section)}
end

def handle_event(
"switch_ledger_operations",
%{"operation_section" => operation_section},
socket
) do
{:noreply, assign(socket, :operation_section, operation_section)}
end

def handle_event("hide_content", _value, socket = %{assigns: %{hide_content: false}}) do
{:noreply, assign(socket, :hide_content, true)}
end

def handle_event("show_content", _value, socket = %{assigns: %{hide_content: true}}) do
{:noreply, assign(socket, :hide_content, false)}
end

def handle_info({:new_transaction, address}, socket) do
{:ok, tx} = get_transaction(address, %{})

Expand Down Expand Up @@ -98,7 +69,7 @@ defmodule ArchEthicWeb.TransactionDetailsLive do

defp handle_transaction(
socket,
tx = %Transaction{address: address, data: %TransactionData{content: content}}
tx = %Transaction{address: address}
) do
balance = ArchEthic.get_balance(address)
previous_address = Transaction.previous_address(tx)
Expand All @@ -114,7 +85,6 @@ defmodule ArchEthicWeb.TransactionDetailsLive do
|> assign(:inputs, ledger_inputs)
|> assign(:calls, contract_inputs)
|> assign(:address, address)
|> assign(:hide_content, byte_size(content) > 1000)
end

def handle_not_existing_transaction(socket, address) do
Expand Down
Loading

0 comments on commit 9594b35

Please sign in to comment.