diff --git a/src/pages/stakingPage/components/RewardsCard.tsx b/src/pages/stakingPage/components/RewardsCard.tsx index 9051f46..65ba5c7 100644 --- a/src/pages/stakingPage/components/RewardsCard.tsx +++ b/src/pages/stakingPage/components/RewardsCard.tsx @@ -4,8 +4,11 @@ import { useAccount } from 'wagmi'; import { GrixLogo } from '@/components/commons/Logo'; import { EthLogo } from '@/components/commons/Logo/EthLogo'; +import { AssetPriceResponse } from '@/types/api'; import { claim, compound } from '@/web3Config/staking/hooks'; +import { useVesting } from '../hooks/useVesting'; + type RewardsCardProps = { data: { claimable: string; @@ -16,26 +19,26 @@ type RewardsCardProps = { refetchData: () => Promise; }; -type DexScreenerResponse = { - grix: { - usd: number; - }; -}; - export const RewardsCard = ({ data, refetchData }: RewardsCardProps): JSX.Element => { const { address } = useAccount(); const [isClaiming, setIsClaiming] = useState(false); const [isCompounding, setIsCompounding] = useState(false); const [grixPrice, setGrixPrice] = useState(null); + const { totalStaked } = useVesting(); const toast = useToast(); // Fetch GRIX price from CoinGecko useEffect(() => { const fetchPrice = async () => { try { - const res = await fetch('https://api.coingecko.com/api/v3/simple/price?ids=grix&vs_currencies=usd'); - const json = (await res.json()) as DexScreenerResponse; - const price = json.grix.usd; + const res = await fetch('https://z61hgkwkn8.execute-api.us-east-1.amazonaws.com/dev/assetprice?asset=GRIX', { + headers: { + 'x-api-key': import.meta.env.VITE_GRIX_API_KEY, + origin: 'https://app.grix.finance', + }, + }); + const json = (await res.json()) as AssetPriceResponse; + const price = json.assetPrice; setGrixPrice(price); } catch { setGrixPrice(null); @@ -143,6 +146,32 @@ export const RewardsCard = ({ data, refetchData }: RewardsCardProps): JSX.Elemen )} + + + + + + Total Staked + + + + {Number(totalStaked).toLocaleString(undefined, { + minimumFractionDigits: 1, + maximumFractionDigits: 1, + })}{' '} + GRIX + {grixPrice && Number(totalStaked) > 0 && ( + +  ($ + {(Number(totalStaked) * grixPrice).toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + })} + ) + + )} + +