Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new history block #448 #450

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 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 _plot_chart(self, token: str, stats_type: str) -> plotly.express.data:
Expand Down Expand Up @@ -427,3 +446,7 @@ def run(self):
self.load_top_loans_chart()
self.load_detail_loan_chart()
self.load_comparison_lending_protocols_chart()
self.get_user_history()



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.")