feat: Add sync and fix emoji error

This commit is contained in:
Nathan Woodburn 2023-12-29 11:42:20 +11:00
parent 5f01cf5e83
commit 6aeb02cdd2
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
11 changed files with 77 additions and 41 deletions

View File

@ -199,3 +199,8 @@ def getDNS(domain: str):
"error": response['error']['message'] "error": response['error']['message']
} }
return response['result']['records'] return response['result']['records']
def getNodeSync():
response = hsd.getInfo()
return response['chain']['progress']*100

View File

@ -10,7 +10,6 @@ import httpx
from requests_doh import DNSOverHTTPSSession, add_dns_provider from requests_doh import DNSOverHTTPSSession, add_dns_provider
import requests import requests
def hip2(domain: str): def hip2(domain: str):
domain_check = False domain_check = False
try: try:
@ -142,10 +141,16 @@ def niami_info(domain: str):
return False return False
response = response.json() response = response.json()
output = { if response["data"]["owner_tx_data"] is not None:
"owner": response["data"]["owner_tx_data"]["address"], output = {
"dns": response["data"]["dnsData"] "owner": response["data"]["owner_tx_data"]["address"],
} "dns": response["data"]["dnsData"]
}
else:
output = {
"owner": None,
"dns": []
}
transactions = requests.get(f"https://api.niami.io/txs/{domain}") transactions = requests.get(f"https://api.niami.io/txs/{domain}")
if transactions.status_code != 200: if transactions.status_code != 200:
@ -156,3 +161,8 @@ def niami_info(domain: str):
return output return output
def emoji_to_punycode(emoji):
try:
return emoji.encode("idna").decode("ascii")
except Exception as e:
return ""

61
main.py
View File

@ -40,7 +40,8 @@ def index():
return render_template("index.html", account=account, available=available, return render_template("index.html", account=account, available=available,
total=total, pending=pending, domains=domains, domain_count=domain_count) total=total, pending=pending, domains=domains,
domain_count=domain_count, sync=account_module.getNodeSync())
#region Transactions #region Transactions
@app.route('/tx') @app.route('/tx')
@ -55,7 +56,8 @@ def transactions():
transactions = account_module.getTransactions(account) transactions = account_module.getTransactions(account)
transactions = render.transactions(transactions) transactions = render.transactions(transactions)
return render_template("tx.html", account=account, tx=transactions) return render_template("tx.html", account=account, sync=account_module.getNodeSync(),
tx=transactions)
@app.route('/send') @app.route('/send')
@ -82,8 +84,8 @@ def send_page():
amount = request.args.get("amount") amount = request.args.get("amount")
return render_template("send.html", account=account,max=max,message=message, return render_template("send.html", account=account,sync=account_module.getNodeSync(),
address=address,amount=amount) max=max,message=message,address=address,amount=amount)
@app.route('/send', methods=["POST"]) @app.route('/send', methods=["POST"])
def send(): def send():
@ -137,7 +139,8 @@ def receive():
address = account_module.getAddress(account) address = account_module.getAddress(account)
return render_template("receive.html", account=account, address=address) return render_template("receive.html", account=account,sync=account_module.getNodeSync(),
address=address)
@app.route('/success') @app.route('/success')
def success(): def success():
@ -150,7 +153,8 @@ def success():
return redirect("/logout") return redirect("/logout")
tx = request.args.get("tx") tx = request.args.get("tx")
return render_template("success.html", account=account, tx=tx) return render_template("success.html", account=account,sync=account_module.getNodeSync(),
tx=tx)
@app.route('/checkaddress') @app.route('/checkaddress')
def check_address(): def check_address():
@ -175,18 +179,21 @@ def search():
search_term = request.args.get("q") search_term = request.args.get("q")
search_term = search_term.lower().strip() search_term = search_term.lower().strip()
# Convert emoji to punycode
search_term = domainLookup.emoji_to_punycode(search_term)
if len(search_term) == 0: if len(search_term) == 0:
return redirect("/") return redirect("/")
domain = account_module.getDomain(search_term) domain = account_module.getDomain(search_term)
if 'error' in domain: if 'error' in domain:
return render_template("search.html", account=account, search_term=search_term, domain=domain['error']) return render_template("search.html", account=account,sync=account_module.getNodeSync(),
search_term=search_term, domain=domain['error'])
print(domain)
if domain['info'] is None: if domain['info'] is None:
return render_template("search.html", account=account, search_term=search_term, return render_template("search.html", account=account, sync=account_module.getNodeSync(),
domain=search_term, state="AVAILABLE", next="Available Now") search_term=search_term,domain=search_term,
state="AVAILABLE", next="Available Now")
state = domain['info']['state'] state = domain['info']['state']
@ -198,6 +205,15 @@ def search():
state = 'REGISTERED' state = 'REGISTERED'
expires = domain['info']['stats']['daysUntilExpire'] expires = domain['info']['stats']['daysUntilExpire']
next = f"Expires in ~{expires} days" next = f"Expires in ~{expires} days"
elif state == 'OPENING':
print(domain['info']['stats'])
next = "Bidding opens in ~" + str(domain['info']['stats']['blocksUntilBidding']) + " blocks"
elif state == 'BIDDING':
next = "Reveal in ~" + str(domain['info']['stats']['blocksUntilReveal']) + " blocks"
elif state == 'REVEAL':
print(domain['info']['stats'])
next = "Reveal ends in ~" + str(domain['info']['stats']['blocksUntilClose']) + " blocks"
domain_info = domainLookup.niami_info(search_term) domain_info = domainLookup.niami_info(search_term)
@ -218,9 +234,10 @@ def search():
dns = render.dns(dns) dns = render.dns(dns)
txs = render.txs(txs) txs = render.txs(txs)
return render_template("search.html", account=account, search_term=search_term, return render_template("search.html", account=account, sync=account_module.getNodeSync(),
domain=domain['info']['name'],raw=domain, search_term=search_term,domain=domain['info']['name'],
state=state, next=next, owner=owner, dns=dns, txs=txs) raw=domain,state=state, next=next, owner=owner,
dns=dns, txs=txs)
@app.route('/manage/<domain>') @app.route('/manage/<domain>')
def manage(domain): def manage(domain):
@ -242,15 +259,16 @@ def manage(domain):
domain_info = account_module.getDomain(domain) domain_info = account_module.getDomain(domain)
if 'error' in domain_info: if 'error' in domain_info:
return render_template("manage.html", account=account, domain=domain, error=domain_info['error']) return render_template("manage.html", account=account, sync=account_module.getNodeSync(),
domain=domain, error=domain_info['error'])
expiry = domain_info['info']['stats']['daysUntilExpire'] expiry = domain_info['info']['stats']['daysUntilExpire']
dns = account_module.getDNS(domain) dns = account_module.getDNS(domain)
dns = render.dns(dns) dns = render.dns(dns)
return render_template("manage.html", account=account, domain=domain, return render_template("manage.html", account=account, sync=account_module.getNodeSync(),
expiry=expiry, dns=dns) domain=domain,expiry=expiry, dns=dns)
@app.route('/manage/<domain>/renew') @app.route('/manage/<domain>/renew')
@ -274,7 +292,8 @@ def renew(domain):
@app.route('/login') @app.route('/login')
def login(): def login():
if 'message' in request.args: if 'message' in request.args:
return render_template("login.html", error=request.args.get("message")) return render_template("login.html", sync=account_module.getNodeSync(),
error=request.args.get("message"))
return render_template("login.html") return render_template("login.html")
@ -287,13 +306,15 @@ def login_post():
# Check if the account is valid # Check if the account is valid
if account.count(":") > 0: if account.count(":") > 0:
return render_template("login.html", error="Invalid account") return render_template("login.html", sync=account_module.getNodeSync(),
error="Invalid account")
account = account + ":" + password account = account + ":" + password
# Check if the account is valid # Check if the account is valid
if not account_module.check_account(account): if not account_module.check_account(account):
return render_template("login.html", error="Invalid account") return render_template("login.html", sync=account_module.getNodeSync(),
error="Invalid account")
# Set the cookie # Set the cookie

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light"> <nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button> <div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get"> <form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div> <div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form> </form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto"> <ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a> <li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown"> <div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light"> <nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button> <div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get"> <form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div> <div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form> </form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto"> <ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a> <li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown"> <div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light"> <nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button> <div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get"> <form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div> <div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form> </form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto"> <ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a> <li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown"> <div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light"> <nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button> <div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get"> <form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div> <div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form> </form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto"> <ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a> <li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown"> <div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light"> <nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button> <div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get"> <form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div> <div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form> </form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto"> <ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a> <li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown"> <div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light"> <nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button> <div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get"> <form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div> <div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form> </form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto"> <ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a> <li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown"> <div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light"> <nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button> <div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get"> <form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div> <div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form> </form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto"> <ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a> <li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown"> <div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">

View File

@ -39,8 +39,8 @@
<nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light"> <nav class="navbar navbar-expand bg-white shadow mb-4 topbar static-top navbar-light">
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button> <div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
<form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get"> <form class="d-none d-sm-inline-block me-auto ms-md-3 my-2 my-md-0 mw-100 navbar-search" action="/search" method="get">
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div> <div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for domain" name="q" value="{{search_term}}"><button class="btn btn-primary py-0" type="submit"><i class="fas fa-search"></i></button></div>
</form> </form><span>Sync: {{sync}}%</span>
<ul class="navbar-nav flex-nowrap ms-auto"> <ul class="navbar-nav flex-nowrap ms-auto">
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a> <li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown"> <div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">