From b675da56d2ab9b407af1552dd6f43b7460ba176a Mon Sep 17 00:00:00 2001 From: Uncle Fatso Date: Fri, 20 Nov 2026 16:03:13 +0300 Subject: [PATCH] final touches on the exodus page Signed-off-by: Uncle Fatso --- package.json | 2 +- .../Bond/components/BondVesting.jsx | 2 +- src/containers/Bond/components/ClaimBonds.jsx | 10 +- src/containers/Breakout/BreakoutModal.jsx | 47 ++- src/containers/Exodus/Exodus.jsx | 33 +- src/containers/Exodus/ExodusList.jsx | 9 +- src/containers/Exodus/ExodusModal.jsx | 78 +++- src/containers/History/BondModal.jsx | 381 +----------------- .../History/BondModals/BondModalBond.jsx | 231 +++++++++++ .../History/BondModals/BondModalClaim.jsx | 174 ++++++++ .../History/BondModals/BondModalExodus.jsx | 224 ++++++++++ src/containers/History/History.jsx | 4 +- src/hooks/bonds/index.js | 21 +- src/hooks/ghost/UnstableProvider.jsx | 22 +- src/hooks/helpers.js | 1 - src/hooks/localstorage/index.jsx | 2 + src/hooks/staking/index.js | 8 +- src/hooks/tokens/index.js | 4 +- 18 files changed, 809 insertions(+), 444 deletions(-) create mode 100644 src/containers/History/BondModals/BondModalBond.jsx create mode 100644 src/containers/History/BondModals/BondModalClaim.jsx create mode 100644 src/containers/History/BondModals/BondModalExodus.jsx diff --git a/package.json b/package.json index 1cae125..361769f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ghost-dao-interface", "private": true, - "version": "0.8.24", + "version": "0.8.25", "type": "module", "scripts": { "dev": "vite", diff --git a/src/containers/Bond/components/BondVesting.jsx b/src/containers/Bond/components/BondVesting.jsx index 9d74149..62c7410 100644 --- a/src/containers/Bond/components/BondVesting.jsx +++ b/src/containers/Bond/components/BondVesting.jsx @@ -1,7 +1,7 @@ import { prettifySecondsInDays } from "../../../helpers/timeUtil"; const BondVesting = ({ vesting }) => { - return <>{vesting > 0 ? prettifySecondsInDays(vesting) : "Instant"}; + return <>{vesting > 0 ? prettifySecondsInDays(vesting) : "Infinity"}; }; export default BondVesting; diff --git a/src/containers/Bond/components/ClaimBonds.jsx b/src/containers/Bond/components/ClaimBonds.jsx index 5f862bb..5a11f23 100644 --- a/src/containers/Bond/components/ClaimBonds.jsx +++ b/src/containers/Bond/components/ClaimBonds.jsx @@ -149,7 +149,10 @@ export const ClaimBonds = ({ chainId, address, secondsTo }) => { {notes.map((note, index) => ( - + {note.quoteToken.name} @@ -211,7 +214,10 @@ export const ClaimBonds = ({ chainId, address, secondsTo }) => { - + {note.quoteToken.name} diff --git a/src/containers/Breakout/BreakoutModal.jsx b/src/containers/Breakout/BreakoutModal.jsx index e62bff4..4f81254 100644 --- a/src/containers/Breakout/BreakoutModal.jsx +++ b/src/containers/Breakout/BreakoutModal.jsx @@ -34,9 +34,16 @@ const BreakoutModal = ({ chainId, address }) => { const [step, setStep] = useState(0); const [isPending, setIsPending] = useState(false); - const [receiver, setReceiver] = useState(account); + const [receiver, setReceiver] = useState(account ?.address); const [convertedReceiver, setConvertedReceiver] = useState(undefined); + const [prevAddress, setPrevAddress] = useState(account?.address); + + if (account?.address !== prevAddress) { + setPrevAddress(account?.address); + if (account?.address && !receiver) setReceiver(account.address); + } + const { symbol: ghstSymbol } = useTokenSymbol(chainId, "GHST"); const { symbol: ftsoSymbol } = useTokenSymbol(chainId, "FTSO"); @@ -80,7 +87,8 @@ const BreakoutModal = ({ chainId, address }) => { const closeModalPure = () => { if (!isPending) { setStep(0); - setReceiver(""); + setReceiver(account?.address ?? ""); + setPrevAddress(undefined); closeModalInner(); } } @@ -318,21 +326,26 @@ const BridgeView = ({ > GHOST Connect - {" "}for your privacy, or{" "} - setReceiver(account)} - sx={{ - color: theme.colors.primary[300], - verticalAlign: "baseline", - }} - > - click here - {" "} - to use connected one. + {" "}for your privacy + {account ? ( + <> + , or{" "} + setReceiver(account ? account.address : "")} + sx={{ + color: theme.colors.primary[300], + verticalAlign: "baseline", + }} + > + click here + {" "} + to use connected one. + + ) : (".")} { : activeDkgAuthorities.dkg_index; }, [dkgHistory, activeDkgAuthorities]); - const currentDkgSession = useMemo(() => { - if (!activeDkgAuthorities) return null; - return dkgHistory.length > 0 - ? dkgHistory[dkgHistory.length - 1].session - : undefined; - }, [dkgHistory, activeDkgAuthorities]); - - const { data: signedExodusRotations, isLoading: signedExodusRotationsLoading, error } = useSWR( + const { data: signedExodusRotations, isLoading: signedExodusRotationsLoading, } = useSWR( casperApi && currentDkgIndex ? ['signedExodusRotations', casperApi, currentDkgIndex] : null, async ([_, api, index]) => { const startIndex = Number(index) - 1; @@ -172,9 +164,17 @@ const Exodus = ({ chainId, address, config }) => { { revalidateOnFocus: true } ); + const currentDkgSession = useMemo(() => { + if (!activeDkgAuthorities) return null; + return dkgHistory.length > 0 + ? dkgHistory[dkgHistory.length - 1].session + : signedExodusRotations?.exodusContext.session; + }, [dkgHistory, activeDkgAuthorities]); + const { isTransactionExecuted: currentDkgVerified, - isTransactionExecutedLoading: currentDkgVerifiedLoading + isTransactionExecutedLoading: currentDkgVerifiedLoading, + refetchTransactionExecuted: currentDkgVerifiedMutate, } = useIsTransactionExecuted( Number(signedExodusRotations ? signedExodusRotations.exodusContext.network_id @@ -191,10 +191,6 @@ const Exodus = ({ chainId, address, config }) => { signedExodusRotations?.exodusContext.session ); - // console.log("status", signedExodusRotations?.dkgIndex, currentDkgIndex) - // console.log(" ", previousDkgVerified, currentDkgVerified) - // console.log(" ", signedExodusRotations?.exodusContext.session, currentDkgSession) - const { data: signedBridges, isLoading: signedBridgesLoading } = useSWR( casperApi && currentDkgIndex ? ['signedBridges', currentDkgIndex] : null, async ([_, idx]) => { @@ -327,18 +323,19 @@ const Exodus = ({ chainId, address, config }) => { fullWidth disabled={ currentDkgVerified || + !currentDkgIndex || + !currentDkgSession || !previousDkgVerified || !signedExodusRotations || signedExodusRotationsLoading || currentDkgVerifiedLoading } onClick={() => { - if (!currentDkgIndex || !currentDkgSession) return; - setVerifiedItem({ type: KEY_ROTATION, gasUsed: GAS_USED[KEY_ROTATION], dkgIndex: currentDkgIndex, + mutate: currentDkgVerifiedMutate, exodusContext: { session: currentDkgSession, network_id: signedExodusRotations diff --git a/src/containers/Exodus/ExodusList.jsx b/src/containers/Exodus/ExodusList.jsx index 90c1cad..df2cb44 100644 --- a/src/containers/Exodus/ExodusList.jsx +++ b/src/containers/Exodus/ExodusList.jsx @@ -40,7 +40,8 @@ const ExodusItem = ({ const { isTransactionExecuted, - isTransactionExecutedLoading + isTransactionExecutedLoading, + refetchTransactionExecuted } = useIsTransactionExecuted(item.exodusContext.network_id, item.exodusContext.session); const chipStatus = useMemo(() => { @@ -113,7 +114,8 @@ const ExodusItem = ({ onClick={() => setVerifiedItem({ exodusContext: item.exodusContext, dkgIndex: item.dkgIndex, - type: item.type + type: item.type, + mutate: refetchTransactionExecuted, })} > Verify @@ -172,7 +174,8 @@ const ExodusItem = ({ onClick={() => setVerifiedItem({ exodusContext: item.exodusContext, dkgIndex: item.dkgIndex, - type: item.type + type: item.type, + mutate: refetchTransactionExecuted, })} > Verify diff --git a/src/containers/Exodus/ExodusModal.jsx b/src/containers/Exodus/ExodusModal.jsx index 978e931..3dbd713 100644 --- a/src/containers/Exodus/ExodusModal.jsx +++ b/src/containers/Exodus/ExodusModal.jsx @@ -1,7 +1,7 @@ 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 { keccak256, hexToBytes, getAddress, toHex, hexToBigInt } from 'viem'; import CloseIcon from '@mui/icons-material/Close'; import CheckIcon from '@mui/icons-material/Check'; @@ -12,11 +12,15 @@ import DataRow from "../../components/DataRow/DataRow"; import GhostStyledIcon from "../../components/Icon/GhostIcon"; import { PrimaryButton } from "../../components/Button"; +import { DecimalBigNumber } from "../../helpers/DecimalBigNumber"; import { formatCurrency, shorten } from "../../helpers"; import { verifySignature, useGatekeeperAddress } from "../../hooks/staking"; import { useUnstableProvider } from "../../hooks/ghost"; +import { useTokenSymbol } from "../../hooks/tokens"; import { useLocalStorage } from "../../hooks/localstorage"; +import { BRIDGE_OUT, KEY_ROTATION } from "./Exodus"; + export const ExodusVerifyModal = ({ chainId, isOpen, @@ -43,18 +47,32 @@ export const ExodusVerifyModal = ({ }); }; + const { symbol: ghstSymbol } = useTokenSymbol(Number(item?.exodusContext.network_id), "GHST"); + const { gatekeeperAddress, gatekeeperIsEmpty } = useGatekeeperAddress(Number(item?.exodusContext.network_id)); - const { data: evmMessageMetadata, isLoading: evmMessageMetadataLoading } = useSWR( + const { data: evmMessageMetadata, isLoading: evmMessageMetadataLoading, error } = useSWR( client && item ? ['evmMessage', client, item] : null, - async ([_, client, it]) => - client.getUnsafeApi().apis.ExodusApi.get_evm_rotation_metadata( - BigInt(it.dkgIndex), - { type: "Evm" } - ) + async ([_, client, it]) => { + switch (it.type) { + case BRIDGE_OUT: + return client.getUnsafeApi().apis.ExodusApi.get_evm_bridge_metadata( + BigInt(it.dkgIndex), + BigInt(it.exodusContext.network_id), + BigInt(it.exodusContext.session), + ) + case KEY_ROTATION: + return client.getUnsafeApi().apis.ExodusApi.get_evm_rotation_metadata( + BigInt(it.dkgIndex), + { type: "Evm" } + ) + default: + return undefined; + } + } ); const upcomingGroupKey = useMemo(() => { @@ -74,6 +92,16 @@ export const ExodusVerifyModal = ({ return getAddress(`0x${hash.slice(-40)}`); }, [evmMessageMetadata]); + const bridgeAmount = useMemo(() => { + if (!evmMessageMetadata) return null; + + const callHex = toHex(evmMessageMetadata.at(0)); + const rawAmountHex = `0x${callHex.slice(74, 138)}`; + + const amountWei = hexToBigInt(rawAmountHex); + return new DecimalBigNumber(amountWei, 18); + }, [evmMessageMetadata]); + const verifySignatureModal = async () => { setIsPending(true); @@ -92,9 +120,11 @@ export const ExodusVerifyModal = ({ address, CONSTANTS.bond.key, txHash, - CONSTANTS.bond.bond + CONSTANTS.bond.exodus ); + await item.mutate(); + onClose(); } finally { setIsPending(false); @@ -118,19 +148,29 @@ export const ExodusVerifyModal = ({ > - New Group Key} - tooltip="Some cool description here." - balance={ + {item?.type === KEY_ROTATION + ? New Group Key} + tooltip="Some cool description here." + balance={ + { + upcomingGroupKey ? shorten(upcomingGroupKey, 12, -8) : "" + } + } + /> + : Bridging Amount} + tooltip="Some cool description here." + balance={ { - upcomingGroupKey ? shorten(upcomingGroupKey, 12, -8) : "" + bridgeAmount ? formatCurrency(bridgeAmount, 5, ghstSymbol) : "" } - } - /> + } /> + } Verification Reward} diff --git a/src/containers/History/BondModal.jsx b/src/containers/History/BondModal.jsx index a9a8ff6..68912e1 100644 --- a/src/containers/History/BondModal.jsx +++ b/src/containers/History/BondModal.jsx @@ -1,374 +1,10 @@ -import { useTransactionReceipt, useTransaction, useToken } from 'wagmi'; -import { decodeEventLog, decodeFunctionData } from 'viem'; -import { useMemo, useCallback } from "react"; -import { useParams } from "react-router-dom"; - -import { Box, Typography, Link } from "@mui/material"; -import ArrowRightIcon from '@mui/icons-material/ArrowRight'; - -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 { getTokenDecimals } from "../../hooks/helpers"; import { useLocalStorage } from "../../hooks/localstorage"; -import { formatNumber, formatCurrency, shorten } from "../../helpers"; -import { DecimalBigNumber } from "../../helpers/DecimalBigNumber"; -import { abi as GhostBondDepository } from "../../abi/GhostBondDepository.json"; -import { abi as GhostGatekeeper } from "../../abi/GhostGatekeeper.json"; -import { abi as ERC20Token } from "../../abi/ERC20.json"; -import TokenBox from "./TokenBox"; +import BondModalClaim from "./BondModals/BondModalClaim"; +import BondModalBond from "./BondModals/BondModalBond"; +import BondModalExodus from "./BondModals/BondModalExodus"; -const BondModalClaim = ({ chainId, isOpen, close, config, historyRecord }) => { - if (historyRecord === null) return null; - const { network } = useParams(); - - const chainInfo = useMemo(() => { - const client = config?.getClient(); - - return { - url: client?.chain?.blockExplorers?.default?.url, - symbol: client?.chain?.nativeCurrency?.symbol, - }; - }, [config]); - - 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; - const decoded = decodeFunctionData({ abi: GhostBondDepository, data: txData.input }); - if (!decoded) return null; - - return { - receiver: decoded.args.at(0), - isGhst: decoded.args.at(1), - bondIds: decoded.args.at(2), - } - }, [txData]); - - const allDecodedLogs = useMemo(() => { - if (!receipt?.logs) return []; - - return receipt.logs.map((log) => { - try { - const decoded = decodeEventLog({ - abi: ERC20Token, - data: log.data, - topics: log.topics, - }); - - return { - eventName: decoded.eventName, - args: decoded.args, - address: log.address - }; - } catch (e) { - return null; - } - }).filter(Boolean); - }, [receipt]); - - const claimedAmount = useMemo(() => { - return allDecodedLogs?.reduce((sum, item) => sum + item.args.value, 0n); - }, [allDecodedLogs]); - - return ( - - {functionArgs && "Bond Claim"} - {(!functionArgs) && "Parsing Transaction Hash"} - - } - onClose={() => close()} - > - {functionArgs && - - - - - - - - - Receiver - - {shorten(functionArgs.receiver, 10, -8)} - - - - - Claimed - - {formatCurrency( - new DecimalBigNumber(claimedAmount ?? 0n, getTokenDecimals(functionArgs.isGhst ? "GHST" : "STNK")), - 5, - functionArgs.isGhst ? "GHST" : "STNK" - )} - - - - - Bond Indexes - - {functionArgs.bondIds.map((bond) => formatNumber(bond)).join(", ")} - - - - - - - View Transaction Details - - - } - - ) -} - -const BondModalBond = ({ chainId, isOpen, close, config, historyRecord }) => { - if (historyRecord === null) return null; - const { network } = useParams(); - const { CONSTANTS } = useLocalStorage(); - - const chainInfo = useMemo(() => { - const client = config?.getClient(); - - return { - url: client?.chain?.blockExplorers?.default?.url, - symbol: client?.chain?.nativeCurrency?.symbol, - }; - }, [config]); - - 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: GhostBondDepository, - data: txData.input - }); - - return { - bondId: decoded.args.at(0), - amount: decoded.args.at(1), - maxPrice: decoded.args.at(2), - receiver: decoded.args.at(3), - } - } catch {} - - try { - const decoded = decodeFunctionData({ - abi: GhostGatekeeper, - data: txData.input, - }); - - return { - bondId: 0, - amount: 0n, - maxPrice: 0n, - receiver: "0x0000000000000000000000000000000000000000", - } - } catch { - return null; - } - }, [txData]); - - const allDecodedLogs = useMemo(() => { - if (!receipt?.logs) return []; - - return receipt.logs.map((log) => { - try { - const decoded = decodeEventLog({ - abi: GhostBondDepository, - data: log.data, - topics: log.topics, - }); - - return { - eventName: decoded.eventName, - args: decoded.args, - address: log.address - }; - } catch (e) { - return null; - } - }).filter(Boolean); - }, [receipt]); - - const { bonds } = useBondInfo(chainId, network, functionArgs ? [functionArgs.bondId] : []); - - const bondPurchasePrice = useMemo(() => { - const log = allDecodedLogs.find(l => l.eventName === 'Bond'); - if (!log) return 1n; - - return log.args.price; - }, [allDecodedLogs]); - - const { data: baseToken } = useToken({ - address: bonds?.at(0)?.baseToken.tokenAddress, - scopeKey: `baseToken-${functionArgs ? functionArgs.bondId : null}-${chainId}`, - chainId - }); - - const { data: quoteToken } = useToken({ - address: bonds?.at(0)?.quoteToken.quoteTokenAddress, - scopeKey: `quoteToken-${functionArgs ? functionArgs.bondId : null}-${chainId}`, - chainId - }); - - const estimatedPayout = useMemo(() => { - const spentAmount = functionArgs ? functionArgs.amount : 0n; - const bondPrice = bondPurchasePrice ? bondPurchasePrice : 1n; - const quoteTokenDecimals = quoteToken ? quoteToken.decimals : 18; - - const mulDivResult = spentAmount * (10n ** 18n) / bondPrice; - return mulDivResult / (10n ** BigInt(quoteTokenDecimals)); - }, [bondPurchasePrice, functionArgs?.amount, baseToken, quoteToken]); - - const convertedAmount = useCallback((value) => { - const decimals = baseToken ? baseToken.decimals : 9; - const symbol = quoteToken ? quoteToken.symbol : "Unknown"; - - const convertedValue = new DecimalBigNumber(value ? value : 0n, decimals); - return formatCurrency(convertedValue.toString(), 5, symbol); - }, [quoteToken, baseToken]); - - return ( - - {(bonds && functionArgs && bondPurchasePrice) && - functionArgs.receiver !== "0x0000000000000000000000000000000000000000" - ? "Bond Purchase" : "Voluntary Verification"} - {(!bonds || !functionArgs || !bondPurchasePrice) && "Parsing Transaction Hash"} - - } - onClose={() => close()} - > - {bonds && functionArgs && bondPurchasePrice && - - - - - - - - - - - - {functionArgs.receiver !== "0x0000000000000000000000000000000000000000" && - <> - Receiver - - {shorten(functionArgs.receiver, 12, -10)} - - - } - - - - Max Price Set - {convertedAmount(functionArgs.maxPrice)} - - - - Effective Price - {convertedAmount(bondPurchasePrice)} - - - - - View Transaction Details - - - } - - ) -} - -const BondModal = ({ chainId, isOpen, close, config, historyRecord }) => { +const BondModal = ({ chainId, isOpen, close, config, historyRecord, address }) => { const { CONSTANTS } = useLocalStorage(); switch (historyRecord.name) { @@ -388,6 +24,15 @@ const BondModal = ({ chainId, isOpen, close, config, historyRecord }) => { config={config} historyRecord={historyRecord} /> + case CONSTANTS.bond.exodus: + return default: return null; } diff --git a/src/containers/History/BondModals/BondModalBond.jsx b/src/containers/History/BondModals/BondModalBond.jsx new file mode 100644 index 0000000..d29c26a --- /dev/null +++ b/src/containers/History/BondModals/BondModalBond.jsx @@ -0,0 +1,231 @@ +import { useTransactionReceipt, useTransaction, useToken } from 'wagmi'; +import { decodeEventLog, decodeFunctionData } from 'viem'; +import { useMemo, useCallback, useState } from "react"; +import { useParams } from "react-router-dom"; + +import { Box, Typography, Link } from "@mui/material"; +import ArrowRightIcon from '@mui/icons-material/ArrowRight'; + +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 { getTokenDecimals } from "../../../hooks/helpers"; +import { useLocalStorage } from "../../../hooks/localstorage"; +import { formatNumber, formatCurrency, shorten } from "../../../helpers"; +import { DecimalBigNumber } from "../../../helpers/DecimalBigNumber"; + +import { abi as GhostBondDepository } from "../../../abi/GhostBondDepository.json"; +import { abi as GhostGatekeeper } from "../../../abi/GhostGatekeeper.json"; +import { abi as ERC20Token } from "../../../abi/ERC20.json"; +import TokenBox from "../TokenBox"; + +const BondModalBond = ({ chainId, 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 { 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: GhostBondDepository, + data: txData.input + }); + + return { + bondId: decoded.args.at(0), + amount: decoded.args.at(1), + maxPrice: decoded.args.at(2), + receiver: decoded.args.at(3), + } + } catch {} + + try { + const decoded = decodeFunctionData({ + abi: GhostGatekeeper, + data: txData.input, + }); + + return { + bondId: 0, + amount: 0n, + maxPrice: 0n, + receiver: "0x0000000000000000000000000000000000000000", + } + } catch { + return null; + } + }, [txData]); + + const allDecodedLogs = useMemo(() => { + if (!receipt?.logs) return []; + + return receipt.logs.map((log) => { + try { + const decoded = decodeEventLog({ + abi: GhostBondDepository, + data: log.data, + topics: log.topics, + }); + + return { + eventName: decoded.eventName, + args: decoded.args, + address: log.address + }; + } catch (e) { + return null; + } + }).filter(Boolean); + }, [receipt]); + + const { bonds } = useBondInfo(chainId, network, functionArgs ? [functionArgs.bondId] : []); + + const bondPurchasePrice = useMemo(() => { + const log = allDecodedLogs.find(l => l.eventName === 'Bond'); + if (!log) return 1n; + + return log.args.price; + }, [allDecodedLogs]); + + const { data: baseToken } = useToken({ + address: bonds?.at(0)?.baseToken.tokenAddress, + scopeKey: `baseToken-${functionArgs ? functionArgs.bondId : null}-${chainId}`, + chainId + }); + + const { data: quoteToken } = useToken({ + address: bonds?.at(0)?.quoteToken.quoteTokenAddress, + scopeKey: `quoteToken-${functionArgs ? functionArgs.bondId : null}-${chainId}`, + chainId + }); + + const estimatedPayout = useMemo(() => { + const spentAmount = functionArgs ? functionArgs.amount : 0n; + const bondPrice = bondPurchasePrice ? bondPurchasePrice : 1n; + const quoteTokenDecimals = quoteToken ? quoteToken.decimals : 18; + + const mulDivResult = spentAmount * (10n ** 18n) / bondPrice; + return mulDivResult / (10n ** BigInt(quoteTokenDecimals)); + }, [bondPurchasePrice, functionArgs?.amount, baseToken, quoteToken]); + + const convertedAmount = useCallback((value) => { + const decimals = baseToken ? baseToken.decimals : 9; + const symbol = quoteToken ? quoteToken.symbol : "Unknown"; + + const convertedValue = new DecimalBigNumber(value ? value : 0n, decimals); + return formatCurrency(convertedValue.toString(), 5, symbol); + }, [quoteToken, baseToken]); + + return ( + + {(bonds && functionArgs && bondPurchasePrice) && + functionArgs.receiver !== "0x0000000000000000000000000000000000000000" + ? "Bond Purchase" : "Voluntary Verification"} + {(!bonds || !functionArgs || !bondPurchasePrice) && "Parsing Transaction Hash"} + + } + onClose={() => close()} + > + {bonds && functionArgs && bondPurchasePrice && + + + + + + + + + + + + {functionArgs.receiver !== "0x0000000000000000000000000000000000000000" && + <> + Receiver + + {shorten(functionArgs.receiver, 12, -10)} + + + } + + + + Max Price Set + {convertedAmount(functionArgs.maxPrice)} + + + + Effective Price + {convertedAmount(bondPurchasePrice)} + + + + + View Transaction Details + + + } + + ) +} + +export default BondModalBond; diff --git a/src/containers/History/BondModals/BondModalClaim.jsx b/src/containers/History/BondModals/BondModalClaim.jsx new file mode 100644 index 0000000..e81f810 --- /dev/null +++ b/src/containers/History/BondModals/BondModalClaim.jsx @@ -0,0 +1,174 @@ +import { useTransactionReceipt, useTransaction, useToken } from 'wagmi'; +import { decodeEventLog, decodeFunctionData } from 'viem'; +import { useMemo, useCallback } from "react"; +import { useParams } from "react-router-dom"; + +import { Box, Typography, Link } from "@mui/material"; +import ArrowRightIcon from '@mui/icons-material/ArrowRight'; + +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 { getTokenDecimals } from "../../../hooks/helpers"; +import { useLocalStorage } from "../../../hooks/localstorage"; +import { formatNumber, formatCurrency, shorten } from "../../../helpers"; +import { DecimalBigNumber } from "../../../helpers/DecimalBigNumber"; + +import { abi as GhostBondDepository } from "../../../abi/GhostBondDepository.json"; +import { abi as GhostGatekeeper } from "../../../abi/GhostGatekeeper.json"; +import { abi as ERC20Token } from "../../../abi/ERC20.json"; +import TokenBox from "../TokenBox"; + +const BondModalClaim = ({ chainId, isOpen, close, config, historyRecord }) => { + if (historyRecord === null) return null; + const { network } = useParams(); + + const chainInfo = useMemo(() => { + const client = config?.getClient(); + + return { + url: client?.chain?.blockExplorers?.default?.url, + symbol: client?.chain?.nativeCurrency?.symbol, + }; + }, [config]); + + 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; + const decoded = decodeFunctionData({ abi: GhostBondDepository, data: txData.input }); + if (!decoded) return null; + + return { + receiver: decoded.args.at(0), + isGhst: decoded.args.at(1), + bondIds: decoded.args.at(2), + } + }, [txData]); + + const allDecodedLogs = useMemo(() => { + if (!receipt?.logs) return []; + + return receipt.logs.map((log) => { + try { + const decoded = decodeEventLog({ + abi: ERC20Token, + data: log.data, + topics: log.topics, + }); + + return { + eventName: decoded.eventName, + args: decoded.args, + address: log.address + }; + } catch (e) { + return null; + } + }).filter(Boolean); + }, [receipt]); + + const claimedAmount = useMemo(() => { + return allDecodedLogs?.reduce((sum, item) => sum + item.args.value, 0n); + }, [allDecodedLogs]); + + return ( + + {functionArgs && "Bond Claim"} + {(!functionArgs) && "Parsing Transaction Hash"} + + } + onClose={() => close()} + > + {functionArgs && + + + + + + + + + Receiver + + {shorten(functionArgs.receiver, 10, -8)} + + + + + Claimed + + {formatCurrency( + new DecimalBigNumber(claimedAmount ?? 0n, getTokenDecimals(functionArgs.isGhst ? "GHST" : "STNK")), + 5, + functionArgs.isGhst ? "GHST" : "STNK" + )} + + + + + Bond Indexes + + {functionArgs.bondIds.map((bond) => formatNumber(bond)).join(", ")} + + + + + + + View Transaction Details + + + } + + ) +} + +export default BondModalClaim; diff --git a/src/containers/History/BondModals/BondModalExodus.jsx b/src/containers/History/BondModals/BondModalExodus.jsx new file mode 100644 index 0000000..abb8874 --- /dev/null +++ b/src/containers/History/BondModals/BondModalExodus.jsx @@ -0,0 +1,224 @@ +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 { 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 { 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, "FTSO")} + + + + Receiver + + + } + + + + Message + + + + + Nonce + + + + + Signature + + + + + + View Transaction Details + + + } + + ) +} + +export default BondModalExodus; diff --git a/src/containers/History/History.jsx b/src/containers/History/History.jsx index 355273e..f821dee 100644 --- a/src/containers/History/History.jsx +++ b/src/containers/History/History.jsx @@ -173,7 +173,7 @@ const HistoryItem = ({ ) } -const HistoryList = ({ chainId, storedTransactions, historyType, config, eraseRecord }) => { +const HistoryList = ({ chainId, address, storedTransactions, historyType, config, eraseRecord }) => { const isSmallScreen = useMediaQuery("(max-width: 900px)"); const [currentTime, setCurrentTime] = useState(Date.now()); @@ -306,6 +306,7 @@ const HistoryList = ({ chainId, storedTransactions, historyType, config, eraseRe setViewModalOpen(null)} isOpen={true} historyRecord={storedTransactions.at(viewModalOpen)} @@ -515,6 +516,7 @@ const History = ({ chainId, config, tryConnectInjected, address }) => { { setErasingIndex(index); setErasingOpen(true); diff --git a/src/hooks/bonds/index.js b/src/hooks/bonds/index.js index e726ffe..c6a86ae 100644 --- a/src/hooks/bonds/index.js +++ b/src/hooks/bonds/index.js @@ -1,4 +1,5 @@ import { useReadContract, useReadContracts } from "wagmi"; +import { useMemo } from "react"; import toast from "react-hot-toast"; import { @@ -254,19 +255,29 @@ export const useNotes = (chainId, address) => { }), }); - const { symbols: quoteTokenSymbols } = useTokenSymbols(chainId, markets?.map(m => m.result?.at(3))); + const quoteTokenNames = useMemo( + () => markets?.map((m) => m.result?.at(3)).filter(Boolean), + [markets] + ); + + const { symbols: quoteTokenSymbols } = useTokenSymbols(chainId, quoteTokenNames); const notes = indexesFor ? indexesFor.map((noteIndex, index) => { const id = Number(noteIndex); const quoteTokenAddress = markets?.at(index).result?.at(3) ? markets.at(index).result.at(3) : ""; - const quoteTokenSymbol = quoteTokenSymbols?.at(index).result ? quoteTokenSymbols.at(index).result : ""; + const quoteTokenSymbol = quoteTokenSymbols?.at(index)?.result ? quoteTokenSymbols.at(index).result : ""; + + const tokenIcos = getTokenIcons(chainId, quoteTokenAddress); + const isEmptyIcon = tokenIcos.length === 1 && tokenIcos.at(0) === ''; + const quoteTokenIcons = isEmptyIcon ? ["WETH"] : tokenIcos; + const chainNames = isEmptyIcon ? [] : getChainTokenNames(chainId, quoteTokenAddress) return { id, quoteToken: { - name: tokenNameConverter(chainId, quoteTokenSymbol), - icons: getTokenIcons(chainId, quoteTokenAddress), - chainNames: getChainTokenNames(chainId, quoteTokenAddress), + chainNames, + icons: quoteTokenIcons, + name: tokenNameConverter(chainId, quoteTokenSymbol === '' ? 'WETH' : quoteTokenSymbol), }, vesting: terms?.at(index).result?.at(2) ? terms.at(index).result.at(2) : 0, created: notesRaw?.at(index).result?.at(1) ? notesRaw.at(index).result.at(1) : 0, diff --git a/src/hooks/ghost/UnstableProvider.jsx b/src/hooks/ghost/UnstableProvider.jsx index 7024748..dcd9b45 100644 --- a/src/hooks/ghost/UnstableProvider.jsx +++ b/src/hooks/ghost/UnstableProvider.jsx @@ -15,6 +15,7 @@ import { casperChainSpec } from "./chainSpecs"; const GHOST_CONNECT_EXTENSION = "GHOST Connect Browser Extension" const MAX_BLOCK_TIMEOUT = 15000 +const MAX_CONNECT_ATTEMPTS = 20; const DEFAULT_CHAIN_ID = "0xcaf9c5ddccc7ba6f96149a6b8a81c26a3641742795cd5e7e0aee79bf3f4e77b7" const UnstableProvider = createContext(null) export const useUnstableProvider = () => useContext(UnstableProvider) @@ -55,14 +56,27 @@ export const UnstableProviderProvider = ({ children }) => { useEffect(() => { if (status !== "connected") return; - let isMounted = true; + (async () => { - const extensions = getInjectedExtensions(); - const targetExt = extensions.find(ext => ext === GHOST_CONNECT_EXTENSION); + let targetExt = null; + let attempts = 0; + + while (attempts < MAX_CONNECT_ATTEMPTS && isMounted) { + const extensions = getInjectedExtensions(); + targetExt = extensions.find(ext => ext === GHOST_CONNECT_EXTENSION); + + if (targetExt) break; + + attempts += 1; + await new Promise((r) => setTimeout(r, 300)); + } if (!targetExt) { - console.warn("Ghost Connect extension not found in window.injectedWeb3"); + console.warn( + `[UnstableProvider] "${GHOST_CONNECT_EXTENSION}" not found after ${MAX_CONNECT_ATTEMPTS} attempts. Available:`, + getInjectedExtensions() + ); return; } diff --git a/src/hooks/helpers.js b/src/hooks/helpers.js index 233568d..7bb7b59 100644 --- a/src/hooks/helpers.js +++ b/src/hooks/helpers.js @@ -261,7 +261,6 @@ export const executeOnChainTransaction = async ({ gas: bufferedGas, }); - // const txHash = await writeContract(config, request); await waitForTransactionReceipt(config, { hash: txHash, onReplaced: () => toast(messages.replacedMsg), diff --git a/src/hooks/localstorage/index.jsx b/src/hooks/localstorage/index.jsx index c4f3a25..af86e60 100644 --- a/src/hooks/localstorage/index.jsx +++ b/src/hooks/localstorage/index.jsx @@ -13,6 +13,7 @@ const DEX_ACTION_REMOVE = "Remove Liquidity"; const BOND_ACTION_BOND = "Bond"; const BOND_ACTION_CLAIM = "Claim"; +const BOND_ACTION_EXODUS = "Exodus"; const STAKE_ACTION_STAKE = "Stake"; const UNSTAKE_ACTION_STAKE = "Unstake"; @@ -41,6 +42,7 @@ const CONSTANTS = { key: BOND_ACTION, bond: BOND_ACTION_BOND, claim: BOND_ACTION_CLAIM, + exodus: BOND_ACTION_EXODUS, }, stake: { key: STAKE_ACTION, diff --git a/src/hooks/staking/index.js b/src/hooks/staking/index.js index 65f813b..4b8a55d 100644 --- a/src/hooks/staking/index.js +++ b/src/hooks/staking/index.js @@ -45,7 +45,11 @@ export const useIsTransactionExecuted = (chainId, index) => { chainId: chainId, }); - const { data: isTransactionExecuted, isLoading: isTransactionExecutedLoading } = useReadContract({ + const { + data: isTransactionExecuted, + isLoading: isTransactionExecutedLoading, + refetch: refetchTransactionExecuted + } = useReadContract({ abi: GhostStorageHistoryAbi, address: storageHistory, functionName: "isTransactionExecuted", @@ -54,7 +58,7 @@ export const useIsTransactionExecuted = (chainId, index) => { chainId: chainId, }); - return { isTransactionExecuted, isTransactionExecutedLoading } + return { isTransactionExecuted, isTransactionExecutedLoading, refetchTransactionExecuted } } export const useCurrentGasPrice = (chainId) => { diff --git a/src/hooks/tokens/index.js b/src/hooks/tokens/index.js index 75a5b33..fb2da4d 100644 --- a/src/hooks/tokens/index.js +++ b/src/hooks/tokens/index.js @@ -141,14 +141,14 @@ export const useTokenSymbol = (chainId, name) => { } export const useTokenSymbols = (chainId, names) => { - const { data: symbols } = useReadContracts({ + const { data: symbols, error } = useReadContracts({ contracts: names?.map((name) => { const contractAddress = getTokenAddress(chainId, name); return { abi: getTokenAbi(name), address: contractAddress, functionName: "symbol", - scopeKey: `symbol-${contractAddress}-${chainId}`, + scopeKey: `symbol-${contractAddress}-${chainId}-${name}`, chainId: chainId, } })