-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replace hardcoded sanchonet with the network from network metrics
- Loading branch information
1 parent
2f3d2f0
commit bb2b647
Showing
25 changed files
with
7,563 additions
and
2,817 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
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
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,68 @@ | ||
import { | ||
createContext, | ||
PropsWithChildren, | ||
useContext, | ||
useEffect, | ||
useMemo, | ||
} from "react"; | ||
import * as Sentry from "@sentry/react"; | ||
|
||
import { NETWORK_NAMES, CEXPLORER_BASE_URLS } from "@/consts"; | ||
import { useGetNetworkMetrics } from "@/hooks"; | ||
|
||
type AppContextType = { | ||
networkName: string; | ||
network: string; | ||
cExplorerBaseUrl: string; | ||
}; | ||
|
||
const AppContext = createContext<AppContextType | null>(null); | ||
|
||
/** | ||
* Provides app context to its children components. | ||
* | ||
* @param children - The child components to render. | ||
*/ | ||
const AppContextProvider = ({ children }: PropsWithChildren) => { | ||
useEffect(() => { | ||
Sentry.setTag("component_name", "AppContextProvider"); | ||
}, []); | ||
|
||
const { networkMetrics } = useGetNetworkMetrics(); | ||
|
||
const value = useMemo( | ||
() => ({ | ||
networkName: | ||
NETWORK_NAMES[ | ||
(networkMetrics?.networkName as keyof typeof NETWORK_NAMES) || | ||
"preview" | ||
], | ||
network: networkMetrics?.networkName || "preview", | ||
cExplorerBaseUrl: | ||
CEXPLORER_BASE_URLS[ | ||
(networkMetrics?.networkName as keyof typeof NETWORK_NAMES) || | ||
"preview" | ||
], | ||
}), | ||
[networkMetrics], | ||
); | ||
|
||
return <AppContext.Provider value={value}>{children}</AppContext.Provider>; | ||
}; | ||
|
||
/** | ||
* Custom hook that provides access to the app context. | ||
* Throws an error if used outside of an AppContextProvider. | ||
* @returns The app context. | ||
*/ | ||
const useAppContext = () => { | ||
const context = useContext(AppContext); | ||
|
||
if (!context) { | ||
throw new Error("useAppContext must be used within an AppContextProvider"); | ||
} | ||
|
||
return context; | ||
}; | ||
|
||
export { AppContextProvider, useAppContext }; |
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
Oops, something went wrong.