Skip to content

Commit

Permalink
fix: resolve all remaining formating issues
Browse files Browse the repository at this point in the history
  • Loading branch information
martines3000 committed Jul 1, 2024
1 parent 1916113 commit 15c87f1
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 59 deletions.
2 changes: 1 addition & 1 deletion packages/dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down
138 changes: 82 additions & 56 deletions packages/dapp/src/app/api/frame/[[...routes]]/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -59,6 +64,7 @@ type State = {
username: string;
avatar: string;
address: string;
platform: PlatformType;
};
type: number;
tip?: number;
Expand All @@ -79,6 +85,7 @@ const app = new Frog<{ State: State }>({
username: '',
avatar: '',
address: '',
platform: PlatformType.farcaster,
},
type: 0,
tip: undefined,
Expand Down Expand Up @@ -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: (
<Box
Expand All @@ -203,16 +210,15 @@ app.frame('/search', async (c) => {
}

// 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({
Expand All @@ -222,7 +228,7 @@ app.frame('/search', async (c) => {
backgroundImage={`url("${APP_URL}/frame/frame_bg1.png")`}
height="100%"
>
<HStack>
<HStack grow height="100%">
<Box marginLeft="32" marginTop="32" height="100%" width="128">
<Image
width="128"
Expand All @@ -232,15 +238,17 @@ app.frame('/search', async (c) => {
src={state.user.avatar}
/>
</Box>
<Box padding="32">
<Box grow padding="32">
<VStack maxWidth="767">
<Text color="secondary" size="32">
Endorsing
</Text>
<Text color="primary" size="32">
{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)}
</Text>
<Text color="secondary" size="28">
Confirm User
Expand Down Expand Up @@ -286,38 +294,39 @@ app.frame('/type-selection', (c) => {
backgroundImage={`url("${APP_URL}/frame/frame_bg1.png")`}
height="100%"
>
<HStack grow>
<HStack grow height="100%">
<Box marginLeft="32" marginTop="32" height="100%" width="128">
<Image
width="128"
height="128"
borderRadius="64"
objectFit="cover"
src={state.user.avatar}
/>
</Box>
<Box grow alignVertical="top" margin="32" height="100%">
<Box grow padding="32">
<VStack maxWidth="767">
<Text color="secondary" size="32">
Endorsing
</Text>
<Text color="primary" size="32">
{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)}
</Text>
<Text color="secondary" size="28">
{ENDORSEMENT_OPTIONS[state.type].value === 'Based energy'
? 'for'
: 'as a'}
{state.type === 0 ? 'for' : 'as a'}
</Text>
<Text color="primary" size="32">
{ENDORSEMENT_OPTIONS[state.type].label}
</Text>
<Spacer size="20" />
<Text color="secondary" size="16" wrap>
<Text color="secondary" size="16">
Select endorsement types
</Text>
<Text color="secondary" size="16" wrap>
<Text color="secondary" size="16">
{'by pressing < and > arrows'}
</Text>
</VStack>
Expand Down Expand Up @@ -370,24 +379,28 @@ app.frame('/form', (c) => {
backgroundImage={`url("${APP_URL}/frame/frame_bg1.png")`}
height="100%"
>
<HStack grow>
<HStack grow height="100%">
<Box marginLeft="32" marginTop="32" height="100%" width="128">
<Image
width="128"
height="128"
borderRadius="64"
objectFit="cover"
src={state.user.avatar}
/>
</Box>
<Box grow alignVertical="top" margin="32" height="100%">
<Box grow alignVertical="top" padding="32">
<VStack maxWidth="767">
<Text color="secondary" size="32">
Endorsing
</Text>
<Text color="primary" size="32">
{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)}
</Text>
<Text color="secondary" size="28">
Add a tip to the endorsement
Expand Down Expand Up @@ -415,24 +428,28 @@ app.frame('/form', (c) => {
backgroundImage={`url("${APP_URL}/frame/frame_bg1.png")`}
height="100%"
>
<HStack grow>
<HStack grow height="100%">
<Box marginLeft="32" marginTop="32" height="100%" width="128">
<Image
width="128"
height="128"
borderRadius="64"
objectFit="cover"
src={state.user.avatar}
/>
</Box>
<Box grow alignVertical="top" margin="32" height="100%">
<Box grow alignVertical="top" padding="32">
<VStack maxWidth="767">
<Text color="secondary" size="32">
Endorsing
</Text>
<Text color="primary" size="32">
{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)}
</Text>
<Spacer size="4" />
<Text color="secondary" size="32">
Expand Down Expand Up @@ -462,24 +479,27 @@ app.frame('/form', (c) => {
backgroundImage={`url("${APP_URL}/frame/frame_bg1.png")`}
height="100%"
>
<HStack grow>
<HStack grow height="100%">
<Box marginLeft="32" marginTop="32" height="100%" width="128">
<Image
width="128"
height="128"
borderRadius="64"
objectFit="cover"
src={state.user.avatar}
/>
</Box>
<Box grow alignVertical="top" margin="32" height="100%">
<Box grow padding="32">
<VStack maxWidth="767">
<Text color="secondary" size="32">
Endorsing
</Text>
<Text color="primary" size="32">
{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)}
</Text>
<Text color="secondary" size="28">
{/* Keep 'for' when 'Based Energy' is selected */}
Expand All @@ -493,13 +513,14 @@ app.frame('/form', (c) => {
)}
{state.comment && (
<Text color="primary" size="20">
Comment: {state.comment}
Comment:{' '}
{state.comment.length > 16
? `${state.comment.slice(0, 16)}...`
: state.comment}
</Text>
)}
<Spacer size="20" />
<Text color="secondary" size="28" wrap>
Confirm Endorsement
</Text>
<Text>Cofirm Endorsement</Text>
</VStack>
</Box>
</HStack>
Expand Down Expand Up @@ -572,9 +593,12 @@ app.frame('/finish', async (c) => {
Successfully endorsed
</Text>
<Text color="primary" size="48">
{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)}
</Text>
<Text color="secondary" size="32">
View transaction on BaseScan
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -236,6 +236,7 @@ export const getMinimalProfileInfoByPlatform = async (
}
}
} catch (error) {
console.log(error);
return {
displayName: null,
address: null,
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp/src/utils/endorsementOptions.ts
Original file line number Diff line number Diff line change
@@ -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' },
Expand Down

0 comments on commit 15c87f1

Please sign in to comment.