diff --git a/src/TransactionDetails.js b/src/TransactionDetails.js index ac1189d..f1460e1 100644 --- a/src/TransactionDetails.js +++ b/src/TransactionDetails.js @@ -1,10 +1,15 @@ -import { Alchemy, Network, Utils } from "alchemy-sdk"; import { useEffect, useState } from "react"; import { useParams, Link } from "react-router-dom"; -import { FaArrowLeft } from "react-icons/fa"; -import "./Home.css"; -import logo from "../src/assets/ethereum_logo.png"; +import { Alchemy, Network } from "alchemy-sdk"; +import "./Home.css"; // Pridajte CSS štýly pre vzhľad import Loading from "../src/Loading.js"; +import logo from "../src/assets/ethereum_logo.png"; +import { + FaArrowLeft, + FaHashtag, + FaFingerprint, + FaCalendarAlt +} from "react-icons/fa"; const settings = { apiKey: process.env.REACT_APP_ALCHEMY_API_KEY, @@ -13,82 +18,88 @@ const settings = { const alchemy = new Alchemy(settings); -function TransactionDetails() { - const { transactionHash } = useParams(); - const [transaction, setTransaction] = useState(null); - const [loading, setLoading] = useState(true); +function AddressDetails() { + const { address } = useParams(); + const [balance, setBalance] = useState(""); + const [transactionCount, setTransactionCount] = useState(0); const [error, setError] = useState(null); + const [loading, setLoading] = useState(true); useEffect(() => { - async function fetchTransactionDetails() { + async function fetchAddressData() { try { - console.log(`Fetching details for transaction hash: ${transactionHash}`); - const txDetails = await alchemy.core.getTransaction(transactionHash); - console.log("Transaction details:", txDetails); - setTransaction(txDetails); + const balance = await alchemy.core.getBalance(address); + const txCount = await alchemy.core.getTransactionCount(address); + + setBalance(balance / 1e18 + " ETH"); // Konverzia na ETH + setTransactionCount(txCount); } catch (error) { - console.error("Failed to fetch transaction details", error); - setError("Failed to fetch transaction details. Please try again."); + setError("Failed to fetch address data."); + console.error("Error fetching address data:", error); } finally { setLoading(false); } } - if (transactionHash) { - fetchTransactionDetails(); - } - }, [transactionHash]); + fetchAddressData(); + }, [address]); - // Convert BigNumber values to string for display - const value = transaction?.value ? Utils.formatUnits(transaction.value, "ether") : "N/A"; - const gas = transaction?.gas ? transaction.gas.toString() : "N/A"; - const gasPrice = transaction?.gasPrice ? Utils.formatUnits(transaction.gasPrice, "gwei") : "N/A"; + if (error) { + return
{error}
; + } return (
- {loading ? ( - - ) : ( -
-
- -

Ethereum Insider

- - - Logo +
+
+ +

Ethereum Insider

+ + + Logo + +
+

The Ethereum Blockchain Explorer

+ {loading ? ( + + ) : ( + <> + + Back to home + +

Address Details

+
+ {/* Block Information Group */} +
+
+ +

+ Address: {address} +

+
+
+ +

+ Balance:{" "} + + {balance} + +

+
+
+ +

+ Transaction Count: {transactionCount} +

+
-

The Ethereum Blockchain Explorer

- {error ? ( -
{error}
- ) : transaction ? ( - <> - - Back to Transactions - -

Transaction Details

-
-

Transaction Hash: {transaction.hash}

-

Block Number: {transaction.blockNumber}

-

Transaction Index: {transaction.transactionIndex}

-

Confirmations: {transaction.confirmations}

-

From: {transaction.from}

-

To: {transaction.to}

-

Value: {value} ETH

-

Gas: {gas}

-

Gas Price: {gasPrice} Gwei

-

Nonce: {transaction.nonce}

-

Chain Id: {transaction.chainId}

-

Data: {transaction.data}

-
- - ) : ( -
No transaction found.
- )}
- )} + + )} +
); } -export default TransactionDetails; +export default AddressDetails;