parent
a34e1a9fff
commit
5c69c523da
@ -1,42 +0,0 @@ |
||||
defmodule ExplorerWeb.PendingTransactionForm do |
||||
@moduledoc "Format a pending Transaction for display." |
||||
|
||||
import ExplorerWeb.Gettext |
||||
|
||||
alias Explorer.Chain.{Address, Transaction} |
||||
|
||||
# Functions |
||||
|
||||
def build(transaction) do |
||||
Map.merge(transaction, %{ |
||||
first_seen: first_seen(transaction), |
||||
formatted_status: gettext("Pending"), |
||||
from_address_hash: from_address_hash(transaction), |
||||
last_seen: last_seen(transaction), |
||||
status: :pending, |
||||
to_address_hash: to_address_hash(transaction) |
||||
}) |
||||
end |
||||
|
||||
def first_seen(transaction) do |
||||
transaction.inserted_at |> Timex.from_now() |
||||
end |
||||
|
||||
def from_address_hash(%Transaction{from_address: from_address}) do |
||||
case from_address do |
||||
%Address{hash: hash} -> hash |
||||
_ -> nil |
||||
end |
||||
end |
||||
|
||||
def last_seen(transaction) do |
||||
transaction.updated_at |> Timex.from_now() |
||||
end |
||||
|
||||
def to_address_hash(%Transaction{to_address: to_address}) do |
||||
case to_address do |
||||
%Address{hash: hash} -> hash |
||||
_ -> nil |
||||
end |
||||
end |
||||
end |
@ -1,4 +1,27 @@ |
||||
defmodule ExplorerWeb.PendingTransactionView do |
||||
use ExplorerWeb, :view |
||||
|
||||
alias Explorer.Chain.{Address, Transaction} |
||||
|
||||
@dialyzer :no_match |
||||
|
||||
# Functions |
||||
|
||||
def from_address_hash(%Transaction{from_address: from_address}) do |
||||
case from_address do |
||||
%Address{hash: hash} -> hash |
||||
_ -> nil |
||||
end |
||||
end |
||||
|
||||
def last_seen(%Transaction{updated_at: updated_at}) do |
||||
Timex.from_now(updated_at) |
||||
end |
||||
|
||||
def to_address_hash(%Transaction{to_address: to_address}) do |
||||
case to_address do |
||||
%Address{hash: hash} -> hash |
||||
_ -> nil |
||||
end |
||||
end |
||||
end |
||||
|
@ -1,37 +0,0 @@ |
||||
defmodule ExplorerWeb.PendingTransactionFormTest do |
||||
use Explorer.DataCase |
||||
|
||||
alias ExplorerWeb.PendingTransactionForm |
||||
|
||||
describe "build/1" do |
||||
test "returns a successful transaction when there is a successful receipt" do |
||||
time = DateTime.utc_now() |
||||
to_address = insert(:address, hash: "0xcafe") |
||||
from_address = insert(:address, hash: "0xbee5") |
||||
|
||||
transaction = |
||||
insert( |
||||
:transaction, |
||||
inserted_at: time, |
||||
updated_at: time, |
||||
to_address_id: to_address.id, |
||||
from_address_id: from_address.id |
||||
) |
||||
|
||||
form = |
||||
PendingTransactionForm.build(transaction |> Repo.preload([:to_address, :from_address])) |
||||
|
||||
assert( |
||||
form == |
||||
Map.merge(transaction |> Repo.preload([:to_address, :from_address]), %{ |
||||
to_address_hash: "0xcafe", |
||||
from_address_hash: "0xbee5", |
||||
first_seen: time |> Timex.from_now(), |
||||
last_seen: time |> Timex.from_now(), |
||||
status: :pending, |
||||
formatted_status: "Pending" |
||||
}) |
||||
) |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue