Skip to content

Commit

Permalink
Merge pull request #81 from EthTx/dev
Browse files Browse the repository at this point in the history
- Added new route `reload`
- Added a button that allows you to delete semantics and download them again
  • Loading branch information
kchojn authored Jan 10, 2022
2 parents fe5a8a3 + 8b4fb82 commit d4ef0db
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 12 deletions.
18 changes: 18 additions & 0 deletions ethtx_ce/frontend/semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
from typing import Optional, List, Dict

from ethtx import EthTx
from ethtx.models.semantics_model import (
AddressSemantics,
ContractSemantics,
Expand Down Expand Up @@ -50,6 +51,23 @@ def semantics(address: str, chain_id: Optional[str] = None) -> show_semantics_pa
return show_semantics_page(raw_semantics)


@frontend_route(bp, "/reload", methods=["POST"])
@auth.login_required
def reload_semantics():
"""Reload raw semantic."""
data = json.loads(request.data)

ethtx: EthTx = current_app.ethtx
ethtx.semantics.database._addresses.remove({"address": data["address"]})
ethtx.semantics.get_semantics.cache_clear()
ethtx.semantics.get_semantics(
data["chain_id"] if data.get("chain_id") else current_app.ethtx._default_chain,
data["address"],
)

return "ok"


@frontend_route(bp, "/save", methods=["POST"])
@auth.login_required
def semantics_save():
Expand Down
65 changes: 53 additions & 12 deletions ethtx_ce/frontend/templates/semantics.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
padding: 5px 10px 5px 10px;
}


label,
input,
select {
Expand Down Expand Up @@ -64,9 +65,6 @@
margin-top: 25px;
}

.ui-dialog {
padding: .3em;
}
</style>

<script>
Expand Down Expand Up @@ -101,7 +99,14 @@
valid = valid && abi.val().length > 0 && isJsonString(abi.val());

if (valid) {
const poke = { address: address.val(), network: network.val(), name: name.val(), abi: abi.val(), chash: chash, standard: standard };
const poke = {
address: address.val(),
network: network.val(),
name: name.val(),
abi: abi.val(),
chash: chash,
standard: standard
};
$.ajax({
url: "/poke",
dataType: 'json',
Expand Down Expand Up @@ -160,7 +165,7 @@

<body>

<h3>Semantics for: {{address}} / {{ metadata.chain }}</h3>
<h3>Semantics for: {{ address }} / {{ metadata.chain }}</h3>
<div id="metadataJSONeditor" style="float: left; width: 55%; height: 320px; margin: 5px;"></div>
<div id="transformationsJSONeditor" style="float: left; width: 43%; height: 320px; margin: 5px;"></div>
<div id="eventsJSONeditor" style="float: left; width: 55%; height: 320px; margin: 5px;"></div>
Expand All @@ -169,6 +174,7 @@ <h3>Semantics for: {{address}} / {{ metadata.chain }}</h3>
<form>
<button id="save-semantics">Save semantics</button>
<button id="poke-abi">Poke ABI</button>
<button id="reload-semantics" style="background-color: #c0392b; color: #fff;">Reload semantics</button>
</form>

<div id="dialog-form" title="Poke ABI">
Expand All @@ -181,7 +187,8 @@ <h3>Semantics for: {{address}} / {{ metadata.chain }}</h3>
<select name="network" id="network">
<option {% if metadata.chain == 'mainnet' %} selected {% endif %} value="mainnet">ETH mainnet</option>
<option {% if metadata.chain == 'goerli' %} selected {% endif %} value="goerli">Goerli testnet</option>
<option {% if metadata.chain == 'rinkeby' %} selected {% endif %} value="rinkeby">Rinkeby testnet</option>
<option {% if metadata.chain == 'rinkeby' %} selected {% endif %} value="rinkeby">Rinkeby testnet
</option>
</select>
<label for="name">Contract name</label>
<input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all">
Expand All @@ -207,17 +214,28 @@ <h3>Semantics for: {{address}} / {{ metadata.chain }}</h3>
statusBar: false
};

const metadata_editor = new JSONEditor(metadataContainer, { ...options, name: 'Metadata' }, {{ metadata | tojson }});
const transformations_editor = new JSONEditor(transformationsContainer, { ...options, name: 'Transformations' }, {{ transformations | tojson }});
const events_editor = new JSONEditor(eventsContainer, { ...options, name: 'Events' }, {{ events | tojson }});
const functions_editor = new JSONEditor(functionsContainer, { ...options, name: 'Functions' }, {{ functions | tojson }})
const metadata_editor = new JSONEditor(metadataContainer, {...options, name: 'Metadata'}, {{ metadata | tojson }});
const transformations_editor = new JSONEditor(transformationsContainer, {
...options,
name: 'Transformations'
}, {{ transformations | tojson }});
const events_editor = new JSONEditor(eventsContainer, {...options, name: 'Events'}, {{ events | tojson }});
const functions_editor = new JSONEditor(functionsContainer, {
...options,
name: 'Functions'
}, {{ functions | tojson }})

$("#save-semantics").button().on("click", function () {
saveSemantics();
{{ name }};
return false;
});

$("#reload-semantics").button().on("click", function () {
reloadSemantics();
return false;
});

// save semantics
function saveSemantics() {
const semantics = {
Expand All @@ -231,7 +249,7 @@ <h3>Semantics for: {{address}} / {{ metadata.chain }}</h3>
url: "/save",
dataType: 'json',
contentType: "application/json; charset=utf-8",
data: JSON.stringify( semantics),
data: JSON.stringify(semantics),
type: 'POST',
success: function (response) {
console.log(response);
Expand All @@ -241,8 +259,31 @@ <h3>Semantics for: {{address}} / {{ metadata.chain }}</h3>
console.log(error);
location.reload();
}
});
})
}

//reload semantics
function reloadSemantics() {
const data = {
address: '{{ address }}',
chain: '{{ metadata.chain }}'
};

$.ajax({
url: "/reload",
dataType: 'json',
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data),
type: 'POST',
success: function (response) {
console.log(response);
location.reload();
},
error: function (error) {
console.log(error);
location.reload();
}
})
}
</script>

Expand Down

0 comments on commit d4ef0db

Please sign in to comment.