Skip to content

Commit

Permalink
test-init
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-t-wang committed May 29, 2024
1 parent 72aa8ef commit e791e47
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ interface Window {
};

MiniKit?: import("./minikit").MiniKit;

WorldApp?: any;
}
14 changes: 14 additions & 0 deletions src/minikit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export class MiniKit {
[ResponseEvent.MiniAppWalletAuth]: () => {},
};

private static sendInit() {
sendWebviewEvent({
command: "init",
payload: { "minikit-version": 1 },
});
}

public static subscribe<E extends ResponseEvent>(
event: E,
handler: EventHandler<E>
Expand All @@ -58,6 +65,8 @@ export class MiniKit {
if (typeof window !== "undefined" && !Boolean(window.MiniKit)) {
try {
window.MiniKit = MiniKit;
this.sendInit();
console.log(window.WorldApp);
} catch (error) {
console.error("Failed to install MiniKit", error);
return { success: false, error };
Expand All @@ -69,6 +78,11 @@ export class MiniKit {

public static isInstalled(debug?: boolean) {
if (debug) console.log("MiniKit is alive!");

if (typeof window !== "undefined" && !Boolean(window.WorldApp)) {
return false;
}

return true;
}

Expand Down

0 comments on commit e791e47

Please sign in to comment.