@@ -185,8 +192,8 @@ export const AppStakingPane: FC = () => {
Deposit{" "}
{" "}
diff --git a/src/components/app/staking/AppStakingPool.tsx b/src/components/app/staking/AppStakingPool.tsx
index 56c88ca9..7dc9eb55 100644
--- a/src/components/app/staking/AppStakingPool.tsx
+++ b/src/components/app/staking/AppStakingPool.tsx
@@ -1,4 +1,4 @@
-import { FC, useState } from "react";
+import { FC, useEffect } from "react";
import {
Carousel,
@@ -7,35 +7,38 @@ import {
CarouselNext,
CarouselPrevious,
} from "@/components/ui/Carousel";
-import { Button, Card } from "@/components/ui";
-import { useGetStakingAprById, useGetUserStakingsByAddress } from "@/services/graph";
-import { useAccount, useReadContract } from "wagmi";
-import { useContractAddress } from "@/hooks/useContractAddress";
+import { TxButton } from "@/components/ui";
+import { useGetUserStakingsByAddress } from "@/services/graph";
+import { useAccount, usePublicClient } from "wagmi";
import { formatUnits, zeroAddress } from "viem";
import {
- useReadLdyDecimals,
- useReadLdyStakingEarned,
useReadLdyStakingGetEarnedUser,
useReadLdyStakingGetUserStakes,
- useReadLdyStakingRewardsDuration,
+ useSimulateLdyStakingGetReward,
+ useSimulateLdyStakingUnstake,
} from "@/generated";
import dayjs from "dayjs";
import localizedFormat from "dayjs/plugin/localizedFormat";
import relativeTime from "dayjs/plugin/relativeTime";
import utc from "dayjs/plugin/utc";
-import { OneMonth, STAKING_APR_INFO_ID } from "@/constants/staking";
+import { OneMonth } from "@/constants/staking";
import { useAPYCalculation } from "@/hooks/useAPYCalculation";
-import { useQueries } from "@tanstack/react-query";
+import { QueryKey, useQueryClient } from "@tanstack/react-query";
+import { twMerge } from "tailwind-merge";
+import { USER_STAKING_QUERY } from "@/services/graph/queries";
+import { IStakingAPRInfo } from "@/services/graph/hooks/useStakingEvent";
dayjs.extend(localizedFormat);
dayjs.extend(relativeTime);
dayjs.extend(utc);
-export const AppStakingPool: FC = () => {
+export const AppStakingPool: FC<{
+ ldyTokenDecimals?: number;
+ ldyTokenBalanceQuery?: QueryKey;
+ stakingAprInfo?: IStakingAPRInfo;
+}> = ({ ldyTokenDecimals, ldyTokenBalanceQuery, stakingAprInfo }) => {
+ const queryClient = useQueryClient();
const account = useAccount();
- const ldyStakingAddress = useContractAddress("LDYStaking");
- const { data: ldyDecimals } = useReadLdyDecimals();
-
- const [claimAmounts, setClaimAmounts] = useState
([0n]);
+ const publicClient = usePublicClient();
// Fetch user staking info including earnedAmount from subgraph
const {
@@ -49,22 +52,35 @@ export const AppStakingPool: FC = () => {
args: [account.address || zeroAddress],
});
- // Fetch staking APR info from subgraph
- const {
- data: stakingAprInfo,
- refetch: refetchStakingAPR,
- isFetching: isFetchingAPR,
- } = useGetStakingAprById(STAKING_APR_INFO_ID);
-
// Fetch claimable rewards array from ldyStaking Contract
- const { data: earnedArray, queryKey: earnedArrayQuery } = useReadLdyStakingGetEarnedUser({
+ const { data: rewardsArray, queryKey: rewardsArrayQuery } = useReadLdyStakingGetEarnedUser({
args: [account.address || zeroAddress],
});
+ // Refetch staking info, earned array from subgraph & contracts on wallet, network change
+ const queryKeys = [rewardsArrayQuery, getUserStakesQuery, [USER_STAKING_QUERY]];
+ useEffect(() => {
+ queryKeys.forEach((k) => queryClient.invalidateQueries({ queryKey: k }));
+ }, [account.address, publicClient]);
+
+ // Refetch staking info(earned info) on rewardsArray change
+ useEffect(() => {
+ // Refetch after 3 seconds due to subgraph latency
+ const timeoutId = setTimeout(() => {
+ queryClient.invalidateQueries({ queryKey: [USER_STAKING_QUERY] });
+ }, 3000);
+ return () => clearTimeout(timeoutId);
+ }, [rewardsArray]);
+
return (
MY $LDY POOLS
-
+
{stakingPools &&
stakingPools.map((poolInfo, index) => (
@@ -75,7 +91,7 @@ export const AppStakingPool: FC = () => {
Staked Amount
- {formatUnits(poolInfo.stakedAmount, ldyDecimals!)}
+ {formatUnits(poolInfo.stakedAmount, ldyTokenDecimals!)}
@@ -93,10 +109,12 @@ export const AppStakingPool: FC = () => {
Earned
- {userStakingInfo
+ {userStakingInfo &&
+ userStakingInfo.stakingUsers &&
+ userStakingInfo.stakingUsers[index]
? formatUnits(
BigInt(userStakingInfo.stakingUsers[index].earnedAmount),
- ldyDecimals!,
+ ldyTokenDecimals!,
)
: 0}{" "}
Token
@@ -106,11 +124,7 @@ export const AppStakingPool: FC = () => {
APY
{stakingAprInfo
- ? useAPYCalculation(
- stakingAprInfo.stakingAPRInfo.APR,
- false,
- Number(poolInfo.duration),
- )
+ ? useAPYCalculation(stakingAprInfo.APR, false, Number(poolInfo.duration))
: "-"}
%
@@ -122,16 +136,46 @@ export const AppStakingPool: FC = () => {
-
+
-
+
diff --git a/src/components/ui/AllowanceTxButton.tsx b/src/components/ui/AllowanceTxButton.tsx
index 6336d2a4..74366eb6 100644
--- a/src/components/ui/AllowanceTxButton.tsx
+++ b/src/components/ui/AllowanceTxButton.tsx
@@ -75,6 +75,8 @@ export const AllowanceTxButton: FC = ({
address: token,
args: [spender, amount],
});
+
+ // Set hasEnoughAllowance when allowance or amount chanages
useEffect(() => {
preparation.refetch();
setHasEnoughAllowance(allowance !== undefined && allowance >= amount);
diff --git a/src/components/ui/TxButton.tsx b/src/components/ui/TxButton.tsx
index 9ef96c83..8df7d835 100644
--- a/src/components/ui/TxButton.tsx
+++ b/src/components/ui/TxButton.tsx
@@ -1,6 +1,6 @@
"use client";
import { FC, type ReactNode, useEffect, useState } from "react";
-import { Button } from "./Button";
+import { Button, ButtonSize, ButtonVariant } from "./Button";
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "./Dialog";
import { Spinner } from "./Spinner";
import { Tooltip, TooltipTrigger, TooltipContent } from "./Tooltip";
@@ -51,7 +51,6 @@ export const TxButton: FC = ({
const account = useAccount();
const publicClient = usePublicClient();
const queryClient = useQueryClient();
-
// Fix Safe math issue when no value is provided
// if (preparation.data && preparation.data.request && !preparation.data.request.value) {
// preparation.data.request.value = 0n;
@@ -106,7 +105,7 @@ export const TxButton: FC = ({
}
return (
<>
-