-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Namadillo: Checks for indexer and keychain compatibility (#1449)
* feat: checks for indexer and keychain compatibility * refactor: decoupling code a bit * feat: improving code readability
- Loading branch information
1 parent
7a5430a
commit 2a7cd74
Showing
9 changed files
with
208 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ReactNode } from "react"; | ||
import { IoWarning } from "react-icons/io5"; | ||
|
||
type FixedWarningBannerProps = { | ||
errorMessage: ReactNode; | ||
}; | ||
|
||
export const FixedWarningBanner = ({ | ||
errorMessage, | ||
}: FixedWarningBannerProps): JSX.Element => { | ||
if (!errorMessage) return <></>; | ||
|
||
return ( | ||
<div className="fixed bottom-0 left-0 w-full bg-yellow z-[9999]"> | ||
<div className="flex flex-row justify-center items-center gap-1 px-12 py-3 text-sm [&_a]:underline"> | ||
<strong className="inline-flex items-center"> | ||
<IoWarning /> WARNING:{" "} | ||
</strong> | ||
<div>{errorMessage}</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
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,4 @@ | ||
{ | ||
"keychain": "0.3.x", | ||
"indexer": "1.1.x" | ||
} |
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; | ||
}; |
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,104 @@ | ||
import { routes } from "App/routes"; | ||
import compatibilty from "compatibility.json"; | ||
import { wallets } from "integrations"; | ||
import { Link } from "react-router-dom"; | ||
import semverSatisfies from "semver/functions/satisfies"; | ||
import semverLtr from "semver/ranges/ltr"; | ||
import { isFirefox } from "./etc"; | ||
|
||
enum CompatibilityOutput { | ||
IncompatibleVersion = -1, | ||
Compatible = 0, | ||
InterfaceOutdated = 1, | ||
} | ||
|
||
// Checks if the versions are compatible using semantic versioning (semver). | ||
// Returns true if the versions are compatible, -1 if the version is outdated, | ||
// or 1 if a required version is lower than the version provided. | ||
const checkVersionsCompatible = ( | ||
currentVersion: string, | ||
requiredVersion: string | ||
): CompatibilityOutput => { | ||
if (semverSatisfies(currentVersion, requiredVersion)) { | ||
return CompatibilityOutput.Compatible; | ||
} | ||
return semverLtr(currentVersion, requiredVersion) ? | ||
CompatibilityOutput.IncompatibleVersion | ||
: CompatibilityOutput.InterfaceOutdated; | ||
}; | ||
|
||
export const checkIndexerCompatibilityErrors = ( | ||
indexerVersion: string | ||
): React.ReactNode => { | ||
const requiredVersion = compatibilty.indexer; | ||
const checkResult = checkVersionsCompatible(indexerVersion, requiredVersion); | ||
|
||
if (checkResult === CompatibilityOutput.IncompatibleVersion) { | ||
return ( | ||
<> | ||
You're using an outdated version of Namada Indexer. Please update | ||
your indexer URL in the{" "} | ||
<Link to={routes.settingsAdvanced}>Advanced Settings</Link> section. | ||
</> | ||
); | ||
} | ||
|
||
if (checkResult === CompatibilityOutput.InterfaceOutdated) { | ||
return ( | ||
<> | ||
Your Namadillo version is not compatible with the current Namada | ||
Indexer. Please upgrade your web interface or pick a different one from | ||
the <a href="https://namada.net/apps#interfaces">Namada Apps</a> list. | ||
</> | ||
); | ||
} | ||
|
||
return ""; | ||
}; | ||
|
||
export const checkKeychainCompatibilityError = ( | ||
keychainVersion: string | ||
): React.ReactNode => { | ||
const targetKeychainVersion = compatibilty.keychain; | ||
const checkResult = checkVersionsCompatible( | ||
keychainVersion, | ||
targetKeychainVersion | ||
); | ||
|
||
if (checkResult === CompatibilityOutput.IncompatibleVersion) { | ||
return ( | ||
<> | ||
Your Namada Keychain version is outdated. Please upgrade it using{" "} | ||
{isFirefox() ? | ||
<a | ||
href={wallets.namada.downloadUrl.firefox} | ||
target="_blank" | ||
rel="nofollow noreferrer" | ||
> | ||
Firefox addons | ||
</a> | ||
: <a | ||
href={wallets.namada.downloadUrl.chrome} | ||
target="_blank" | ||
rel="nofollow noreferrer" | ||
> | ||
Chrome store | ||
</a> | ||
}{" "} | ||
or websites. | ||
</> | ||
); | ||
} | ||
|
||
if (checkResult === CompatibilityOutput.InterfaceOutdated) { | ||
return ( | ||
<> | ||
Your Namadillo version is not compatible with the keychain installed. | ||
Please upgrade your web interface or pick a different one from the{" "} | ||
<a href="https://namada.net/apps#interfaces">Namada Apps</a> list. | ||
</> | ||
); | ||
} | ||
|
||
return ""; | ||
}; |
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 @@ | ||
export const isFirefox = (): boolean => /firefox/i.test(navigator.userAgent); |
2a7cd74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://namada-interface-dev.netlify.app as production
🚀 Deployed on https://676f1ce94e3074b433e331d2--namada-interface-dev.netlify.app