forked from blockscout/blockscout
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add an admin method to import contract methods.
- Loading branch information
1 parent
434b445
commit b9ade78
Showing
8 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import $ from 'jquery' | ||
|
||
const runTask = (event) => { | ||
const element = event.currentTarget | ||
const $element = $(element) | ||
const $loading = $element.find('[data-loading-message]') | ||
const $errorMessage = $element.find('[data-error-message]') | ||
const $successMessage = $element.find('[data-success-message]') | ||
const apiPath = element.dataset.api_path | ||
|
||
$errorMessage.hide() | ||
$successMessage.hide() | ||
$loading.show() | ||
|
||
$.get(apiPath) | ||
.done(response => { | ||
$successMessage.show() | ||
$loading.hide() | ||
}) | ||
.fail(() => { | ||
$loading.hide() | ||
$errorMessage.show() | ||
}) | ||
} | ||
|
||
$('#run-create-contract-methods').click(runTask) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
apps/block_scout_web/lib/block_scout_web/controllers/admin/tasks_controller.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule BlockScoutWeb.Admin.TaskController do | ||
use BlockScoutWeb, :controller | ||
|
||
require Logger | ||
|
||
alias Explorer.Chain.ContractMethod | ||
|
||
@ok_resp Poison.encode!(%{status: "success"}) | ||
@not_ok_resp Poison.encode!(%{status: "failure"}) | ||
|
||
def create_contract_methods(conn, _) do | ||
case ContractMethod.import_all() do | ||
:ok -> | ||
send_resp(conn, 200, Poison.encode!(@ok_resp)) | ||
|
||
{:error, error} -> | ||
Logger.error(fn -> ["Something went wrong while creating contract methods: ", inspect(error)] end) | ||
|
||
send_resp(conn, 500, Poison.encode!(@not_ok_resp)) | ||
end | ||
end | ||
end |
37 changes: 36 additions & 1 deletion
37
apps/block_scout_web/lib/block_scout_web/templates/admin/dashboard/index.html.eex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,36 @@ | ||
<div data-test="administrator_dashboard"></div> | ||
<div data-test="administrator_dashboard"> | ||
<div class="container"> | ||
<div class="row"> | ||
<h2>Tasks</h2> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-sm-6"> | ||
<div class="card"> | ||
<div class="card-body"> | ||
<div class="card-title"> | ||
<h3>Create Contract Methods</h3> | ||
</div> | ||
<div class="card-text"> | ||
<p> | ||
<%= gettext("For any existing contracts in the database, insert all ABI entries into the contract_methods table. Use this in case you have verified smart contracts before early March 2019 and you want other contracts with the same functions to show those ABI's as candidate matches.") %> | ||
</p> | ||
</div> | ||
|
||
<button id="run-create-contract-methods" data-api_path="<%= BlockScoutWeb.AdminRouter.Helpers.create_contract_methods_path(@conn, :create_contract_methods) %>" class="btn btn-primary"> | ||
<%= gettext("Run") %> | ||
|
||
<span data-loading-message class="loading-spinner-small mr-2" style="display: none;"> | ||
<span class="loading-spinner-block-1"></span> | ||
<span class="loading-spinner-block-2"></span> | ||
</span> | ||
|
||
<span data-success-message style="display: none;"> - Success</span> | ||
<span data-error-message style="display: none;"> - Failed</span> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters