-
Notifications
You must be signed in to change notification settings - Fork 13
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
12 changed files
with
199 additions
and
159 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
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
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,2 @@ | ||
export const ONE_SECOND = 1000; | ||
export const ONE_MINUTE = 60 * ONE_SECOND; |
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,62 @@ | ||
import { createContext, PropsWithChildren, useContext, useMemo } from "react"; | ||
|
||
import { useBTCTipHeight } from "@/app/hooks/useBTCTipHeight"; | ||
import { useVersions } from "@/app/hooks/useVersions"; | ||
import type { GlobalParamsVersion } from "@/app/types/globalParams"; | ||
import { getCurrentGlobalParamsVersion } from "@/utils/globalParams"; | ||
|
||
interface VersionInfoProps { | ||
currentVersion?: GlobalParamsVersion; | ||
currentHeight?: number; | ||
nextVersion?: GlobalParamsVersion; | ||
isApprochingNextVersion: boolean; | ||
firstActivationHeight: number; | ||
isError?: boolean; | ||
isLoading?: boolean; | ||
} | ||
|
||
const VersionInfoContext = createContext<VersionInfoProps | undefined>({ | ||
isApprochingNextVersion: false, | ||
firstActivationHeight: 0, | ||
}); | ||
|
||
export function useVersionInfo() { | ||
return useContext(VersionInfoContext); | ||
} | ||
|
||
export function VersionInfo({ children }: PropsWithChildren) { | ||
const { | ||
data: versions, | ||
isError: isVersionError, | ||
isLoading: isVersionLoading, | ||
} = useVersions(); | ||
const { | ||
data: height, | ||
isError: isHeightError, | ||
isLoading: isHeightLoading, | ||
} = useBTCTipHeight(); | ||
|
||
const context = useMemo(() => { | ||
if (!versions || !height) return; | ||
|
||
return { | ||
currentHeight: height, | ||
isError: isHeightError || isVersionError, | ||
isLoading: isVersionLoading || isHeightLoading, | ||
...getCurrentGlobalParamsVersion(height + 1, versions), | ||
}; | ||
}, [ | ||
versions, | ||
height, | ||
isHeightError, | ||
isVersionError, | ||
isVersionLoading, | ||
isHeightLoading, | ||
]); | ||
|
||
return ( | ||
<VersionInfoContext.Provider value={context}> | ||
{children} | ||
</VersionInfoContext.Provider> | ||
); | ||
} |
Oops, something went wrong.