import React, { useCallback } from "react"; import { qaToZil, hexAddrToZilAddr, isValidAddr } from "src/utils/Utils"; import AddressDisp from "src/components/Misc/Disp/AddressDisp/AddressDisp"; import { EventLogEntry, EventParam } from "@zilliqa-js/core/src/types"; import "./TransactionFlow.css"; interface IProps { modalData: any; display: boolean; closeModal: Function; } const TransitionModal: React.FC = ({ display, modalData, closeModal, }) => { 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]} ); }, [] ); const events = modalData ? modalData.events ? modalData.events : modalData.txData.receipt.event_logs : []; return ( <> {display ? (
closeModal()}> Close
{modalData.data ? ( <>
Transition details
Tag {modalData.data.msg._tag === "" ? "-" : modalData.data.msg._tag}
Contract Address
Accepts $ZIL {modalData.data.accepted === undefined ? "-" : `${modalData.data.accepted}`}
Depth {modalData.data.depth}
Amount {qaToZil(modalData.data.msg._amount)}
Recipient {modalData.data.msg._recipient ? ( ) : null}
{modalData.data.msg.params && modalData.data.msg.params.length > 0 && ( <>
{modalData.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 )}
)} ) : ( <> {modalData.txData ? ( <>
Transaction details
From
To
Amount {modalData.txData.amount}
) : null} )}
Events
{events && 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: any) => acc === null ? ( x ) : (
{acc}
{x}
), null )}
) : null} ); }; export default TransitionModal;