import {
Box,
Container,
Grid,
GridItem,
HStack,
Icon,
Image,
Text,
VStack,
keyframes,
useColorMode,
useToast,
} from "@chakra-ui/react";
import React, { useContext, useEffect, useState } from "react";
import { MdContentCopy, MdOutlineErrorOutline } from "react-icons/md";
import Pagination from "../Pagination";
import GlobalStateContext from "../../Contexts/GlobalStateContext";
import { Link, useLocation, useNavigate } from "react-router-dom";
import ToastBox from "../ToastBox";
import { formatRelativeDate } from "../../Constants/Constants";
import {
useGetTransAllQuery,
useGetTransCountQuery,
} from "../../Services/api.service";
import rbtLogoOutline from "../../assets/images/rubix-filled.svg";
import { HiOutlineRefresh } from "react-icons/hi";
export const rotate = keyframes`
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
`;
const LatestTransactions = () => {
const toast = useToast();
const navigate = useNavigate();
const location = useLocation();
useEffect(() => {
window.scrollTo({ top: 0, behavior: "smooth" }); // Scroll to top smoothly when params change
}, [location]);
const { colorMode } = useColorMode();
const [isRotating, setIsRotating] = useState(false);
const [currentPage, setCurrentPage] = useState(1); // Tracks the current page
const [pageSize, setPageSize] = useState(10); // Number of items per page
const [totalItems, setTotalItems] = useState(null); // Total items in the dataset
const {
data: transCount,
isLoading: isTransCountLoading,
refetch: transCountRefetch,
errors: transCountErrors,
} = useGetTransCountQuery();
// Fetch transactions based on the current page and page size
const {
data: transAll,
isLoading: isTransAllLoading,
refetch: transAllRefetch,
} = useGetTransAllQuery({
pageNumber: currentPage,
pageSize: pageSize,
});
// Set interval to refetch data every 30 seconds
// useEffect(() => {
// const intervalId = setInterval(() => {
// transCountRefetch(); // Refetch transaction count
// transAllRefetch(); // Refetch transactions
// }, 30000); // 30000 ms = 30 seconds
// return () => clearInterval(intervalId); // Clear interval on component unmount
// }, [transCountRefetch, transAllRefetch]);
useEffect(() => {
setTotalItems(transCount?.data?.transactionCount);
}, [transCount]);
function copyToClipboard(text) {
navigator.clipboard
.writeText(text)
.then(() => {
toast({
render: () => (
),
});
})
.catch((err) => {
console.error("Failed to copy text: ", err);
});
}
const handleRefreshClick = () => {
setIsRotating(true); // Start rotation
// Simulate any refresh logic here
setTimeout(() => {
setIsRotating(false); // Stop rotation after 3 seconds
}, 3000); // 3 seconds = 3000ms
};
return (
Sr. no
Transactions
{transAll?.data?.items?.map(
(
{
transactionId,
smartContract,
sender,
receiver,
contract,
timestamp,
amount,
transactionType,
subNetworkId,
},
index
) => (
{index + 1}.
{/* */}
navigate(`/transaction/${transactionId}`)}
>
{transactionId}
copyToClipboard(transactionId)}
/>
Sender:
navigate(`/did-info/${sender}`)}
>
{sender}
copyToClipboard(sender)} />
Receiver:
navigate(`/did-info/${receiver}`)}
>
{receiver}
copyToClipboard(receiver)}
/>
{smartContract && (
Smart contract ID :
{smartContract}
)}
Date and Time Stamp :
{formatRelativeDate(timestamp)}
Amount:
{amount}
Transaction type :
{transactionType}
{subNetworkId === "MainNet" ? "Main net" : "Subnet ID"}{" "}
:
{subNetworkId}
{/* */}
)
)}
);
};
export default LatestTransactions;