Skip to content

Commit

Permalink
feat: expose method to fetch user details (#122)
Browse files Browse the repository at this point in the history
* Add method to fetch user details

* format
  • Loading branch information
Takaros999 authored Dec 19, 2024
1 parent c01f618 commit 02875a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
25 changes: 14 additions & 11 deletions packages/core/minikit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
} from "types";
import { validatePaymentPayload } from "helpers/payment/client";
import { getUserProfile } from "helpers/usernames";
import { User } from "./types/user";

export const sendMiniKitEvent = <
T extends WebViewBasePayload = WebViewBasePayload,
Expand Down Expand Up @@ -92,11 +93,7 @@ export class MiniKit {
* @deprecated you should use MiniKit.user.walletAddress instead
*/
public static walletAddress: string | null = null;
public static user: {
walletAddress: string | null;
username: string | null;
profilePictureUrl: string | null;
} | null = null;
public static user: User | null = null;

private static sendInit() {
sendWebviewEvent({
Expand All @@ -118,12 +115,8 @@ export class MiniKit {
) => {
if (payload.status === "success") {
MiniKit.walletAddress = payload.address;
getUserProfile(payload.address).then((queryResponse) => {
MiniKit.user = {
username: queryResponse.username,
profilePictureUrl: queryResponse.profilePictureUrl,
walletAddress: payload.address,
};
MiniKit.getUserByAddress(payload.address).then((user) => {
MiniKit.user = user;
});
}

Expand Down Expand Up @@ -259,6 +252,16 @@ export class MiniKit {
return isInstalled;
}

public static getUserByAddress = async (address: string): Promise<User> => {
const userProfile = await getUserProfile(address);

return {
walletAddress: address,
username: userProfile.username,
profilePictureUrl: userProfile.profilePictureUrl,
};
};

public static commands = {
verify: (payload: VerifyCommandInput): VerifyCommandPayload | null => {
if (
Expand Down
5 changes: 5 additions & 0 deletions packages/core/types/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type User = {
walletAddress: string;
username: string | null;
profilePictureUrl: string | null;
};

0 comments on commit 02875a1

Please sign in to comment.