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

wallet-amount #925

Merged
Merged
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
37 changes: 36 additions & 1 deletion components/UI/profileCard/profileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React, {
import styles from "@styles/dashboard.module.css";
import { CDNImage } from "@components/cdn/image";
import { useStarkProfile, type Address } from "@starknet-react/core";
import Skeleton from "@mui/material/Skeleton";
import trophyIcon from "public/icons/trophy.svg";
import xpIcon from "public/icons/xpBadge.svg";
import useCreationDate from "@hooks/useCreationDate";
Expand All @@ -21,6 +22,11 @@ import { getTweetLink } from "@utils/browserService";
import { hexToDecimal } from "@utils/feltService";
import { TEXT_TYPE } from "@constants/typography";
import Typography from "../typography/typography";
import { calculateTotalBalance } from "../../../services/argentPortfolioService";
const MAX_RETRIES = 1000;
const RETRY_DELAY = 2000;
const controller = new AbortController();
const { signal } = controller;

type ProfileCardProps = {
rankingData: RankingData;
Expand All @@ -36,6 +42,7 @@ const ProfileCard: FunctionComponent<ProfileCardProps> = ({
isOwner,
}) => {
const [userXp, setUserXp] = useState<number>();
const [totalBalance, setTotalBalance] = useState<number | null>(null);
Marchand-Nicolas marked this conversation as resolved.
Show resolved Hide resolved
const sinceDate = useCreationDate(identity);
const formattedAddress = (
identity.owner.startsWith("0x") ? identity.owner : `0x${identity.owner}`
Expand All @@ -48,6 +55,30 @@ const ProfileCard: FunctionComponent<ProfileCardProps> = ({
return rank;
}, []);

useEffect(() => {
const fetchTotalBalance = async () => {
let attempts = 0;
while (true) {
try {
const balance = await calculateTotalBalance(formattedAddress, "USD", {signal});
setTotalBalance(balance);
return; // Exit if successful
} catch (err) {
attempts++;
console.error(`Attempt ${attempts} - Error fetching total balance:`, err);

if (attempts >= MAX_RETRIES) {
console.error("Failed to fetch total balance after multiple attempts.");
} else {
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
}
}
}
};

fetchTotalBalance();
}, [formattedAddress]);

const computeData = useCallback(() => {
if (
rankingData &&
Expand Down Expand Up @@ -108,7 +139,11 @@ const ProfileCard: FunctionComponent<ProfileCardProps> = ({
type={TEXT_TYPE.BODY_SMALL}
className={`${styles.wallet_amount} font-extrabold`}
>
$2,338.34
{totalBalance !== null ? (
`$${totalBalance.toFixed(2)}`
) : (
<Skeleton variant="text" width={60} height={30} />
)}
</Typography>
<EyeIcon />
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/admin/questDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const AdminQuestDetails: FunctionComponent<QuestDetailsProps> = ({
key={task.id}
name={task.name}
customError={
task?.name?.includes("Discord" || "discord")
task?.name?.toLowerCase().includes("discord")
? customError
: ""
}
Expand Down
2 changes: 1 addition & 1 deletion components/quests/questDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ const QuestDetails: FunctionComponent<QuestDetailsProps> = ({
key={task.id}
name={task.name}
customError={
task.name?.includes("Discord" || "discord")
task?.name?.toLowerCase().includes("discord")
? customError
: ""
}
Expand Down
Loading