final touches on the exodus page
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
parent
ce7c973929
commit
b675da56d2
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ghost-dao-interface",
|
||||
"private": true,
|
||||
"version": "0.8.24",
|
||||
"version": "0.8.25",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -149,7 +149,10 @@ export const ClaimBonds = ({ chainId, address, secondsTo }) => {
|
||||
{notes.map((note, index) => (
|
||||
<Box key={index} mt="32px">
|
||||
<Box display="flex" alignItems="center">
|
||||
<TokenStack chainTokenNames={note.quoteToken.chainNames} tokens={note.quoteToken.icons} />
|
||||
<TokenStack
|
||||
chainTokenNames={note.quoteToken.chainNames}
|
||||
tokens={note.quoteToken.icons}
|
||||
/>
|
||||
<Box ml="8px">
|
||||
<Typography>{note.quoteToken.name}</Typography>
|
||||
</Box>
|
||||
@ -211,7 +214,10 @@ export const ClaimBonds = ({ chainId, address, secondsTo }) => {
|
||||
<TableRow key={index}>
|
||||
<TableCell style={{ padding: "8px 0" }}>
|
||||
<Box display="flex" alignItems="center">
|
||||
<TokenStack chainTokenNames={note.quoteToken.chainNames} tokens={note.quoteToken.icons} />
|
||||
<TokenStack
|
||||
chainTokenNames={note.quoteToken.chainNames}
|
||||
tokens={note.quoteToken.icons}
|
||||
/>
|
||||
<Box display="flex" flexDirection="column" ml="16px">
|
||||
<Typography>{note.quoteToken.name}</Typography>
|
||||
</Box>
|
||||
|
||||
@ -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
|
||||
</Link>
|
||||
{" "}for your privacy, or{" "}
|
||||
<Link
|
||||
component="button"
|
||||
type="button"
|
||||
variant="body1"
|
||||
underline="hover"
|
||||
onClick={() => setReceiver(account)}
|
||||
sx={{
|
||||
color: theme.colors.primary[300],
|
||||
verticalAlign: "baseline",
|
||||
}}
|
||||
>
|
||||
click here
|
||||
</Link>{" "}
|
||||
to use connected one.
|
||||
{" "}for your privacy
|
||||
{account ? (
|
||||
<>
|
||||
, or{" "}
|
||||
<Link
|
||||
component="button"
|
||||
type="button"
|
||||
variant="body1"
|
||||
underline="hover"
|
||||
onClick={() => setReceiver(account ? account.address : "")}
|
||||
sx={{
|
||||
color: theme.colors.primary[300],
|
||||
verticalAlign: "baseline",
|
||||
}}
|
||||
>
|
||||
click here
|
||||
</Link>{" "}
|
||||
to use connected one.
|
||||
</>
|
||||
) : (".")}
|
||||
</Typography>
|
||||
|
||||
<BridgeGhostAddressCard
|
||||
|
||||
@ -47,9 +47,8 @@ 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 BRIDGE_OUT = "Bridge-Out";
|
||||
export const KEY_ROTATION = "Key Rotation";
|
||||
export const BRIDGE_OUT = "Bridge-Out";
|
||||
|
||||
const GAS_USED = {
|
||||
[KEY_ROTATION]: 166000n + 21000n + 5969n + 67585n,
|
||||
@ -131,14 +130,7 @@ const Exodus = ({ chainId, address, config }) => {
|
||||
: 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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 = ({
|
||||
>
|
||||
<Box display="flex" flexDirection="column">
|
||||
<Box mb="15px" display="flex" flexDirection="column" gap="1px" sx={{ "& .DataRow-root": { margin: "0 !important" } }}>
|
||||
<DataRow
|
||||
title={<Typography variant="caption">New Group Key</Typography>}
|
||||
tooltip="Some cool description here."
|
||||
balance={<Link
|
||||
href={`${nativeMetadata.url}/address/${upcomingGroupKey}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{item?.type === KEY_ROTATION
|
||||
? <DataRow
|
||||
title={<Typography variant="caption">New Group Key</Typography>}
|
||||
tooltip="Some cool description here."
|
||||
balance={<Link
|
||||
href={`${nativeMetadata.url}/address/${upcomingGroupKey}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Typography variant="caption">{
|
||||
upcomingGroupKey ? shorten(upcomingGroupKey, 12, -8) : ""
|
||||
}</Typography>
|
||||
</Link>}
|
||||
/>
|
||||
: <DataRow
|
||||
title={<Typography variant="caption">Bridging Amount</Typography>}
|
||||
tooltip="Some cool description here."
|
||||
balance={
|
||||
<Typography variant="caption">{
|
||||
upcomingGroupKey ? shorten(upcomingGroupKey, 12, -8) : ""
|
||||
bridgeAmount ? formatCurrency(bridgeAmount, 5, ghstSymbol) : ""
|
||||
}</Typography>
|
||||
</Link>}
|
||||
/>
|
||||
} />
|
||||
}
|
||||
|
||||
<DataRow
|
||||
title={<Typography variant="caption">Verification Reward</Typography>}
|
||||
|
||||
@ -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 (
|
||||
<Modal
|
||||
maxWidth="420px"
|
||||
minHeight="200px"
|
||||
open={isOpen}
|
||||
headerText={
|
||||
<>
|
||||
{functionArgs && "Bond Claim"}
|
||||
{(!functionArgs) && "Parsing Transaction Hash"}
|
||||
</>
|
||||
}
|
||||
onClose={() => close()}
|
||||
>
|
||||
{functionArgs && <Box display="flex" flexDirection="column" gap="15px">
|
||||
<Box width="100%" gap="20px" display="flex" flexDirection="column" justifyContent="space-between" alignItems="flex-start">
|
||||
<Box display="flex" flexDirection="row" justifyContent="space-between" alignItems="center" width="100%" gap="25px">
|
||||
<Box
|
||||
display="flex"
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
flexShrink={0}
|
||||
sx={{ width: "60px", height: "60px" }}
|
||||
>
|
||||
<Token
|
||||
parentSx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
"& svg:nth-of-type(2)": {
|
||||
transform: "translate(50%, -50%)",
|
||||
zIndex: 100,
|
||||
}
|
||||
}}
|
||||
sx={{ transform: "scale(1.65)" }}
|
||||
chainTokenName={chainInfo.symbol}
|
||||
name={functionArgs.isGhst ? "GHST" : "STNK"}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" flexDirection="column" justifyContent="space-between" width="100%">
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
<Typography>Receiver</Typography>
|
||||
<Link
|
||||
href={`${chainInfo.url}/address/${functionArgs.receiver}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Typography>{shorten(functionArgs.receiver, 10, -8)}</Typography>
|
||||
</Link>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
<Typography>Claimed</Typography>
|
||||
<Typography>
|
||||
{formatCurrency(
|
||||
new DecimalBigNumber(claimedAmount ?? 0n, getTokenDecimals(functionArgs.isGhst ? "GHST" : "STNK")),
|
||||
5,
|
||||
functionArgs.isGhst ? "GHST" : "STNK"
|
||||
)}
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
<Typography>Bond Indexes</Typography>
|
||||
<Typography width="160px" textAlign="right">
|
||||
{functionArgs.bondIds.map((bond) => formatNumber(bond)).join(", ")}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<PrimaryButton
|
||||
fullWidth
|
||||
component="a"
|
||||
href={`${chainInfo.url}/tx/${historyRecord.txHash}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
View Transaction Details
|
||||
</PrimaryButton>
|
||||
</Box>
|
||||
</Box>}
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
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 (
|
||||
<Modal
|
||||
maxWidth="420px"
|
||||
minHeight="200px"
|
||||
open={isOpen}
|
||||
headerText={
|
||||
<>
|
||||
{(bonds && functionArgs && bondPurchasePrice) &&
|
||||
functionArgs.receiver !== "0x0000000000000000000000000000000000000000"
|
||||
? "Bond Purchase" : "Voluntary Verification"}
|
||||
{(!bonds || !functionArgs || !bondPurchasePrice) && "Parsing Transaction Hash"}
|
||||
</>
|
||||
}
|
||||
onClose={() => close()}
|
||||
>
|
||||
{bonds && functionArgs && bondPurchasePrice && <Box display="flex" flexDirection="column" gap="15px">
|
||||
<Box width="100%" gap="20px" display="flex" flexDirection="column" justifyContent="space-between" alignItems="flex-start">
|
||||
<Box width="100%" display="flex" flexDirection="row" justifyContent="space-around" alignItems="center">
|
||||
<TokenBox
|
||||
tokenAmount={functionArgs.amount}
|
||||
decimals={quoteToken ? quoteToken.decimals : 18}
|
||||
tokenSymbol={bonds.at(0) ? bonds.at(0).quoteToken.name : "Unknown"}
|
||||
chainTokenSymbol={bonds.at(0) ? bonds.at(0).quoteToken.chainNames.at(0) : chainInfo.symbol}
|
||||
/>
|
||||
|
||||
<GhostStyledIcon sx={{ fontSize: '24px' }} component={ArrowRightIcon} />
|
||||
|
||||
<TokenBox
|
||||
tokenAmount={estimatedPayout}
|
||||
decimals={baseToken ? baseToken.decimals : 9}
|
||||
tokenSymbol={bonds.at(0) ? bonds.at(0).baseToken.name : "Unknown"}
|
||||
chainTokenSymbol={bonds.at(0) ? bonds.at(0).baseToken.chainNames.at(0) : chainInfo.symbol}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" flexDirection="column" justifyContent="space-between" width="100%">
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
{functionArgs.receiver !== "0x0000000000000000000000000000000000000000" &&
|
||||
<>
|
||||
<Typography>Receiver</Typography>
|
||||
<Link
|
||||
href={`${chainInfo.url}/address/${functionArgs.receiver}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Typography>{shorten(functionArgs.receiver, 12, -10)}</Typography>
|
||||
</Link>
|
||||
</>
|
||||
}
|
||||
</Box>
|
||||
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
<Typography>Max Price Set</Typography>
|
||||
<Typography>{convertedAmount(functionArgs.maxPrice)}</Typography>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
<Typography>Effective Price</Typography>
|
||||
<Typography>{convertedAmount(bondPurchasePrice)}</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<PrimaryButton
|
||||
fullWidth
|
||||
component="a"
|
||||
href={`${chainInfo.url}/tx/${historyRecord.txHash}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
View Transaction Details
|
||||
</PrimaryButton>
|
||||
</Box>
|
||||
</Box>}
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
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 <BondModalExodus
|
||||
chainId={chainId}
|
||||
isOpen={isOpen}
|
||||
close={close}
|
||||
config={config}
|
||||
address={address}
|
||||
historyRecord={historyRecord}
|
||||
/>
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
231
src/containers/History/BondModals/BondModalBond.jsx
Normal file
231
src/containers/History/BondModals/BondModalBond.jsx
Normal file
@ -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 (
|
||||
<Modal
|
||||
maxWidth="420px"
|
||||
minHeight="200px"
|
||||
open={isOpen}
|
||||
headerText={
|
||||
<>
|
||||
{(bonds && functionArgs && bondPurchasePrice) &&
|
||||
functionArgs.receiver !== "0x0000000000000000000000000000000000000000"
|
||||
? "Bond Purchase" : "Voluntary Verification"}
|
||||
{(!bonds || !functionArgs || !bondPurchasePrice) && "Parsing Transaction Hash"}
|
||||
</>
|
||||
}
|
||||
onClose={() => close()}
|
||||
>
|
||||
{bonds && functionArgs && bondPurchasePrice && <Box display="flex" flexDirection="column" gap="15px">
|
||||
<Box width="100%" gap="20px" display="flex" flexDirection="column" justifyContent="space-between" alignItems="flex-start">
|
||||
<Box width="100%" display="flex" flexDirection="row" justifyContent="space-around" alignItems="center">
|
||||
<TokenBox
|
||||
tokenAmount={functionArgs.amount}
|
||||
decimals={quoteToken ? quoteToken.decimals : 18}
|
||||
tokenSymbol={bonds.at(0) ? bonds.at(0).quoteToken.name : "Unknown"}
|
||||
chainTokenSymbol={bonds.at(0) ? bonds.at(0).quoteToken.chainNames.at(0) : chainInfo.symbol}
|
||||
/>
|
||||
|
||||
<GhostStyledIcon sx={{ fontSize: '24px' }} component={ArrowRightIcon} />
|
||||
|
||||
<TokenBox
|
||||
tokenAmount={estimatedPayout}
|
||||
decimals={baseToken ? baseToken.decimals : 9}
|
||||
tokenSymbol={bonds.at(0) ? bonds.at(0).baseToken.name : "Unknown"}
|
||||
chainTokenSymbol={bonds.at(0) ? bonds.at(0).baseToken.chainNames.at(0) : chainInfo.symbol}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" flexDirection="column" justifyContent="space-between" width="100%">
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
{functionArgs.receiver !== "0x0000000000000000000000000000000000000000" &&
|
||||
<>
|
||||
<Typography>Receiver</Typography>
|
||||
<Link
|
||||
href={`${chainInfo.url}/address/${functionArgs.receiver}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Typography>{shorten(functionArgs.receiver, 12, -10)}</Typography>
|
||||
</Link>
|
||||
</>
|
||||
}
|
||||
</Box>
|
||||
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
<Typography>Max Price Set</Typography>
|
||||
<Typography>{convertedAmount(functionArgs.maxPrice)}</Typography>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
<Typography>Effective Price</Typography>
|
||||
<Typography>{convertedAmount(bondPurchasePrice)}</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<PrimaryButton
|
||||
fullWidth
|
||||
component="a"
|
||||
href={`${chainInfo.url}/tx/${historyRecord.txHash}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
View Transaction Details
|
||||
</PrimaryButton>
|
||||
</Box>
|
||||
</Box>}
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
export default BondModalBond;
|
||||
174
src/containers/History/BondModals/BondModalClaim.jsx
Normal file
174
src/containers/History/BondModals/BondModalClaim.jsx
Normal file
@ -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 (
|
||||
<Modal
|
||||
maxWidth="420px"
|
||||
minHeight="200px"
|
||||
open={isOpen}
|
||||
headerText={
|
||||
<>
|
||||
{functionArgs && "Bond Claim"}
|
||||
{(!functionArgs) && "Parsing Transaction Hash"}
|
||||
</>
|
||||
}
|
||||
onClose={() => close()}
|
||||
>
|
||||
{functionArgs && <Box display="flex" flexDirection="column" gap="15px">
|
||||
<Box width="100%" gap="20px" display="flex" flexDirection="column" justifyContent="space-between" alignItems="flex-start">
|
||||
<Box display="flex" flexDirection="row" justifyContent="space-between" alignItems="center" width="100%" gap="25px">
|
||||
<Box
|
||||
display="flex"
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
flexShrink={0}
|
||||
sx={{ width: "60px", height: "60px" }}
|
||||
>
|
||||
<Token
|
||||
parentSx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
"& svg:nth-of-type(2)": {
|
||||
transform: "translate(50%, -50%)",
|
||||
zIndex: 100,
|
||||
}
|
||||
}}
|
||||
sx={{ transform: "scale(1.65)" }}
|
||||
chainTokenName={chainInfo.symbol}
|
||||
name={functionArgs.isGhst ? "GHST" : "STNK"}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" flexDirection="column" justifyContent="space-between" width="100%">
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
<Typography>Receiver</Typography>
|
||||
<Link
|
||||
href={`${chainInfo.url}/address/${functionArgs.receiver}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Typography>{shorten(functionArgs.receiver, 10, -8)}</Typography>
|
||||
</Link>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
<Typography>Claimed</Typography>
|
||||
<Typography>
|
||||
{formatCurrency(
|
||||
new DecimalBigNumber(claimedAmount ?? 0n, getTokenDecimals(functionArgs.isGhst ? "GHST" : "STNK")),
|
||||
5,
|
||||
functionArgs.isGhst ? "GHST" : "STNK"
|
||||
)}
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
<Typography>Bond Indexes</Typography>
|
||||
<Typography width="160px" textAlign="right">
|
||||
{functionArgs.bondIds.map((bond) => formatNumber(bond)).join(", ")}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<PrimaryButton
|
||||
fullWidth
|
||||
component="a"
|
||||
href={`${chainInfo.url}/tx/${historyRecord.txHash}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
View Transaction Details
|
||||
</PrimaryButton>
|
||||
</Box>
|
||||
</Box>}
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
export default BondModalClaim;
|
||||
224
src/containers/History/BondModals/BondModalExodus.jsx
Normal file
224
src/containers/History/BondModals/BondModalExodus.jsx
Normal file
@ -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 <Skeleton width="185px" />;
|
||||
|
||||
return (
|
||||
<Link
|
||||
style={{ display: "flex", flexDirection: "row", justifyContent: "center", alignItems: "center" }}
|
||||
onClick={() => copyToClipboard(value, index)}
|
||||
>
|
||||
<Typography>{shorten(value, 12, -10)}</Typography>
|
||||
<GhostStyledIcon
|
||||
sx={{ marginLeft: "5px", width: "12px", height: "12px" }}
|
||||
viewBox="0 0 25 25"
|
||||
component={copiedIndex === index ? CheckIcon : ContentPasteIcon}
|
||||
/>
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
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 (
|
||||
<Modal
|
||||
maxWidth="420px"
|
||||
minHeight="200px"
|
||||
open={isOpen}
|
||||
headerText={
|
||||
<>
|
||||
{(functionArgs && allDecodedLogs) && voluntaryVerification
|
||||
? "Voluntary Verification" : "Exodus Verification"}
|
||||
{(!functionArgs || !allDecodedLogs) && "Parsing Transaction Hash"}
|
||||
</>
|
||||
}
|
||||
onClose={() => close()}
|
||||
>
|
||||
{<Box display="flex" flexDirection="column" gap="15px">
|
||||
<Box width="100%" gap="20px" display="flex" flexDirection="column" justifyContent="space-between" alignItems="flex-start">
|
||||
{!voluntaryVerification && <Box width="100%" display="flex" flexDirection="column" justifyContent="space-around" alignItems="center">
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
<Typography>Exodus Reward</Typography>
|
||||
<Typography>{formatCurrency(stakedAmount, 5, "FTSO")}</Typography>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
<Typography>Receiver</Typography>
|
||||
<ClickableHex
|
||||
index={0}
|
||||
value={address}
|
||||
copiedIndex={copiedIndex}
|
||||
copyToClipboard={copyToClipboard}
|
||||
/>
|
||||
</Box>
|
||||
</Box>}
|
||||
|
||||
<Box display="flex" flexDirection="column" justifyContent="space-between" width="100%">
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
<Typography>Message</Typography>
|
||||
<ClickableHex
|
||||
index={1}
|
||||
copiedIndex={copiedIndex}
|
||||
copyToClipboard={copyToClipboard}
|
||||
value={functionArgs?.message}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
<Typography>Nonce</Typography>
|
||||
<ClickableHex
|
||||
index={2}
|
||||
copiedIndex={copiedIndex}
|
||||
copyToClipboard={copyToClipboard}
|
||||
value={functionArgs?.nonce}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" justifyContent="space-between" width="100%">
|
||||
<Typography>Signature</Typography>
|
||||
<ClickableHex
|
||||
index={3}
|
||||
copiedIndex={copiedIndex}
|
||||
copyToClipboard={copyToClipboard}
|
||||
value={functionArgs?.signature}
|
||||
/>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<PrimaryButton
|
||||
fullWidth
|
||||
component="a"
|
||||
href={`${chainInfo.url}/tx/${historyRecord.txHash}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
View Transaction Details
|
||||
</PrimaryButton>
|
||||
</Box>
|
||||
</Box>}
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
export default BondModalExodus;
|
||||
@ -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
|
||||
<BondModal
|
||||
chainId={chainId}
|
||||
config={config}
|
||||
address={address}
|
||||
close={() => setViewModalOpen(null)}
|
||||
isOpen={true}
|
||||
historyRecord={storedTransactions.at(viewModalOpen)}
|
||||
@ -515,6 +516,7 @@ const History = ({ chainId, config, tryConnectInjected, address }) => {
|
||||
<HistoryList
|
||||
chainId={chainId}
|
||||
config={config}
|
||||
address={address}
|
||||
eraseRecord={(index) => {
|
||||
setErasingIndex(index);
|
||||
setErasingOpen(true);
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -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,
|
||||
}
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user