From 1e4898351246881336eee1e7563baa3d21226b85 Mon Sep 17 00:00:00 2001 From: Prashant Varma Date: Mon, 21 Oct 2024 12:46:07 +0530 Subject: [PATCH 1/2] [feat]: FE optimization using react query and test cases --- apps/client/actions/Event/getEventDetails.ts | 12 +- apps/client/actions/OTP/sendOtp.ts | 9 +- apps/client/actions/OTP/validateOtp.ts | 2 +- apps/client/app/(lobby)/auth/signin/page.tsx | 2 +- apps/client/app/(lobby)/wallet/page.tsx | 2 + apps/client/app/globals.css | 9 + apps/client/app/layout.tsx | 8 +- apps/client/app/page.tsx | 35 +- .../components/landing/Appbar/Navbar.tsx | 6 +- .../client/components/landing/Auth/Singin.tsx | 76 +- .../components/landing/Home/EventCard.tsx | 12 +- .../components/landing/Home/HomeWrapper.tsx | 36 + .../components/landing/Home/TradeComp.tsx | 14 +- .../landing/Orderbook/Orderbook.tsx | 75 +- .../landing/Recharge/WalletCards.tsx | 7 +- .../components/ui/OtpVerificationForm.tsx | 83 +- apps/client/components/ui/line-chart.tsx | 2 +- .../components/ui/signin-input-form.tsx | 93 + apps/client/lib/auth.ts | 5 +- apps/client/lib/error.ts | 6 +- apps/client/package.json | 3 +- apps/client/providers/_provider.tsx | 18 + package-lock.json | 30 +- package.json | 3 +- tests/package-lock.json | 2171 +++++++++++++++++ tests/package.json | 21 + tests/src/engine.test.ts | 3 + tests/src/index.ts | 3 + tests/src/orderbook.test.ts | 7 + tests/tsconfig.json | 8 + 30 files changed, 2551 insertions(+), 210 deletions(-) create mode 100644 apps/client/components/landing/Home/HomeWrapper.tsx create mode 100644 apps/client/components/ui/signin-input-form.tsx create mode 100644 apps/client/providers/_provider.tsx create mode 100644 tests/package-lock.json create mode 100644 tests/package.json create mode 100644 tests/src/engine.test.ts create mode 100644 tests/src/index.ts create mode 100644 tests/src/orderbook.test.ts create mode 100644 tests/tsconfig.json diff --git a/apps/client/actions/Event/getEventDetails.ts b/apps/client/actions/Event/getEventDetails.ts index 462e6c86..80acaa65 100644 --- a/apps/client/actions/Event/getEventDetails.ts +++ b/apps/client/actions/Event/getEventDetails.ts @@ -6,17 +6,7 @@ export async function getEventDetails(eventId: string) { const event = await prisma.event.findUnique({ where: { id: eventId, - }, - include: { - orderBook: { - include: { - yes: true, - no: true, - - }, - }, - }, - }); + }}); if (!event) { throw new Error("Event not found"); diff --git a/apps/client/actions/OTP/sendOtp.ts b/apps/client/actions/OTP/sendOtp.ts index 877dfcfa..8e34e228 100644 --- a/apps/client/actions/OTP/sendOtp.ts +++ b/apps/client/actions/OTP/sendOtp.ts @@ -10,13 +10,12 @@ const twilioClient = twilio( export const sendSMSOTP = async (phoneNumber: string) => { if(phoneNumber.length <= 10)return { success: false, message: "Failed to update OTP" }; try { - const OTP = Math.floor(1000 + Math.random() * 9000).toString(); + const OTP = Math.floor(100000 + Math.random() * 9000).toString(); // Check if OTP already exists const isOtpDataExists = await prisma.oTP.findUnique({ where: { otpID: phoneNumber }, }); - console.log("isOtpDataExists", isOtpDataExists); if (isOtpDataExists) { // Update existing OTP @@ -27,13 +26,11 @@ export const sendSMSOTP = async (phoneNumber: string) => { expiresAt: new Date(Date.now() + 10 * 60 * 1000) }, }); - console.log("updateOtp", updateOtp); if (!updateOtp) { return { success: false, message: "Failed to update OTP" }; } else { const res = await sendTwillioMsg(OTP, phoneNumber) - console.log("res in update", res) return res; } } else { @@ -45,13 +42,11 @@ export const sendSMSOTP = async (phoneNumber: string) => { expiresAt: new Date(Date.now() + 10 * 60 * 1000), }, }); - console.log("newOTP", newOTP); if (!newOTP) { return { success: false, message: "Failed to create OTP" }; } const res = await sendTwillioMsg(OTP, phoneNumber) - console.log("res in new otp", res) return res; } } catch (error) { @@ -68,7 +63,7 @@ async function sendTwillioMsg(OTP: string, phoneNumber: string) { from: process.env.TWILIO_NUMBER, to: phoneNumber, }); - console.log(message); + console.log(message); // just to get rid of linting error return { success: true, message: "send OTP" }; } catch (error) { diff --git a/apps/client/actions/OTP/validateOtp.ts b/apps/client/actions/OTP/validateOtp.ts index 7448e2f4..ba348cff 100644 --- a/apps/client/actions/OTP/validateOtp.ts +++ b/apps/client/actions/OTP/validateOtp.ts @@ -9,7 +9,7 @@ export const verifySMSOTPAction = async (otp: string, phoneNumber: string) => { otp, }, }); - console.log(otpData); + // console.log("otpData", otpData); if(otpData?.isVerified){ return { verified: true, message: "User Already Exists" }; } diff --git a/apps/client/app/(lobby)/auth/signin/page.tsx b/apps/client/app/(lobby)/auth/signin/page.tsx index 08df5ff9..f2df4774 100644 --- a/apps/client/app/(lobby)/auth/signin/page.tsx +++ b/apps/client/app/(lobby)/auth/signin/page.tsx @@ -1,6 +1,6 @@ "use client" +import { Login } from '@/components/landing/Auth/Singin'; import React from 'react'; -import { Login } from '../../../../components/landing/Auth/Singin'; const Page = () => { return ( diff --git a/apps/client/app/(lobby)/wallet/page.tsx b/apps/client/app/(lobby)/wallet/page.tsx index 496f84d9..4a0b68de 100644 --- a/apps/client/app/(lobby)/wallet/page.tsx +++ b/apps/client/app/(lobby)/wallet/page.tsx @@ -15,6 +15,7 @@ const Page = () => { {}} @@ -22,6 +23,7 @@ const Page = () => { {}} diff --git a/apps/client/app/globals.css b/apps/client/app/globals.css index 16c47d13..4c160b72 100644 --- a/apps/client/app/globals.css +++ b/apps/client/app/globals.css @@ -130,4 +130,13 @@ body{ } html { @apply bg-gray-100; +} + +.no-scrollbar::-webkit-scrollbar { + display: none; +} + +.no-scrollbar { + -ms-overflow-style: none; /* IE and Edge */ + scrollbar-width: none; /* Firefox */ } \ No newline at end of file diff --git a/apps/client/app/layout.tsx b/apps/client/app/layout.tsx index eae0dc2e..603f93de 100644 --- a/apps/client/app/layout.tsx +++ b/apps/client/app/layout.tsx @@ -1,9 +1,9 @@ import type { Metadata } from "next"; import localFont from "next/font/local"; import "./globals.css"; -import { SessionProviders } from "@/providers/session-provider"; import Navbar from "@/components/landing/Appbar/Navbar"; import { Toaster } from "react-hot-toast"; +import { Providers } from "@/providers/_provider"; const geistSans = localFont({ src: "./fonts/GeistVF.woff", @@ -31,10 +31,10 @@ export default function RootLayout({ - - + + {children} - + diff --git a/apps/client/app/page.tsx b/apps/client/app/page.tsx index 9d4b2aa9..ee177b31 100644 --- a/apps/client/app/page.tsx +++ b/apps/client/app/page.tsx @@ -1,35 +1,12 @@ -import { HeroComp } from "@/components/landing/Home/HeroComp"; -import ToggleSections from "@/components/landing/Home/ToogleSections"; -import { TradeComp } from "@/components/landing/Home/TradeComp"; -import { DownloadBanner } from "@/components/landing/Home/DownloadBanner"; -import TradingNewsComponent from "@/components/landing/Home/TradingNewsComponent"; -import FeatureComponent from "@/components/landing/Home/Features"; -import ProboCare from "@/components/landing/Home/ProboCare"; +"use client" +import HomeWrapper from "@/components/landing/Home/HomeWrapper"; +// import OrderBook from "@/components/landing/Orderbook/Orderbook"; export default function Page() { return ( -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
+
+ + {/* */}
); } diff --git a/apps/client/components/landing/Appbar/Navbar.tsx b/apps/client/components/landing/Appbar/Navbar.tsx index 37cb4088..a42cf9fb 100644 --- a/apps/client/components/landing/Appbar/Navbar.tsx +++ b/apps/client/components/landing/Appbar/Navbar.tsx @@ -31,12 +31,12 @@ export const Navbar = () => { ); return ( -