import React, { useState, useCallback } from "react"; import { qaToZil, hexAddrToZilAddr, isValidAddr, qaToZilSimplified, } from "src/utils/Utils"; import { QueryPreservingLink } from "src/services/network/networkProvider"; import AddressDisp from "src/components/Misc/Disp/AddressDisp/AddressDisp"; import { EventLogEntry, EventParam } from "@zilliqa-js/core/src/types"; import "./TransactionFlow.css"; interface IProps { link: { source: string; target: string; data?: any; amount?: number | string; index?: any; events?: EventLogEntry[]; }; noDetails?: boolean; parent?: any; } const TxBlock: React.FC = ({ link, parent, noDetails }) => { const [modalOpen, setModalOpen] = useState(false); const highlightEventParams = useCallback( (params: EventParam[]): React.ReactNode => { if (params.length === 0) return null; return params .map((param, index) => ( {param.type} {param.vname} )) .reduce((acc: React.ReactNode | null, ele) => acc === null ? <>{[ele]} : <>{[acc, ", ", ele]} ); }, [] ); if (parent) { const start = document.getElementById(`txblock-${parent.index}`); const end = document.getElementById(`txblock-${link.index}`); if (start !== null && end !== null) { /* @ts-ignore */ const line = new LeaderLine({ start, end, color: "#fff", path: "grid", // middleLabel: "test", size: 4, }); line.positionByWindowResize = false; const scrollableBox = document.querySelector(".transaction-flow"); // const ns = document.querySelector(".leader-line:last-of-type"); /* @ts-ignore */ //scrollableBox.appendChild(ns); /* @ts-ignore */ if (AnimEvent) { /* @ts-ignore */ scrollableBox.addEventListener( "scroll", /* @ts-ignore */ AnimEvent.add(function () { line.position(); }), false ); } } } const openModal = () => { if (link.index !== 0) { document.body.classList.add("has-modal-open"); setModalOpen(true); } }; const closeModal = () => { document.body.classList.remove("has-modal-open"); setModalOpen(false); }; return (
{!noDetails && link.index !== 0 ? (
closeModal()}> Close
Transition details
{link.data ? ( ) : null}
Tag {link.data.msg._tag === "" ? "-" : link.data.msg._tag}
Contract Address
Accepts $ZIL {link.data.accepted === undefined ? "-" : `${link.data.accepted}`}
Depth {link.data.depth}
Amount {qaToZil(link.data.msg._amount)}
Recipient {link.data.msg._recipient ? ( ) : null}
{link.data.msg.params && link.data.msg.params.length > 0 && ( <>
{link.data.msg.params.map((param: any, index: any) => ( ))}
Variable Value
{param.vname} {typeof param.value === "object" ? (
                              {JSON.stringify(param.value, null, "\t")}
                            
) : Array.isArray(param.value) ? ( param.value.toString() ) : isValidAddr(param.value.toString()) ? ( ) : ( param.value )}
)}
Transition Events
{link.events ? ( <> {link.events .map((event: EventLogEntry, index: number) => ( <>
{event._eventname} {" ("} {highlightEventParams(event.params)} {")"}
{event.params.length > 0 && ( <> {event.params.map((param, index) => ( ))} )}
Variable Value
{param.vname} {typeof param.value === "object" ? (
                                        {JSON.stringify(param.value, null, 2)}
                                      
) : Array.isArray(param.value) ? ( param.value.toString() ) : isValidAddr(param.value.toString()) ? ( ) : ( param.value )}
)) .reduce( (acc: React.ReactNode | null, x) => acc === null ? ( x ) : ( <> {acc}
{x} ), null )} ) : null}
) : null}
openModal()} id={`txblock-${link.index}`} > {!noDetails ? ( from {hexAddrToZilAddr(link.source)} ) : null} {!noDetails ? ( <>
{link.amount ? (
{qaToZilSimplified(link.amount)} ZIL
) : null} {link.data && link.data.msg ? ( <>
{link.data.msg._tag}
Amount: {link.data.msg._amount}
click to expand
{link.data.msg.params ? (
{Object.entries(link.data.msg.params).map( ([key, value]: any): any => { return (
{key}: {JSON.stringify(value)}
); } )}
) : null}
) : ( <> {!link.amount ? (
contract call
) : null} )}
{hexAddrToZilAddr(link.target)} ) : (
{hexAddrToZilAddr(link.source)}
)}
); }; export default TxBlock;