From a877b5bf9e8f2f368f687623ae60803995f93611 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 31 Jan 2025 16:17:31 +1100 Subject: [PATCH] feat: Updated rendering and added support for custom explorers --- render.py | 67 +++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/render.py b/render.py index 6a7b697..acf00d8 100644 --- a/render.py +++ b/render.py @@ -3,6 +3,14 @@ import json import urllib.parse from flask import render_template from domainLookup import punycode_to_emoji +import os + +# Get Explorer URL +TX_EXPLORER_URL = os.getenv("EXPLORER_TX") +if TX_EXPLORER_URL is None: + TX_EXPLORER_URL = "https://niami.io/tx/" + + def domains(domains, mobile=False): html = '' @@ -21,10 +29,17 @@ def domains(domains, mobile=False): if emoji != name: name = f'{emoji} ({name})' + + link = f'/manage/{domain["name"]}' + link_action = "Manage" + if domain['registered'] == False: + link_action = "Register" + link = f'/auction/{domain["name"]}/register' + if not mobile: - html += f'{name}{expires} days{paid} HNSManage' + html += f'{name}{expires} days{paid:,.2f} HNS{link_action}' else: - html += f'{name}{expires} days' + html += f'{name}{expires} days' return html @@ -58,17 +73,15 @@ def transactions(txs): amount += output["value"] amount = amount / 1000000 - amount = round(amount, 2) - amount = "{:,}".format(amount) - hash = "" + hash[:8] + "..." + hash = f"{hash[:8]}..." if confirmations < 5: - confirmations = "" + str(confirmations) + "" + confirmations = f"{confirmations}" else: - confirmations = "" + str(confirmations) + "" + confirmations = f"{confirmations:,}" - html += f'{action}{address}{hash}{confirmations}{amount} HNS' + html += f'{action}{address}{hash}{confirmations}{amount:,.2f} HNS' return html @@ -92,14 +105,14 @@ def dns(data, edit=False): elif entry['type'] == 'DS': - ds = str(entry['keyTag']) + " " + str(entry['algorithm']) + " " + str(entry['digestType']) + " " + entry['digest'] + ds = f'{entry['keyTag']} {entry['algorithm']} {entry['digestType']} {entry['digest']}' html_output += f"{ds}\n" else: value = "" for key, val in entry.items(): if key != 'type': - value += str(val) + " " + value += f'{val} ' html_output += f"{value}\n" if edit: @@ -119,18 +132,16 @@ def txs(data): for entry in data: html_output += f"{entry['action']}\n" - html_output += f"{entry['txid'][:8]}...\n" + html_output += f"{entry['txid'][:8]}...\n" amount = entry['amount'] amount = amount / 1000000 - amount = round(amount, 2) if entry['blind'] == None: - html_output += f"{amount} HNS\n" + html_output += f"{amount:,.2f} HNS\n" else: blind = entry['blind'] blind = blind / 1000000 - blind = round(blind, 2) - html_output += f"{amount} + {blind} HNS\n" + html_output += f"{amount:,.2f} + {blind:,.2f} HNS\n" html_output += f"{timestamp_to_readable_time(entry['time'])}\n" html_output += f"\n" @@ -149,20 +160,17 @@ def bids(bids,reveals): for bid in bids: lockup = bid['lockup'] lockup = lockup / 1000000 - lockup = round(lockup, 2) html += "" - html += f"{lockup} HNS" + html += f"{lockup:,.2f} HNS" revealed = False for reveal in reveals: if reveal['bid'] == bid['prevout']['hash']: revealed = True value = reveal['value'] value = value / 1000000 - value = round(value, 2) - html += f"{value} HNS" + html += f"{value:,.2f} HNS" bidValue = lockup - value - bidValue = round(bidValue, 2) - html += f"{bidValue} HNS" + html += f"{bidValue:,.2f} HNS" break if not revealed: html += f"Hidden until reveal" @@ -183,22 +191,17 @@ def bidDomains(bids,domains, sortState=False): if bid['name'] == domain['name']: lockup = bid['lockup'] lockup = lockup / 1000000 - lockup = round(lockup, 2) bidValue = bid['value'] / 1000000 - bidValue = round(bidValue, 2) blind = lockup - bidValue - bidValue = "{:,}".format(bidValue) - blind = round(blind, 2) - blind = "{:,}".format(blind) - bidDisplay = f'{bidValue} HNS + {blind} HNS blind' + bidDisplay = f'{bidValue:,.2f} HNS + {blind:,.2f} HNS blind' html += "" html += f"{domain['name']}" html += f"{domain['state']}" html += f"{bidDisplay}" - html += f"{bid['height']}" + html += f"{bid['height']:,}" html += "" else: for domain in domains: @@ -206,19 +209,15 @@ def bidDomains(bids,domains, sortState=False): if bid['name'] == domain['name']: lockup = bid['lockup'] lockup = lockup / 1000000 - lockup = round(lockup, 2) bidValue = bid['value'] / 1000000 - bidValue = round(bidValue, 2) blind = lockup - bidValue - bidValue = "{:,}".format(bidValue) - blind = "{:,}".format(blind) - bidDisplay = f'{bidValue} HNS + {blind} HNS blind' + bidDisplay = f'{bidValue:,.2f} HNS + {blind:,.2f} HNS blind' html += "" html += f"{domain['name']}" html += f"{domain['state']}" html += f"{bidDisplay}" - html += f"{domain['height']}" + html += f"{domain['height']:,}" html += "" return html