From 57f6b4d6d1b080f884c7b31c2a1fd9c9bc54e9e9 Mon Sep 17 00:00:00 2001 From: Amanda Sposito Date: Wed, 6 Jun 2018 19:45:01 -0300 Subject: [PATCH] Add check mark in tab when smart contract is verified --- apps/explorer/lib/explorer/chain.ex | 1 + .../test/explorer/smart_contract/verifier_test.exs | 3 +-- .../address_internal_transaction/index.html.eex | 12 ++++++++---- .../templates/address_transaction/index.html.eex | 12 ++++++++---- .../lib/explorer_web/views/address_contract_view.ex | 5 +---- .../views/address_internal_transaction_view.ex | 2 +- .../explorer_web/views/address_transaction_view.ex | 2 +- .../lib/explorer_web/views/address_view.ex | 6 +++++- 8 files changed, 26 insertions(+), 17 deletions(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 69166410e5..79a978ebcd 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -491,6 +491,7 @@ defmodule Explorer.Chain do query = from( address in Address, + preload: [:smart_contract], where: address.hash == ^hash ) diff --git a/apps/explorer/test/explorer/smart_contract/verifier_test.exs b/apps/explorer/test/explorer/smart_contract/verifier_test.exs index 451638dea1..d2104768b6 100644 --- a/apps/explorer/test/explorer/smart_contract/verifier_test.exs +++ b/apps/explorer/test/explorer/smart_contract/verifier_test.exs @@ -64,8 +64,7 @@ defmodule Explorer.SmartContract.VerifierTest do address_hash = "0x0f95fa9bc0383e699325f2658d04e8d96d87b90c" params = %{ - "contract_source_code" => - "pragma solidity ^0.4.24; contract SimpleStorage { ", + "contract_source_code" => "pragma solidity ^0.4.24; contract SimpleStorage { ", "compiler" => "0.4.24", "name" => "SimpleStorage", "optimization" => false diff --git a/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex b/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex index 46c418389f..baf46761b7 100644 --- a/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex @@ -24,10 +24,14 @@ <%= if contract?(@address) do %> <% end %> diff --git a/apps/explorer_web/lib/explorer_web/templates/address_transaction/index.html.eex b/apps/explorer_web/lib/explorer_web/templates/address_transaction/index.html.eex index 1644de9737..a9323e1c88 100644 --- a/apps/explorer_web/lib/explorer_web/templates/address_transaction/index.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/address_transaction/index.html.eex @@ -24,10 +24,14 @@ <%= if contract?(@address) do %> <% end %> diff --git a/apps/explorer_web/lib/explorer_web/views/address_contract_view.ex b/apps/explorer_web/lib/explorer_web/views/address_contract_view.ex index 74f64dbb68..11377e816d 100644 --- a/apps/explorer_web/lib/explorer_web/views/address_contract_view.ex +++ b/apps/explorer_web/lib/explorer_web/views/address_contract_view.ex @@ -1,8 +1,5 @@ defmodule ExplorerWeb.AddressContractView do use ExplorerWeb, :view - alias Explorer.Chain.{Address, SmartContract} - - def smart_contract_verified?(%Address{smart_contract: nil}), do: false - def smart_contract_verified?(%Address{smart_contract: %SmartContract{}}), do: true + import ExplorerWeb.AddressView, only: [smart_contract_verified?: 1] end diff --git a/apps/explorer_web/lib/explorer_web/views/address_internal_transaction_view.ex b/apps/explorer_web/lib/explorer_web/views/address_internal_transaction_view.ex index edde922751..ddcd7f9ea4 100644 --- a/apps/explorer_web/lib/explorer_web/views/address_internal_transaction_view.ex +++ b/apps/explorer_web/lib/explorer_web/views/address_internal_transaction_view.ex @@ -1,7 +1,7 @@ defmodule ExplorerWeb.AddressInternalTransactionView do use ExplorerWeb, :view - import ExplorerWeb.AddressView, only: [contract?: 1] + import ExplorerWeb.AddressView, only: [contract?: 1, smart_contract_verified?: 1] def format_current_filter(filter) do case filter do diff --git a/apps/explorer_web/lib/explorer_web/views/address_transaction_view.ex b/apps/explorer_web/lib/explorer_web/views/address_transaction_view.ex index 155e5e3e01..abebb26c8c 100644 --- a/apps/explorer_web/lib/explorer_web/views/address_transaction_view.ex +++ b/apps/explorer_web/lib/explorer_web/views/address_transaction_view.ex @@ -1,7 +1,7 @@ defmodule ExplorerWeb.AddressTransactionView do use ExplorerWeb, :view - import ExplorerWeb.AddressView, only: [contract?: 1] + import ExplorerWeb.AddressView, only: [contract?: 1, smart_contract_verified?: 1] alias ExplorerWeb.TransactionView diff --git a/apps/explorer_web/lib/explorer_web/views/address_view.ex b/apps/explorer_web/lib/explorer_web/views/address_view.ex index fe130f9c29..c801a29292 100644 --- a/apps/explorer_web/lib/explorer_web/views/address_view.ex +++ b/apps/explorer_web/lib/explorer_web/views/address_view.ex @@ -1,7 +1,8 @@ defmodule ExplorerWeb.AddressView do use ExplorerWeb, :view - alias Explorer.Chain.{Address, Wei} + alias Explorer.Chain.{Address, Wei, SmartContract} + alias Explorer.ExchangeRates.Token alias ExplorerWeb.ExchangeRates.USD @@ -51,4 +52,7 @@ defmodule ExplorerWeb.AddressView do |> QRCode.to_png() |> Base.encode64() end + + def smart_contract_verified?(%Address{smart_contract: %SmartContract{}}), do: true + def smart_contract_verified?(%Address{smart_contract: nil}), do: false end