-
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
Showing
4 changed files
with
87 additions
and
15 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,18 @@ | ||
import { useFinalizationThreshold } from '../hooks/useFinalizationThreshold'; | ||
import { formatResetPeriod } from './BalanceDisplay'; | ||
|
||
interface FinalizationThresholdProps { | ||
chainId: number; | ||
} | ||
|
||
export function FinalizationThreshold({ chainId }: FinalizationThresholdProps) { | ||
const { finalizationThreshold } = useFinalizationThreshold(chainId); | ||
|
||
if (finalizationThreshold === null) return null; | ||
|
||
return ( | ||
<span className="px-2 py-1 text-xs bg-[#00ff00]/10 text-[#00ff00] rounded"> | ||
Finalization: {formatResetPeriod(finalizationThreshold)} | ||
</span> | ||
); | ||
} |
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,52 @@ | ||
import { useState, useEffect } from 'react'; | ||
|
||
interface ChainConfig { | ||
defaultFinalizationThresholdSeconds: number; | ||
supportedChains: Array<{ | ||
chainId: string; | ||
finalizationThresholdSeconds: number; | ||
}>; | ||
} | ||
|
||
export function useFinalizationThreshold(chainId: number) { | ||
const [finalizationThreshold, setFinalizationThreshold] = useState<number | null>(null); | ||
const [isLoading, setIsLoading] = useState(true); | ||
const [error, setError] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
const fetchFinalizationThreshold = async () => { | ||
try { | ||
const response = await fetch('/health'); | ||
if (!response.ok) { | ||
throw new Error('Failed to fetch chain configuration'); | ||
} | ||
const data = await response.json(); | ||
const chainConfig: ChainConfig = data.chainConfig; | ||
|
||
// Find the chain-specific threshold or use default | ||
const chainSpecific = chainConfig.supportedChains.find( | ||
chain => chain.chainId === chainId.toString() | ||
); | ||
|
||
setFinalizationThreshold( | ||
chainSpecific?.finalizationThresholdSeconds ?? | ||
chainConfig.defaultFinalizationThresholdSeconds | ||
); | ||
setError(null); | ||
} catch (err) { | ||
setError( | ||
err instanceof Error | ||
? err.message | ||
: 'Failed to fetch finalization threshold' | ||
); | ||
setFinalizationThreshold(null); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
fetchFinalizationThreshold(); | ||
}, [chainId]); | ||
|
||
return { finalizationThreshold, isLoading, error }; | ||
} |