Skip to content

Commit

Permalink
feat: add static appId var (#83)
Browse files Browse the repository at this point in the history
* Move wallet address to config, add appId to config

* add appid on install to demo

* move vars to toplevel

* missing appid should not break stuff
  • Loading branch information
michalstruck authored Oct 24, 2024
1 parent 3316c55 commit a83c9fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion demo/with-next/components/ClientContent/Versions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
MiniKitInstallErrorMessage,
} from "@worldcoin/minikit-js";

const appId = "your-app-id";

export const Versions = () => {
const isValid = () => {
if (
Expand Down Expand Up @@ -35,7 +37,7 @@ export const Versions = () => {
};

const reinstall = () => {
MiniKit.install();
MiniKit.install(appId);
JSON.stringify(isValid() ?? null, null, 2);
};
return (
Expand Down
4 changes: 3 additions & 1 deletion demo/with-next/components/MiniKitProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import { MiniKit } from "@worldcoin/minikit-js";
import { useEffect, ReactNode } from "react";

const appId = "your-app-id";

export const MiniKitProvider = ({ children }: { children: ReactNode }) => {
useEffect(() => {
MiniKit.install();
MiniKit.install(appId);
}, []);

return <>{children}</>;
Expand Down
9 changes: 8 additions & 1 deletion packages/core/minikit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class MiniKit {
[ResponseEvent.MiniAppSignTypedData]: () => {},
};

public static appId: string | null = null;
public static walletAddress: string | null = null;

private static sendInit() {
Expand Down Expand Up @@ -140,7 +141,7 @@ export class MiniKit {
);
}

public static install(): MiniKitInstallReturnType {
public static install(appId?: string): MiniKitInstallReturnType {
if (typeof window === "undefined" || Boolean(window.MiniKit)) {
return {
success: false,
Expand All @@ -150,6 +151,12 @@ export class MiniKit {
};
}

if (!appId) {
console.warn("App ID not provided during install");
} else {
MiniKit.appId = appId;
}

if (!window.WorldApp) {
return {
success: false,
Expand Down

0 comments on commit a83c9fb

Please sign in to comment.