-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65e7d09
commit e7666eb
Showing
8 changed files
with
128 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Address } from 'viem' | ||
import { FC } from 'react' | ||
import { | ||
useGetNotifyRewardLogs, | ||
useGetGaugeNotifyRewardLogs, | ||
useGetBuilderRewards, | ||
} from '@/app/collective-rewards/rewards' | ||
import { MetricsCardWithSpinner } from '@/components/MetricsCard/MetricsCard' | ||
import { useHandleErrors } from '@/app/collective-rewards/utils' | ||
|
||
type AllTimeShareProps = { | ||
gauge: Address | ||
data: { | ||
[token: string]: { | ||
symbol: string | ||
address: Address | ||
} | ||
} | ||
} | ||
|
||
export const AllTimeShare: FC<AllTimeShareProps> = ({ gauge, data: { rif } }) => { | ||
const { data: rewardsPerToken, isLoading: logsLoading, error: rewardsError } = useGetNotifyRewardLogs() | ||
const { | ||
data: gaugeRewardsPerToken, | ||
isLoading: gaugeLogsLoading, | ||
error: gaugeRewardsError, | ||
} = useGetGaugeNotifyRewardLogs(gauge) | ||
const { | ||
data: claimableRewards, | ||
isLoading: claimableRewardsLoading, | ||
error: claimableRewardsError, | ||
} = useGetBuilderRewards(rif.address, gauge) | ||
|
||
const error = rewardsError ?? gaugeRewardsError ?? claimableRewardsError | ||
|
||
useHandleErrors([{ error, title: 'Error loading all time share' }]) | ||
|
||
let isLoading: boolean = logsLoading || gaugeLogsLoading || claimableRewardsLoading | ||
|
||
if (!rewardsPerToken[rif.address] || !gaugeRewardsPerToken[rif.address]) { | ||
return <MetricsCardWithSpinner title="All time share" amount="0%" isLoading={isLoading} borderless /> | ||
} | ||
|
||
const rifRewards = rewardsPerToken[rif.address].reduce((acc, event) => { | ||
const amount = event.args.amount_ | ||
return acc + amount | ||
}, 0n) | ||
const gaugeRifRewards = gaugeRewardsPerToken[rif.address].reduce((acc, event) => { | ||
const amount = event.args.builderAmount_ | ||
return acc + amount | ||
}, 0n) | ||
|
||
const totalRewards = gaugeRifRewards + (claimableRewards ?? 0n) | ||
|
||
const amount = !rifRewards ? '0%' : `${(totalRewards * 100n) / rifRewards}%` | ||
|
||
return <MetricsCardWithSpinner title="All time share" amount={amount} isLoading={isLoading} borderless /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 43 additions & 6 deletions
49
src/app/collective-rewards/rewards/hooks/useGetNotifyRewardLogs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/app/collective-rewards/rewards/utils/getLastCycleRewards.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters