feat: Add js loading of /tx page
All checks were successful
Build Docker / Build Image (push) Successful in 2m44s
All checks were successful
Build Docker / Build Image (push) Successful in 2m44s
This commit is contained in:
85
main.py
85
main.py
@@ -81,7 +81,10 @@ def transactions():
|
||||
return redirect("/login")
|
||||
|
||||
account = account_module.check_account(request.cookies.get("account"))
|
||||
# Get the transactions
|
||||
if not account:
|
||||
return redirect("/logout")
|
||||
|
||||
# Get the page parameter
|
||||
page = request.args.get('page')
|
||||
try:
|
||||
page = int(page)
|
||||
@@ -90,34 +93,10 @@ def transactions():
|
||||
|
||||
if page < 1:
|
||||
page = 1
|
||||
|
||||
# Check for force refresh parameter
|
||||
force_refresh = request.args.get('refresh') == 'true'
|
||||
|
||||
# Create a cache key based on account and page
|
||||
cache_key = f"{account}_{page}"
|
||||
|
||||
# Check if data is in cache and not expired
|
||||
current_time = time.time()
|
||||
if not force_refresh and cache_key in tx_cache and (current_time - tx_cache[cache_key]['time'] < TX_CACHE_TIMEOUT):
|
||||
transactions = tx_cache[cache_key]['data']
|
||||
txCount = len(transactions)
|
||||
transactions_html = tx_cache[cache_key]['html']
|
||||
else:
|
||||
# Fetch transactions from account module
|
||||
transactions = account_module.getTransactions(account, page)
|
||||
txCount = len(transactions)
|
||||
transactions_html = render.transactions(transactions)
|
||||
|
||||
# Store in cache
|
||||
tx_cache[cache_key] = {
|
||||
'data': transactions,
|
||||
'html': transactions_html,
|
||||
'time': current_time
|
||||
}
|
||||
# Return the template with loading state - transactions will be loaded via AJAX
|
||||
return render_template("tx.html", account=account,
|
||||
tx=transactions_html,
|
||||
page=page, txCount=txCount)
|
||||
page=page, txCount=0)
|
||||
|
||||
|
||||
@app.route('/send')
|
||||
@@ -1084,6 +1063,7 @@ def reveal_auction(domain):
|
||||
# Check if the user is logged in
|
||||
if request.cookies.get("account") is None:
|
||||
return redirect("/login")
|
||||
|
||||
|
||||
if not account_module.check_account(request.cookies.get("account")):
|
||||
return redirect("/logout")
|
||||
@@ -1529,6 +1509,57 @@ def api_hsd(function):
|
||||
|
||||
return jsonify({"error": "Invalid function", "result": "Invalid function"}), 400
|
||||
|
||||
@app.route('/api/v1/transactions', methods=["GET"])
|
||||
def api_transactions():
|
||||
# Check if the user is logged in
|
||||
if request.cookies.get("account") is None:
|
||||
return jsonify({"error": "Not logged in"})
|
||||
|
||||
account = account_module.check_account(request.cookies.get("account"))
|
||||
if not account:
|
||||
return jsonify({"error": "Invalid account"})
|
||||
|
||||
# Get the page parameter
|
||||
page = request.args.get('page')
|
||||
try:
|
||||
page = int(page)
|
||||
except:
|
||||
page = 1
|
||||
|
||||
if page < 1:
|
||||
page = 1
|
||||
|
||||
# Check for force refresh parameter
|
||||
force_refresh = request.args.get('refresh') == 'true'
|
||||
|
||||
# Create a cache key based on account and page
|
||||
cache_key = f"{account}_{page}"
|
||||
|
||||
# Check if data is in cache and not expired
|
||||
current_time = time.time()
|
||||
if not force_refresh and cache_key in tx_cache and (current_time - tx_cache[cache_key]['time'] < TX_CACHE_TIMEOUT):
|
||||
transactions = tx_cache[cache_key]['data']
|
||||
txCount = len(transactions)
|
||||
transactions_html = tx_cache[cache_key]['html']
|
||||
else:
|
||||
# Fetch transactions from account module
|
||||
transactions = account_module.getTransactions(account, page)
|
||||
txCount = len(transactions)
|
||||
transactions_html = render.transactions(transactions)
|
||||
|
||||
# Store in cache
|
||||
tx_cache[cache_key] = {
|
||||
'data': transactions,
|
||||
'html': transactions_html,
|
||||
'time': current_time
|
||||
}
|
||||
|
||||
return jsonify({
|
||||
"html": transactions_html,
|
||||
"txCount": txCount,
|
||||
"page": page
|
||||
})
|
||||
|
||||
@app.route('/api/v1/wallet/<function>', methods=["GET"])
|
||||
def api_wallet(function):
|
||||
# Check if the user is logged in
|
||||
|
||||
Reference in New Issue
Block a user