import { useTransactionReceipt, useTransaction, useToken } from 'wagmi'; import { decodeEventLog, decodeFunctionData, toHex } from 'viem'; import { useMemo, useCallback, useState } from "react"; import { useParams } from "react-router-dom"; import { Box, Typography, Link, Skeleton } from "@mui/material"; import CheckIcon from '@mui/icons-material/Check'; import ContentPasteIcon from '@mui/icons-material/ContentPaste'; import GhostStyledIcon from "../../../components/Icon/GhostIcon"; import Modal from "../../../components/Modal/Modal"; import Token from "../../../components/Token/Token"; import { PrimaryButton } from "../../../components/Button"; import { useBondInfo } from "../../../hooks/bonds"; import { useTokenSymbol } from "../../../hooks/tokens"; import { getTokenDecimals } from "../../../hooks/helpers"; import { useLocalStorage } from "../../../hooks/localstorage"; import { formatNumber, formatCurrency, shorten } from "../../../helpers"; import { DecimalBigNumber } from "../../../helpers/DecimalBigNumber"; import { abi as GhostStaking } from "../../../abi/GhostStaking.json"; import { abi as GhostGatekeeper } from "../../../abi/GhostGatekeeper.json"; import { abi as ERC20Token } from "../../../abi/ERC20.json"; import TokenBox from "../TokenBox"; const ClickableHex = ({ copyToClipboard, index, value, copiedIndex }) => { if (!value) return ; return ( copyToClipboard(value, index)} > {shorten(value, 12, -10)} ) } const BondModalExodus = ({ chainId, address, isOpen, close, config, historyRecord }) => { if (historyRecord === null) return null; const { network } = useParams(); const { CONSTANTS } = useLocalStorage(); const [copiedIndex, setCopiedIndex] = useState(null); const copyToClipboard = (text, index) => { navigator.clipboard.writeText(text).then(() => { setCopiedIndex(index); setTimeout(() => setCopiedIndex(null) , 800); }); }; const chainInfo = useMemo(() => { const client = config?.getClient(); return { url: client?.chain?.blockExplorers?.default?.url, symbol: client?.chain?.nativeCurrency?.symbol, }; }, [config]); const { symbol: ftsoSymbol } = useTokenSymbol(chainId, "FTSO"); const { data: receipt, isLoading, error } = useTransactionReceipt({ hash: historyRecord?.txHash, query: { enabled: !!historyRecord?.txHash && isOpen, } }); const { data: txData } = useTransaction({ chainId, hash: historyRecord.txHash, }); const functionArgs = useMemo(() => { if (!txData) return null; try { const decoded = decodeFunctionData({ abi: GhostGatekeeper, data: txData.input, }); return { message: decoded?.args.at(0), nonce: toHex(decoded?.args.at(1)), signature: toHex(decoded?.args.at(2)), } } catch (err) { return null; } }, [txData]); const allDecodedLogs = useMemo(() => { if (!receipt?.logs) return []; return receipt.logs.map((log) => { try { const decoded = decodeEventLog({ abi: GhostGatekeeper, data: log.data, topics: log.topics, }); return { eventName: decoded.eventName, args: decoded.args, address: log.address }; } catch (e) {} try { const decoded = decodeEventLog({ abi: GhostStaking, data: log.data, topics: log.topics, }); return { eventName: decoded.eventName, args: decoded.args, address: log.address }; } catch (e) { return null; } }).filter(Boolean); }, [receipt]); const voluntaryVerification = useMemo(() => { return !!allDecodedLogs.find(l => l.eventName === "VoluntaryVerification"); }, [allDecodedLogs]) const stakedAmount = useMemo(() => { const log = allDecodedLogs.find(l => l.eventName === 'Staked'); if (!log) return 1n; return new DecimalBigNumber(log.args.amount, getTokenDecimals("FTSO")); }, [allDecodedLogs]); return ( {(functionArgs && allDecodedLogs) && voluntaryVerification ? "Voluntary Verification" : "Exodus Verification"} {(!functionArgs || !allDecodedLogs) && "Parsing Transaction Hash"} } onClose={() => close()} > { {!voluntaryVerification && Exodus Reward {formatCurrency(stakedAmount, 5, ftsoSymbol)} Receiver } Message Nonce Signature View Transaction Details } ) } export default BondModalExodus;