import React, { useMemo } from "react"; import { OverlayTrigger, Tooltip } from "react-bootstrap"; import { QueryPreservingLink } from "src/services/network/networkProvider"; import { qaToZilSimplified, qaToZil, hexAddrToZilAddr } from "src/utils/Utils"; import numbro from "numbro"; import ToAddrDispSimplified from "src/components/Misc/Disp/ToAddrDisp/ToAddrDispSimplified"; import DisplayTable from "src/components/HomePage/Dashboard/DisplayTable/DisplayTable"; import TypeDisplay from "./TypeDisplay"; import AgeDisplay from "./AgeDisplay"; import { faExclamationCircle } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import "./TransactionsCard.css"; interface IProps { transactions: []; fungibleToken?: any; addr: string; } const TransactionsCard: React.FC = ({ transactions: txs, addr, fungibleToken, }) => { const transactions: any[] = txs.flatMap( (tx: { receipt: { transitions: [] } }) => { if (fungibleToken && tx.receipt.transitions.length) { console.log(tx.receipt.transitions); const tokenTx: any | undefined = tx.receipt.transitions.find( (transition: { msg: { _tag: string } }) => transition.msg._tag === "TransferSuccessCallBack" ); if (tokenTx !== undefined) { const toAddr = tokenTx.msg.params.find( (p: any) => p.vname === "recipient" ); const fromAddr = tokenTx.msg.params.find( (p: any) => p.vname === "sender" ); const amount = tokenTx.msg.params.find( (p: any) => p.vname === "amount" ); return [ { ...tx }, { ...tx, ID: "token-transfer", toAddr: toAddr.value, fromAddr: fromAddr.value, amount: amount.value, type: "token-transfer", fungibleToken, }, ]; } } return { ...tx, }; } ); const columns = useMemo( () => [ { id: "alert-col", Header: "", Cell: ({ row }: { row: any }) => { return (
{row.original.receipt && !row.original.receipt.success && ( )}
); }, }, { id: "hash-col", Header: "Hash", accessor: "hash", Cell: ({ row }: { row: any }) => { return row.original.ID !== "token-transfer" ? (
{"0x" + row.original.ID}
) : ( `${fungibleToken.name.value} Transfer` ); }, }, { id: "from-col", Header: "From", accessor: "fromAddr", Cell: ({ value }: { value: string }) => { const ziladdr = hexAddrToZilAddr(value); return ( <> {addr === ziladdr ? ( {addr} ) : ( {ziladdr} )} ); }, }, { id: "type-col", Header: "", Cell: ({ row }: { row: any }) => { console.log(row.original); return ( <> ); }, }, { id: "to-col", Header: "To", Cell: ({ row }: { row: any }) => { return ( ); }, }, { id: "amount-col", Header: "Amount", Cell: ({ row }: any) => { const value = row.original.amount; let formattedValue: string = numbro(qaToZilSimplified(value)).format({ thousandSeparated: true, mantissa: 3, }) + " ZIL"; if (row.original.ID === "token-transfer") { formattedValue = value / Math.pow(10, parseInt(fungibleToken.decimals.value)) + ` ${fungibleToken.symbol.value}`; } return ( {numbro(value).format({ thousandSeparated: true })} } >
{formattedValue}
); }, }, { id: "fee-col", Header: "Fee", Cell: ({ row }: any) => { const fee = parseFloat(row.original.receipt.cumulative_gas) * row.original.gasPrice; return ( {fee} Qa} >
{qaToZil(fee, 4)}
); }, }, ], [addr] ); return (
); }; export default TransactionsCard;