feat: Simplify tx page

This commit is contained in:
2025-06-27 14:08:01 +10:00
parent eead0d03cc
commit df09a32280
3 changed files with 50 additions and 28 deletions

Binary file not shown.

View File

@@ -30,6 +30,7 @@ elif HSD_NETWORK == "regtest":
HSD_WALLET_PORT = 14039 HSD_WALLET_PORT = 14039
HSD_NODE_PORT = 14037 HSD_NODE_PORT = 14037
CONVERT_NAME = False
hsd = api.hsd(HSD_API, HSD_IP, HSD_NODE_PORT) hsd = api.hsd(HSD_API, HSD_IP, HSD_NODE_PORT)
@@ -96,11 +97,20 @@ def transactions(txs):
if len(txs) == 0: if len(txs) == 0:
return '<tr><td colspan="5">No transactions found</td></tr>' return '<tr><td colspan="5">No transactions found</td></tr>'
html = '' html = ''
for tx in txs: print(f"Processing {len(txs)} transactions")
for tx in txs:
action = "HNS Transfer" action = "HNS Transfer"
address = tx["outputs"][0]["address"] address = tx["outputs"][0]["address"]
hash = tx["hash"] hash = tx["hash"]
confirmations=tx["confirmations"] confirmations=tx["confirmations"]
mined_date = "Pending"
if confirmations >= 1:
mined_date = tx["mdate"]
if mined_date is None:
mined_date = "Pending"
else:
# Format 2025-06-27T01:49:14Z
mined_date = datetime.datetime.strptime(mined_date, "%Y-%m-%dT%H:%M:%SZ").strftime("%d %b %Y")
incomming = True incomming = True
amount = 0 amount = 0
isMulti = False isMulti = False
@@ -140,36 +150,42 @@ def transactions(txs):
humanAction = action humanAction = action
if action == "HNS Transfer": if action == "HNS Transfer":
if amount > 0: if amount >= 0:
humanAction = "Received HNS" humanAction = f"Received {amount:,.2f} HNS"
else: else:
humanAction = "Sent HNS" humanAction = f"Sent {(amount*-1):,.2f} HNS"
elif action == "FINALIZE": elif action == "FINALIZE":
if incomming and not isMulti: if incomming and not isMulti:
name = hsd.rpc_getNameByHash(nameHashes[0]) humanAction = "Received Domain"
if name["error"] is None: if CONVERT_NAME:
name = name["result"] name = hsd.rpc_getNameByHash(nameHashes[0])
humanAction = f"Received {renderDomain(name)}" if name["error"] is None:
name = name["result"]
humanAction = f"Received {renderDomain(name)}"
elif incomming and isMulti: elif incomming and isMulti:
humanAction = "Received Multiple Domains" humanAction = "Received Multiple Domains"
elif not isMulti: elif not isMulti:
name = hsd.rpc_getNameByHash(nameHashes[0]) humanAction = "Finalized Domain Transfer"
if name["error"] is None: if CONVERT_NAME:
name = name["result"] name = hsd.rpc_getNameByHash(nameHashes[0])
humanAction = f"Finalized {renderDomain(name)}" if name["error"] is None:
name = name["result"]
humanAction = f"Finalized {renderDomain(name)}"
else: else:
humanAction = "Finalized Multiple Domain Transfers" humanAction = "Finalized Multiple Domain Transfers"
elif isMulti: elif isMulti:
humanAction = actionMapPlural.get(action, "Unknown Action") humanAction = actionMapPlural.get(action, "Unknown Action")
else: else:
humanAction = actionMap.get(action, "Unknown Action") humanAction = actionMap.get(action, "Unknown Action")
name = hsd.rpc_getNameByHash(nameHashes[0]) if CONVERT_NAME:
if name["error"] is None: name = hsd.rpc_getNameByHash(nameHashes[0])
name = name["result"] if name["error"] is None:
name = name["result"]
else:
name = None
humanAction += renderDomain(name) if name else "domain"
else: else:
name = None humanAction += "domain"
humanAction += renderDomain(name) if name else "domain"
if amount < 0: if amount < 0:
amount = f"<span style='color: red;'>{amount:,.2f}</span>" amount = f"<span style='color: red;'>{amount:,.2f}</span>"
elif amount > 0: elif amount > 0:
@@ -179,12 +195,18 @@ def transactions(txs):
# hash = f"<a target='_blank' href='{TX_EXPLORER_URL}{hash}'>{hash[:8]}...</a>" # hash = f"<a target='_blank' href='{TX_EXPLORER_URL}{hash}'>{hash[:8]}...</a>"
txdate = ""
if confirmations < 5: if confirmations < 5:
confirmations = f"<td class='hide-mobile' style='background-color: red;'>{confirmations}</td>" txdate = f"<span style='color: red;'>{mined_date}</span>"
else: else:
confirmations = f"<td class='hide-mobile'>{confirmations:,}</td>" txdate = f"<span>{mined_date}</span>"
# confirmations = f"<td class='hide-mobile'>{confirmations:,}</td>"
html += f'<tr><td><a style="color:var(--bs-body-color);" target="_blank" href="{TX_EXPLORER_URL}{hash}">{humanAction}</a></td><td class="hide-mobile">{address}</td>{confirmations}<td class="amount-column">{amount} HNS</td></tr>' html += f'''
<tr>
<td style='white-space: nowrap;'>{txdate}</td>
<td><a style="color:var(--bs-body-color);" target="_blank" href="{TX_EXPLORER_URL}{hash}">{humanAction}</a></td>
</tr>
'''
return html return html

View File

@@ -82,10 +82,10 @@
<table id="dataTable" class="table my-0"> <table id="dataTable" class="table my-0">
<thead> <thead>
<tr> <tr>
<th>Date</th>
<th>Transaction</th> <th>Transaction</th>
<th class="hide-mobile">Address</th> <!-- <th class="hide-mobile">Address</th> -->
<th class="hide-mobile">Confirmations</th> <!-- <th class="amount-column">Amount</th> -->
<th class="amount-column">Amount</th>
</tr> </tr>
</thead> </thead>
<tbody id="transactions-tbody"> <tbody id="transactions-tbody">
@@ -102,10 +102,10 @@
</tbody> </tbody>
<tfoot> <tfoot>
<tr> <tr>
<td><strong>Date</strong></td>
<td><strong>Transaction</strong></td> <td><strong>Transaction</strong></td>
<td class="hide-mobile"><strong>Address</strong></td> <!-- <td class="hide-mobile"><strong>Address</strong></td> -->
<td class="hide-mobile"><strong>Confirmations</strong></td> <!-- <td class="amount-column"><strong>Amount</strong></td> -->
<td class="amount-column"><strong>Amount</strong></td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>