From 480d8f3884cd42147a300ed16e20ff11e2939d45 Mon Sep 17 00:00:00 2001 From: Kevin O'Connell Date: Thu, 17 Oct 2024 15:51:08 -0700 Subject: [PATCH] fix cast response --- src/components/NetworkResponse.tsx | 53 ++++++++++++++++-------------- src/constants.ts | 23 +++++++++++-- src/lib/utils.ts | 6 ++-- 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/src/components/NetworkResponse.tsx b/src/components/NetworkResponse.tsx index 8e2aeb2..3af5acd 100644 --- a/src/components/NetworkResponse.tsx +++ b/src/components/NetworkResponse.tsx @@ -283,12 +283,12 @@ const NetworkResponse = ({ identifier }: any) => { warpcastCastHubMissing )} {renderHeader( - 'Neynar hub', + 'Neynar hub-api', neynarHubAuthor, neynarAuthorHubMissing )} {renderHeader( - 'Neynar hub', + 'Neynar hub-api', neynarHubCast, neynarCastHubMissing )} @@ -326,29 +326,32 @@ const NetworkResponse = ({ identifier }: any) => { )} {showOtherHubs && ( -
- {hubs.slice(2).map((hub, index) => { - const hubData = data?.hubData?.[index + 2]; - const hubAuthor = hubData?.author; - const hubCast = hubData?.cast; - const missingObjectsAuthor = checkWarning(hubAuthor); - const missingObjectsCast: any[] = []; - return ( -
- {renderHeader( - `${capitalizeNickname(hub.shortname)}`, - hubAuthor, - missingObjectsAuthor - )} - {renderHeader( - `${capitalizeNickname(hub.shortname)}`, - hubCast, - missingObjectsCast - )} -
- ); - })} -
+ <> + {data?.hubData + .slice(2) + .map((hub: any, index: number) => { + const hubData = hub; + const hubAuthor = hubData?.author; + const hubCast = hubData?.cast; + const missingObjectsAuthor = + checkWarning(hubAuthor); + const missingObjectsCast: any[] = []; + return ( +
+ {renderHeader( + `${capitalizeNickname(hub.name)}`, + hubAuthor, + missingObjectsAuthor + )} + {renderHeader( + `${capitalizeNickname(hub.name)}`, + hubCast, + missingObjectsCast + )} +
+ ); + })} + )} )} diff --git a/src/constants.ts b/src/constants.ts index 5a6f118..7792b9a 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -5,7 +5,15 @@ export const seo = { url: 'https://explorer.neynar.com', }; -export const hubs = [ +const additionalHubs = + process.env.ADDITIONAL_HUBS?.split(',').map((hub) => hub.trim()) || []; + +const extractFirstLetter = (hubUrl: string) => { + const hubName = hubUrl.match(/https?:\/\/([^.]+)\.hubs\.neynar\.com/); + return hubName ? hubName[1].charAt(0).toUpperCase() : 'Unknown'; +}; + +const defaultHubs = [ { shortname: 'Warpcast hub (Lamia)', url: 'https://lamia.farcaster.xyz:2281', @@ -14,8 +22,19 @@ export const hubs = [ { shortname: 'Warpcast hub (Hoyt)', url: 'https://hoyt.farcaster.xyz:2281' }, ]; +export const hubs = [ + ...defaultHubs, + ...additionalHubs.map((hubUrl) => { + const firstLetter = extractFirstLetter(hubUrl); + return { + shortname: `Neynar hub ${firstLetter}`, + url: hubUrl, + }; + }), +]; + export const neynarHub = { - shortname: 'Neynar hub', + shortname: 'Neynar hub-api', url: 'https://hub-api.neynar.com', }; export const defaultHash = '0x3e7326f8da760ed926c1fe82e1444cd528fe6c78'; diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 32e6beb..2b59782 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -344,7 +344,7 @@ export async function fetchCastFromHub( api_key?: string; 'x-airstack-hubs'?: string; } = { 'Content-Type': 'application/json' }; - if (hub.shortname === 'Neynar hub') { + if (hub.shortname.includes('Neynar hub')) { headers.api_key = `${process.env.NEXT_PUBLIC_NEYNAR_API_KEY}`; } const response = await axios.get( @@ -392,7 +392,7 @@ async function fetchLink(hub: HubType, fid: string, target_fid: string) { 'Content-Type': string; api_key?: string; } = { 'Content-Type': 'application/json' }; - if (hub.shortname === 'Neynar hub') { + if (hub.shortname.includes('Neynar')) { headers.api_key = `${process.env.NEXT_PUBLIC_NEYNAR_API_KEY}`; } try { @@ -439,7 +439,7 @@ export async function fetchFidFromHub( api_key?: string; 'x-airstack-hubs'?: string; } = { 'Content-Type': 'application/json' }; - if (hub.shortname === 'Neynar hub') { + if (hub.shortname.includes('Neynar')) { headers.api_key = `${process.env.NEXT_PUBLIC_NEYNAR_API_KEY}`; } if (followRelationship) {