mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-11-21 18:28:00 -05:00
formatting
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
import { NeynarAPIClient, Configuration, WebhookUserCreated } from '@neynar/nodejs-sdk';
|
||||
import {
|
||||
NeynarAPIClient,
|
||||
Configuration,
|
||||
WebhookUserCreated,
|
||||
} from '@neynar/nodejs-sdk';
|
||||
import { APP_URL } from './constants';
|
||||
|
||||
let neynarClient: NeynarAPIClient | null = null;
|
||||
|
||||
// Example usage:
|
||||
// const client = getNeynarClient();
|
||||
// const user = await client.lookupUserByFid(fid);
|
||||
// const user = await client.lookupUserByFid(fid);
|
||||
export function getNeynarClient() {
|
||||
if (!neynarClient) {
|
||||
const apiKey = process.env.NEYNAR_API_KEY;
|
||||
@@ -33,12 +37,12 @@ export async function getNeynarUser(fid: number): Promise<User | null> {
|
||||
|
||||
type SendMiniAppNotificationResult =
|
||||
| {
|
||||
state: "error";
|
||||
state: 'error';
|
||||
error: unknown;
|
||||
}
|
||||
| { state: "no_token" }
|
||||
| { state: "rate_limit" }
|
||||
| { state: "success" };
|
||||
| { state: 'no_token' }
|
||||
| { state: 'rate_limit' }
|
||||
| { state: 'success' };
|
||||
|
||||
export async function sendNeynarMiniAppNotification({
|
||||
fid,
|
||||
@@ -58,19 +62,19 @@ export async function sendNeynarMiniAppNotification({
|
||||
target_url: APP_URL,
|
||||
};
|
||||
|
||||
const result = await client.publishFrameNotifications({
|
||||
targetFids,
|
||||
notification
|
||||
const result = await client.publishFrameNotifications({
|
||||
targetFids,
|
||||
notification,
|
||||
});
|
||||
|
||||
if (result.notification_deliveries.length > 0) {
|
||||
return { state: "success" };
|
||||
return { state: 'success' };
|
||||
} else if (result.notification_deliveries.length === 0) {
|
||||
return { state: "no_token" };
|
||||
return { state: 'no_token' };
|
||||
} else {
|
||||
return { state: "error", error: result || "Unknown error" };
|
||||
return { state: 'error', error: result || 'Unknown error' };
|
||||
}
|
||||
} catch (error) {
|
||||
return { state: "error", error };
|
||||
return { state: 'error', error };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user