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

Fetch data from /api/get_stats and display in frontend #143

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Changes from 1 commit
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
66 changes: 48 additions & 18 deletions frontend/src/pages/spotnet/information/Informaion.jsx
whateverfw marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,41 +1,71 @@
import './information.css'
import './information.css';
import { ReactComponent as Star } from "../../../assets/particles/star.svg";
import React from "react";
import React, { useEffect, useState } from "react";

const Informaion = () => {
const Information = () => {
const [data, setData] = useState({ total_opened_amount: 0, unique_users: 0 });
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);

useEffect(() => {
const fetchData = async () => {
try {
const response = await fetch(`${process.env.REACT_APP_BACKEND_URL}/api/get_stats`);
if (!response.ok) {
whateverfw marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('Failed to fetch data');
}
const result = await response.json();
setData({
total_opened_amount: result.total_opened_amount,
unique_users: result.unique_users,
});
} catch (error) {
setError(error.message);
} finally {
setLoading(false);
}
};

fetchData();
}, []);

const starData = [
{ top: 9, left: -6.2, size: 20 },
{ top: 9, left: 39, size: 15,},
{ top: 9, left: 39, size: 15 },
{ top: -8, left: 85, size: 18 },
{ top: 74, left: 43, size: 22 },
]
return(
];

return (
<div className="information">
<div className="card-info__container">
<div className="card-info flex">
<h1>TVL</h1>
<h3>$245.7k</h3>
<h3>{loading ? "Loading..." : error ? `Error: ${error}` : data.total_opened_amount}</h3>
</div>
whateverfw marked this conversation as resolved.
Show resolved Hide resolved
<div className="card-gradients infos">
<div className="card-gradient"></div>
<div className="card-gradient"></div>
</div>
<div className="card-info flex">
<h1>TVL</h1>
<h3>$245.7k</h3>
<h1>Users</h1>
<h3>{loading ? "Loading..." : error ? `Error: ${error}` : data.unique_users}</h3>
</div>
{starData.map((star, index) => (
<Star key={index} style={{
position: 'absolute',
top: `${star.top}%`,
left: `${star.left}%`,
width: `${star.size}%`,
height: `${star.size}%`
}}/>
<Star
key={index}
whateverfw marked this conversation as resolved.
Show resolved Hide resolved
style={{
position: 'absolute',
top: `${star.top}%`,
left: `${star.left}%`,
width: `${star.size}%`,
height: `${star.size}%`
}}
/>
))}
</div>
</div>
)
);
}

export default Informaion;
export default Information;
Loading