make possible to verify exodus bridge-out from history modal
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
parent
a78b583be3
commit
852d3c86ce
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ghost-dao-interface",
|
||||
"private": true,
|
||||
"version": "0.8.27",
|
||||
"version": "0.8.28",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@ -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 (
|
||||
<Modal
|
||||
maxWidth="420px"
|
||||
@ -252,7 +333,7 @@ const BridgeOutModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
||||
}
|
||||
</Box>
|
||||
}
|
||||
onClose={close}
|
||||
onClose={() => !isPending ? close() : {}}
|
||||
>
|
||||
<Box display="flex" flexDirection="column">
|
||||
<Box width="100%" gap="5px" display="flex" flexDirection="column" justifyContent="space-between" alignItems="center">
|
||||
@ -359,13 +440,15 @@ const BridgeOutModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
||||
|
||||
<PrimaryButton
|
||||
fullWidth
|
||||
disabled={isTransactionExecuted || !signedBridge}
|
||||
onClick={() => {
|
||||
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"
|
||||
}
|
||||
</PrimaryButton>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
@ -122,7 +122,7 @@ const HistoryItem = ({
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" flexDirection="column" alignItems="flex-end">
|
||||
<Box display="flex" flexDirection="column" alignItems="center">
|
||||
<Typography>{item?.name ?? "Unknown"}{item?.isCustom ? " (Custom)" : ""}</Typography>
|
||||
{chipStatus}
|
||||
</Box>
|
||||
@ -298,6 +298,7 @@ const HistoryList = ({ chainId, address, storedTransactions, historyType, config
|
||||
config={config}
|
||||
close={() => setViewModalOpen(null)}
|
||||
isOpen={true}
|
||||
address={address}
|
||||
historyRecord={storedTransactions.at(viewModalOpen)}
|
||||
/>
|
||||
)}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user