From 15c87f19a980776b68e2ce58245254f3f796cfad Mon Sep 17 00:00:00 2001 From: martines3000 Date: Mon, 1 Jul 2024 19:54:23 +0200 Subject: [PATCH] fix: resolve all remaining formating issues --- packages/dapp/package.json | 2 +- .../src/app/api/frame/[[...routes]]/route.tsx | 138 +++++++++++------- .../getMinimalProfileInfoByPlatform.ts | 3 +- packages/dapp/src/utils/endorsementOptions.ts | 2 +- 4 files changed, 86 insertions(+), 59 deletions(-) diff --git a/packages/dapp/package.json b/packages/dapp/package.json index 18e58a1..18a4af8 100644 --- a/packages/dapp/package.json +++ b/packages/dapp/package.json @@ -3,7 +3,7 @@ "private": true, "version": "0.0.0", "scripts": { - "dev": "infisical run --env=dev --path=/dapp -- next dev", + "dev": "next dev", "build": "rimraf .next && next build", "start": "next start", "lint": "biome check .", diff --git a/packages/dapp/src/app/api/frame/[[...routes]]/route.tsx b/packages/dapp/src/app/api/frame/[[...routes]]/route.tsx index 2ae75d0..a292af4 100644 --- a/packages/dapp/src/app/api/frame/[[...routes]]/route.tsx +++ b/packages/dapp/src/app/api/frame/[[...routes]]/route.tsx @@ -20,12 +20,17 @@ import { serveStatic } from 'frog/serve-static'; import { createPublicClient, http } from 'viem'; import { base } from 'viem/chains'; import { EESCore } from '@/lib/contracts/abis'; -import { APP_URL, PlatformType } from '@/utils'; -import { getMinimalProfileInfoByPlatform } from '@/lib/airstack'; +import { APP_URL, PlatformType, formatAddress } from '@/utils'; +import { + getAvatarForPlatform, + getBasicPlatformProfileInfo, + getProfileInfo, +} from '@/lib/airstack'; import { regexEns, regexEth, regexLens } from '@/utils/regex'; import { EXPLORERS } from '@/lib/contracts/explorers'; import { CONTRACT_ADDRESSES } from '@/lib/contracts'; import { ENDORSEMENT_OPTIONS } from '@/utils/endorsementOptions'; +import { Space } from 'lucide-react'; const options_length = ENDORSEMENT_OPTIONS.length; @@ -59,6 +64,7 @@ type State = { username: string; avatar: string; address: string; + platform: PlatformType; }; type: number; tip?: number; @@ -79,6 +85,7 @@ const app = new Frog<{ State: State }>({ username: '', avatar: '', address: '', + platform: PlatformType.farcaster, }, type: 0, tip: undefined, @@ -165,21 +172,21 @@ app.frame('/search', async (c) => { let platform; if (regexEns.test(inputText)) { - platform = 'ens'; + platform = PlatformType.ens; } else if (regexLens.test(inputText)) { - platform = 'lens'; + platform = PlatformType.lens; } else if (regexEth.test(inputText)) { - platform = 'ethereum'; + platform = PlatformType.ethereum; } else { - platform = 'farcaster'; + platform = PlatformType.farcaster; } - const userData = await getMinimalProfileInfoByPlatform( - PlatformType[platform as keyof typeof PlatformType], - inputText - ); + const profileInfo = await getProfileInfo(inputText, platform); + const userData = getBasicPlatformProfileInfo(profileInfo, platform); + const address = profileInfo.Wallet?.addresses?.[0]; + let avatar = getAvatarForPlatform(profileInfo, platform); - if (!userData.address) { + if (!address) { return c.res({ image: ( { } // If no avatar is available use address to generate one - if (!userData.avatar && userData.address) { - userData.avatar = blo(userData.address, 128); + if (!avatar) { + avatar = blo(address, 128); } const state = deriveState((previousState) => { - if (userData.displayName) { - previousState.user.username = userData.displayName; - } - if (userData.avatar) previousState.user.avatar = userData.avatar; - if (userData.address) previousState.user.address = userData.address; + previousState.user.username = userData.handle ?? ''; + previousState.user.avatar = avatar; + previousState.user.address = address; + previousState.user.platform = platform; }); return c.res({ @@ -222,7 +228,7 @@ app.frame('/search', async (c) => { backgroundImage={`url("${APP_URL}/frame/frame_bg1.png")`} height="100%" > - + { src={state.user.avatar} /> - + Endorsing - {state.user.username.length > 18 - ? `${state.user.username.slice(0, 16)}...` - : state.user.username} + {state.user.username && + (state.user.username.length > 18 + ? `${state.user.username.slice(0, 16)}...` + : state.user.username)} + {!state.user.username && formatAddress(state.user.address)} Confirm User @@ -286,38 +294,39 @@ app.frame('/type-selection', (c) => { backgroundImage={`url("${APP_URL}/frame/frame_bg1.png")`} height="100%" > - + - + Endorsing - {state.user.username.length > 18 - ? `${state.user.username.slice(0, 16)}...` - : state.user.username} + {state.user.username && + (state.user.username.length > 18 + ? `${state.user.username.slice(0, 16)}...` + : state.user.username)} + {!state.user.username && formatAddress(state.user.address)} - {ENDORSEMENT_OPTIONS[state.type].value === 'Based energy' - ? 'for' - : 'as a'} + {state.type === 0 ? 'for' : 'as a'} {ENDORSEMENT_OPTIONS[state.type].label} - + Select endorsement types - + {'by pressing < and > arrows'} @@ -370,24 +379,28 @@ app.frame('/form', (c) => { backgroundImage={`url("${APP_URL}/frame/frame_bg1.png")`} height="100%" > - + - + Endorsing - {state.user.username.length > 18 - ? `${state.user.username.slice(0, 16)}...` - : state.user.username} + {state.user.username && + (state.user.username.length > 18 + ? `${state.user.username.slice(0, 16)}...` + : state.user.username)} + {!state.user.username && + formatAddress(state.user.address)} Add a tip to the endorsement @@ -415,24 +428,28 @@ app.frame('/form', (c) => { backgroundImage={`url("${APP_URL}/frame/frame_bg1.png")`} height="100%" > - + - + Endorsing - {state.user.username.length > 18 - ? `${state.user.username.slice(0, 16)}...` - : state.user.username} + {state.user.username && + (state.user.username.length > 18 + ? `${state.user.username.slice(0, 16)}...` + : state.user.username)} + {!state.user.username && + formatAddress(state.user.address)} @@ -462,24 +479,27 @@ app.frame('/form', (c) => { backgroundImage={`url("${APP_URL}/frame/frame_bg1.png")`} height="100%" > - + - + Endorsing - {state.user.username.length > 18 - ? `${state.user.username.slice(0, 16)}...` - : state.user.username} + {state.user.username && + (state.user.username.length > 18 + ? `${state.user.username.slice(0, 16)}...` + : state.user.username)} + {!state.user.username && formatAddress(state.user.address)} {/* Keep 'for' when 'Based Energy' is selected */} @@ -493,13 +513,14 @@ app.frame('/form', (c) => { )} {state.comment && ( - Comment: {state.comment} + Comment:{' '} + {state.comment.length > 16 + ? `${state.comment.slice(0, 16)}...` + : state.comment} )} - - Confirm Endorsement - + Cofirm Endorsement @@ -572,9 +593,12 @@ app.frame('/finish', async (c) => { Successfully endorsed - {previousState.user.username.length > 18 - ? `${previousState.user.username.slice(0, 16)}...` - : previousState.user.username} + {previousState.user.username && + (previousState.user.username.length > 18 + ? `${previousState.user.username.slice(0, 16)}...` + : previousState.user.username)} + {!previousState.user.username && + formatAddress(previousState.user.address)} View transaction on BaseScan @@ -630,7 +654,9 @@ app.transaction('/endorsement', async (c) => { previousState.user.address as `0x${string}`, ENDORSEMENT_OPTIONS[previousState.type ?? 0].label, previousState.comment ?? '', - previousState.user.username ?? '', // FIXME: Need address here if no username found + `${previousState.user.platform}:${ + previousState.user.username ?? previousState.user.address + }`, ], to: CONTRACT_ADDRESS as `0x${string}`, // If tip is available, add it to the transaction, otherwise just pay the endorsement fee diff --git a/packages/dapp/src/lib/airstack/getMinimalProfileInfoByPlatform.ts b/packages/dapp/src/lib/airstack/getMinimalProfileInfoByPlatform.ts index db53962..87e8fb0 100644 --- a/packages/dapp/src/lib/airstack/getMinimalProfileInfoByPlatform.ts +++ b/packages/dapp/src/lib/airstack/getMinimalProfileInfoByPlatform.ts @@ -69,7 +69,7 @@ export const getMinimalProfileInfoByPlatform = async ( } const jsonResponse = await response.json(); - + console.log(jsonResponse); // Check if we successfully decoded the response if (!jsonResponse) { throw new Error('Failed to fetch profile'); @@ -236,6 +236,7 @@ export const getMinimalProfileInfoByPlatform = async ( } } } catch (error) { + console.log(error); return { displayName: null, address: null, diff --git a/packages/dapp/src/utils/endorsementOptions.ts b/packages/dapp/src/utils/endorsementOptions.ts index bfd28be..ec7dd8a 100644 --- a/packages/dapp/src/utils/endorsementOptions.ts +++ b/packages/dapp/src/utils/endorsementOptions.ts @@ -1,9 +1,9 @@ export const ENDORSEMENT_OPTIONS = [ + { value: 'Based energy 🔵', label: 'Based energy 🔵' }, { value: 'Developer', label: 'Developer' }, { value: 'Hacker', label: 'Hacker' }, { value: 'Buidler', label: 'Buidler' }, { value: 'Memer', label: 'Memer' }, - { value: 'Based energy 🔵', label: 'Based energy 🔵' }, { value: 'Crypto OG', label: 'Crypto OG' }, { value: 'Web3 explorer', label: 'Web3 explorer' }, { value: 'Friend', label: 'Friend' },