diff --git a/.papi/polkadot-api.json b/.papi/polkadot-api.json index 8820e5a..b4ab7d7 100644 --- a/.papi/polkadot-api.json +++ b/.papi/polkadot-api.json @@ -3,7 +3,7 @@ "descriptorPath": ".papi\\descriptors", "entries": { "casper": { - "metadata": "metadatas/casper_runtime.scale" + "metadata": "casper_runtime.scale" } } } diff --git a/package.json b/package.json index b097b2f..4be941b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ghost-dao-interface", "private": true, - "version": "0.8.14", + "version": "0.8.15", "type": "module", "scripts": { "dev": "vite", diff --git a/src/containers/Exodus/Exodus.jsx b/src/containers/Exodus/Exodus.jsx index 3cffdd3..a2bc7e7 100644 --- a/src/containers/Exodus/Exodus.jsx +++ b/src/containers/Exodus/Exodus.jsx @@ -6,7 +6,6 @@ import { keccak256, hexToBytes, getAddress, toHex } from 'viem'; import { Box, Divider, - Link, CircularProgress, Container, Typography, @@ -22,23 +21,16 @@ import { } from "@mui/material"; import SearchIcon from '@mui/icons-material/Search'; -import CloseIcon from '@mui/icons-material/Close'; -import Chip from "../../components/Chip/Chip"; -import Modal from "../../components/Modal/Modal"; import Paper from "../../components/Paper/Paper"; import Metric from "../../components/Metric/Metric"; import { Tab, Tabs } from "../../components/Tabs/Tabs"; -import DataRow from "../../components/DataRow/DataRow"; import PageTitle from "../../components/PageTitle/PageTitle"; import GhostStyledIcon from "../../components/Icon/GhostIcon"; -import TokenStack from "../../components/TokenStack/TokenStack"; import MetricCollection from "../../components/Metric/MetricCollection"; -import { PrimaryButton, TertiaryButton } from "../../components/Button"; -import LinearProgressBar from "../../components/Progress/LinearProgressBar"; import { useTotalReserves, useCapturedPriceSnapshots } from "../../hooks/treasury"; -import { useCurrentGasPrice, useIsTransactionExecuted } from "../../hooks/staking"; +import { useCurrentGasPrice } from "../../hooks/staking"; import { useFtsoPrice, useReservePrice } from "../../hooks/prices"; import { useTokenSymbol } from "../../hooks/tokens"; import { useUniswapV2Pair } from "../../hooks/uniswapv2"; @@ -49,412 +41,17 @@ import { formatCurrency, formatNumber, shorten } from "../../helpers"; import { DecimalBigNumber } from "../../helpers/DecimalBigNumber"; import { UNISWAP_V2_FACTORY } from "../../constants/addresses"; -const SELECTABLE_OPTIONS = ["All Exoduses", "Rotations", "Governance", "Bridge-Out"]; +import { ExodusVerifyModal } from "./ExodusModal"; +import ExodusStatusCard from "./ExodusStatusCard"; +import ExodusList from "./ExodusList"; +const SELECTABLE_OPTIONS = ["All Exoduses", "Rotations", "Governance", "Bridge-Out"]; const KEY_ROTATION = "Key Rotation"; const GAS_USED = { [KEY_ROTATION]: 300000n, } -const ExodusStatusCard = ({ progressPercent, executionDiscount, currentGasPrice, maxGasPrice }) => { - const theme = useTheme(); - - return ( - - - - Execution Discount: - 0 - ? theme.colors.feedback.success - : theme.colors.feedback.error - }}> - {formatNumber(executionDiscount, 2)}% - - - - - Gas Price: - {`${formatNumber(currentGasPrice, 5)} / ${formatNumber(maxGasPrice, 5)} gwei`} - - - - - - - ); -}; - -const ExodusItem = ({ - item, - chainId, - gasPrice, - ftsoSymbol, - nativeMetadata, - setVerifiedItem, - isSmallScreen, - currentTwapPrice -}) => { - const theme = useTheme(); - const isVerySmallScreen = useMediaQuery("(max-width: 450px)"); - - const { - isTransactionExecuted, - isTransactionExecutedLoading - } = useIsTransactionExecuted(chainId, item.data.at(0)?.session); - - const chipStatus = useMemo(() => { - const width = isVerySmallScreen ? "21px" : "100px"; - - if (isTransactionExecuted && !isTransactionExecutedLoading) { - return - } - - return - }, [isTransactionExecutedLoading, isTransactionExecuted]); - - if (isSmallScreen || isVerySmallScreen) { - return ( - <> - - - - - - {item.type} - - {"Something here"} - - - - - - {chipStatus} - - - - - - {nativeMetadata.symbol} Cost - { - formatCurrency( - currentTwapPrice(gasPrice * GAS_USED[item.type]).toString(), - 5, - ftsoSymbol - ) - } - - - - Reward - - {formatCurrency( - new DecimalBigNumber(gasPrice * GAS_USED[item.type], 18), - 5, - nativeMetadata.symbol - )} - - - - - - Verify - - - - ) - } - - return ( - - - - - - {item.type} - - {"Something here"} - - - - - - - {chipStatus} - - - - {formatCurrency( - new DecimalBigNumber(gasPrice * GAS_USED[item.type], 18), - 5, - nativeMetadata.symbol - )} - - - - { - formatCurrency( - currentTwapPrice(gasPrice * GAS_USED[item.type]).toString(), - 5, - ftsoSymbol - ) - } - - - - - setVerifiedItem({ dkgIndex: item.dkgIndex, type: item.type })} - > - Verify - - - - - ) -} - -const ExodusList = ({ - chainId, - nativeMetadata, - setVerifiedItem, - ftsoSymbol, - gasPrice, - currentTwapPrice, - signedExodusRotations, - signedExodusRotationsLoading, -}) => { - const isSmallScreen = useMediaQuery("(max-width: 900px)"); - - const chainedExoduses = useMemo(() => { - let chain = []; - - if (Array.isArray(signedExodusRotations)) chain = [...chain, ...signedExodusRotations]; - - return chain; - }, [signedExodusRotations]); - - if (signedExodusRotationsLoading) { - return ( - - - Loading Signed Rotations... - - ) - } - - if (isSmallScreen) { - return ( - - {chainedExoduses.map((item, i) => { - return ( - - ) - })} - - ) - } else { - return ( - - - - - Exodus - Status - {nativeMetadata.symbol} Cost - Reward - - - - - {chainedExoduses.map((item, i) => { - return ( - - ) - })} - -
-
- ) - } -} - -const ExodusVerify = ({ - chainId, - isOpen, - onClose, - nativeMetadata, - address, - casperApi, - item, - ftsoSymbol, - gasPrice, - currentTwapPrice, -}) => { - const [isPending, setIsPending] = useState(false); - - const { data: signedExodusRotation } = useSWR( - casperApi && item ? ['signedExodusRotations', casperApi, item] : null, - async ([_, api, it]) => api.query.GhostExodus.ExodusSignedRotations.getValue(it.dkgIndex, { type: "Evm" }), - ); - - const upcomingGroupKey = useMemo(() => { - if (!signedExodusRotation) return null; - - const publicKey = signedExodusRotation?.at(1)["r#type"].value.public_key; - if (!publicKey) return null; - - const cleanHex = publicKey.startsWith('0x04') && publicKey.length === 130 - ? `0x${publicKey.slice(4)}` - : publicKey.startsWith('0x') - ? publicKey - : `0x${publicKey}`; - - const hash = keccak256(cleanHex); - - return getAddress(`0x${hash.slice(-40)}`); - }, [signedExodusRotation]); - - const signedMessageMetadata = useMemo(() => { - if (!signedExodusRotation) return null; - - const nonce = signedExodusRotation?.at(1).nonce; - const signature = signedExodusRotation?.at(1).signature; - - return { - nonce: nonce ? toHex(nonce) : null, - signature: signature ? toHex(signature) : null, - message: "0xdeadbeef", - }; - }, [signedExodusRotation]) - - return ( - Verify {item?.type}} - onClose={!isPending && onClose} - topRight={ - - } - > - - - New Group Key} - tooltip="Some cool description here." - balance={ - { - upcomingGroupKey ? shorten(upcomingGroupKey, 12, -8) : "" - } - } - /> - - Verification Reward} - tooltip="Some cool description here." - balance={{ - formatCurrency( - currentTwapPrice( - (gasPrice ? gasPrice : 0n) * - (GAS_USED[item?.type] ? GAS_USED[item?.type] : 0n) - ).toString(), - 5, - ftsoSymbol - ) - }} - /> - - - - Nonce} - tooltip="Some cool description here." - balance={ - {signedMessageMetadata?.nonce ? shorten(signedMessageMetadata.nonce, 12, -10) : ""} - } - /> - - Signture} - tooltip="Some cool description here." - balance={ - {signedMessageMetadata?.signature ? shorten(signedMessageMetadata.signature, 12, -10) : ""} - } - /> - - Signed Message} - tooltip="Some cool description here." - balance={ - {signedMessageMetadata?.message ? signedMessageMetadata.message : ""} - } - /> - - - { - alert("not ready for now"); - onClose(); - }} - > - Verify - - - - ) -} - const Exodus = ({ chainId, address, config }) => { const theme = useTheme(); @@ -527,7 +124,7 @@ const Exodus = ({ chainId, address, config }) => { const promises = Array.from({ length }, (_, index) => start + index).map(index => api.query.GhostExodus.ExodusSignedRotations.getValue(index, { type: "Evm" }) - .then(data => ({ dkgIndex: index, type: KEY_ROTATION, data })) + .then(data => ({ dkgIndex: index, type: KEY_ROTATION, gasUsed: GAS_USED[KEY_ROTATION], data })) ); return Promise.all(promises); @@ -546,7 +143,7 @@ const Exodus = ({ chainId, address, config }) => { paddingRight: isSmallScreen || isVerySmallScreen ? "0" : "3.3rem", }} > - { gasPrice={gasPrice} currentTwapPrice={currentTwapPrice} onClose={() => setVerifiedItem(null)} + gasUsed={GAS_USED[verifiedItem?.type]} /> diff --git a/src/containers/Exodus/ExodusList.jsx b/src/containers/Exodus/ExodusList.jsx new file mode 100644 index 0000000..7019d70 --- /dev/null +++ b/src/containers/Exodus/ExodusList.jsx @@ -0,0 +1,270 @@ +import { useMemo } from "react"; +import { + Box, + Link, + CircularProgress, + Container, + Typography, + TableContainer, + TableCell, + Table, + TableHead, + TableRow, + TableBody, + useMediaQuery, + useTheme, +} from "@mui/material"; + +import Chip from "../../components/Chip/Chip"; +import { TertiaryButton } from "../../components/Button"; +import TokenStack from "../../components/TokenStack/TokenStack"; + +import { useIsTransactionExecuted } from "../../hooks/staking"; + +import { formatCurrency } from "../../helpers"; +import { DecimalBigNumber } from "../../helpers/DecimalBigNumber"; + +const ExodusItem = ({ + item, + chainId, + gasPrice, + ftsoSymbol, + nativeMetadata, + setVerifiedItem, + isSmallScreen, + currentTwapPrice +}) => { + const theme = useTheme(); + const isVerySmallScreen = useMediaQuery("(max-width: 450px)"); + + const { + isTransactionExecuted, + isTransactionExecutedLoading + } = useIsTransactionExecuted(chainId, item.data.at(0)?.session); + + const chipStatus = useMemo(() => { + const width = isVerySmallScreen ? "21px" : "100px"; + + if (isTransactionExecuted && !isTransactionExecutedLoading) { + return + } + + return + }, [isTransactionExecutedLoading, isTransactionExecuted]); + + if (isSmallScreen || isVerySmallScreen) { + return ( + <> + + + + + + {item.type} + + {"Something here"} + + + + + + {chipStatus} + + + + + + {nativeMetadata.symbol} Cost + { + formatCurrency( + currentTwapPrice(gasPrice * item.gasUsed).toString(), + 5, + ftsoSymbol + ) + } + + + + Reward + + {formatCurrency( + new DecimalBigNumber(gasPrice * item.gasUsed, 18), + 5, + nativeMetadata.symbol + )} + + + + + + setVerifiedItem({ + exodusSession: item.data.at(0).session, + dkgIndex: item.dkgIndex, + type: item.type + })} + > + Verify + + + + + ) + } + + return ( + + + + + + {item.type} + + {"Something here"} + + + + + + + {chipStatus} + + + + {formatCurrency( + new DecimalBigNumber(gasPrice * item.gasUsed, 18), + 5, + nativeMetadata.symbol + )} + + + + { + formatCurrency( + currentTwapPrice(gasPrice * item.gasUsed).toString(), + 5, + ftsoSymbol + ) + } + + + + + setVerifiedItem({ + exodusSession: item.data.at(0).session, + dkgIndex: item.dkgIndex, + type: item.type + })} + > + Verify + + + + + ) +} + +const ExodusList = ({ + chainId, + nativeMetadata, + setVerifiedItem, + ftsoSymbol, + gasPrice, + currentTwapPrice, + signedExodusRotations, + signedExodusRotationsLoading, +}) => { + const isSmallScreen = useMediaQuery("(max-width: 900px)"); + + const chainedExoduses = useMemo(() => { + let chain = []; + + if (Array.isArray(signedExodusRotations)) chain = [...chain, ...signedExodusRotations]; + + return chain; + }, [signedExodusRotations]); + + if (signedExodusRotationsLoading) { + return ( + + + Loading Signed Rotations... + + ) + } + + if (isSmallScreen) { + return ( + + {chainedExoduses.map((item, i) => { + return ( + + ) + })} + + ) + } else { + return ( + + + + + Exodus + Status + {nativeMetadata.symbol} Cost + Reward + + + + + {chainedExoduses.map((item, i) => { + return ( + + ) + })} + +
+
+ ) + } +} + +export default ExodusList; diff --git a/src/containers/Exodus/ExodusModal.jsx b/src/containers/Exodus/ExodusModal.jsx new file mode 100644 index 0000000..acb5626 --- /dev/null +++ b/src/containers/Exodus/ExodusModal.jsx @@ -0,0 +1,196 @@ +import useSWR from "swr"; +import { useState, useMemo } from "react"; +import { Box, Divider, Link, Skeleton, Typography } from "@mui/material"; +import { keccak256, hexToBytes, getAddress, toHex } from 'viem'; + +import CloseIcon from '@mui/icons-material/Close'; +import CheckIcon from '@mui/icons-material/Check'; +import ContentPasteIcon from '@mui/icons-material/ContentPaste'; + +import Modal from "../../components/Modal/Modal"; +import DataRow from "../../components/DataRow/DataRow"; +import GhostStyledIcon from "../../components/Icon/GhostIcon"; +import { PrimaryButton } from "../../components/Button"; + +import { formatCurrency, shorten } from "../../helpers"; +import { useUnstableProvider } from "../../hooks/ghost"; + +export const ExodusVerifyModal = ({ + chainId, + isOpen, + onClose, + nativeMetadata, + address, + casperApi, + item, + ftsoSymbol, + gasPrice, + gasUsed, + currentTwapPrice, +}) => { + const [isPending, setIsPending] = useState(false); + const [copiedIndex, setCopiedIndex] = useState(null); + + const { client } = useUnstableProvider(); + + const copyToClipboard = (text, index) => { + navigator.clipboard.writeText(text).then(() => { + setCopiedIndex(index); + setTimeout(() => setCopiedIndex(null) , 800); + }); + }; + + const { data: signedExodusRotation } = useSWR( + casperApi && item ? ['signedExodusRotations', casperApi, item] : null, + async ([_, api, it]) => api.query.GhostExodus.ExodusSignedRotations.getValue(it.dkgIndex, { type: "Evm" }), + ); + + const { data: evmMessageMetadata, isLoading: evmMessageMetadataLoading } = useSWR( + client && item ? ['evmMessage', client, item] : null, + async ([_, client, it]) => + client.getUnsafeApi().apis.ExodusApi.get_evm_rotation_metadata( + BigInt(it.dkgIndex), + { type: "Evm" } + ) + ); + + const upcomingGroupKey = useMemo(() => { + if (!signedExodusRotation) return null; + + const publicKey = signedExodusRotation?.at(1)["r#type"].value.public_key; + if (!publicKey) return null; + + const cleanHex = publicKey.startsWith('0x04') && publicKey.length === 130 + ? `0x${publicKey.slice(4)}` + : publicKey.startsWith('0x') + ? publicKey + : `0x${publicKey}`; + + const hash = keccak256(cleanHex); + + return getAddress(`0x${hash.slice(-40)}`); + }, [signedExodusRotation]); + + return ( + Verify {item ? item.type : ""}} + onClose={!isPending && onClose} + topRight={ + + } + > + + + New Group Key} + tooltip="Some cool description here." + balance={ + { + upcomingGroupKey ? shorten(upcomingGroupKey, 12, -8) : "" + } + } + /> + + Verification Reward} + tooltip="Some cool description here." + balance={{ + formatCurrency( + currentTwapPrice((gasPrice ? gasPrice : 0n) * (gasUsed ? gasUsed : 0n)).toString(), + 5, + ftsoSymbol + ) + }} + /> + + + + Raw Message} + tooltip="Some cool description here." + balance={evmMessageMetadata?.at(0) + ? copyToClipboard(toHex(evmMessageMetadata.at(0)), 0)} + > + + {shorten(toHex(evmMessageMetadata.at(0)), 12, -10)} + + + + : + } + /> + + Nonce} + tooltip="Some cool description here." + balance={evmMessageMetadata?.at(1) + ? copyToClipboard(toHex(evmMessageMetadata.at(1)), 1)} + > + + {shorten(toHex(evmMessageMetadata.at(1)), 12, -10)} + + + + : + } + /> + + Signture} + tooltip="Some cool description here." + balance={evmMessageMetadata?.at(2) + ? copyToClipboard(toHex(evmMessageMetadata.at(2)), 2)} + > + + {shorten(toHex(evmMessageMetadata.at(2)), 12, -10)} + + + + : + } + /> + + + { + alert("not ready for now"); + onClose(); + }} + > + Verify + + + + ) +} diff --git a/src/containers/Exodus/ExodusStatusCard.jsx b/src/containers/Exodus/ExodusStatusCard.jsx new file mode 100644 index 0000000..acf345a --- /dev/null +++ b/src/containers/Exodus/ExodusStatusCard.jsx @@ -0,0 +1,39 @@ +import { Box, Typography, useTheme } from "@mui/material"; +import { formatNumber } from "../../helpers"; +import LinearProgressBar from "../../components/Progress/LinearProgressBar"; + +const ExodusStatusCard = ({ progressPercent, executionDiscount, currentGasPrice, maxGasPrice }) => { + const theme = useTheme(); + + return ( + + + + Execution Discount: + 0 + ? theme.colors.feedback.success + : theme.colors.feedback.error + }}> + {formatNumber(executionDiscount, 2)}% + + + + + Gas Price: + {`${formatNumber(currentGasPrice, 5)} / ${formatNumber(maxGasPrice, 5)} gwei`} + + + + + + + ); +}; + +export default ExodusStatusCard;