Skip to content

Commit

Permalink
Merge pull request #450 from OthmanImam/AddNewHistoryBlock#448
Browse files Browse the repository at this point in the history
Add new history block #448
  • Loading branch information
djeck1432 authored Feb 25, 2025
2 parents 55431a5 + 55856d3 commit 5ca9d2f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
20 changes: 20 additions & 0 deletions apps/dashboard_app/charts/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This module defines the Dashboard class for rendering a DeRisk dashboard using Streamlit.
"""

import numpy as np
import pandas as pd
import plotly
Expand All @@ -25,6 +26,7 @@
get_bar_chart_figures,
get_main_chart_figure,
get_specific_loan_usd_amounts,
get_user_history
)
from .utils import (
get_protocol_data_mappings,
Expand All @@ -33,6 +35,7 @@
transform_loans_data,
transform_main_chart_data,
)



class Dashboard:
Expand Down Expand Up @@ -385,6 +388,22 @@ def load_comparison_lending_protocols_chart(self):
figure = self._plot_chart(token, "supply")
st.plotly_chart(figure, True)

def get_user_history(self, wallet_id):
"""
Fetch and return the transaction history for a specific user.
"""
user_data = get_user_history(wallet_id)
if user_data is None or user_data.empty:
st.error("No data found for this user.")
return None

user_data.columns = [CommonValues.protocol.value, CommonValues.total_usd.value]
user_data = user_data.sort_values(CommonValues.total_usd.value, ascending=False)
user_data.reset_index(drop=True, inplace=True)

st.dataframe(user_data)
return user_data

# TODO: add last update functionality

def load_leaderboard(self):
Expand Down Expand Up @@ -465,4 +484,5 @@ def run(self):
self.load_top_loans_chart()
self.load_detail_loan_chart()
self.load_comparison_lending_protocols_chart()
self.get_user_history()
self.load_leaderboard()
26 changes: 25 additions & 1 deletion apps/dashboard_app/charts/main_chart_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import math
from decimal import Decimal

import pandas as pd
import streamlit as st
import plotly.express
import plotly.graph_objs
from shared.amms import SwapAmm
Expand Down Expand Up @@ -385,4 +385,28 @@ def get_user_history(user_id: str, df: pd.DataFrame) -> pd.DataFrame:
print(f"User ID {user_id} not found in the DataFrame.")
return pd.DataFrame()

def display_user_history_chart(df: pd.DataFrame):
"""
Displays a chart based on the user's wallet ID input to show their transaction history.
Args:
df (pd.DataFrame): The DataFrame containing all transactions.
"""
st.subheader("Input Wallet ID to View History")

wallet_id = st.text_input("Enter Wallet ID:")

if wallet_id:
user_history_data = get_user_history(wallet_id, df)

if not user_history_data.empty:
st.dataframe(user_history_data)

st.subheader(f"Collateral and Debt History for Wallet ID: {wallet_id}")
chart_data = user_history_data.set_index("Transaction")[["Collateral", "Debt"]]
st.line_chart(chart_data)
else:
st.error("No data found for this wallet ID.")



0 comments on commit 5ca9d2f

Please sign in to comment.