From 9b06522202e17da1b1106244ea359fa3aa58ed72 Mon Sep 17 00:00:00 2001 From: Dylan Ireland Date: Fri, 3 May 2024 02:11:46 -0400 Subject: [PATCH] Max NFT limit --- client/src/App.tsx | 36 ++++++++++++++++++------- client/src/apiClient.ts | 10 +++++++ client/src/components/Maxed.tsx | 19 +++++++++++++ client/src/components/Welcome.tsx | 4 ++- server/src/controller/UserController.ts | 15 +++++++++++ server/src/routes.ts | 5 ++++ 6 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 client/src/components/Maxed.tsx diff --git a/client/src/App.tsx b/client/src/App.tsx index 60af378..999bc3d 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -7,7 +7,8 @@ import { AppTheme } from './theme'; import { Welcome } from './components/Welcome'; import Instructions from './components/Instructions'; import Success from './components/Success'; -import { checkUser } from './apiClient'; +import { checkMax, checkUser } from './apiClient'; +import Maxed from './components/Maxed'; export const ActiveAccountContext = createContext(null); @@ -33,6 +34,7 @@ const App = () => { const [themeMode, setThemeMode] = useState(ThemeModeType.light); const [activeAccount, setActiveAccount] = useState(null); const [claimed, setClaimed] = useState(false); + const [maxedOut, setMaxedOut] = useState(false); useEffect(() => { clickRef?.on('csprclick:signed_in', (evt: any) => { @@ -49,22 +51,38 @@ const App = () => { }); }, [clickRef?.on]); + function userCheck() { + checkUser(activeAccount.public_key) + .then(hasClaimed => { + setClaimed(hasClaimed); + }) + .catch(error => { + console.error(error.message); + }); + } + + useEffect(() => { + checkMax() + .then(maxedOut => { + setMaxedOut(maxedOut); + }) + .catch(error => { + console.error(error.message); + }); + }); + useEffect(() => { if (activeAccount !== null) { - checkUser(activeAccount.public_key) - .then(hasClaimed => { - setClaimed(hasClaimed); - }) - .catch(error => { - console.error(error.message); - }); + userCheck(); } else { setClaimed(false); } }, [activeAccount]); let contentElement = ; - if (claimed) { + if (maxedOut) { + contentElement = ; + } else if (claimed) { contentElement = ; } diff --git a/client/src/apiClient.ts b/client/src/apiClient.ts index dec2161..31d7352 100644 --- a/client/src/apiClient.ts +++ b/client/src/apiClient.ts @@ -18,6 +18,16 @@ export async function checkUser(publicKey: string): Promise { params: { publicKey: publicKey }, }); + if (response.status == 200) { + return response.data as boolean; + } else { + throw new Error('User not found'); + } +} + +export async function checkMax(): Promise { + const response = await axios.get('http://localhost:3001/max'); + if (response.status == 200) { return response.data as boolean; } else { diff --git a/client/src/components/Maxed.tsx b/client/src/components/Maxed.tsx new file mode 100644 index 0000000..827180d --- /dev/null +++ b/client/src/components/Maxed.tsx @@ -0,0 +1,19 @@ +import styled from 'styled-components'; +import { StyledContentContainer } from '../App'; + +export default function Maxed() { + const MaxedContainer = styled(StyledContentContainer)` + padding-block: 100px; + `; + + return ( + <> + +
+

All NFTs Already Claimed

+

All 500 Code of Creation NFTs have already been claimed.

+
+
+ + ); +} diff --git a/client/src/components/Welcome.tsx b/client/src/components/Welcome.tsx index bed5e99..0da12e0 100644 --- a/client/src/components/Welcome.tsx +++ b/client/src/components/Welcome.tsx @@ -23,6 +23,9 @@ const HeadingContainer = styled.div(({ theme }) => margin: 'auto', marginTop: ['80px', '50px', 0], textAlign: 'center', + h2: { + color: 'white', + }, }) ); @@ -31,7 +34,6 @@ const StyledLogo = styled.img(({ theme }) => position: 'relative', top: 30, left: 30, - //transform: 'translateX(-50%)', width: '200px', objectFit: 'contain', }) diff --git a/server/src/controller/UserController.ts b/server/src/controller/UserController.ts index 0cdeaa0..4fd9272 100644 --- a/server/src/controller/UserController.ts +++ b/server/src/controller/UserController.ts @@ -40,6 +40,21 @@ export class UserController { } } + async max(request: Request, response: Response, next: NextFunction) { + try { + const userCount = await this.userRepository.count(); + + if (userCount >= 500) { + response.send("true"); + } else { + response.send("false"); + } + } catch (error) { + console.error(error); + response.sendStatus(500); + } + } + async destroy(request: Request, response: Response, next: NextFunction) { await this.userRepository.clear() response.sendStatus(200); diff --git a/server/src/routes.ts b/server/src/routes.ts index a137d1c..ff6cfee 100644 --- a/server/src/routes.ts +++ b/server/src/routes.ts @@ -15,6 +15,11 @@ export const Routes = [{ route: "/user", controller: UserController, action: "check" +}, { + method: "get", + route: "/max", + controller: UserController, + action: "max" }, { method: "get", route: "/destroy",