1
0

Basic interaction implemented

This commit is contained in:
Jon Michael Aanes 2024-06-10 00:13:16 +02:00
parent f70f23335b
commit cc442b3a2e
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
2 changed files with 21 additions and 2 deletions

View File

@ -71,9 +71,26 @@ function address_to_url(address: BlockchainAddress): string {
}
function ui_show_route() {
if (CURRENT_ROUTE.from == null || CURRENT_ROUTE.to == null) {
return;
}
const infoFrom = TOKENS[CURRENT_ROUTE.from.asString()];
const infoTo = TOKENS[CURRENT_ROUTE.to.asString()];
const symbolFrom = infoFrom.latest_state == null ? "???" : infoFrom.latest_state.symbol;
const symbolTo = infoTo.latest_state == null ? "???" : infoTo.latest_state.symbol;
for (const a of document.querySelectorAll("[data-input-token]")) {
(<HTMLElement>a).innerText = symbolFrom;
}
for (const a of document.querySelectorAll("[data-output-token]")) {
(<HTMLElement>a).innerText = symbolTo;
}
}
function reroute() {
console.log("Rerouting", CURRENT_ROUTE);
// Do not route if from or to are not assigned yet.
if (CURRENT_ROUTE.from == null || CURRENT_ROUTE.to == null) {
@ -82,6 +99,8 @@ function reroute() {
// Perform routing.
// TODO
ui_show_route();
}
function routeFrom(address: BlockchainAddress) {
@ -114,7 +133,7 @@ function ui_add_token(tokenState: TokenStateV1 | TokenStateV2, address: Blockcha
value="To" />
</form>
`;
spanFrom.addEventListener("click", () => routeTo(address));
spanTo.addEventListener("click", () => routeTo(address));
const spanSymbol= document.createElement("a");
spanSymbol.innerText = tokenState.symbol;
spanSymbol.title = tokenState.name;

View File

@ -12,6 +12,6 @@
"strict": true,
"sourceMap": true,
"jsx": "react",
"lib": ["dom", "es2015", "es2016", "es2017", "esnext"]
"lib": ["dom", "es2015", "es2016", "es2017", "esnext", "dom.iterable"]
}
}