Spaces:
Build error
Build error
File size: 6,387 Bytes
4585d4c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# Transaction History Page
# This page displays the user's transaction history, showing credits and debits
import streamlit as st
from pages import app
st.header("π Transaction History")
if not app.wallet:
st.error("β Please connect a wallet first")
st.info("π Go to 'Import/Generate Wallet' to get started")
st.stop()
# Button to refresh transaction history
col1, col2 = st.columns([3, 1])
with col1:
st.markdown("View your transaction history, including credits and debits")
with col2:
if st.button("π Refresh History", type="secondary"):
with st.spinner("Updating transaction history..."):
success = app.update_transaction_history()
if success:
st.success("Transaction history updated!")
else:
st.error("Failed to update transaction history")
st.rerun()
# If we don't have any transactions yet, try to fetch them
if not app.transactions:
with st.spinner("Fetching your transaction history..."):
app.update_transaction_history()
st.session_state.app = app
# Show transaction summary
st.markdown("---")
st.subheader("π° Balance Summary")
# Calculate summary statistics
if app.transactions:
total_credits = sum(txn.amount for txn in app.transactions if txn.is_credit and txn.status == "completed")
total_debits = sum(txn.amount for txn in app.transactions if not txn.is_credit and txn.status == "completed")
net_balance = total_credits - total_debits
# Display summary
col1, col2, col3 = st.columns(3)
with col1:
st.metric("Total Credits", f"{total_credits:.4f} APT", delta=f"{total_credits:.2f}")
with col2:
st.metric("Total Debits", f"{total_debits:.4f} APT", delta=f"-{total_debits:.2f}", delta_color="inverse")
with col3:
st.metric("Net Balance", f"{net_balance:.4f} APT")
# Display current blockchain balance
st.markdown("---")
with st.spinner("Checking current blockchain balance..."):
try:
current_balance = app.get_account_balance_sync(app.wallet.address())
st.info(f"Current blockchain balance: **{current_balance:.4f} APT**")
except Exception as e:
st.warning(f"Could not fetch current balance: {str(e)}")
else:
st.info("No transactions found. Your transaction history will appear here once you make transfers.")
# Display transaction list
st.markdown("---")
st.subheader("π Transaction List")
if app.transactions:
# Create tabs for all/credits/debits
tab1, tab2, tab3 = st.tabs(["All Transactions", "Credits (Received)", "Debits (Sent)"])
with tab1:
# All transactions
for idx, txn in enumerate(app.transactions):
with st.expander(
f"{'βοΈ Received' if txn.is_credit else 'βοΈ Sent'} {txn.amount:.4f} APT - {time.strftime('%Y-%m-%d %H:%M', time.localtime(txn.timestamp))}",
expanded=(idx == 0) # Only expand first one by default
):
st.markdown(f"""
**Transaction:** `{txn.txn_hash[:10]}...{txn.txn_hash[-6:]}`
**From:** `{txn.sender[:10]}...{txn.sender[-6:]}`
**To:** `{txn.recipient[:10]}...{txn.recipient[-6:]}`
**Amount:** {txn.amount:.8f} APT
**Status:** {txn.status.title()}
**Date:** {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(txn.timestamp))}
""")
# Add link to explorer
st.markdown(f"[View on Explorer](https://explorer.aptoslabs.com/txn/{txn.txn_hash}?network=testnet)")
with tab2:
# Credits only
credits = [txn for txn in app.transactions if txn.is_credit]
if credits:
for idx, txn in enumerate(credits):
with st.expander(
f"βοΈ Received {txn.amount:.4f} APT - {time.strftime('%Y-%m-%d %H:%M', time.localtime(txn.timestamp))}",
expanded=(idx == 0)
):
st.markdown(f"""
**Transaction:** `{txn.txn_hash[:10]}...{txn.txn_hash[-6:]}`
**From:** `{txn.sender[:10]}...{txn.sender[-6:]}`
**To:** `{txn.recipient[:10]}...{txn.recipient[-6:]}`
**Amount:** {txn.amount:.8f} APT
**Status:** {txn.status.title()}
**Date:** {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(txn.timestamp))}
""")
# Add link to explorer
st.markdown(f"[View on Explorer](https://explorer.aptoslabs.com/txn/{txn.txn_hash}?network=testnet)")
else:
st.info("No credits (received funds) found in transaction history.")
with tab3:
# Debits only
debits = [txn for txn in app.transactions if not txn.is_credit]
if debits:
for idx, txn in enumerate(debits):
with st.expander(
f"βοΈ Sent {txn.amount:.4f} APT - {time.strftime('%Y-%m-%d %H:%M', time.localtime(txn.timestamp))}",
expanded=(idx == 0)
):
st.markdown(f"""
**Transaction:** `{txn.txn_hash[:10]}...{txn.txn_hash[-6:]}`
**From:** `{txn.sender[:10]}...{txn.sender[-6:]}`
**To:** `{txn.recipient[:10]}...{txn.recipient[-6:]}`
**Amount:** {txn.amount:.8f} APT
**Status:** {txn.status.title()}
**Date:** {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(txn.timestamp))}
""")
# Add link to explorer
st.markdown(f"[View on Explorer](https://explorer.aptoslabs.com/txn/{txn.txn_hash}?network=testnet)")
else:
st.info("No debits (sent funds) found in transaction history.")
else:
st.info("No transactions found. Your transactions will appear here once you make transfers.")
# Add tips for transaction history
st.markdown("---")
st.markdown("""
### π About Transaction Tracking
- **Credits**: Funds received by your wallet
- **Debits**: Funds sent from your wallet
- **Blockchain Validation**: All transactions are verified and stored on the Aptos blockchain
- **History**: Transaction history is cached locally during your session
""") |