diff --git a/demo/with-next/components/ClientContent/WalletAuth.tsx b/demo/with-next/components/ClientContent/WalletAuth.tsx index b9ef61c1..7e3844f7 100644 --- a/demo/with-next/components/ClientContent/WalletAuth.tsx +++ b/demo/with-next/components/ClientContent/WalletAuth.tsx @@ -88,6 +88,9 @@ export const WalletAuth = () => { } setReceivedWalletAuthPayload(payload); + console.log("From object", MiniKit?.walletAddress); + //@ts-ignore + console.log("From static", window.MiniKit?.walletAddress); }); return () => { diff --git a/src/minikit.ts b/src/minikit.ts index df8999a6..aa642ea6 100644 --- a/src/minikit.ts +++ b/src/minikit.ts @@ -60,6 +60,8 @@ export class MiniKit { [ResponseEvent.MiniAppSignTypedData]: () => {}, }; + public static walletAddress: string | null = null; + private static sendInit() { sendWebviewEvent({ command: "init", @@ -71,7 +73,24 @@ export class MiniKit { event: E, handler: EventHandler ) { - this.listeners[event] = handler; + if (event === ResponseEvent.MiniAppWalletAuth) { + const originalHandler = + handler as EventHandler; + + const wrappedHandler: EventHandler = ( + payload + ) => { + if (payload.status === "success") { + MiniKit.walletAddress = payload.address; + } + + originalHandler(payload); + }; + + this.listeners[event] = wrappedHandler as EventHandler; + } else { + this.listeners[event] = handler; + } } public static unsubscribe(event: ResponseEvent) { diff --git a/src/package.json b/src/package.json index a48d16ce..67e7f120 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "@worldcoin/minikit-js", - "version": "0.0.28-internal-alpha", + "version": "0.0.29-internal-alpha", "homepage": "https://docs.worldcoin.org/id/minikit", "description": "Internal Alpha: Mini-kit JS is a lightweight sdk for building mini-apps compatible with World App", "license": "MIT",