From d1d08b1afe11b800e210db523cbc222ac9468cdd Mon Sep 17 00:00:00 2001 From: Stephen Gordon Date: Thu, 21 Mar 2024 21:09:50 +0000 Subject: [PATCH] wrapped pages in auth component --- src/app/@auth/layout.tsx | 5 +- src/app/components/AuthPage/AuthPage.tsx | 46 +------ src/app/home/page.tsx | 151 ++++++++++++----------- src/app/menu/page.tsx | 7 ++ src/app/payee/page.tsx | 19 +-- src/app/send/page.tsx | 29 +---- src/app/transaction/page.tsx | 9 +- src/app/transactions/page.tsx | 115 ++++++++--------- src/app/tx/page.tsx | 131 ++++++++++---------- 9 files changed, 244 insertions(+), 268 deletions(-) diff --git a/src/app/@auth/layout.tsx b/src/app/@auth/layout.tsx index 61875f3..5fb6453 100644 --- a/src/app/@auth/layout.tsx +++ b/src/app/@auth/layout.tsx @@ -2,6 +2,7 @@ import SheetLayout from '@/app/components/Layouts/SheetLayout'; import { Metadata } from 'next'; import * as React from 'react'; +import AuthPage from '../components/AuthPage/AuthPage'; export default function ComponentsLayout({ children, @@ -10,7 +11,9 @@ export default function ComponentsLayout({ }) { return ( <> - {children} + + {children} + ); } diff --git a/src/app/components/AuthPage/AuthPage.tsx b/src/app/components/AuthPage/AuthPage.tsx index f353197..9f53631 100644 --- a/src/app/components/AuthPage/AuthPage.tsx +++ b/src/app/components/AuthPage/AuthPage.tsx @@ -4,56 +4,22 @@ import { useEffect } from "react" // privy import { usePrivySmartAccount } from "@zerodev/privy"; -// hooks -import useUserAgent from '@/app/hooks/useUserAgent'; - export default function AuthPage ({children} : {children: React.ReactNode}) { const router = useRouter(); - const { authenticated, login, zeroDevReady, user } = usePrivySmartAccount(); - const { userAgent, isMobile, isStandalone, isIOS } = useUserAgent(); + const { authenticated } = usePrivySmartAccount(); useEffect(() => { + if (!authenticated) { + router.push('/login'); + } - /* if (window) { - console.log("window is here") - if (window.matchMedia('(display-mode: standalone)').matches) { - console.log('standalone') - if (authenticated && zeroDevReady) { - // route home - console.log('authenticated'); - router.push('/home'); - } else { - router.push('/login'); - } - } else { - console.log('not standalone') - router.push('/'); - } - - } */ - - - - if (authenticated && zeroDevReady) { - // route home - console.log('authenticated'); - router.push('/home'); - } else { - router.push('/login'); - } - - - - - - - }, [authenticated, zeroDevReady]); + }, [authenticated]); return ( - <> {children} + <>{children} ) } \ No newline at end of file diff --git a/src/app/home/page.tsx b/src/app/home/page.tsx index 4c51f73..caf16fe 100644 --- a/src/app/home/page.tsx +++ b/src/app/home/page.tsx @@ -34,6 +34,7 @@ import useGetAddress from '../hooks/useGetAddress'; import { motion, useScroll, useTransform } from 'framer-motion'; import useGetTokenBalance from '../hooks/useGetTokenBalance'; +import AuthPage from '../components/AuthPage/AuthPage'; export default function Page() { // privy @@ -70,83 +71,84 @@ export default function Page() { const usdcBalance = useGetTokenBalance(address as string) console.log('usdcBalance', usdcBalance); return ( -
-
- { + +
+
+ { dispatch(setSheet(true)); }} */ href={{ - pathname: '/menu', - query: { isNavOpen: true }, - }} - > - router.push(`/menu?isNavOpen=true`)} /> - -
-
-
- + pathname: '/menu', + query: { isNavOpen: true }, + }} + > + router.push(`/menu?isNavOpen=true`)} /> +
- - {/* */} - {/* {address} */} - - - -
- { - dispatch(setSheet(true)); - }} - href={{ - pathname: '/search', - }} - > - - +
+
+
- -
- { - dispatch(setSheet(true)); - }} - href={{ - pathname: '/receive', - }} - > - + +
+ +
+ { + dispatch(setSheet(true)); + }} + href={{ + pathname: '/receive', + }} + > +
- - -
- -
- {/* + + +
+ +
+ {/*
@@ -165,15 +167,16 @@ export default function Page() { */} - {/*
+ {/*
Activity
*/} - + +
-
+ ); } diff --git a/src/app/menu/page.tsx b/src/app/menu/page.tsx index 377b386..c8d8dd9 100644 --- a/src/app/menu/page.tsx +++ b/src/app/menu/page.tsx @@ -1,4 +1,11 @@ +import { useRouter } from "next/navigation"; +import { useEffect } from "react"; + export default function Page() { + const router = useRouter(); + useEffect(() => { + router.push('/home') + }, []) return ( <>

backup Menu

diff --git a/src/app/payee/page.tsx b/src/app/payee/page.tsx index 11a5ac7..88af965 100644 --- a/src/app/payee/page.tsx +++ b/src/app/payee/page.tsx @@ -1,11 +1,14 @@ -'use client' -import { useRouter } from 'next/router'; -// Next -import { useSearchParams } from 'next/navigation'; +import { useRouter } from 'next/navigation'; +import { useEffect } from 'react'; export default function Page() { - const searchParams = useSearchParams(); - let address = searchParams.get('address'); - - return

Payee: {address}

; + const router = useRouter(); + useEffect(() => { + router.push('/home'); + }, []); + return ( + <> +

backup payee

+ + ); } diff --git a/src/app/send/page.tsx b/src/app/send/page.tsx index b3cff41..1da4cab 100644 --- a/src/app/send/page.tsx +++ b/src/app/send/page.tsx @@ -1,33 +1,14 @@ -'use client'; - -import BackButton from '@/app/components/Navigation/BackButton/BackButton'; -// components -import SendUsdc from '@/app/components/SendUsdc/SendUsdc'; import { useRouter } from 'next/navigation'; +import { useEffect } from 'react'; export default function Page() { const router = useRouter(); + useEffect(() => { + router.push('/home'); + }, []); return ( <> -
- -
-
{ - router.push('/home'); - }} - > - -
-
-

Send

-
-
-
- -
- -
+

backup Send

); } diff --git a/src/app/transaction/page.tsx b/src/app/transaction/page.tsx index 2d6d4c8..c91c801 100644 --- a/src/app/transaction/page.tsx +++ b/src/app/transaction/page.tsx @@ -1,9 +1,14 @@ -'use client'; +import { useRouter } from 'next/navigation'; +import { useEffect } from 'react'; export default function Page() { + const router = useRouter(); + useEffect(() => { + router.push('/home'); + }, []); return ( <> -

Backup Tx Page

+

backup tx page

); } diff --git a/src/app/transactions/page.tsx b/src/app/transactions/page.tsx index fb9f4fa..01eb40a 100644 --- a/src/app/transactions/page.tsx +++ b/src/app/transactions/page.tsx @@ -19,6 +19,7 @@ import { //import { format, parseISO } from 'date-fns'; import { format, parseISO, set } from 'date-fns'; +import AuthPage from '../components/AuthPage/AuthPage'; export default function Page() { const [transactions, setTxs] = useState([]); @@ -93,63 +94,67 @@ export default function Page() { }, [transactionState]); // Add transactions as a dependency return ( - { + + { setShowTxs(true); }} */ - className='absolute w-full text-xl' - > - - - - Recent Transactions - - - - - {showTxs && ( - <> - {groupedTransactions && ( - <> -
- {groupedTransactions.map((month, i) => ( -
-
-

- {month.monthName} -

-
- {month.transactions.map((transaction, j) => ( - + + + + Recent Transactions + + + + + {showTxs && ( + <> + {groupedTransactions && ( + <> +
+ {groupedTransactions.map((month, i) => ( +
+
-
- -
- - ))} -
- ))} -
- - )} - - )} - - - - +

+ {month.monthName} +

+
+ {month.transactions.map((transaction, j) => ( + +
+ +
+
+ ))} +
+ ))} +
+ + )} + + )} +
+
+
+
+
); } diff --git a/src/app/tx/page.tsx b/src/app/tx/page.tsx index d1fa07a..c1e584f 100644 --- a/src/app/tx/page.tsx +++ b/src/app/tx/page.tsx @@ -16,6 +16,7 @@ import { Send, QrCode } from 'lucide-react'; import { Avatar } from '@/app/components/ui/avatar'; import { RootState } from '@/GlobalRedux/store'; +import AuthPage from '../components/AuthPage/AuthPage'; export default function Page() { console.log('Tx Modal Page'); const dispatch = useDispatch(); @@ -41,76 +42,78 @@ export default function Page() { }, [txState]); return ( - <> - {!isLoading && ( - -
-
-
- - {transaction.from == address ? '+$' : '-$'} + + <> + {!isLoading && ( + +
+
+
+ + {transaction.from == address ? '+$' : '-$'} - {transaction.value} -
-
- {transaction.from == address ? 'From' : 'To'}{' '} - {truncateEthAddress(transaction.from)} -
-
-
- {}} - href={{ - pathname: '/send', - query: { address: transaction.from }, - }} - > - - + {transaction.value}
-
- - - +
+ {transaction.from == address ? 'From' : 'To'}{' '} + {truncateEthAddress(transaction.from)}
-
-
-
-

Status

-

Completed

+
+
+ {}} + href={{ + pathname: '/send', + query: { address: transaction.from }, + }} + > + + +
+
+ + + +
-
-

Tx Hash

-

- {truncateEthAddress(transaction.hash)} -

+
+
+

Status

+

Completed

+
+
+

Tx Hash

+

+ {truncateEthAddress(transaction.hash)} +

+
-
- - )} - + + )} + + ); }