From 852d3c86ce90c516e9c5c908d83485731adea479 Mon Sep 17 00:00:00 2001 From: Uncle Fatso Date: Sat, 21 Nov 2026 20:49:13 +0300 Subject: [PATCH] make possible to verify exodus bridge-out from history modal Signed-off-by: Uncle Fatso --- package.json | 2 +- src/containers/History/BridgeOutModal.jsx | 109 +++++++++++++++++++--- src/containers/History/History.jsx | 3 +- 3 files changed, 99 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 6843dba..56ea2a0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ghost-dao-interface", "private": true, - "version": "0.8.27", + "version": "0.8.28", "type": "module", "scripts": { "dev": "vite", diff --git a/src/containers/History/BridgeOutModal.jsx b/src/containers/History/BridgeOutModal.jsx index 31e8601..bb63d5e 100644 --- a/src/containers/History/BridgeOutModal.jsx +++ b/src/containers/History/BridgeOutModal.jsx @@ -3,6 +3,7 @@ import { getAddress } from 'viem'; import { useMemo, useState } from "react"; import { Box, Typography, Link, Skeleton, useTheme } from "@mui/material"; import { useUnstableProvider } from "../../hooks/ghost"; +import { useLocalStorage } from "../../hooks/localstorage"; import { Binary } from "polkadot-api"; import { blake2AsU8a } from '@polkadot/util-crypto'; @@ -22,15 +23,18 @@ import GhostStyledIcon from "../../components/Icon/GhostIcon"; import InfoTooltip from "../../components/Tooltip/InfoTooltip"; import { PrimaryButton } from "../../components/Button"; -import { useIsTransactionExecuted } from "../../hooks/staking"; import { DecimalBigNumber } from "../../helpers/DecimalBigNumber"; +import { useIsTransactionExecuted, useGatekeeperAddress, verifySignature } from "../../hooks/staking"; import { countBitmapOnes, shorten, formatNumber, formatCurrency } from "../../helpers"; -const BridgeOutModal = ({ chainId, isOpen, close, config, historyRecord }) => { +const BridgeOutModal = ({ chainId, isOpen, close, config, address, historyRecord }) => { const navigate = useNavigate(); const { network } = useParams(); + const [isPending, setIsPending] = useState(false); const [copiedIndex, setCopiedIndex] = useState(null); + + const { tryStoreInHistory, CONSTANTS } = useLocalStorage(); const { casperApi, client, account } = useUnstableProvider(); const copyToClipboard = (text, index) => { @@ -42,9 +46,12 @@ const BridgeOutModal = ({ chainId, isOpen, close, config, historyRecord }) => { const { isTransactionExecuted, - isTransactionExecutedLoading + isTransactionExecutedLoading, + refetchTransactionExecuted } = useIsTransactionExecuted(chainId, historyRecord.txHash.exodusSession); + const { gatekeeperAddress } = useGatekeeperAddress(chainId); + const localString = new Date(historyRecord.submitted).toLocaleString(); const { data: chainProperties } = useSWR( @@ -125,19 +132,71 @@ const BridgeOutModal = ({ chainId, isOpen, close, config, historyRecord }) => { session: BigInt(historyRecord.txHash.exodusSession), network_id: BigInt(chainId) } - ) + ), + { + refreshInterval: 12000, + revalidateOnFocus: true, + } ); - const { data: roastSessionStates, error } = useSWR( + const { data: roastSessionStates } = useSWR( casperApi && historyRecord && chainId ? ["roastSessionStates"] : null, () => casperApi.query.GhostExodus.RoastSessionStates.getEntries( { session: BigInt(historyRecord.txHash.exodusSession), network_id: BigInt(chainId) } - ) + ), + { + refreshInterval: 12000, + revalidateOnFocus: true, + } ); + const { data: previousDkgExodusSession, isLoading: previousDkgExodusSessionLoading } = useSWR( + casperApi && historyRecord + ? ["previousDkgExodusSession", casperApi, historyRecord.txHash.dkgIndex] + : null, + async ([_, api, startIndex]) => { + if (startIndex < 0) return null; + + let previousDkgIndex = startIndex; + for (let idx = startIndex; idx >= 0; idx--) { + const entry = await casperApi.query.GhostExodus.ExodusSignedRotations.getValue( + idx, + { type: 'Evm', value: undefined } + ); + + if (entry) { + const [exodusContext, signedMessage] = entry; + if (chainId != null && exodusContext.network_id !== BigInt(chainId)) continue; + if (exodusContext.session > BigInt(historyRecord.txHash.exodusSession)) { + previousDkgIndex = idx; + } else { + return exodusContext.session; + } + } + } + + return null + } + ); + + const { data: evmMessageMetadata, isLoading: evmMessageMetadataLoading, error } = useSWR( + client && historyRecord?.txHash ? ['evmMessage', client, historyRecord.txHash] : null, + async ([_, client, record]) => + client.getUnsafeApi().apis.ExodusApi.get_evm_bridge_metadata( + BigInt(record.dkgIndex), + BigInt(chainId), + BigInt(record.exodusSession), + ) + ); + + const { + isTransactionExecuted: previousDkgExecuted, + isTransactionExecutedLoading: previousDkgExecutedLoading + } = useIsTransactionExecuted(chainId, previousDkgExodusSession); + const roastProgress = useMemo(() => { if (!roastSessionStates || roastSessionStates.length === 0) { return { @@ -226,6 +285,28 @@ const BridgeOutModal = ({ chainId, isOpen, close, config, historyRecord }) => { } }, [decodedArgs, historyRecord, chainProperties]); + const verifyBridgeOut = async () => { + setIsPending(true); + + try { + const txHash = await verifySignature({ + chainId, + account: address, + gatekeeper: gatekeeperAddress, + calldata: toHex(evmMessageMetadata.at(0)), + nonce: toHex(evmMessageMetadata.at(1)), + signature: toHex(evmMessageMetadata.at(2)), + }); + + if (txHash) { + tryStoreInHistory(chainId, address, CONSTANTS.bond.key, txHash, CONSTANTS.bond.exodus); + await refetchTransactionExecuted(); + } + } finally { + setIsPending(false); + } + } + return ( { } } - onClose={close} + onClose={() => !isPending ? close() : {}} > @@ -359,13 +440,15 @@ const BridgeOutModal = ({ chainId, isOpen, close, config, historyRecord }) => { { - close(); - navigate(`/${network}/exodus`) - }} + disabled={isPending || !decodedArgs || !previousDkgExecuted || isTransactionExecuted || !signedBridge} + onClick={() => !previousDkgExecuted ? navigate(`/${network}/exodus`) : verifyBridgeOut() } > - {isTransactionExecuted ? "Bridge-Out Finished" : "Verify Bridge-Out"} + {isPending + ? "Pending..." + : isTransactionExecuted + ? "Bridge-Out Finished" + : previousDkgExecuted ? "Verify Bridge-Out" : "DKG Rotations Needed" + } diff --git a/src/containers/History/History.jsx b/src/containers/History/History.jsx index f821dee..a18ff77 100644 --- a/src/containers/History/History.jsx +++ b/src/containers/History/History.jsx @@ -122,7 +122,7 @@ const HistoryItem = ({ - + {item?.name ?? "Unknown"}{item?.isCustom ? " (Custom)" : ""} {chipStatus} @@ -298,6 +298,7 @@ const HistoryList = ({ chainId, address, storedTransactions, historyType, config config={config} close={() => setViewModalOpen(null)} isOpen={true} + address={address} historyRecord={storedTransactions.at(viewModalOpen)} /> )}