|
|
|
@ -78,11 +78,42 @@ async def user(request, username=None): |
|
|
|
|
invalid = re.compile("[^A-Za-z0-9_\-\.]") |
|
|
|
|
username = re.sub(r"(?:(?:/)?\bu)?/|@|\s", "", username) |
|
|
|
|
if invalid.findall(username): |
|
|
|
|
return html(template.render(quote=quote, addresses={"btc":-1,"eth":-1,"nano":-1}, totals={"btc":-1,"eth":-1,"nano":-1}, user=username)) |
|
|
|
|
return html(template.render(quote=quote, addresses={"btc":-1,"eth":-1,"nano":-1}, totals={"btc":-1,"eth":-1,"nano":-1}, user=username, address=-1)) |
|
|
|
|
|
|
|
|
|
prices, dt = await utils.get_price() |
|
|
|
|
if dt < datetime.now()-timedelta(hours=1): |
|
|
|
|
await utils.update_price() |
|
|
|
|
|
|
|
|
|
addr_patterns = { |
|
|
|
|
"btc": re.compile(r"^[bc1|13][a-zA-HJ-NP-Z0-9]{25,43}$"), |
|
|
|
|
"eth": re.compile(r"^(0x[a-fA-F0-9]{40})$"), |
|
|
|
|
"nano": re.compile(r"^(nano_[13][1-9a-z]{59})$") |
|
|
|
|
} |
|
|
|
|
xmr_pattern = re.compile(r"^[48][0-9AB][1-9A-HJ-NP-Za-km-z]{93}$") |
|
|
|
|
addr_matches = {currency: addr_patterns[currency].match(username) for currency in addr_patterns} |
|
|
|
|
if xmr_pattern.match(username) and not any(list(addr_matches.values())): |
|
|
|
|
# if the address only matches the Monero address pattern |
|
|
|
|
return html(template.render(quote=quote, address=username, user=-2)) |
|
|
|
|
elif any(list(addr_matches.values())): |
|
|
|
|
address = username |
|
|
|
|
username = await utils.get_address_data(address) |
|
|
|
|
if username == -1: |
|
|
|
|
addresses = {currency: [] for currency in ("btc", "eth", "nano")} |
|
|
|
|
totals = {currency: 0.0 for currency in ("btc", "eth", "nano")} |
|
|
|
|
# get all information about the address (it may be on multiple blockchains) |
|
|
|
|
for currency in ("btc", "eth", "nano"): |
|
|
|
|
if addr_matches[currency]: |
|
|
|
|
balance = await utils.check_balance(address, currency) |
|
|
|
|
addresses[currency].append([address, None, balance]) |
|
|
|
|
totals[currency] += balance * float(prices[currency]) |
|
|
|
|
total_float = sum(totals[currency]*float(prices[currency]) for currency in ("btc", "eth", "nano")) |
|
|
|
|
total_usd = f"{total_float:,.2f}" |
|
|
|
|
totals = {currency: [totals[currency], f"{totals[currency]:,.{digits}f}".rstrip("0").rstrip(".")] for currency, digits in (("btc", 8), ("eth", 12), ("nano", 12))} |
|
|
|
|
return html(template.render(quote=quote, addresses=addresses, totals=totals, total_usd=total_usd, user=-1, address=address)) |
|
|
|
|
# else the username is known and all addresses of the user should show up. |
|
|
|
|
else: |
|
|
|
|
# if no address hide this info in the user page |
|
|
|
|
address = -1 |
|
|
|
|
|
|
|
|
|
addresses = await utils.get_user_data(username) |
|
|
|
|
|
|
|
|
@ -93,7 +124,7 @@ async def user(request, username=None): |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if addresses["btc"] == -2: |
|
|
|
|
return html(template.render(quote=quote, addresses={"btc":-2,"eth":-2,"nano":-2}, totals={"btc":-2,"eth":-2,"nano":-2}, user=username)) |
|
|
|
|
return html(template.render(quote=quote, addresses={"btc":-2,"eth":-2,"nano":-2}, totals={"btc":-2,"eth":-2,"nano":-2}, user=username, address=address)) |
|
|
|
|
|
|
|
|
|
# add up totals and format the balances |
|
|
|
|
|
|
|
|
@ -115,7 +146,7 @@ async def user(request, username=None): |
|
|
|
|
|
|
|
|
|
return html(template.render(quote=quote, addresses=addresses, |
|
|
|
|
totals=totals, total_usd=total_usd, |
|
|
|
|
user=username)) |
|
|
|
|
user=username, address=address)) |
|
|
|
|
|
|
|
|
|
@app.route("/ranking", name="ranking") |
|
|
|
|
async def ranking(request): |
|
|
|
|