Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose method to fetch user details #122

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};
Loading