Skip to content

Commit

Permalink
Replaced sg username with path and name (#4913)
Browse files Browse the repository at this point in the history
* Replaced sg username with path and name

* Fixed profile scouted builder activity display

* Fixed broken type issues

* Fixed seeder

* Fixed type issues with tests

* Fixed broken tests

* Upload nft artwork fix

* Made claim page private

* updated script

* Update nft artwork fn

* Fixed broken tests

* e2e test

---------

Co-authored-by: Matt Casey <[email protected]>
  • Loading branch information
Devorein and mattcasey authored Oct 29, 2024
1 parent 0fa6774 commit efcdb07
Show file tree
Hide file tree
Showing 105 changed files with 584 additions and 922 deletions.
13 changes: 6 additions & 7 deletions apps/scoutgame/__e2e__/UserPage/buyNft.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { prisma } from '@charmverse/core/prisma-client';
import { getBuilderContractAddress } from '@packages/scoutgame/builderNfts/constants';
import { currentSeason } from '@packages/scoutgame/dates';
import { mockBuilder, mockBuilderNft } from '@packages/scoutgame/testing/database';
import { delay } from '@root/lib/utils/async';
import { custom, http } from 'viem';
import { optimism } from 'viem/chains';

import { expect, test } from '../test';

Expand Down Expand Up @@ -37,16 +33,19 @@ test.describe('Buy Nft', () => {
});

await userPage.mockNftAPIs({
builder,
builder: {
id: builder.id,
path: builder.path!
},
isSuccess: true
});

await utils.loginAsUserId(builder.id);
await page.goto(`/home`);
await page.waitForURL('**/home');

await page.goto(`/u/${builder.username}`);
await page.waitForURL(`**/u/${builder.username}`);
await page.goto(`/u/${builder.path}`);
await page.waitForURL(`**/u/${builder.path}`);

// Card CTA button
const scoutButton = page.locator('data-test=scout-button').first();
Expand Down
10 changes: 2 additions & 8 deletions apps/scoutgame/__e2e__/po/UserPage.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ export class UserPage extends GeneralPageLayout {
super(page);
}

async mockNftAPIs({
builder,
isSuccess
}: {
builder: { id: string; username?: string | null; path?: string | null };
isSuccess: boolean;
}) {
async mockNftAPIs({ builder, isSuccess }: { builder: { id: string; path: string }; isSuccess: boolean }) {
// Used for debugging all routes. Keep caution as the next page.route() function will not run anymore.
// await page.route('**', (route) => {
// console.log('Intercepted URL:', route.request().url());
Expand Down Expand Up @@ -139,7 +133,7 @@ export class UserPage extends GeneralPageLayout {
});

// Mocking server action to handle the pending transaction and mint the NFT without calling decent
await this.page.route(`**/u/${builder.username}`, async (route) => {
await this.page.route(`**/u/${builder.path}`, async (route) => {
const method = route.request().method();
const body = route.request().postDataJSON()?.[0];

Expand Down
2 changes: 1 addition & 1 deletion apps/scoutgame/app/(general)/claim/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default async function Claim({ searchParams }: { searchParams: { tab: str
return (
<ClaimPage
period={searchParams.tab}
username={user.username ?? ''}
displayName={user.displayName}
totalUnclaimedPoints={points}
bonusPartners={bonusPartners}
/>
Expand Down
2 changes: 1 addition & 1 deletion apps/scoutgame/app/(general)/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default async function Profile({
<ProfilePage
user={{
...user,
path: null,
path: user.path!,
...userStats
}}
tab={tab}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import type { Metadata, ResolvingMetadata } from 'next';
import type { ResolvedOpenGraph } from 'next/dist/lib/metadata/types/opengraph-types';
import { notFound } from 'next/navigation';

import { FarcasterMetadata } from 'components/[username]/FarcasterMetadata';
import { PublicProfilePage } from 'components/[username]/PublicProfilePage';
import { FarcasterMetadata } from 'components/[path]/FarcasterMetadata';
import { PublicProfilePage } from 'components/[path]/PublicProfilePage';
import { getUserByPath } from 'lib/users/getUserByPath';

export const dynamic = 'force-dynamic';

type Props = {
params: { username: string };
params: { path: string };
searchParams: { [key: string]: string | string[] | undefined };
};

export async function generateMetadata({ params, searchParams }: Props, parent: ResolvingMetadata): Promise<Metadata> {
const user = await getUserByPath(params.username);
export async function generateMetadata({ params }: Props, parent: ResolvingMetadata): Promise<Metadata> {
const user = await getUserByPath(params.path);

if (!user) {
return {};
Expand All @@ -24,19 +24,19 @@ export async function generateMetadata({ params, searchParams }: Props, parent:
const previousOg = previousMetadata.openGraph || ({} as ResolvedOpenGraph);

return {
title: `${user.username} user profile`,
title: `${user.displayName} user profile`,
openGraph: {
images: user.nftImageUrl || user.avatar || previousOg.images || '',
title: `${user.username} user profile`
title: `${user.displayName} user profile`
},
twitter: {
title: `${user.username} user profile`
title: `${user.displayName} user profile`
}
};
}

export default async function Profile({ params, searchParams }: Props) {
const user = await getUserByPath(params.username);
const user = await getUserByPath(params.path);
const tab = searchParams.tab || (user?.builderStatus === 'approved' ? 'builder' : 'scout');

if (!user || typeof tab !== 'string') {
Expand Down
10 changes: 5 additions & 5 deletions apps/scoutgame/app/api/builders/search/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import { searchBuilders } from 'lib/builders/searchBuilders';

export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const username = searchParams.get('username');
if (typeof username !== 'string') {
return new Response('username is required', { status: 400 });
const search = searchParams.get('search');
if (typeof search !== 'string') {
return new Response('path is required', { status: 400 });
}
try {
const result = await searchBuilders({
username
search
});

return Response.json(result);
} catch (error) {
log.error('Error requesting user from farcaster', { error, username });
log.error('Error requesting user from farcaster', { error, search });
return new Response(`Unknown error: ${(error as Error).message}`, { status: 500 });
}
}
10 changes: 4 additions & 6 deletions apps/scoutgame/app/api/session/refresh/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function GET(req: NextRequest) {
select: {
bio: true,
displayName: true,
username: true,
path: true,
farcasterId: true
}
});
Expand All @@ -35,13 +35,12 @@ export async function GET(req: NextRequest) {
});
if (profile) {
const bio = profile.profile.bio.text;
const displayName = profile.display_name || profile.username;
const username = profile.username;
const displayName = profile.display_name;

const hasProfileChanged =
// Re-enable this once Neynar fixes their caching mechanism
// scout.avatar !== profile.body.avatarUrl ||
scout.bio !== bio || scout.displayName !== displayName || scout.username !== username;
scout.bio !== bio || scout.displayName !== displayName;

if (hasProfileChanged) {
await prisma.scout.update({
Expand All @@ -52,8 +51,7 @@ export async function GET(req: NextRequest) {
// Re-enable this once Neynar fixes their caching mechanism
// avatar: profile.pfp_url,
bio,
displayName,
username
displayName
}
});
log.info('Updated Farcaster profile', { userId, profile });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function FarcasterMetadata({
{/* Button 1 */}
<meta name='fc:frame:button:1' content='Scout Builder' />
<meta name='fc:frame:button:1:action' content='link' />
<meta name='fc:frame:button:1:target' content={`${process.env.DOMAIN}/u/${user.username}`} />
<meta name='fc:frame:button:1:target' content={`${process.env.DOMAIN}/u/${user.path}`} />
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function PublicProfilePage({ user, tab }: { user: UserProfile; tab: strin
</Hidden>
<PublicProfileTabsMenu
tab={tab}
username={user.username ?? ''}
path={user.path}
isApprovedBuilder={user.builderStatus === 'approved' || user.builderStatus === 'banned'}
/>
{tab === 'builder' ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import { TabsMenu } from 'components/common/Tabs/TabsMenu';

export function PublicProfileTabsMenu({
tab,
username,
path,
isApprovedBuilder
}: {
tab: string;
username: string;
path: string;
isApprovedBuilder?: boolean;
}) {
const router = useRouter();

useEffect(() => {
if (!isApprovedBuilder && tab === 'builder') {
router.push(`/u/${username}/?tab=scout`);
router.push(`/u/${path}/?tab=scout`);
}
}, [isApprovedBuilder, tab, username]);
}, [isApprovedBuilder, tab, path]);

Check warning on line 23 in apps/scoutgame/components/[path]/PublicProfileTabsMenu.tsx

View workflow job for this annotation

GitHub Actions / Test apps

React Hook useEffect has a missing dependency: 'router'. Either include it or remove the dependency array

Check warning on line 23 in apps/scoutgame/components/[path]/PublicProfileTabsMenu.tsx

View workflow job for this annotation

GitHub Actions / Test apps

React Hook useEffect has a missing dependency: 'router'. Either include it or remove the dependency array

Check warning on line 23 in apps/scoutgame/components/[path]/PublicProfileTabsMenu.tsx

View workflow job for this annotation

GitHub Actions / Test apps

React Hook useEffect has a missing dependency: 'router'. Either include it or remove the dependency array

Check warning on line 23 in apps/scoutgame/components/[path]/PublicProfileTabsMenu.tsx

View workflow job for this annotation

GitHub Actions / Test apps

React Hook useEffect has a missing dependency: 'router'. Either include it or remove the dependency array

Check warning on line 23 in apps/scoutgame/components/[path]/PublicProfileTabsMenu.tsx

View workflow job for this annotation

GitHub Actions / Test app

React Hook useEffect has a missing dependency: 'router'. Either include it or remove the dependency array

Check warning on line 23 in apps/scoutgame/components/[path]/PublicProfileTabsMenu.tsx

View workflow job for this annotation

GitHub Actions / Test

React Hook useEffect has a missing dependency: 'router'. Either include it or remove the dependency array

Check warning on line 23 in apps/scoutgame/components/[path]/PublicProfileTabsMenu.tsx

View workflow job for this annotation

GitHub Actions / Validate code

React Hook useEffect has a missing dependency: 'router'. Either include it or remove the dependency array

return (
<TabsMenu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export async function PublicScoutProfile({ publicUser }: { publicUser: BasicUser
<PublicScoutProfileContainer
scout={{
...scout,
path: scout.path!,
githubLogin: scout.githubUser[0]?.login
}}
allTimePoints={allTimePoints}
Expand Down
6 changes: 3 additions & 3 deletions apps/scoutgame/components/claim/ClaimPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import { UnclaimedPointsTable } from './components/PointsTable/UnclaimedPointsTa
export type ClaimPageProps = {
totalUnclaimedPoints: number;
bonusPartners: string[];
username: string;
displayName: string;
period: string;
};

export function ClaimPage({ username, totalUnclaimedPoints, bonusPartners, period }: ClaimPageProps) {
export function ClaimPage({ displayName, totalUnclaimedPoints, bonusPartners, period }: ClaimPageProps) {
return (
<PageContainer>
<Stack
Expand All @@ -31,7 +31,7 @@ export function ClaimPage({ username, totalUnclaimedPoints, bonusPartners, perio
<Stack flex={1} gap={4}>
<PointsClaimScreen
totalUnclaimedPoints={totalUnclaimedPoints}
username={username}
displayName={displayName}
bonusPartners={bonusPartners}
/>
{totalUnclaimedPoints === 0 ? null : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ function BuilderRewardsTableRow({ reward }: { reward: BuilderReward }) {
return (
<TableRow>
<TableCell>
<Link href={`/u/${reward.username}`}>
<Link href={`/u/${reward.path}`}>
<Stack direction='row' alignItems='center' gap={1}>
<Avatar src={reward.avatar} name={reward.username} size='small' />
<Avatar src={reward.avatar} name={reward.path!} size='small' />
<Typography noWrap overflow='hidden'>
{reward.username}
{reward.displayName}
</Typography>
</Stack>
</Link>
Expand Down Expand Up @@ -64,7 +64,7 @@ export function BuilderRewardsTable({
}}
>
{builderRewards.map((reward) => (
<BuilderRewardsTableRow key={reward.username} reward={reward} />
<BuilderRewardsTableRow key={reward.path} reward={reward} />
))}
<TableRow>
<TableCell colSpan={week ? 3 : 2}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ function PointsClaimSuccessModal({

export function PointsClaimScreen({
totalUnclaimedPoints,
username,
displayName,
bonusPartners
}: {
totalUnclaimedPoints: number;
username: string;
displayName: string;
bonusPartners: string[];
}) {
const { executeAsync, isExecuting, result } = useAction(claimPointsAction);
Expand Down Expand Up @@ -98,7 +98,7 @@ export function PointsClaimScreen({
>
<Stack flexDirection='column' alignItems='center' gap={0.5}>
<Typography variant='h6'>
<b>{username}</b> <span style={{ fontSize: '0.8em' }}>will receive</span>
<b>{displayName}</b> <span style={{ fontSize: '0.8em' }}>will receive</span>
</Typography>
<Stack flexDirection='row' alignItems='center' gap={1}>
<Typography variant='h4' fontWeight={500}>
Expand All @@ -123,7 +123,7 @@ export function PointsClaimScreen({
) : (
<>
<Typography textAlign='center' color='secondary' variant='h5'>
Hey {username},
Hey {displayName},
</Typography>
<Typography textAlign='center' variant='h6'>
You have no rewards to claim.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ScoutButton } from '../../ScoutButton/ScoutButton';
import { BuilderCardNftDisplay } from './BuilderCardNftDisplay';
import { BuilderCardStats } from './BuilderCardStats';

type RequiredBuilderInfoFields = 'username' | 'builderStatus' | 'id' | 'path';
type RequiredBuilderInfoFields = 'displayName' | 'builderStatus' | 'id' | 'path';

export function BuilderCard({
builder,
Expand All @@ -36,7 +36,7 @@ export function BuilderCard({
>
<BuilderCardNftDisplay
nftImageUrl={builder.nftImageUrl}
username={builder.username}
path={builder.path}
showHotIcon={showHotIcon}
size={size}
hideDetails={hideDetails}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@ export function BuilderCardActivity({
}) {
const [isDialogOpen, setIsDialogOpen] = useState(false);
const isMobile = useMediaQuery((theme: Theme) => theme.breakpoints.down('sm'), { noSsr: true });
let gemHeight = size === 'x-small' ? 12 : size === 'small' ? 13.5 : size === 'medium' ? 14.5 : 16;
if (isMobile) {
gemHeight *= 0.75;
}
const gemHeight = size === 'x-small' || size === 'small' ? 12.5 : size === 'medium' ? 14.5 : 16;
return (
<>
<Tooltip title={<BuilderCardActivityTooltip />}>
<Stack
flexDirection='row'
gap={{
xs: 0.75,
md: 1.25
md: size === 'medium' || size === 'large' ? 1.25 : 0.75
}}
width='100%'
height={gemHeight}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ const nftDisplaySize = {
export function BuilderCardNftDisplay({
nftImageUrl,
children,
username,
path,
showHotIcon = false,
size = 'medium',
hideDetails = false
}: {
username: string | null;
path: string;
nftImageUrl?: string | null;
showHotIcon?: boolean;
children?: React.ReactNode;
Expand All @@ -43,7 +43,7 @@ export function BuilderCardNftDisplay({
<Box overflow='hidden' width={width} height={height} sx={{ backgroundColor: 'black.dark' }}>
<CardActionArea
LinkComponent={Link}
href={`/u/${username}`}
href={`/u/${path}`}
sx={{
position: 'relative',
width: '100%',
Expand Down
Loading

0 comments on commit efcdb07

Please sign in to comment.