diff --git a/src/app/collective-rewards/CycleContext.tsx b/src/app/collective-rewards/CycleContext.tsx deleted file mode 100644 index 2e88e79f..00000000 --- a/src/app/collective-rewards/CycleContext.tsx +++ /dev/null @@ -1,85 +0,0 @@ -import { createContext, FC, ReactNode, useContext, useEffect, useState } from 'react' -import { DateTime } from 'luxon' -import { useGetCycleStartAndDuration } from './hooks/useGetCycleStartAndDuration' -import { getCycleNext } from '@/app/collective-rewards/utils/getCycleNext' -import { getEndDistributionWindow } from '@/app/collective-rewards/utils/getEndDistributionWindow' - -export type Cycle = { - cycleStart: DateTime - cycleDuration: DateTime - cycleNext: DateTime - endDistributionWindow: DateTime -} - -type CycleContextValue = { - data: Cycle - isLoading: boolean - error: Error | null -} - -export const CycleContext = createContext({ - data: {} as Cycle, - isLoading: false, - error: null, -}) - -type CycleProviderProps = { - children: ReactNode -} - -export const CycleContextProvider: FC = ({ children }) => { - const [cycleNext, setCycleNext] = useState(0n) - const [endDistributionWindow, setEndDistributionWindow] = useState(0n) - const [fetchDataIsLoading, setFetchDataIsLoading] = useState(false) - const [fetchDataError, setFetchDataError] = useState(null) - const { - data: cycleStartAndDuration, - isLoading: cycleStartAndDurationLoading, - error: cycleStartAndDurationError, - } = useGetCycleStartAndDuration() - const [cycleStart, cycleDuration] = cycleStartAndDuration || [] - - useEffect(() => { - if (!cycleStart) { - return - } - - const fetchData = async () => { - try { - setFetchDataIsLoading(true) - const [cycleNext, endDistributionWindow] = await Promise.all([ - getCycleNext(cycleStart), - getEndDistributionWindow(cycleStart), - ]) - - // Update the state - setCycleNext(cycleNext) - setEndDistributionWindow(endDistributionWindow) - setFetchDataIsLoading(false) - } catch (error) { - setFetchDataError(error as Error) - console.error('Failed to fetch cycle data:', error) - } - } - - fetchData() - }, [cycleStart]) // This will trigger whenever cycleStart changes - - const isLoading = cycleStartAndDurationLoading || fetchDataIsLoading - const error = cycleStartAndDurationError || fetchDataError - - const valueOfContext: CycleContextValue = { - data: { - cycleStart: DateTime.fromSeconds(Number(cycleStart)), - cycleDuration: DateTime.fromSeconds(Number(cycleDuration)), - cycleNext: DateTime.fromSeconds(Number(cycleNext)), - endDistributionWindow: DateTime.fromSeconds(Number(endDistributionWindow)), - }, - isLoading, - error, - } - - return {children} -} - -export const useCycleContext = () => useContext(CycleContext) diff --git a/src/app/collective-rewards/builder/LastCycleRewards.tsx b/src/app/collective-rewards/builder/LastCycleRewards.tsx deleted file mode 100644 index 92c546ba..00000000 --- a/src/app/collective-rewards/builder/LastCycleRewards.tsx +++ /dev/null @@ -1,78 +0,0 @@ -import { formatBalanceToHuman } from '@/app/user/Balances/balanceUtils' -import { Address } from 'viem' -import { usePricesContext } from '@/shared/context/PricesContext' -import { FC, useEffect } from 'react' -import { useAlertContext } from '@/app/providers' -import { - NotifyRewardEventLog, - useGetNotifyRewardLogs, -} from '@/app/collective-rewards/hooks/useGetNotifyRewardLogs' -import { Cycle, useCycleContext } from '@/app/collective-rewards/CycleContext' -import { MetricsCardMultipleRowsWithSpinner } from '@/app/collective-rewards/components/MetricsCardMultipleRows' -import { getLastCycleRewards } from '@/app/collective-rewards/builder/utils/getLastCycleRewards' -import { formatMetrics } from '@/app/collective-rewards/builder/utils/formatMetrics' - -type LastCycleRewardsProps = { - gauge: Address - currency?: string - data: { - [token: string]: { - symbol: string - address: Address - } - } -} - -const useHandleErrors = (errors: { error: Error | null; title: string }[]) => { - const { setMessage } = useAlertContext() - - useEffect(() => { - errors.forEach(({ error, title }) => { - if (error) { - setMessage({ - severity: 'error', - title, - content: error.message, - }) - console.error(`🐛 ${title}:`, error) - } - }) - }, [errors, setMessage]) -} - -export const LastCycleRewards: FC = ({ - gauge, - data: { rif, rbtc }, - currency = 'USD', -}) => { - const { data: cycle, isLoading: cycleLoading, error: cycleError } = useCycleContext() - const { data: rewardsPerToken, isLoading: logsLoading, error: rewardsError } = useGetNotifyRewardLogs(gauge) - const { prices } = usePricesContext() - - useHandleErrors([ - { error: cycleError, title: 'Error loading cycle' }, - { error: rewardsError, title: 'Error loading rewards' }, - ]) - - const getRewardMetrics = (cycle: Cycle, logs: NotifyRewardEventLog, symbol: string, currency: string) => { - const lastCycleRewards = getLastCycleRewards(cycle, logs) - const lastCycleRewardsInHuman = Number(formatBalanceToHuman(lastCycleRewards.sponsorsAmount)) - const price = prices[symbol]?.price ?? 0 - - return formatMetrics(lastCycleRewardsInHuman, price, symbol, currency) - } - - const rifRewardsMetrics = getRewardMetrics(cycle, rewardsPerToken[rif.address], rif.symbol, currency) - const rbtcRewardsMetrics = getRewardMetrics(cycle, rewardsPerToken[rbtc.address], rbtc.symbol, currency) - - const isLoading = cycleLoading || logsLoading - - return ( - - ) -} diff --git a/src/app/collective-rewards/builder/Rewards.tsx b/src/app/collective-rewards/builder/Rewards.tsx deleted file mode 100644 index 40a57446..00000000 --- a/src/app/collective-rewards/builder/Rewards.tsx +++ /dev/null @@ -1,73 +0,0 @@ -import { Address, getAddress } from 'viem' -import { HeaderTitle, Paragraph, Typography } from '@/components/Typography' -import { tokenContracts } from '@/lib/contracts' -import { PricesContextProvider } from '@/shared/context/PricesContext' -import { FC } from 'react' -import { Button } from '@/components/Button' -import { useClaimAllRewards, useClaimStateReporting } from '@/app/collective-rewards/hooks/useClaimAllRewards' -import { Popover } from '@/components/Popover' -import { getCoinBaseAddress } from '@/app/collective-rewards/utils/getCoinBaseAddress' -import { CycleContextProvider } from '@/app/collective-rewards/CycleContext' -import { LastCycleRewards } from '@/app/collective-rewards/builder/LastCycleRewards' - -type RewardsProps = { - builder: Address - gauge: Address -} - -export const Rewards: FC = ({ builder, gauge }) => { - const { isClaimFunctionReady, claimAllRewards, ...claimTx } = useClaimAllRewards(builder) - - useClaimStateReporting({ ...claimTx }) - - const data = { - rif: { - address: getAddress(tokenContracts.RIF), - symbol: 'RIF', - }, - rbtc: { - address: getCoinBaseAddress(), - symbol: 'RBTC', - }, - } - - return ( - <> - <> -
- As a Builder - - {' '} - Monitor the rewards you are getting from your Collective Rewards. - -
- - -
- -
-
-
- - - - Wait a moment, please. Preparing the claim functionality. - - } - trigger="hover" - background="dark" - size="small" - position="bottom" - className="z-[100]" - > - - - - ) -} diff --git a/src/app/collective-rewards/builder/utils/formatMetrics.ts b/src/app/collective-rewards/builder/utils/formatMetrics.ts deleted file mode 100644 index 8242c185..00000000 --- a/src/app/collective-rewards/builder/utils/formatMetrics.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { formatCurrency, toFixed } from '@/lib/utils' - -export const formatMetrics = (amount: number, price: number, symbol: string, currency: string) => ({ - amount: `${toFixed(amount)} ${symbol}`, - fiatAmount: `= ${currency} ${formatCurrency(amount * price, currency)}`, -}) diff --git a/src/app/collective-rewards/builder/utils/getLastCycleRewards.ts b/src/app/collective-rewards/builder/utils/getLastCycleRewards.ts deleted file mode 100644 index 61fa6ffe..00000000 --- a/src/app/collective-rewards/builder/utils/getLastCycleRewards.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { NotifyRewardEventLog } from '@/app/collective-rewards/hooks/useGetNotifyRewardLogs' -import { Cycle } from '@/app/collective-rewards/CycleContext' - -type Log = NotifyRewardEventLog[number] -type CycleRewards = { - builderAmount: bigint - sponsorsAmount: bigint -} - -export const getLastCycleRewards = (cycle: Cycle, notifyRewardLogs?: NotifyRewardEventLog) => { - const { cycleDuration, endDistributionWindow, cycleStart } = cycle - const distributionWindow = endDistributionWindow.diff(cycleStart) - const lastCycleStart = cycleStart.minus({ millisecond: +cycleDuration }) - const lastCycleAfterDistribution = lastCycleStart.plus({ millisecond: +distributionWindow }) - - if (!notifyRewardLogs) { - return { builderAmount: 0n, sponsorsAmount: 0n } - } - - return notifyRewardLogs.reduce( - (acc, event) => { - const { - timeStamp, - args: { sponsorsAmount_, builderAmount_ }, - } = event as Log & { timeStamp: number } - - // Check if the event is in the last cycle - if ( - timeStamp > lastCycleAfterDistribution.toSeconds() && - timeStamp < endDistributionWindow.toSeconds() - ) { - acc.builderAmount += builderAmount_ - acc.sponsorsAmount += sponsorsAmount_ - } - - return acc - }, - { builderAmount: 0n, sponsorsAmount: 0n }, - ) -} diff --git a/src/app/collective-rewards/components/MetricsCardMultipleRows.tsx b/src/app/collective-rewards/components/MetricsCardMultipleRows.tsx deleted file mode 100644 index 506c50ab..00000000 --- a/src/app/collective-rewards/components/MetricsCardMultipleRows.tsx +++ /dev/null @@ -1,103 +0,0 @@ -import { cn, shortAddress } from '@/lib/utils' -import { FC, ReactNode } from 'react' -import { Address } from 'viem' -import { BoxIcon } from 'lucide-react' -import { EXPLORER_URL } from '@/lib/constants' -import { withSpinner } from '@/components/LoadingSpinner/withLoadingSpinner' -import { Span, Typography } from '../../../components/Typography' - -type MetricsCardRow = { - amount: string - fiatAmount?: string -} - -type MetricsCardMultipleRowsProps = { - /** - * The title of the card, usually indicating the type of balance. - */ - title: ReactNode - - data: { - [token: string]: MetricsCardRow - } - - /** - * Whether the card should have a border or not. - */ - borderless?: boolean - - /** - * The address of the contract to link to. - */ - contractAddress?: Address - 'data-testid'?: string -} - -const DEFAULT_CLASSES = 'h-min-[79px] w-full py-[12px] px-[12px] flex flex-col bg-foreground' - -export const MetricsCardRow: FC = ({ amount, fiatAmount }) => ( -
- - {amount} - - {fiatAmount && ( - - {fiatAmount} - - )} -
-) - -/** - * Card for displaying balance and corresponding (fiat) value. - */ -export const MetricsCardMultipleRows: FC = ({ - title, - borderless = false, - data: { rif, rbtc }, - contractAddress, - 'data-testid': dataTestId, -}) => { - const borderClasses = borderless ? '' : 'border border-white border-opacity-40 rounded-lg' - return ( -
- {typeof title === 'string' ? ( -
- - {title} - -
- ) : ( - title - )} - - - {contractAddress && ( - - - - {shortAddress(contractAddress)} - - - )} -
- ) -} - -export const MetricsCardMultipleRowsWithSpinner = withSpinner(MetricsCardMultipleRows) diff --git a/src/app/collective-rewards/metrics/context/CycleContext.tsx b/src/app/collective-rewards/metrics/context/CycleContext.tsx index 781cc89e..9a9952f3 100644 --- a/src/app/collective-rewards/metrics/context/CycleContext.tsx +++ b/src/app/collective-rewards/metrics/context/CycleContext.tsx @@ -42,13 +42,11 @@ export const CycleContextProvider: FC = ({ children }) => { isLoading: cycleStartLoading, error: cycleStartError, } = useGetCycleStart(timestamp) - console.log('🚀 ~ cycleStart:', cycleStart) const { data: endDistributionWindow, isLoading: endDistributionWindowLoading, error: endDistributionWindowError, } = useGetEndDistributionWindow(timestamp) - console.log('🚀 ~ endDistributionWindow:', endDistributionWindow) const isLoading = cycleStartAndDurationLoading || cycleStartLoading || endDistributionWindowLoading const error = cycleStartAndDurationError ?? cycleStartError ?? endDistributionWindowError diff --git a/src/app/collective-rewards/rewards/ClaimableRewards.tsx b/src/app/collective-rewards/rewards/ClaimableRewards.tsx new file mode 100644 index 00000000..0b520671 --- /dev/null +++ b/src/app/collective-rewards/rewards/ClaimableRewards.tsx @@ -0,0 +1,126 @@ +import { FC } from 'react' +import { Address } from 'viem' +import { useGetBuilderRewards } from '@/app/collective-rewards/user' +import { usePricesContext } from '@/shared/context/PricesContext' +import { + formatMetrics, + useClaimBuilderRewards, + useClaimStateReporting, + MetricsCardWithSpinner, +} from '@/app/collective-rewards/rewards' +import { formatBalanceToHuman } from '@/app/user/Balances/balanceUtils' +import { Popover } from '@/components/Popover' +import { useHandleErrors } from '@/app/collective-rewards/utils' + +type Token = { + symbol: string + address: Address +} + +type ClaimableRewardsProps = { + builder: Address + gauge: Address + currency?: string + data: { + [token: string]: Token + } +} + +const ClaimYourRewardsSvg = () => ( + + + +) + +const getAction = (onClick: () => void, disabled: boolean) => ( + +

Claim your rewards

+ + } + size="small" + position="top" + trigger="hover" + > + +
+) + +const useGetRewardMetrics = ( + builder: Address, + gauge: Address, + tokenAddress: Address, + symbol: string, + currency: string, +) => { + const { data: rewards, isLoading, error } = useGetBuilderRewards(tokenAddress, gauge) + const { prices } = usePricesContext() + + const price = prices[symbol]?.price ?? 0 + const rewardsInHuman = Number(formatBalanceToHuman(rewards ?? 0n)) + const rewardMetrics = formatMetrics(rewardsInHuman, price, symbol, currency) + + const { isClaimFunctionReady, claimRewards, ...claimTx } = useClaimBuilderRewards(builder, tokenAddress) + useClaimStateReporting({ ...claimTx }) + + const action = getAction(claimRewards, !isClaimFunctionReady) + + return { + data: { + ...rewardMetrics, + action, + }, + error, + isLoading, + } +} + +export const ClaimableRewards: FC = ({ + builder, + gauge, + data: { rif, rbtc }, + currency = 'USD', +}) => { + const { prices } = usePricesContext() + + const { + data: rifRewardsMetrics, + isLoading: rifLoading, + error: rifError, + } = useGetRewardMetrics(builder, gauge, rif.address, rif.symbol, currency) + const { + data: rbtcRewardsMetrics, + isLoading: rbtcLoading, + error: rbtcError, + } = useGetRewardMetrics(builder, gauge, rbtc.address, rbtc.symbol, currency) + + useHandleErrors([ + { error: rifError, title: 'Error loading builder rif rewards' }, + { error: rbtcError, title: 'Error loading builder rbtc rewards' }, + ]) + + const isLoading = rifLoading || rbtcLoading + + return ( +
+ +
+ ) +} diff --git a/src/app/collective-rewards/rewards/LastCycleRewards.tsx b/src/app/collective-rewards/rewards/LastCycleRewards.tsx index 19750f0b..8af7bda5 100644 --- a/src/app/collective-rewards/rewards/LastCycleRewards.tsx +++ b/src/app/collective-rewards/rewards/LastCycleRewards.tsx @@ -2,11 +2,14 @@ import { formatBalanceToHuman } from '@/app/user/Balances/balanceUtils' import { Address } from 'viem' import { usePricesContext } from '@/shared/context/PricesContext' import { FC } from 'react' -import { NotifyRewardEventLog, useGetNotifyRewardLogs } from '@/app/collective-rewards/rewards' import { Cycle, useCycleContext } from '@/app/collective-rewards/metrics/context/CycleContext' -import { MetricsCardWithSpinner } from './components' -import { getLastCycleRewards } from '@/app/collective-rewards/rewards/utils/getLastCycleRewards' -import { formatMetrics } from '@/app/collective-rewards/rewards/utils/formatMetrics' +import { + NotifyRewardEventLog, + useGetNotifyRewardLogs, + MetricsCardWithSpinner, + formatMetrics, + getLastCycleRewards, +} from '@/app/collective-rewards/rewards' import { useHandleErrors } from '@/app/collective-rewards/utils' type LastCycleRewardsProps = { diff --git a/src/app/collective-rewards/rewards/MyRewards.tsx b/src/app/collective-rewards/rewards/MyRewards.tsx index 012c89fb..e7499a61 100644 --- a/src/app/collective-rewards/rewards/MyRewards.tsx +++ b/src/app/collective-rewards/rewards/MyRewards.tsx @@ -3,9 +3,10 @@ import { Address, getAddress } from 'viem' import { RewardsSection, RewardsSectionHeader, - useClaimAllRewards, + useClaimBuilderRewards, useClaimStateReporting, LastCycleRewards, + ClaimableRewards, } from '@/app/collective-rewards/rewards' import { CycleContextProvider } from '@/app/collective-rewards/metrics' import { PricesContextProvider } from '@/shared/context/PricesContext' @@ -16,7 +17,7 @@ import { Button } from '@/components/Button' import { Paragraph } from '@/components/Typography' export const Rewards: FC<{ builder: Address; gauge: Address }> = ({ builder, gauge }) => { - const { isClaimFunctionReady, claimAllRewards, ...claimTx } = useClaimAllRewards(builder) + const { isClaimFunctionReady, claimRewards, ...claimTx } = useClaimBuilderRewards(builder) useClaimStateReporting({ ...claimTx }) @@ -44,7 +45,7 @@ export const Rewards: FC<{ builder: Address; gauge: Address }> = ({ builder, gau
-
Claimable Rewards
+
Estimated Rewards
All time rewards
@@ -62,7 +63,7 @@ export const Rewards: FC<{ builder: Address; gauge: Address }> = ({ builder, gau position="bottom" className="z-[100]" > - diff --git a/src/app/collective-rewards/rewards/components/Metrics/MetricsCard.tsx b/src/app/collective-rewards/rewards/components/Metrics/MetricsCard.tsx index 6931a60c..9cd28564 100644 --- a/src/app/collective-rewards/rewards/components/Metrics/MetricsCard.tsx +++ b/src/app/collective-rewards/rewards/components/Metrics/MetricsCard.tsx @@ -9,6 +9,7 @@ import { Span, Typography } from '@/components/Typography' type MetricsCardRow = { amount: string fiatAmount?: string + action?: JSX.Element } type MetricsCardProps = { @@ -35,29 +36,32 @@ type MetricsCardProps = { const DEFAULT_CLASSES = 'h-min-[79px] w-full py-[12px] px-[12px] flex flex-col bg-foreground' -export const MetricsCardRow: FC = ({ amount, fiatAmount }) => ( -
- - {amount} - - {fiatAmount && ( +export const MetricsCardRow: FC = ({ amount, fiatAmount, action }) => ( +
+
- {fiatAmount} + {amount} - )} + {fiatAmount && ( + + {fiatAmount} + + )} +
+ {action}
) diff --git a/src/app/collective-rewards/rewards/hooks/index.ts b/src/app/collective-rewards/rewards/hooks/index.ts index e227d850..f95bb072 100644 --- a/src/app/collective-rewards/rewards/hooks/index.ts +++ b/src/app/collective-rewards/rewards/hooks/index.ts @@ -1,4 +1,4 @@ -export * from './useClaimAllRewards' +export * from './useClaimBuilderRewards' export * from './useGetRewardDistributedLogs' export * from './useGetTokenProjectedReward' export * from './useGetNotifyRewardLogs' diff --git a/src/app/collective-rewards/rewards/hooks/useClaimAllRewards.ts b/src/app/collective-rewards/rewards/hooks/useClaimBuilderRewards.ts similarity index 90% rename from src/app/collective-rewards/rewards/hooks/useClaimAllRewards.ts rename to src/app/collective-rewards/rewards/hooks/useClaimBuilderRewards.ts index 4645e2a3..a4cfcb74 100644 --- a/src/app/collective-rewards/rewards/hooks/useClaimAllRewards.ts +++ b/src/app/collective-rewards/rewards/hooks/useClaimBuilderRewards.ts @@ -6,7 +6,7 @@ import { useEffect, useMemo } from 'react' import { useAlertContext } from '@/app/providers' import { useGetBuilderToGauge } from '@/app/collective-rewards/user' -export const useClaimAllRewards = (builder: Address) => { +export const useClaimBuilderRewards = (builder: Address, rewardToken?: Address) => { const { writeContractAsync, error: executionError, data: hash, isPending } = useWriteContract() const { data: gauge, @@ -52,18 +52,18 @@ export const useClaimAllRewards = (builder: Address) => { } }, [gauge, gaugeError, builder, executionError, receiptError, isFetched]) - const claimAllRewards = () => { + const claimBuilderReward = () => { return writeContractAsync({ abi: GaugeAbi, address: gauge as Address, functionName: 'claimBuilderReward', - args: [], + args: rewardToken ? [rewardToken] : [], }) } return { isClaimFunctionReady, - claimAllRewards: () => isClaimFunctionReady && claimAllRewards(), + claimRewards: () => isClaimFunctionReady && claimBuilderReward(), error, isPendingTx: isPending, isLoadingReceipt: isLoading, @@ -78,7 +78,7 @@ export const useClaimStateReporting = ({ isLoadingReceipt, isSuccess, receipt, -}: Omit, 'isClaimFunctionReady' | 'claimAllRewards'>) => { +}: Omit, 'isClaimFunctionReady' | 'claimRewards'>) => { const { setMessage } = useAlertContext() useEffect(() => { diff --git a/src/app/collective-rewards/rewards/index.ts b/src/app/collective-rewards/rewards/index.ts index 01cdddf9..752b7b97 100644 --- a/src/app/collective-rewards/rewards/index.ts +++ b/src/app/collective-rewards/rewards/index.ts @@ -3,3 +3,4 @@ export * from './hooks' export * from './utils' export * from './MyRewards' export * from './LastCycleRewards' +export * from './ClaimableRewards' diff --git a/src/app/collective-rewards/user/hooks/index.ts b/src/app/collective-rewards/user/hooks/index.ts index 94fc413a..7ca66e5e 100644 --- a/src/app/collective-rewards/user/hooks/index.ts +++ b/src/app/collective-rewards/user/hooks/index.ts @@ -1,4 +1,5 @@ export * from './useGetBuilders' +export * from './useGetBuilderRewards' export * from './useGetIsWhitelistedBuilder' export * from './useGetWhitelistedBuilders' export * from './useGetWhitelistedBuildersLength' diff --git a/src/app/collective-rewards/user/hooks/useGetBuilderRewards.ts b/src/app/collective-rewards/user/hooks/useGetBuilderRewards.ts new file mode 100644 index 00000000..a16ec25f --- /dev/null +++ b/src/app/collective-rewards/user/hooks/useGetBuilderRewards.ts @@ -0,0 +1,22 @@ +import { GaugeAbi } from '@/lib/abis/v2/GaugeAbi' +import { Address } from 'viem' +import { useReadContract } from 'wagmi' + +export const useGetBuilderRewards = (rewardToken: Address, gauge?: Address) => { + const { data, isLoading, error } = useReadContract({ + address: gauge!, + abi: GaugeAbi, + functionName: 'builderRewards', + args: [rewardToken], + query: { + refetchInterval: 30_000, + enabled: !!gauge, + }, + }) + + return { + data, + isLoading, + error, + } +} diff --git a/src/app/collective-rewards/user/hooks/useGetCycleStartAndDuration.ts b/src/app/collective-rewards/user/hooks/useGetCycleStartAndDuration.ts deleted file mode 100644 index 95bd2aff..00000000 --- a/src/app/collective-rewards/user/hooks/useGetCycleStartAndDuration.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { EpochTimeKeeperAbi } from '@/lib/abis/v2/EpochTimeKeeperAbi' -import { SponsorsManagerAddress } from '@/lib/contracts' -import { useReadContract } from 'wagmi' - -export const useGetCycleStartAndDuration = () => { - const { data, isLoading, error } = useReadContract({ - address: SponsorsManagerAddress, - abi: EpochTimeKeeperAbi, - functionName: 'getEpochStartAndDuration', - query: { - refetchInterval: 30_000, - }, - }) - - return { - data, - isLoading, - error, - } -} diff --git a/src/app/collective-rewards/user/hooks/useGetNotifyRewardLogs.ts b/src/app/collective-rewards/user/hooks/useGetNotifyRewardLogs.ts index c0358191..298cbc4b 100644 --- a/src/app/collective-rewards/user/hooks/useGetNotifyRewardLogs.ts +++ b/src/app/collective-rewards/user/hooks/useGetNotifyRewardLogs.ts @@ -31,6 +31,7 @@ export const useGetNotifyRewardLogs = (gauge?: Address) => { queryKey: ['notifyRewardLogs'], refetchInterval: 30_000, initialData: {}, + enabled: !!gauge, }) return { diff --git a/src/app/collective-rewards/utils/getBuilderToGauge.ts b/src/app/collective-rewards/utils/getBuilderToGauge.ts deleted file mode 100644 index 2c0c222d..00000000 --- a/src/app/collective-rewards/utils/getBuilderToGauge.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BuilderRegistryAbi } from '@/lib/abis/v2/BuilderRegistryAbi' -import { SponsorsManagerAddress } from '@/lib/contracts' -import { Address } from 'viem' -import { config } from '@/config' -import { readContract } from 'wagmi/actions' - -export const getBuilderToGauge = async (builder: Address): Promise
=> { - return readContract(config, { - address: SponsorsManagerAddress, - abi: BuilderRegistryAbi, - functionName: 'builderToGauge', - args: [builder], - }) -} diff --git a/src/app/collective-rewards/utils/getCycleNext.ts b/src/app/collective-rewards/utils/getCycleNext.ts deleted file mode 100644 index 21fb8240..00000000 --- a/src/app/collective-rewards/utils/getCycleNext.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { EpochTimeKeeperAbi } from '@/lib/abis/v2/EpochTimeKeeperAbi' -import { SponsorsManagerAddress } from '@/lib/contracts' -import { config } from '@/config' -import { readContract } from 'wagmi/actions' - -export const getCycleNext = async (timestamp: bigint): Promise => { - return readContract(config, { - address: SponsorsManagerAddress, - abi: EpochTimeKeeperAbi, - functionName: 'epochNext', - args: [timestamp], - }) -} diff --git a/src/app/collective-rewards/utils/getEndDistributionWindow.ts b/src/app/collective-rewards/utils/getEndDistributionWindow.ts deleted file mode 100644 index fd36512b..00000000 --- a/src/app/collective-rewards/utils/getEndDistributionWindow.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { EpochTimeKeeperAbi } from '@/lib/abis/v2/EpochTimeKeeperAbi' -import { SponsorsManagerAddress } from '@/lib/contracts' -import { config } from '@/config' -import { readContract } from 'wagmi/actions' - -export const getEndDistributionWindow = async (timestamp: bigint): Promise => { - return readContract(config, { - address: SponsorsManagerAddress, - abi: EpochTimeKeeperAbi, - functionName: 'endDistributionWindow', - args: [timestamp], - }) -}