Skip to content

Commit

Permalink
Fix onboarding page
Browse files Browse the repository at this point in the history
  • Loading branch information
motechFR committed Dec 5, 2024
1 parent 664505d commit 91058a2
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 28 deletions.
14 changes: 11 additions & 3 deletions apps/scoutgame/app/(general)/scout/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ export default async function Scout({

let builders: BuilderInfo[] = [];

let remainingStarterCards = MAX_STARTER_PACK_PURCHASES;

if (user?.id) {
const purchases = await prisma.nFTPurchaseEvent.count({
where: { builderNFT: { nftType: 'season_1_starter_pack', season: currentSeason }, scoutId: user.id }
});
const purchases = await prisma.nFTPurchaseEvent
.aggregate({
where: { builderNFT: { nftType: 'season_1_starter_pack', season: currentSeason }, scoutId: user.id },
_sum: { tokensPurchased: true }
})
.then((res) => res._sum.tokensPurchased || 0);

remainingStarterCards = MAX_STARTER_PACK_PURCHASES - purchases;

if (purchases < MAX_STARTER_PACK_PURCHASES) {
const [_, starterPackBuilders] = await safeAwaitSSRData(getStarterpackBuilders({ season: currentSeason }));
Expand All @@ -46,6 +53,7 @@ export default async function Scout({
buildersLayout={buildersLayout}
tab={tab}
starterpackBuilders={builders}
remainingStarterCards={remainingStarterCards}
/>
);
}
21 changes: 13 additions & 8 deletions apps/scoutgame/app/(info)/welcome/scout-info/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { BuilderNftType } from '@charmverse/core/prisma-client';
import { getStarterpackBuilders } from '@packages/scoutgame/builders/getStarterPackBuilders';
import { currentSeason } from '@packages/scoutgame/dates';
import { getBuildersByFid } from '@packages/scoutgame/social/getBuildersByFid';
import { safeAwaitSSRData } from '@packages/scoutgame/utils/async';
Expand All @@ -15,16 +17,19 @@ export const metadata: Metadata = {
};

export default async function ScoutInfo() {
// FID of the builder that we want to show in the ScoutInfoPage
const builderfId = 547807;
const [, builderByFid] = await safeAwaitSSRData(
getBuildersByFid({ fids: [builderfId], limit: 1, season: currentSeason })
);
const builder = builderByFid?.builders?.at(0);
const starterPackBuilders = await getStarterpackBuilders({ season: currentSeason, limit: 1 });

if (!builder) {
const starterPackBuilder = await getBuildersByFid({
// piesrtasty
fids: [547807],
season: currentSeason,
nftType: BuilderNftType.season_1_starter_pack,
limit: 1
});

if (!starterPackBuilder.builders[0]) {
return null;
}

return <ScoutInfoPage builder={builder} />;
return <ScoutInfoPage builder={starterPackBuilder.builders[0]} />;
}
8 changes: 6 additions & 2 deletions apps/scoutgame/components/scout/ScoutPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export function ScoutPage({
scoutTab,
buildersLayout,
tab,
starterpackBuilders
starterpackBuilders,
remainingStarterCards
}: {
scoutSort: string;
builderSort: string;
Expand All @@ -43,6 +44,7 @@ export function ScoutPage({
buildersLayout: string;
tab: string;
starterpackBuilders: BuilderInfo[];
remainingStarterCards?: number;
}) {
const urlString = Object.entries({ tab, scoutSort, builderSort, scoutOrder, builderOrder })
.filter(([, value]) => isTruthy(value))
Expand Down Expand Up @@ -70,7 +72,9 @@ export function ScoutPage({
gap: 2
}}
>
{starterpackBuilders.length ? <StarterPackCarousel builders={starterpackBuilders} /> : null}
{starterpackBuilders.length ? (
<StarterPackCarousel builders={starterpackBuilders} remainingStarterCards={remainingStarterCards} />
) : null}
<Typography variant='h5' color='secondary' textAlign='center' fontWeight='bold' mb={2} mt={2}>
Scout today's HOT Builders!
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function ScoutInfoContent({ builder }: { builder: BuilderInfo }) {
</Typography>
<Box>
<Box my={2}>
<BuilderCard builder={builder} />
<BuilderCard builder={builder} disableProfileUrl />
</Box>
<Typography my={2}>
You score points by collecting the NFTs of Builders. You can Scout your first 3 builders for 95% off their
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type DevUser = {
id: number;
avatar: string;
farcasterId?: number;
createStarterPack?: boolean;
};

const devUsers: Record<string, DevUser> = {
Expand Down Expand Up @@ -46,12 +47,14 @@ const devUsers: Record<string, DevUser> = {
piesrtasty: {
id: 339341,
avatar: 'https://imagedelivery.net/BXluQx4ige9GuW0Ia56BHw/ea9d8fd1-fbf4-4ae3-21a2-c1ca069bf200/original',
farcasterId: 547807
farcasterId: 547807,
createStarterPack: true
},
maurelian: {
id: 23033765,
avatar: 'https://imagedelivery.net/BXluQx4ige9GuW0Ia56BHw/e2beaac4-eacd-472b-9e96-6ca93d9d3000/original',
farcasterId: 4179
farcasterId: 4179,
createStarterPack: true
}
};

Expand Down Expand Up @@ -145,7 +148,9 @@ async function seedBuilderNFTs() {
log.info(`-- Processing builder ${login}`);
const nft = await registerBuilderNFT({ builderId: builderId as string, season: currentSeason });

await registerBuilderStarterPackNFT({ builderId: nft.builderId, season: currentSeason });
if (devUsers[login].createStarterPack) {
await registerBuilderStarterPackNFT({ builderId: nft.builderId, season: currentSeason });
}

await generateNftPurchaseEvents({ builderId: nft.builderId, amount: 4 });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ export function BuilderCard({
showPurchaseButton = false,
hideDetails = false,
showHotIcon = false,
size = 'medium'
size = 'medium',
disableProfileUrl = false
}: {
size?: 'x-small' | 'small' | 'medium' | 'large';
builder: Omit<Partial<BuilderInfo>, RequiredBuilderInfoFields> & Pick<BuilderInfo, RequiredBuilderInfoFields>;
hideDetails?: boolean;
showPurchaseButton?: boolean;
showHotIcon?: boolean;
disableProfileUrl?: boolean;
}) {
return (
<Card
Expand All @@ -39,6 +41,7 @@ export function BuilderCard({
showHotIcon={showHotIcon}
size={size}
hideDetails={hideDetails}
disableProfileUrl={disableProfileUrl}
>
{builder.builderStatus === 'banned' ? (
<Typography textAlign='center'>SUSPENDED</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,24 @@ export function BuilderCardNftDisplay({
path,
showHotIcon = false,
size = 'medium',
hideDetails = false
hideDetails = false,
disableProfileUrl = false
}: {
path: string;
nftImageUrl?: string | null;
showHotIcon?: boolean;
children?: React.ReactNode;
size?: 'x-small' | 'small' | 'medium' | 'large';
hideDetails?: boolean;
disableProfileUrl?: boolean;
}) {
const width = nftDisplaySize[size].width;
const height = nftDisplaySize[size].height;

return (
<Box overflow='hidden' width={width} height={height} sx={{ backgroundColor: 'black.dark', borderRadius: '4px' }}>
<CardActionArea
disabled={disableProfileUrl}
LinkComponent={Link}
href={`/u/${path}`}
sx={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ import { Carousel } from '../../../components/common/Carousel/Carousel';
import 'swiper/css';
import 'swiper/css/autoplay';
import { getEditorialDescription } from './editorial';
import { StarterPackInfo } from './StarterPackInfo';

export function StarterPackCarousel({ builders }: { builders: BuilderInfo[] }) {
export function StarterPackCarousel({
builders,
remainingStarterCards
}: {
builders: BuilderInfo[];
remainingStarterCards?: number;
}) {
return (
<Stack gap={2}>
<Typography variant='h5' color='secondary' fontWeight={600} textAlign='center'>
Scout your Starter Pack
</Typography>
<StarterPackInfo remainingStarterCards={remainingStarterCards} />
<Carousel slidesPerView={1} autoplay={false} boxProps={{ width: { xs: '100%', md: '80%' }, margin: '0 auto' }}>
{builders.map((builder) => (
<Stack
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Box, Typography } from '@mui/material';

export function StarterPackInfo({ remainingStarterCards = 3 }: { remainingStarterCards?: number }) {
return (
<Box display='flex' flexDirection='column' gap={2}>
<Typography variant='h5' color='secondary' fontWeight={600} textAlign='center'>
Scout your Starter Pack
</Typography>
<Typography variant='h6' textAlign='center'>
Scout up to {remainingStarterCards} Builders in this Starter Set <br />
Starter Cards at 20 points (up to 95% off)
</Typography>
<Typography textAlign='center'>* Starter Cards earn 1/10th the points of Season Cards.</Typography>
</Box>
);
}
9 changes: 8 additions & 1 deletion packages/scoutgame/src/builders/getStarterPackBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import type { Season } from '../dates';

import type { BuilderInfo } from './interfaces';

export async function getStarterpackBuilders({ season }: { season: Season }): Promise<BuilderInfo[]> {
export async function getStarterpackBuilders({
season,
limit
}: {
season: Season;
limit?: number;
}): Promise<BuilderInfo[]> {
const starterPackBuilders = await prisma.userWeeklyStats.findMany({
where: {
user: {
Expand All @@ -17,6 +23,7 @@ export async function getStarterpackBuilders({ season }: { season: Season }): Pr
}
}
},
take: limit,
select: {
user: {
select: {
Expand Down
9 changes: 8 additions & 1 deletion packages/scoutgame/src/builders/getStarterpackBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import type { Season } from '../dates';

import type { BuilderInfo } from './interfaces';

export async function getStarterpackBuilders({ season }: { season: Season }): Promise<BuilderInfo[]> {
export async function getStarterpackBuilders({
season,
limit
}: {
season: Season;
limit?: number;
}): Promise<BuilderInfo[]> {
const starterPackBuilders = await prisma.userWeeklyStats.findMany({
where: {
user: {
Expand All @@ -17,6 +23,7 @@ export async function getStarterpackBuilders({ season }: { season: Season }): Pr
}
}
},
take: limit,
select: {
user: {
select: {
Expand Down
10 changes: 7 additions & 3 deletions packages/scoutgame/src/social/getBuildersByFid.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { BuilderNftType } from '@charmverse/core/prisma-client';
import { prisma } from '@charmverse/core/prisma-client';
import type { Last7DaysGems } from '@packages/scoutgame/builders/getTodaysHotBuilders';
import type { BuilderInfo } from '@packages/scoutgame/builders/interfaces';
Expand All @@ -7,19 +8,22 @@ import { uniqueValues } from '@packages/utils/array';
export async function getBuildersByFid({
fids,
limit,
season
season,
nftType = 'default'
}: {
fids: number[];
limit: number;
season: string;
nftType?: BuilderNftType;
}): Promise<{ builders: BuilderInfo[] }> {
const builders = await prisma.scout
.findMany({
where: {
builderStatus: 'approved',
builderNfts: {
some: {
season
season,
nftType
}
},
farcasterId: {
Expand All @@ -40,7 +44,7 @@ export async function getBuildersByFid({
builderNfts: {
where: {
season,
nftType: 'default'
nftType
},
select: {
contractAddress: true,
Expand Down

0 comments on commit 91058a2

Please sign in to comment.