Skip to content

Commit

Permalink
fix(TwaLoader): fix version at least
Browse files Browse the repository at this point in the history
  • Loading branch information
Razzwan committed Nov 13, 2023
1 parent 10b2882 commit e6e49d9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@altiore/twa",
"version": "1.2.11",
"version": "1.2.12",
"description": "React components for Telegram WebApp",
"source": "./src/index.ts",
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions src/TwaLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const TwaLoader: FC<IProps> = ({
loading = null,
isTWApp = null,
noTWApp = null,
minVersion = null,
minVersion,
showNotification = false,
}): React.JSX.Element | null => {
useEffect(() => {
Expand All @@ -32,7 +32,7 @@ export const TwaLoader: FC<IProps> = ({

const { isLoaded, isLoading } = useTwa();

const isCorrectVersion = useVersionAtLeast(minVersion ?? '6.2');
const isCorrectVersion = useVersionAtLeast(minVersion);

const isVersionAtLeast = useIsVersionAtLeast();

Expand Down
6 changes: 4 additions & 2 deletions src/useVersionAtLeast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ export type VersionAtLeastFunction = (version: string | number) => boolean;
* The hook provided isVersionAtLeast function of the type {@link VersionAtLeastFunction}
* @group Hooks
*/
export const useVersionAtLeast = (version: string | number): boolean => {
export const useVersionAtLeast = (
version?: string | number | null,
): boolean => {
const WebApp = useWebApp();

return useMemo<boolean>(
() => WebApp?.isVersionAtLeast?.(version) ?? false,
() => (version ? Boolean(WebApp?.isVersionAtLeast?.(version)) : false),
[WebApp, version],
);
};

0 comments on commit e6e49d9

Please sign in to comment.