From 325e97c550d12c0d60c8c47c29dcf51c59d54c29 Mon Sep 17 00:00:00 2001 From: Ste Date: Sun, 4 Feb 2024 15:38:00 +0000 Subject: [PATCH] finished view a tx by id --- src/app/@auth/(.)transaction/page.tsx | 98 ++++++++++++++++++------ src/app/components/Layouts/Sheet.tsx | 4 +- src/app/components/activity/Activity.tsx | 11 ++- tailwind.config.ts | 5 +- 4 files changed, 87 insertions(+), 31 deletions(-) diff --git a/src/app/@auth/(.)transaction/page.tsx b/src/app/@auth/(.)transaction/page.tsx index 16b86b2..2c694d1 100644 --- a/src/app/@auth/(.)transaction/page.tsx +++ b/src/app/@auth/(.)transaction/page.tsx @@ -1,48 +1,96 @@ 'use client'; - -import { useRouter } from "next/router"; +import Link from 'next/link'; import { useSearchParams } from 'next/navigation'; + import { useEffect, useState } from "react"; -import { Alchemy, Network } from 'alchemy-sdk'; +//redux +import { useSelector } from "react-redux"; + +import truncateEthAddress from 'truncate-eth-address'; export default function Page() { - const config = { - apiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY, - network: Network.MATIC_MUMBAI, - }; - const alchemy = new Alchemy(config); - const [transactions, setTransactions] = useState({}) + const [transaction, setTransaction] = useState({}) + + const [isLoading, setIsLoading] = useState(true) const searchParams = useSearchParams(); let hash = searchParams.get('hash'); + const txState = useSelector((state: any) => state.transactions.value); + + const address = useSelector((state: any) => state.address.value); + useEffect(() => { - const getData = async () => { - try { - const response = await alchemy.transact.getTransaction(hash); - console.log('response', response); - setTransactions(response); - } catch (error) { + console.log('txState', txState) + const filteredTransaction = txState.filter((tx: any) => tx.hash == hash); + + + setTransaction(filteredTransaction[0]); + console.log('filteredTransaction', filteredTransaction) + setIsLoading(false) + + }, [txState]) - } - } - getData(); - }, []) return ( <> -
-
-

Tx

-

{hash}

-
-
+ { + isLoading &&
Loading...
+ } + { + !isLoading && ( +
+
+
+ {transaction.from == address ? "+$" : "-$"} + + {transaction.value} +
+
+ {transaction.from == address ? "From" : "To"} {truncateEthAddress(transaction.from)} +
+
+ + + + + + +
+
+
+

Status

+

Completed

+
+
+

Tx Hash

+

{truncateEthAddress(transaction.hash)}

+
+
+
+
+ ) + } ); } diff --git a/src/app/components/Layouts/Sheet.tsx b/src/app/components/Layouts/Sheet.tsx index 7e51a7d..4a47342 100644 --- a/src/app/components/Layouts/Sheet.tsx +++ b/src/app/components/Layouts/Sheet.tsx @@ -45,9 +45,9 @@ const Sheet = ({ children }) => { borderTopLeftRadius: '32px', borderTopRightRadius: '32px', }} - className='bg-paper' + className='bg-paper-one' > -
{children}
+
{children}
)} diff --git a/src/app/components/activity/Activity.tsx b/src/app/components/activity/Activity.tsx index 6e4dcea..a480092 100644 --- a/src/app/components/activity/Activity.tsx +++ b/src/app/components/activity/Activity.tsx @@ -4,18 +4,22 @@ import useGetAddress from "@/app/hooks/useGetAddress"; import useGetRecentTransactions from "@/app/hooks/useGetRecentTransactions"; import Link from "next/link"; import { useEffect, useState } from "react"; +import { useDispatch } from "react-redux"; +import { setTransactions } from "@/GlobalRedux/Features/transactions/transactionsSlice"; export default function Activity() { - const [transactions, setTransactions] = useState([]) + const [transactions, setTxs] = useState([]) const address = "0xc8C26Ab40fe4723519fE66B8dBb625FC070A982c" + const dispatch = useDispatch(); + useEffect(() => { const getData = async () => { try { const recentTransactions = await useGetRecentTransactions(); - setTransactions(recentTransactions?.transfers.slice(0, 3)); + setTxs(recentTransactions?.transfers.slice(0, 3)); } catch (error) { console.error("Error while getting recent transactions:", error); } @@ -28,11 +32,12 @@ export default function Activity() { if (transactions) { console.log("transactions console", transactions[0]); } + dispatch(setTransactions(transactions)); }, [transactions]); // Add transactions as a dependency return ( <> -
+
Recent
diff --git a/tailwind.config.ts b/tailwind.config.ts index fc8e407..ce92b10 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -11,7 +11,10 @@ export default { colors: { main: '#101012', dark: '#101012', - paper: '#2C2D33', + 'paper': { + one: '#2C2D33', + two: '#43444C', + }, purple: '#6A48F2', primary: { // Customize it on globals.css :root