-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement versions component for demo
- Loading branch information
1 parent
a5a8338
commit cf25a5a
Showing
3 changed files
with
103 additions
and
0 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,75 @@ | ||
"use client"; | ||
|
||
import { | ||
MiniKit, | ||
MiniKitInstallErrorCode, | ||
MiniKitInstallErrorMessage, | ||
} from "@worldcoin/minikit-js"; | ||
import { useEffect } from "react"; | ||
|
||
export const Versions = () => { | ||
useEffect(() => { | ||
if ( | ||
typeof window === "undefined" || | ||
typeof window.WorldApp === "undefined" | ||
) { | ||
return; | ||
} | ||
|
||
// @ts-ignore | ||
console.log(MiniKit.commandsValid(window.WorldApp?.supported_commands)); | ||
}, []); | ||
|
||
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 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> | ||
); | ||
}; |
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,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>; | ||
}>; | ||
}; | ||
} |