From 091b01eaa047dcc98842abd7f4e7dba7ac4ce240 Mon Sep 17 00:00:00 2001 From: Stephen Gordon Date: Thu, 28 Mar 2024 16:58:44 +0000 Subject: [PATCH] removed transactions modal --- src/app/@auth/(.)send/page.tsx | 4 +- src/app/@drawer/(.)transactions/page.tsx | 229 ----------------------- src/app/components/SendUsdc/SendUsdc.tsx | 76 ++------ src/app/components/activity/Activity.tsx | 3 +- src/app/transactions/page.tsx | 201 ++++++++++++-------- 5 files changed, 146 insertions(+), 367 deletions(-) delete mode 100644 src/app/@drawer/(.)transactions/page.tsx diff --git a/src/app/@auth/(.)send/page.tsx b/src/app/@auth/(.)send/page.tsx index 2d8f895..5031f7a 100644 --- a/src/app/@auth/(.)send/page.tsx +++ b/src/app/@auth/(.)send/page.tsx @@ -56,9 +56,9 @@ export default function Page() { -
+ -
+ ); } diff --git a/src/app/@drawer/(.)transactions/page.tsx b/src/app/@drawer/(.)transactions/page.tsx deleted file mode 100644 index a796eab..0000000 --- a/src/app/@drawer/(.)transactions/page.tsx +++ /dev/null @@ -1,229 +0,0 @@ -'use client'; -// react -import { useEffect, useState } from 'react'; -// hooks -import useGetRecentTransactions from '@/app/hooks/useGetRecentTransactions'; -import RecentTransaction from '@/app/components/RecentTransaction/RecentTransaction'; -// framer motion -import { motion } from 'framer-motion'; -// redux -import { useDispatch, useSelector } from 'react-redux'; -import { setTransactions } from '@/GlobalRedux/Features/transactions/transactionsSlice'; -import useGetAddress from '@/app/hooks/useGetAddress'; -import { - CardTitle, - CardHeader, - Card, - CardContent, -} from '@/app/components/ui/card'; - -import BackButton from '@/app/components/Navigation/BackButton/BackButton'; - - -// next -import { useSearchParams } from 'next/navigation'; -import { useRouter } from 'next/navigation'; - -//import { format, parseISO } from 'date-fns'; -import { format, parseISO, set, fromUnixTime } from 'date-fns'; - -export default function Page() { - //next - const searchParams = useSearchParams(); - let isSheetOpen = searchParams.get('isSheetOpen'); - - // state - const [transactions, setTxs] = useState([]); - const [allTransactions, setAllTransactions] = useState([]); - - const [groupedTransactions, setGroupedTransactions] = useState([]); - - // animate - const [showMoreTx, setShowMoreTx] = useState(true); - - const isOpen = useSelector((state: any) => state.sheet.value); - - // animate - const [showTxs, setShowTxs] = useState(true); - - const dispatch = useDispatch(); - - // address - const address = useGetAddress(); - - // router - const router = useRouter(); - - const transactionState = useSelector( - (state: any) => state.transactions.value - ); - - interface Transaction { - to: string; - from: string; - value: string; - timeStamp: string; - } - - useEffect(() => { - const getData = async () => { - try { - const recentTransactions = await useGetRecentTransactions(address); - setAllTransactions(recentTransactions); - dispatch(setTransactions(recentTransactions)); - } catch (error) { - console.error('Error while getting recent transactions:', error); - } - }; - - getData(); - }, []); - - - - useEffect(() => { - - console.log("transState in page",transactionState) - setTxs(transactionState); - - const groupedTransactionsByMonth: { [key: string]: any[] } = - transactions.reduce((groups, transaction) => { - const monthKey = format( - fromUnixTime(transaction.timeStamp), - 'yyyy-MM' - ); - if (!groups[monthKey]) { - groups[monthKey] = []; - } - groups[monthKey].push(transaction); - return groups; - }, {}); - - // Convert grouped transactions object into an array of arrays with month names - const arrayOfMonthArrays: { - monthName: string; - transactions: Transaction[]; - }[] = Object.entries(groupedTransactionsByMonth).map( - ([monthKey, transactions]) => ({ - monthName: format(parseISO(monthKey), 'MMMM yyyy'), // Format month name along with the year - transactions, - }) - ); - setGroupedTransactions(arrayOfMonthArrays); - console.log('groupedTransactionsByMonth', arrayOfMonthArrays); - }, [transactionState]); // Add transactions as a dependency - - return ( - <> - {isSheetOpen && ( - { - setShowTxs(true); - }} */ - className='from-background to bg-accent/80 absolute z-50 min-h-screen w-full overflow-hidden bg-gradient-to-br text-xl backdrop-blur-xl' - > - - - -
{ - router.back(); - }} - > - -
-

Recent Transactions

-
-
-
- - - {showTxs && ( - <> - {groupedTransactions && ( - <> -
- {groupedTransactions.map((month, i) => ( -
-
-

- {month.monthName} -

-
- {month.transactions - .map((transaction, j) => ( - - - - - - ))} - {/* {showMoreTx && ( - - {month.transactions - .slice(5, 20) - .map((transaction, j) => ( - - - - - - ))} - - )} */} -
- ))} -
- - )} - - )} -
-
-
-
- )} - - ); -} diff --git a/src/app/components/SendUsdc/SendUsdc.tsx b/src/app/components/SendUsdc/SendUsdc.tsx index eed81a9..e465819 100644 --- a/src/app/components/SendUsdc/SendUsdc.tsx +++ b/src/app/components/SendUsdc/SendUsdc.tsx @@ -63,71 +63,29 @@ export default function SendUsdc() { } }, [usdcAmount]); - // Send transaction function - const sendTx = async () => { - try { - // Encode the data with Viem Function - // Requires the abi of the contract, the function name, and the arguments address and amount - // @ts-ignore - if (!zeroDevReady) { - console.log('not ready to send'); - return; - } - if (usdcAmount == '' || usdcAmount == '0') { - console.log('amount is 0'); - return; - } - const encoded: any = encodeFunctionData({ - // @ts-ignore - abi: erc20Abi, - functionName: 'transfer', - args: [payee as `0x${string}`, parseUnits(usdcAmount, 6)], - }); - console.log('Sending USDC'); - setLoading(true); - const txnHash = await sendTransaction({ - to: usdc, // ERC20 address - value: BigInt(0), // default to 0 - data: encoded, - }); - console.log('Txn hash:', txnHash); - - if (txnHash) { - setLoading(false); - setTransactionStatus(true); - setTimeout(() => { - dispatch(setSheet(false)); - /* router.push(`/transaction?hash=${txnHash}`); */ - const balance = router.push('/home'); - }, 1000); - } - } catch (error) { - console.log(error); - } - }; + return ( <>
- - - - - -
+ + + + + ); } diff --git a/src/app/components/activity/Activity.tsx b/src/app/components/activity/Activity.tsx index 8c3994e..208f7a3 100644 --- a/src/app/components/activity/Activity.tsx +++ b/src/app/components/activity/Activity.tsx @@ -93,8 +93,7 @@ export default function Activity() {