generated from theodorusclarence/ts-nextjs-tailwind-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
085d532
commit 325e97c
Showing
4 changed files
with
87 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<any>({}) | ||
const [transaction, setTransaction] = useState<any>({}) | ||
|
||
const [isLoading, setIsLoading] = useState<boolean>(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 ( | ||
<> | ||
<div className='grid'> | ||
<div className='my-4'> | ||
<p className='my-4 text-center text-xl text-gray-300'>Tx</p> | ||
<p className='my-4 text-center text-xl text-gray-300'>{hash}</p> | ||
</div> | ||
</div> | ||
{ | ||
isLoading && <div>Loading...</div> | ||
} | ||
{ | ||
!isLoading && ( | ||
<div className='grid p-4'> | ||
<div className='my-4'> | ||
<div className="flex text-white font-bold text-xl"> | ||
{transaction.from == address ? "+$" : "-$"} | ||
|
||
{transaction.value} | ||
</div> | ||
<div className="text-blue-400"> | ||
{transaction.from == address ? "From" : "To"} {truncateEthAddress(transaction.from)} | ||
</div> | ||
<div className='mt-10 flex justify-between'> | ||
<Link | ||
href={{ | ||
pathname: '/search', | ||
query: { address: transaction.to }, | ||
}} | ||
> | ||
<button className='rounded w-40 bg-purple px-4 py-2 text-white hover:bg-blue-700 text-lg'> | ||
Send | ||
</button> | ||
|
||
</Link> | ||
<Link | ||
href={{ | ||
pathname: '/receive', | ||
query: { address: transaction.to }, | ||
}} | ||
> | ||
<button className='rounded w-40 bg-purple px-4 py-2 text-white hover:bg-blue-700 text-lg'> | ||
Receive | ||
</button> | ||
</Link> | ||
</div> | ||
<div className='bg-paper-two p-4 rounded-xl mt-4'> | ||
<div className='flex justify-between mb-4'> | ||
<p>Status</p> | ||
<p>Completed</p> | ||
</div> | ||
<div className='flex justify-between'> | ||
<p>Tx Hash</p> | ||
<p className='text-blue-400'>{truncateEthAddress(transaction.hash)}</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters