-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement WorldApp global var check #39
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"use client"; | ||
|
||
import { | ||
MiniKit, | ||
MiniKitInstallErrorCode, | ||
MiniKitInstallErrorMessage, | ||
} from "@worldcoin/minikit-js"; | ||
|
||
export const Versions = () => { | ||
const isValid = () => { | ||
if ( | ||
typeof window === "undefined" || | ||
typeof window.WorldApp === "undefined" | ||
) { | ||
return { isValid: false, error: "window.WorldApp is undefined" }; | ||
} | ||
|
||
try { | ||
// @ts-ignore | ||
if (MiniKit.commandsValid(window.WorldApp?.supported_commands)) { | ||
return { isValid: true }; | ||
} else { | ||
return { | ||
isValid: false, | ||
error: | ||
MiniKitInstallErrorMessage[MiniKitInstallErrorCode.AppOutOfDate], | ||
}; | ||
} | ||
} catch (error) { | ||
return { | ||
isValid: false, | ||
error: "Something went wrong on version validation", | ||
}; | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="grid gap-y-4"> | ||
<h2 className="font-bold text-2xl">Versions</h2> | ||
|
||
<div> | ||
<p>window.WorldApp:</p> | ||
|
||
<div className="bg-gray-300 min-h-[100px] p-2"> | ||
<pre | ||
suppressHydrationWarning | ||
className="break-all whitespace-break-spaces" | ||
> | ||
{JSON.stringify(window?.WorldApp ?? null, null, 2)} | ||
</pre> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<p>Is versions Valid:</p> | ||
|
||
<div className="bg-gray-300 min-h-[100px] p-2"> | ||
<pre className="break-all whitespace-break-spaces"> | ||
{JSON.stringify(isValid() ?? null, null, 2)} | ||
</pre> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,12 @@ import { User } from "./User"; | |
import { Nav } from "./Nav"; | ||
import { WalletAuth } from "./WalletAuth"; | ||
import { ExternalLinks } from "./ExternalLinks"; | ||
import dynamic from "next/dynamic"; | ||
|
||
const VersionsNoSSR = dynamic( | ||
() => import("./Versions").then((comp) => comp.Versions), | ||
{ ssr: false } | ||
); | ||
|
||
export const ClientContent = () => { | ||
return ( | ||
|
@@ -18,6 +24,8 @@ export const ClientContent = () => { | |
<hr /> | ||
|
||
<div className="grid gap-y-8"> | ||
<VersionsNoSSR /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andy-t-wang Made it dynamic import because in the demo we are using window.WorldApp inside the JSX markup, and nextjs still trying to hydrate this component end it cause hydration error, text inside <pre*>window.WorldApp</pre*> is not matches between server and client because window is not exist on server |
||
<hr /> | ||
<VerifyAction /> | ||
<hr /> | ||
<Pay /> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
interface Window { | ||
webkit?: { | ||
messageHandlers?: { | ||
minikit?: { | ||
postMessage?: (payload: Record<string, any>) => void; | ||
}; | ||
}; | ||
}; | ||
|
||
Android?: { | ||
postMessage?: (payload: string) => void; | ||
}; | ||
|
||
MiniKit?: import("@worldcoin/minikit-js").MiniKit; | ||
|
||
WorldApp?: { | ||
world_app_version: number; | ||
device_os: "ios" | "android"; | ||
|
||
supported_commands: Array<{ | ||
name: import("@worldcoin/minikit-js").Command; | ||
supported_versions: Array<number>; | ||
}>; | ||
}; | ||
} |
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.
@andy-t-wang
Result
Desktop:
From the app: