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

upd: sGEM1 price #384

Merged
merged 1 commit into from
Jan 30, 2025
Merged
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
25 changes: 22 additions & 3 deletions src/modules/Users/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import { findAllValidPeriods } from "./functions";

import { account, apiData } from "@store";
import { account, apiData, assetsPrices } from "@store";

import { contests } from "@stabilitydao/stability";

Expand All @@ -42,18 +42,20 @@

const Users = (): JSX.Element => {
const $apiData: ApiMainReply | undefined = useStore(apiData);
const $assetsPrices = useStore(assetsPrices);
const $account = useStore(account);

// const activeContestInfo = contests?.[currentPeriod];
// const pastContestInfo = contests?.[previousPeriod];

const [userBalance, setUserBalance] = useState({ points: "-", gems: "-" });
const [userData, setUserData] = useState<any>([]); // todo: change type to user rewards

Check warning on line 52 in src/modules/Users/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
const [gemsEarned, setGemsEarned] = useState("0");
const [rewardsTotalSupply, setRewardsTotalSupply] = useState({
points: "0",
gems: "900k",
});
const [gemPrice, setGemPrice] = useState("-");

const [contestsToClaim, setContestsToClaim] = useState([]);

Expand Down Expand Up @@ -92,6 +94,19 @@
}
};

const getSGEMPrice = async () => {
const sonicPrices = $assetsPrices["146"];

if (sonicPrices) {
const _sGEM1Price =
Number(
sonicPrices[sGEM1?.toLowerCase() as keyof typeof sonicPrices]?.price
).toFixed(3) ?? "0.010";

setGemPrice(_sGEM1Price);
}
};

const getRewardsTotalSupply = async () => {
if ($apiData?.leaderboards?.absolute.length) {
const pointsTotalSupply = $apiData?.leaderboards?.absolute.reduce(
Expand Down Expand Up @@ -270,9 +285,13 @@
initTableData();
}, [activeContest, allContests]);

useEffect(() => {
getSGEMPrice();
}, [$assetsPrices]);

useEffect(() => {
getRewardsTotalSupply();
}, [$apiData?.leaderboards?.absolute]);
}, [$apiData]);

useEffect(() => {
if ($account) {
Expand Down Expand Up @@ -334,7 +353,7 @@
</div>
<div className="flex flex-col items-start">
<span className="text-[#EAD9B2] text-[15px] font-regular mb-[-10px]">
Price: 0.01 USDc
Price: ${gemPrice}
</span>
<span className="font-medium text-[30px]">
Balance: {userBalance.gems}
Expand Down
Loading