Skip to content

Commit 1fa8e79

Browse files
refactor(block-time): migrate hooks batch 4 + remove legacy constants (DAO-1983 C6/6)
Drop AVERAGE_BLOCKTIME and DEFAULT_NUMBER_OF_SECONDS_PER_BLOCK; Countdown uses useBlockTime. Completes call-site migration.
1 parent 9ba933c commit 1fa8e79

18 files changed

Lines changed: 24 additions & 44 deletions

src/components/Countdown/Countdown.stories.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Countdown } from './Countdown'
33
import { TimeSource } from './types'
44
import Big from '@/lib/big'
55
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
6+
import { BlockTimeProvider } from '@/shared/context/BlockTimeContext'
67

78
const queryClient = new QueryClient()
89

@@ -16,7 +17,9 @@ const meta: Meta<typeof Countdown> = {
1617
decorators: [
1718
Story => (
1819
<QueryClientProvider client={queryClient}>
19-
<Story />
20+
<BlockTimeProvider>
21+
<Story />
22+
</BlockTimeProvider>
2023
</QueryClientProvider>
2124
),
2225
],

src/components/Countdown/Countdown.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1+
'use client'
2+
13
import moment from 'moment'
24
import { useBlockNumber } from 'wagmi'
35

46
import { Paragraph } from '@/components/Typography'
57
import Big from '@/lib/big'
6-
import { DEFAULT_NUMBER_OF_SECONDS_PER_BLOCK } from '@/lib/constants'
78
import { cn } from '@/lib/utils'
9+
import { useBlockTime } from '@/shared/context/BlockTimeContext'
810

911
import { CountdownProps, TimeSource } from './types'
1012

1113
/**
1214
* Calculates the time remaining in seconds
1315
*/
14-
const calculateTimeRemaining = (end: Big, currentTime: Big, timeSource: TimeSource): number => {
16+
const calculateTimeRemaining = (
17+
end: Big,
18+
currentTime: Big,
19+
timeSource: TimeSource,
20+
secondsPerBlock: number,
21+
): number => {
1522
const remaining = end.minus(currentTime)
1623
if (remaining.lte(0)) return 0
1724

1825
if (timeSource === 'blocks') {
19-
return remaining.mul(DEFAULT_NUMBER_OF_SECONDS_PER_BLOCK).toNumber()
26+
return remaining.mul(secondsPerBlock).toNumber()
2027
} else {
2128
return remaining.toNumber()
2229
}
@@ -104,6 +111,7 @@ export function Countdown({
104111
className,
105112
colorDirection = 'normal',
106113
}: CountdownProps) {
114+
const { secondsPerBlock } = useBlockTime()
107115
const { data: currentBlockNumber } = useBlockNumber()
108116

109117
// Calculate current time based on timeSource
@@ -114,7 +122,7 @@ export function Countdown({
114122
: Big(0)
115123
: Big(Math.floor(Date.now() / 1000))
116124

117-
const timeRemainingSec = calculateTimeRemaining(end, currentTime, timeSource)
125+
const timeRemainingSec = calculateTimeRemaining(end, currentTime, timeSource, secondsPerBlock)
118126
const ratio = calculateRatio(end, currentTime, referenceStart)
119127

120128
// Color coding is automatically disabled if ratio cannot be calculated (no referenceStart)

src/lib/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ export const DEPOSITOR_ROLE = '0x013e1f410e70025de956b8838ba99c3a9a9f7eb3e6d6780
8989
// keccak256('WHITELISTED_USER_ROLE') — mirrors Roles.sol (internal constant, no on-chain getter)
9090
export const WHITELISTED_USER_ROLE = '0x013e1f410e70025de956b8838ba99c3a9a9f7eb3e6d678062363333c8abd7ea0'
9191

92-
export const AVERAGE_BLOCKTIME = 60_000
9392
export const CACHE_REVALIDATE_SECONDS = 20
9493

9594
export const RIF = 'RIF'
@@ -111,7 +110,6 @@ export const GRANT_TOKEN_LIMITS = {
111110
export const RNS_REGISTRY_ADDRESS = process.env.NEXT_PUBLIC_RNS_REGISTRY_ADDRESS as Address
112111

113112
export const NODE_URL = process.env.NEXT_PUBLIC_NODE_URL
114-
export const DEFAULT_NUMBER_OF_SECONDS_PER_BLOCK = 25
115113

116114
export const GOOGLE_TAG_ID = 'GTM-PTL6VZMT'
117115

src/shared/hooks/contracts/btc-vault/useReadRbtcVaultForMultipleArgs.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useMemo } from 'react'
22
import { UseReadContractReturnType, useReadContracts } from 'wagmi'
33

44
import { getAbi, type RBTCAsyncVaultAbi } from '@/lib/abis/btc-vault'
5-
import { AVERAGE_BLOCKTIME } from '@/lib/constants'
65
import { rbtcVault } from '@/lib/contracts'
76

87
import { UseReadContractForMultipleArgsConfig, ViewPureFunctionName } from '../types'
@@ -32,7 +31,6 @@ export const useReadRbtcVaultForMultipleArgs = <TFunctionName extends RbtcAsyncV
3231
})),
3332
query: {
3433
retry: true,
35-
refetchInterval: AVERAGE_BLOCKTIME,
3634
...query,
3735
},
3836
})

src/shared/hooks/contracts/btc-vault/useReadSyntheticYield.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useReadContract, UseReadContractParameters, UseReadContractReturnType } from 'wagmi'
22

33
import { getAbi, SyntheticYieldAbi } from '@/lib/abis/btc-vault'
4-
import { AVERAGE_BLOCKTIME } from '@/lib/constants'
54
import { syntheticYield } from '@/lib/contracts'
65

76
import { UseReadContractConfig, ViewPureFunctionName } from '../types'
@@ -24,7 +23,6 @@ export const useReadSyntheticYield = <TFunctionName extends SyntheticYieldFuncti
2423
...(config as any),
2524
query: {
2625
retry: true,
27-
refetchInterval: AVERAGE_BLOCKTIME,
2826
...query,
2927
},
3028
})

src/shared/hooks/contracts/collective-rewards/useReadBackersManager.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useReadContract, UseReadContractParameters, UseReadContractReturnType } from 'wagmi'
22

33
import { type BackersManagerAbi, getAbi } from '@/lib/abis/tok'
4-
import { AVERAGE_BLOCKTIME } from '@/lib/constants'
54
import { BackersManagerAddress } from '@/lib/contracts'
65

76
import { UseReadContractConfig, ViewPureFunctionName } from '../types'
@@ -24,7 +23,6 @@ export const useReadBackersManager = <TFunctionName extends BackersManagerFuncti
2423
...(config as any),
2524
query: {
2625
retry: true,
27-
refetchInterval: AVERAGE_BLOCKTIME,
2826
...query,
2927
},
3028
})

src/shared/hooks/contracts/collective-rewards/useReadBuilderRegistry.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useReadContract, UseReadContractParameters, UseReadContractReturnType } from 'wagmi'
22

33
import { type BuilderRegistryAbi, getAbi } from '@/lib/abis/tok'
4-
import { AVERAGE_BLOCKTIME } from '@/lib/constants'
54
import { BuilderRegistryAddress } from '@/lib/contracts'
65

76
import { UseReadContractConfig, ViewPureFunctionName } from '../types'
@@ -24,7 +23,6 @@ export const useReadBuilderRegistry = <TFunctionName extends BuilderRegistryFunc
2423
...(config as any),
2524
query: {
2625
retry: true,
27-
refetchInterval: AVERAGE_BLOCKTIME,
2826
...query,
2927
},
3028
})

src/shared/hooks/contracts/collective-rewards/useReadBuilderRegistryForMultipleArgs.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { getAbi } from '@/lib/abis/tok'
2-
import { AVERAGE_BLOCKTIME } from '@/lib/constants'
32
import { BuilderRegistryAddress } from '@/lib/contracts'
43
import { renderHook } from '@testing-library/react'
54
import { afterEach, describe, expect, it, Mock, vi } from 'vitest'
65
import { useReadContracts } from 'wagmi'
76
import { useReadBuilderRegistryForMultipleArgs } from './useReadBuilderRegistryForMultipleArgs'
87

9-
// Mock wagmi's useReadContracts
108
vi.mock('wagmi', () => ({
119
useReadContracts: vi.fn(),
1210
}))
@@ -59,7 +57,6 @@ describe('useReadBuilderRegistries hook', () => {
5957
],
6058
query: {
6159
retry: true,
62-
refetchInterval: AVERAGE_BLOCKTIME,
6360
},
6461
}),
6562
)

src/shared/hooks/contracts/collective-rewards/useReadBuilderRegistryForMultipleArgs.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useMemo } from 'react'
22
import { UseReadContractParameters, UseReadContractReturnType, useReadContracts } from 'wagmi'
33

44
import { type BuilderRegistryAbi, getAbi } from '@/lib/abis/tok'
5-
import { AVERAGE_BLOCKTIME } from '@/lib/constants'
65
import { BuilderRegistryAddress } from '@/lib/contracts'
76

87
import { UseReadContractForMultipleArgsConfig, ViewPureFunctionName } from '../types'
@@ -33,7 +32,6 @@ export const useReadBuilderRegistryForMultipleArgs = <TFunctionName extends Buil
3332
})),
3433
query: {
3534
retry: true,
36-
refetchInterval: AVERAGE_BLOCKTIME,
3735
...query,
3836
},
3937
})

src/shared/hooks/contracts/collective-rewards/useReadCycleTimeKeeper.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useReadContract, UseReadContractParameters, UseReadContractReturnType } from 'wagmi'
22

33
import { type CycleTimeKeeperAbi, getAbi } from '@/lib/abis/tok'
4-
import { AVERAGE_BLOCKTIME } from '@/lib/constants'
54
import { BackersManagerAddress } from '@/lib/contracts'
65

76
import { UseReadContractConfig, ViewPureFunctionName } from '../types'
@@ -24,7 +23,6 @@ export const useReadCycleTimeKeeper = <TFunctionName extends CycleTimeKeeperFunc
2423
...(config as any),
2524
query: {
2625
retry: true,
27-
refetchInterval: AVERAGE_BLOCKTIME,
2826
...query,
2927
},
3028
})

0 commit comments

Comments
 (0)