-
Notifications
You must be signed in to change notification settings - Fork 122
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
1 parent
6382ce6
commit ba53629
Showing
3 changed files
with
57 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { indexerHeartbeatAtom } from "atoms/settings"; | ||
import { useAtomValue } from "jotai"; | ||
import { useEffect, useState } from "react"; | ||
import { | ||
checkIndexerCompatibilityErrors, | ||
checkKeychainCompatibilityError, | ||
} from "utils/compatibility"; | ||
import { useNamadaKeychain } from "./useNamadaKeychain"; | ||
|
||
export const useCompatibilityErrors = (): React.ReactNode | undefined => { | ||
const indexerHealth = useAtomValue(indexerHeartbeatAtom); | ||
const keychain = useNamadaKeychain(); | ||
const [errorMessage, setErrorMessage] = useState< | ||
React.ReactNode | undefined | ||
>(); | ||
|
||
const verifyKeychainVersion = async (): Promise<void> => { | ||
const namadaKeychain = await keychain.namadaKeychain.get(); | ||
if (namadaKeychain) { | ||
const version = namadaKeychain.version(); | ||
const versionErrorMessage = checkKeychainCompatibilityError(version); | ||
if (versionErrorMessage) { | ||
setErrorMessage(versionErrorMessage); | ||
} | ||
} | ||
}; | ||
|
||
const verifyIndexerVersion = async (): Promise<void> => { | ||
const versionErrorMessage = checkIndexerCompatibilityErrors( | ||
indexerHealth.data?.version || "" | ||
); | ||
|
||
if (versionErrorMessage) { | ||
setErrorMessage(versionErrorMessage); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
verifyKeychainVersion(); | ||
}, [keychain]); | ||
|
||
useEffect(() => { | ||
indexerHealth.isSuccess && verifyIndexerVersion(); | ||
}, [indexerHealth]); | ||
|
||
return errorMessage; | ||
}; |