Skip to content

Commit

Permalink
ui
Browse files Browse the repository at this point in the history
  • Loading branch information
doffn authored Jan 21, 2025
1 parent 4a0775a commit 8b2bb8e
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
95 changes: 95 additions & 0 deletions api/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,100 @@ def dex():
</body>
'''

@app.route('/ui', methods=['GET'])
def ui():
try:
# Fetch the token data
new = DexBot(Api, ID, chain=False)
mes = new.format_token_data() # This will connect and fetch the token data
tokens = json.loads(json.dumps(mes)) # Parse JSON data into a Python object

token_rows = ""
for token in tokens:
# Extract data safely and handle missing values
chain_id = token.get("chainId", "Unknown Chain")
dex_id = token.get("dexId", "Unknown Dex")
url = token.get("url", "#")
base_token = token.get("baseToken", {})
price_usd = token.get("priceUsd", "N/A")
volume = token.get("volume", {}).get("h24", 0)
image_url = token.get("info", {}).get("imageUrl", "https://via.placeholder.com/50")
socials = token.get("info", {}).get("socials", [])
token_name = base_token.get("name", "Unknown Token")
token_symbol = base_token.get("symbol", "N/A")

# Create HTML rows for each token
token_rows += f'''
<div class="token-row">
<div class="token-image">
<img src="{image_url}" alt="{token_symbol}">
</div>
<div class="token-info">
<h3>{token_name} ({token_symbol})</h3>
<p>Price: $ {float(price_usd):.2f}</p>
<p>Volume (24h): $ {int(volume):,}</p>
<p>Chain: {chain_id}, Dex: {dex_id}</p>
</div>
<div class="token-links">
<a href="{url}" target="_blank" class="btn">View on Dex</a>
{''.join([f'<a href="{social.get("url", "#")}" target="_blank" class="icon-{social.get("type", "link")}"><i class="bx bxl-{social.get("type", "link")}"></i></a>' for social in socials])}
</div>
</div>
'''

return f'''
<html>
<head>
<style>
body {{
font-family: Arial, sans-serif;
background-color: black;
color: white;
margin: 0;
padding: 0;
}}
.token-container {{
display: flex;
flex-direction: column;
gap: 1rem;
padding: 1rem;
}}
.token-row {{
display: flex;
gap: 1rem;
border: 1px solid white;
padding: 1rem;
border-radius: 8px;
background: #333;
}}
.token-image img {{
width: 50px;
height: 50px;
border-radius: 50%;
}}
.token-info {{
flex-grow: 1;
}}
.token-links a {{
margin-right: 0.5rem;
text-decoration: none;
color: #fff;
background: #007bff;
padding: 0.5rem 1rem;
border-radius: 5px;
}}
</style>
</head>
<body>
<div class="token-container">
{token_rows}
</div>
</body>
</html>
'''
except Exception as e:
return f"<h1>Error: {str(e)}</h1>"


if __name__ == '__main__':
app.run(debug=True)
2 changes: 1 addition & 1 deletion vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dest": "api/index.py"
},
{
"src": "/service",
"src": "/ui",
"dest": "api/index.py"
},
{
Expand Down

0 comments on commit 8b2bb8e

Please sign in to comment.