Skip to content

Commit

Permalink
refactor: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscotobar committed Nov 21, 2024
1 parent 5a2277b commit 91d4bb0
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CycleContextProvider } from '@/app/collective-rewards/metrics'
import { Token } from '@/app/collective-rewards/rewards'
import { Token, useGetBuildersRewards } from '@/app/collective-rewards/rewards'
import { BuilderContextProviderWithPrices } from '@/app/collective-rewards/user'
import { getCoinbaseAddress, useHandleErrors } from '@/app/collective-rewards/utils'
import { Button } from '@/components/Button'
Expand All @@ -21,7 +21,6 @@ import {
} from '@/app/collective-rewards/shared'
import { getAddress } from 'viem'
import { tokenContracts } from '@/lib/contracts'
import { useGetBuildersRewards } from './hooks/useGetBuildersRewards'

enum RewardsColumnKeyEnum {
builder = 'builder',
Expand Down
1 change: 0 additions & 1 deletion src/app/collective-rewards/leaderboard/hooks/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/app/collective-rewards/leaderboard/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export * from './hooks'

export * from './BuildersLeaderBoardTable'
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,20 @@ const RewardsTable: FC<BackerRewardsTable> = ({ builder, gauges, tokens }) => {
({
address,
builderName,
stateDetails,
rewardPercentage,
estimatedRewards,
totalAllocationPercentage,
claimableRewards,
allTimeRewards,
}) => (
<TableRow key={address} className="text-[14px] border-hidden">
<BuilderNameCell tableHeader={tableHeaders[0]} builderName={builderName} address={address} />
<BuilderNameCell
tableHeader={tableHeaders[0]}
builderName={builderName}
address={address}
stateDetails={stateDetails}
/>
<BackerRewardsPercentage tableHeader={tableHeaders[1]} percentage={rewardPercentage} />
<LazyRewardCell
tableHeader={tableHeaders[2]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const useGetBackerRewards = (
// TODO: check which gauges are we going to use
// TODO: check which builders are we going to use
const { data: builders, isLoading: buildersLoading, error: buildersError } = useBuilderContext()
console.log('🚀 ~ builders:', builders)
const buildersAddress = builders?.map(({ address }) => address)
const {
data: buildersRewardsPct,
Expand Down Expand Up @@ -68,7 +69,7 @@ export const useGetBackerRewards = (
const rifPrice = prices[rif.symbol]?.price ?? 0
const rbtcPrice = prices[rbtc.symbol]?.price ?? 0

const data = builders.map(({ address, builderName, gauge }) => {
const data = builders.map(({ address, builderName, gauge, stateDetails }) => {
const builderTotalAllocation = totalAllocation[gauge]
const backerAllocationOf = allocationOf[gauge]
const totalAllocationPercentage = builderTotalAllocation
Expand All @@ -82,6 +83,7 @@ export const useGetBackerRewards = (
return {
address,
builderName,
stateDetails,
rewardPercentage,
estimatedRewards: {
rif: {
Expand Down
1 change: 1 addition & 0 deletions src/app/collective-rewards/rewards/builders/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './useClaimBuilderRewards'
export * from './useGetBuilderRewards'
export * from './useGetBuilderRewardsClaimedLogs'
export * from './useGetRewardPercentageToApply'
export * from './useGetBuildersRewards'
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const useGetBuildersRewards = ({ rif, rbtc }: { [token: string]: Token },
isLoading: activeBuildersLoading,
error: activeBuildersError,
} = useGetFilteredBuilders({ builderName: '', status: 'Active', stateFlags: { activated: true } })
console.log('🚀 ~ useGetBuildersRewards ~ activeBuilders:', activeBuilders)

const {
data: totalPotentialRewards,
Expand Down
20 changes: 12 additions & 8 deletions src/app/collective-rewards/shared/components/Table/TableCells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,14 @@ export const LazyRewardCell = memo(RewardCell, ({ rewards: prevReward }, { rewar
prevReward.every((reward, key) => reward.fiat.value === nextReward[key].fiat.value),
)

type BuilderCellProps = {
tableHeader: TableHeader
builderName: string
address: Address
stateDetails: BuilderStateDetails
type BuilderStatusFlagProps = {
stateDetails?: BuilderStateDetails
}

const BuilderStatusFlag = ({ stateDetails }: { stateDetails: BuilderStateDetails }) => {
const isDeactivated = !stateDetails.kycApproved || !stateDetails.communityApproved
const isPaused = stateDetails.paused
const BuilderStatusFlag: FC<BuilderStatusFlagProps> = ({ stateDetails }) => {
//TODO: check what to do here with the states for the MVP
const isDeactivated = stateDetails && (!stateDetails.kycApproved || !stateDetails.communityApproved)
const isPaused = stateDetails && stateDetails.paused

const color = isDeactivated ? '#932309' : isPaused ? '#F9E1FF' : 'transparent'
const content = isDeactivated ? 'Status: Deactivated' : isPaused ? 'Status: Paused' : ''
Expand All @@ -88,6 +86,12 @@ const BuilderStatusFlag = ({ stateDetails }: { stateDetails: BuilderStateDetails
)
}

type BuilderCellProps = {
tableHeader: TableHeader
builderName: string
address: Address
} & BuilderStatusFlagProps

export const BuilderNameCell: FC<BuilderCellProps> = ({
tableHeader: { className },
builderName,
Expand Down
4 changes: 2 additions & 2 deletions src/app/collective-rewards/user/context/BuilderContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const BuilderContextProvider: FC<BuilderProviderProps> = ({ children }) =

const filteredBuilders = useMemo(() => {
return builders.reduce<ProposalByBuilder>((acc, builder) => {
const { status, address, gauge } = builder
const { status, address, gauge, stateDetails } = builder
const proposal = getMostAdvancedProposal(builder, proposalsStateMap)

if (proposal) {
Expand All @@ -75,7 +75,7 @@ export const BuilderContextProvider: FC<BuilderProviderProps> = ({ children }) =
acc[address] = {
builderName,
status: getBuilderStatus(status),
stateDetails: builder.stateDetails,
stateDetails,
address,
proposalId,
proposalName,
Expand Down
11 changes: 10 additions & 1 deletion src/app/collective-rewards/user/hooks/useGetBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,17 @@ export const useGetBuilders = (): BuildersLoader => {
} = useReadContracts({ contracts: builderStatesCalls, query: { refetchInterval: AVERAGE_BLOCKTIME } })
const builderStates = builderStatesResult?.map(({ result }) => result as BuilderStateStruct)

// TODO: how to validate builders from mvp
const builderStateDetails = builders?.reduce<BuilderStateDetailsMap>((acc, builder, index) => {
const builderState = (builderStates?.[index] ?? []) as BuilderStateStruct
const builderState = (builderStates?.[index] ?? [
false,
false,
false,
false,
false,
'',
'',
]) as BuilderStateStruct
const [activated, kycApproved, communityApproved, paused, revoked] = builderState
acc[builder] = { activated, kycApproved, communityApproved, paused, revoked }
return acc
Expand Down

0 comments on commit 91d4bb0

Please sign in to comment.