make the bond purchase functionality work again
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
parent
ce6e316feb
commit
4de736ea08
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ghost-dao-interface",
|
"name": "ghost-dao-interface",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.8.3",
|
"version": "0.8.4",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
{"abi":[{"inputs":[{"internalType":"address","name":"_ftso","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidPair","type":"error"},{"inputs":[{"internalType":"address","name":"pair","type":"address"}],"name":"getKValue","outputs":[{"internalType":"uint256","name":"k","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"}],"name":"getTotalValue","outputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"}],"name":"markdown","outputs":[{"internalType":"uint256","name":"reserve","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"valuation","outputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"stateMutability":"view","type":"function"}]}
|
{"abi":[{"inputs":[{"internalType":"address","name":"_ftso","type":"address"},{"internalType":"uint256","name":"_numerator","type":"uint256"},{"internalType":"uint256","name":"_denominator","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidPair","type":"error"},{"inputs":[],"name":"fraction","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"},{"internalType":"bool","name":"isCoefficient","type":"bool"}],"name":"getKValue","outputs":[{"internalType":"uint256","name":"k","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"},{"internalType":"bool","name":"isCoefficient","type":"bool"}],"name":"getTotalValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"}],"name":"markdown","outputs":[{"internalType":"uint256","name":"reserve","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"valuation","outputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"stateMutability":"view","type":"function"}]}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -27,6 +27,10 @@ import { useLocalStorage } from "../../hooks/localstorage";
|
|||||||
import { useLiveBonds } from "../../hooks/bonds";
|
import { useLiveBonds } from "../../hooks/bonds";
|
||||||
import { useFtsoPrice } from "../../hooks/prices";
|
import { useFtsoPrice } from "../../hooks/prices";
|
||||||
|
|
||||||
|
const SLIPPAGE_PREFIX = "bond-slippage";
|
||||||
|
const DECIMALS_PREFIX = "bond-decimals";
|
||||||
|
const RECIPIENT_PREFIX = "bond-recipient";
|
||||||
|
|
||||||
const BondModalContainer = ({ chainId, address, config, connect }) => {
|
const BondModalContainer = ({ chainId, address, config, connect }) => {
|
||||||
const { id, network } = useParams();
|
const { id, network } = useParams();
|
||||||
const { liveBonds } = useLiveBonds(chainId, network);
|
const { liveBonds } = useLiveBonds(chainId, network);
|
||||||
@ -46,35 +50,32 @@ export const BondModal = ({ bond, chainId, address, config, connect }) => {
|
|||||||
const isVerySmallScreen = useMediaQuery("(max-width: 379px)");
|
const isVerySmallScreen = useMediaQuery("(max-width: 379px)");
|
||||||
|
|
||||||
const [isSettingsOpen, setSettingsOpen] = useState(false);
|
const [isSettingsOpen, setSettingsOpen] = useState(false);
|
||||||
const { getStorageValue, setStorageValue } = useLocalStorage();
|
const { useStorageValue, setStorageValue } = useLocalStorage();
|
||||||
|
|
||||||
const [slippage, setSlippage] = useState(() => getStorageValue(chainId, address, "bond-slippage", "10"));
|
const { data: slippage } = useStorageValue(chainId, address, SLIPPAGE_PREFIX, "10");
|
||||||
const [formatDecimals, setFormatDecimals] = useState(() => getStorageValue(chainId, address, "bond-decimals", "5"));
|
const { data: formatDecimals } = useStorageValue(chainId, address, DECIMALS_PREFIX, "5");
|
||||||
const [recipientAddress, setRecipientAddressInner] = useState(() => getStorageValue(chainId, address, "bond-recipient", address));
|
const { data: recipientAddress } = useStorageValue(chainId, address, RECIPIENT_PREFIX, address);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
ReactGA.send({ hitType: "pageview", page: pathname });
|
ReactGA.send({ hitType: "pageview", page: pathname });
|
||||||
}, [pathname])
|
}, [pathname])
|
||||||
|
|
||||||
const setRecipientAddress = useCallback((value) => {
|
const setRecipientAddress = useCallback((value) => {
|
||||||
setRecipientAddressInner(value);
|
|
||||||
if (isAddress(value)) {
|
if (isAddress(value)) {
|
||||||
setStorageValue(chainId, address, "bond-recipient", value);
|
setStorageValue(chainId, address, RECIPIENT_PREFIX, value);
|
||||||
}
|
}
|
||||||
}, [chainId, address]);
|
}, [chainId, address]);
|
||||||
|
|
||||||
const setSlippageInner = useCallback((value) => {
|
const setSlippage = useCallback((value) => {
|
||||||
const maybeValue = parseFloat(value);
|
const maybeValue = parseFloat(value);
|
||||||
if (!maybeValue || parseFloat(value) <= 100) {
|
if (!maybeValue || parseFloat(value) <= 100) {
|
||||||
setSlippage(value);
|
setStorageValue(chainId, address, SLIPPAGE_PREFIX, value);
|
||||||
setStorageValue(chainId, address, "bond-slippage", value);
|
|
||||||
}
|
}
|
||||||
}, [chainId, address]);
|
}, [chainId, address]);
|
||||||
|
|
||||||
const setFormatDecimalsInner = useCallback((value) => {
|
const setFormatDecimals = useCallback((value) => {
|
||||||
if (Number(value) <= 17) {
|
if (Number(value) <= 17) {
|
||||||
setFormatDecimals(value);
|
setStorageValue(chainId, address, DECIMALS_PREFIX, value);
|
||||||
setStorageValue(chainId, address, "bond-decimals", value);
|
|
||||||
}
|
}
|
||||||
}, [chainId, address]);
|
}, [chainId, address]);
|
||||||
|
|
||||||
@ -132,8 +133,8 @@ export const BondModal = ({ bond, chainId, address, config, connect }) => {
|
|||||||
recipientAddress={recipientAddress}
|
recipientAddress={recipientAddress}
|
||||||
formatDecimals={formatDecimals}
|
formatDecimals={formatDecimals}
|
||||||
onRecipientAddressChange={event => setRecipientAddress(event.currentTarget.value)}
|
onRecipientAddressChange={event => setRecipientAddress(event.currentTarget.value)}
|
||||||
onSlippageChange={event => setSlippageInner(event.currentTarget.value)}
|
onSlippageChange={event => setSlippage(event.currentTarget.value)}
|
||||||
onDecimalsChange={event => setFormatDecimalsInner(event.currentTarget.value)}
|
onDecimalsChange={event => setFormatDecimals(event.currentTarget.value)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Container
|
<Container
|
||||||
|
|||||||
@ -77,7 +77,7 @@ export const BondConfirmModal = ({
|
|||||||
const [acknowledgedWarmup, setAcknowledgedWarmup] = useState(false);
|
const [acknowledgedWarmup, setAcknowledgedWarmup] = useState(false);
|
||||||
const [isPending, setIsPending] = useState(false);
|
const [isPending, setIsPending] = useState(false);
|
||||||
|
|
||||||
const { tryStoreBondInHistory } = useLocalStorage();
|
const { tryStoreInHistory, CONSTANTS } = useLocalStorage();
|
||||||
|
|
||||||
useEffect(() => setAcknowledgedWarmup(acknowledgedWarmup || !needsWarmup), [acknowledgedWarmup, needsWarmup]);
|
useEffect(() => setAcknowledgedWarmup(acknowledgedWarmup || !needsWarmup), [acknowledgedWarmup, needsWarmup]);
|
||||||
|
|
||||||
@ -144,14 +144,15 @@ export const BondConfirmModal = ({
|
|||||||
isNative
|
isNative
|
||||||
});
|
});
|
||||||
|
|
||||||
tryStoreBondInHistory(chainId, sender, txHash);
|
if (txHash) tryStoreInHistory(chainId, sender, CONSTANTS.bond.key, txHash, CONSTANTS.bond.name);
|
||||||
|
|
||||||
setIsPending(false);
|
setIsPending(false);
|
||||||
handleConfirmCloseMaster();
|
handleConfirmCloseMaster();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
maxWidth="476px"
|
maxWidth="426px"
|
||||||
minHeight="200px"
|
minHeight="200px"
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
headerContent={<Typography variant="h4">{bondQuoteTokenName} Bond</Typography>}
|
headerContent={<Typography variant="h4">{bondQuoteTokenName} Bond</Typography>}
|
||||||
|
|||||||
@ -278,7 +278,7 @@ const BondInputArea = ({
|
|||||||
>
|
>
|
||||||
<PrimaryButton
|
<PrimaryButton
|
||||||
fullWidth
|
fullWidth
|
||||||
disabled={incorrectInputAmount || bond.isSoldOut || (!showDisclaimer && !checked)}
|
disabled={incorrectInputAmount || bond.isSoldOut || (showDisclaimer && !checked)}
|
||||||
onClick={() => setModalOpen(true)}
|
onClick={() => setModalOpen(true)}
|
||||||
>
|
>
|
||||||
Bond
|
Bond
|
||||||
|
|||||||
189
src/containers/History/BondModal.jsx
Normal file
189
src/containers/History/BondModal.jsx
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
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 { PrimaryButton } from "../../components/Button";
|
||||||
|
|
||||||
|
import { useBondInfo } from "../../hooks/bonds";
|
||||||
|
import { formatCurrency, shorten } from "../../helpers";
|
||||||
|
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
||||||
|
|
||||||
|
import { abi as GhostBondDepository } from "../../abi/GhostBondDepository.json";
|
||||||
|
import TokenBox from "./TokenBox";
|
||||||
|
|
||||||
|
const BondModal = ({ 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 {
|
||||||
|
bondId: decoded.args.at(0),
|
||||||
|
amount: decoded.args.at(1),
|
||||||
|
maxPrice: decoded.args.at(2),
|
||||||
|
receiver: decoded.args.at(3),
|
||||||
|
}
|
||||||
|
}, [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 null;
|
||||||
|
|
||||||
|
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 && "Bond Purchase"}
|
||||||
|
{(!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%">
|
||||||
|
<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 BondModal;
|
||||||
@ -5,40 +5,14 @@ import { useMemo } from "react";
|
|||||||
import ArrowRightIcon from '@mui/icons-material/ArrowRight';
|
import ArrowRightIcon from '@mui/icons-material/ArrowRight';
|
||||||
import { Box, Typography, Link } from "@mui/material";
|
import { Box, Typography, Link } from "@mui/material";
|
||||||
|
|
||||||
import Token from "../../components/Token/Token";
|
|
||||||
import Modal from "../../components/Modal/Modal";
|
import Modal from "../../components/Modal/Modal";
|
||||||
import GhostStyledIcon from "../../components/Icon/GhostIcon";
|
import GhostStyledIcon from "../../components/Icon/GhostIcon";
|
||||||
import { PrimaryButton } from "../../components/Button";
|
import { PrimaryButton } from "../../components/Button";
|
||||||
|
|
||||||
import { abi as UniswapV2PairAbi } from "../../abi/UniswapV2Pair.json";
|
import { abi as UniswapV2PairAbi } from "../../abi/UniswapV2Pair.json";
|
||||||
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
|
||||||
import { formatNumber, shorten } from "../../helpers";
|
import { formatNumber, shorten } from "../../helpers";
|
||||||
|
|
||||||
const TokenBox = ({ tokenAmount, tokenSymbol, decimals, chainTokenSymbol }) => {
|
import TokenBox from "./TokenBox";
|
||||||
return (
|
|
||||||
<Box display="flex" flexDirection="column" width="70px">
|
|
||||||
<Token
|
|
||||||
parentSx={{
|
|
||||||
height: "80px",
|
|
||||||
"& svg:nth-of-type(2)": {
|
|
||||||
transform: "translate(10%, -50%)",
|
|
||||||
zIndex: 100,
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
sx={{ transform: "scale(1.65)", }}
|
|
||||||
chainTokenName={chainTokenSymbol}
|
|
||||||
name={tokenSymbol}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Box display="flex" flexDirection="column" alignItems="center">
|
|
||||||
<Typography>{formatNumber(
|
|
||||||
new DecimalBigNumber(tokenAmount ? tokenAmount : 0n, decimals),
|
|
||||||
5
|
|
||||||
)}</Typography>
|
|
||||||
</Box>
|
|
||||||
</Box>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const DexViewModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
const DexViewModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
||||||
if (historyRecord === null) return null;
|
if (historyRecord === null) return null;
|
||||||
|
|||||||
@ -43,6 +43,7 @@ import SettingsModal from "./SettingsModal";
|
|||||||
import DexViewModal from "./DexViewModal";
|
import DexViewModal from "./DexViewModal";
|
||||||
import StakingViewModal from "./StakingViewModal";
|
import StakingViewModal from "./StakingViewModal";
|
||||||
import BridgeInModal from "./BridgeInModal";
|
import BridgeInModal from "./BridgeInModal";
|
||||||
|
import BondModal from "./BondModal";
|
||||||
|
|
||||||
const HistoryItem = ({ item, chainId, config, currentTime, eraseRecord, setViewModalOpen, isSmallScreen, finalityDelay }) => {
|
const HistoryItem = ({ item, chainId, config, currentTime, eraseRecord, setViewModalOpen, isSmallScreen, finalityDelay }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@ -68,7 +69,7 @@ const HistoryItem = ({ item, chainId, config, currentTime, eraseRecord, setViewM
|
|||||||
}
|
}
|
||||||
|
|
||||||
return <Chip sx={{ width: width }} label={isVerySmallScreen ? "" : "Ready"} template={"success"} />
|
return <Chip sx={{ width: width }} label={isVerySmallScreen ? "" : "Ready"} template={"success"} />
|
||||||
}, [item, currentTime, isVerySmallScreen, finalityDelay])
|
}, [item, currentTime, isVerySmallScreen, finalityDelay]);
|
||||||
|
|
||||||
if (isSmallScreen || isVerySmallScreen) {
|
if (isSmallScreen || isVerySmallScreen) {
|
||||||
return (
|
return (
|
||||||
@ -264,6 +265,16 @@ const HistoryList = ({ chainId, storedTransactions, historyType, config, eraseRe
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{viewModalOpen !== null && historyType === CONSTANTS.bond.key && (
|
||||||
|
<BondModal
|
||||||
|
chainId={chainId}
|
||||||
|
config={config}
|
||||||
|
close={() => setViewModalOpen(null)}
|
||||||
|
isOpen={true}
|
||||||
|
historyRecord={storedTransactions.at(viewModalOpen)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{historyContainer}
|
{historyContainer}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
33
src/containers/History/TokenBox.jsx
Normal file
33
src/containers/History/TokenBox.jsx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import Token from "../../components/Token/Token";
|
||||||
|
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
||||||
|
import { formatNumber } from "../../helpers";
|
||||||
|
|
||||||
|
import { Box, Typography } from "@mui/material";
|
||||||
|
|
||||||
|
const TokenBox = ({ tokenAmount, tokenSymbol, decimals, chainTokenSymbol }) => {
|
||||||
|
return (
|
||||||
|
<Box display="flex" flexDirection="column" width="70px">
|
||||||
|
<Token
|
||||||
|
parentSx={{
|
||||||
|
height: "80px",
|
||||||
|
"& svg:nth-of-type(2)": {
|
||||||
|
transform: "translate(10%, -50%)",
|
||||||
|
zIndex: 100,
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
sx={{ transform: "scale(1.65)", }}
|
||||||
|
chainTokenName={chainTokenSymbol}
|
||||||
|
name={tokenSymbol}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Box display="flex" flexDirection="column" alignItems="center">
|
||||||
|
<Typography>{formatNumber(
|
||||||
|
new DecimalBigNumber(tokenAmount ? tokenAmount : 0n, decimals),
|
||||||
|
5
|
||||||
|
)}</Typography>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TokenBox;
|
||||||
@ -27,11 +27,7 @@ import { shorten } from "../../helpers";
|
|||||||
import { tokenNameConverter } from "../../helpers/tokenConverter";
|
import { tokenNameConverter } from "../../helpers/tokenConverter";
|
||||||
|
|
||||||
export const useLiveBonds = (chainId, chainName) => {
|
export const useLiveBonds = (chainId, chainName) => {
|
||||||
const ftsoPrice = useFtsoPrice(chainId);
|
const { data: liveIndexesRaw, refetch: refetchLiveMarkets } = useReadContract({
|
||||||
const baseTokenPerUsd = useReservePrice(chainId);
|
|
||||||
const originalCoefficient = useOrinalCoefficient(chainId);
|
|
||||||
|
|
||||||
const { data: liveIndexesRaw, refetch } = useReadContract({
|
|
||||||
abi: BondAbi,
|
abi: BondAbi,
|
||||||
address: BOND_DEPOSITORY_ADDRESSES[chainId],
|
address: BOND_DEPOSITORY_ADDRESSES[chainId],
|
||||||
functionName: "liveMarkets",
|
functionName: "liveMarkets",
|
||||||
@ -39,8 +35,18 @@ export const useLiveBonds = (chainId, chainName) => {
|
|||||||
chainId: chainId,
|
chainId: chainId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { bonds } = useBondInfo(chainId, chainName, liveIndexesRaw);
|
||||||
|
|
||||||
|
return { liveBonds: bonds, refetch: refetchLiveMarkets };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useBondInfo = (chainId, chainName, indexes) => {
|
||||||
|
const ftsoPrice = useFtsoPrice(chainId);
|
||||||
|
const baseTokenPerUsd = useReservePrice(chainId);
|
||||||
|
const originalCoefficient = useOrinalCoefficient(chainId);
|
||||||
|
|
||||||
const { data: markets } = useReadContracts({
|
const { data: markets } = useReadContracts({
|
||||||
contracts: liveIndexesRaw?.map((id) => ({
|
contracts: indexes?.map((id) => ({
|
||||||
abi: BondAbi,
|
abi: BondAbi,
|
||||||
address: BOND_DEPOSITORY_ADDRESSES[chainId],
|
address: BOND_DEPOSITORY_ADDRESSES[chainId],
|
||||||
functionName: "markets",
|
functionName: "markets",
|
||||||
@ -51,7 +57,7 @@ export const useLiveBonds = (chainId, chainName) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { data: terms } = useReadContracts({
|
const { data: terms } = useReadContracts({
|
||||||
contracts: liveIndexesRaw?.map((id) => ({
|
contracts: indexes?.map((id) => ({
|
||||||
abi: BondAbi,
|
abi: BondAbi,
|
||||||
address: BOND_DEPOSITORY_ADDRESSES[chainId],
|
address: BOND_DEPOSITORY_ADDRESSES[chainId],
|
||||||
functionName: "terms",
|
functionName: "terms",
|
||||||
@ -62,7 +68,7 @@ export const useLiveBonds = (chainId, chainName) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { data: metas } = useReadContracts({
|
const { data: metas } = useReadContracts({
|
||||||
contracts: liveIndexesRaw?.map((id) => ({
|
contracts: indexes?.map((id) => ({
|
||||||
abi: BondAbi,
|
abi: BondAbi,
|
||||||
address: BOND_DEPOSITORY_ADDRESSES[chainId],
|
address: BOND_DEPOSITORY_ADDRESSES[chainId],
|
||||||
functionName: "metadatas",
|
functionName: "metadatas",
|
||||||
@ -73,7 +79,7 @@ export const useLiveBonds = (chainId, chainName) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { data: marketPrices } = useReadContracts({
|
const { data: marketPrices } = useReadContracts({
|
||||||
contracts: liveIndexesRaw?.map((id) => ({
|
contracts: indexes?.map((id) => ({
|
||||||
abi: BondAbi,
|
abi: BondAbi,
|
||||||
address: BOND_DEPOSITORY_ADDRESSES[chainId],
|
address: BOND_DEPOSITORY_ADDRESSES[chainId],
|
||||||
functionName: "marketPrice",
|
functionName: "marketPrice",
|
||||||
@ -86,7 +92,7 @@ export const useLiveBonds = (chainId, chainName) => {
|
|||||||
const { data: quotePrices } = useReadContracts({
|
const { data: quotePrices } = useReadContracts({
|
||||||
contracts: markets?.map((_, index) => {
|
contracts: markets?.map((_, index) => {
|
||||||
const quoteTokenDecimals = metas?.at(index).result?.at(5) ? metas.at(index).result.at(5) : 18;
|
const quoteTokenDecimals = metas?.at(index).result?.at(5) ? metas.at(index).result.at(5) : 18;
|
||||||
const quoteTokenAddress = markets?.at(index).result?.at(1) ? markets.at(index).result.at(1) : "";
|
const quoteTokenAddress = markets?.at(index).result?.at(3) ? markets.at(index).result.at(3) : "";
|
||||||
const one = 10n ** BigInt(quoteTokenDecimals);
|
const one = 10n ** BigInt(quoteTokenDecimals);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -102,7 +108,7 @@ export const useLiveBonds = (chainId, chainName) => {
|
|||||||
|
|
||||||
const { data: markdowns } = useReadContracts({
|
const { data: markdowns } = useReadContracts({
|
||||||
contracts: markets?.map((_, index) => {
|
contracts: markets?.map((_, index) => {
|
||||||
const quoteTokenAddress = markets?.at(index).result?.at(1) ? markets.at(index).result.at(1) : "";
|
const quoteTokenAddress = markets?.at(index).result?.at(3) ? markets.at(index).result.at(3) : "";
|
||||||
return {
|
return {
|
||||||
abi: BondingCalculatorAbi,
|
abi: BondingCalculatorAbi,
|
||||||
address: BONDING_CALCULATOR_ADDRESSES[chainId],
|
address: BONDING_CALCULATOR_ADDRESSES[chainId],
|
||||||
@ -114,18 +120,19 @@ export const useLiveBonds = (chainId, chainName) => {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const { symbols: quoteTokenSymbols } = useTokenSymbols(chainId, markets?.map(m => m.result?.at(1)));
|
const { symbols: quoteTokenSymbols } = useTokenSymbols(chainId, markets?.map(m => m.result?.at(3)));
|
||||||
const { symbol: baseTokenSymbol } = useTokenSymbol(chainId, "FTSO");
|
const { symbol: baseTokenSymbol } = useTokenSymbol(chainId, "FTSO");
|
||||||
|
|
||||||
const liveBonds = liveIndexesRaw ? liveIndexesRaw.map((bondIndex, index) => {
|
const bonds = indexes ? indexes.map((bondIndex, index) => {
|
||||||
const id = Number(bondIndex);
|
const id = Number(bondIndex);
|
||||||
|
|
||||||
const marketPrice = marketPrices?.at(index).result ? marketPrices.at(index).result : 0n;
|
const marketPrice = marketPrices?.at(index).result ? marketPrices.at(index).result : 0n;
|
||||||
const marketCapacity = markets?.at(index).result?.at(0) ? markets.at(index).result.at(0) : 0n;
|
const marketCapacity = markets?.at(index).result?.at(0) ? markets.at(index).result.at(0) : 0n;
|
||||||
const quoteTokenAddress = markets?.at(index).result?.at(1) ? markets.at(index).result.at(1) : "";
|
const quoteTokenAddress = markets?.at(index).result?.at(3) ? markets.at(index).result.at(3) : "";
|
||||||
const capacityInQuote = markets?.at(index).result?.at(2) ? markets.at(index).result.at(2) : 0n;
|
const capacityInQuote = markets?.at(index).result?.at(4) ? markets.at(index).result.at(4) : 0n;
|
||||||
const marketMaxPayout = markets?.at(index).result?.at(4) ? markets.at(index).result.at(4) : 0n;
|
const marketMaxPayout = markets?.at(index).result?.at(6) ? markets.at(index).result.at(6) : 0n;
|
||||||
const quoteTokenDecimals = metas?.at(index).result?.at(5) ? metas.at(index).result.at(5) : 18;
|
const quoteTokenDecimals = metas?.at(index).result?.at(5) ? metas.at(index).result.at(5) : 18;
|
||||||
|
|
||||||
const quoteTokenPerUsd = quotePrices?.at(index).result
|
const quoteTokenPerUsd = quotePrices?.at(index).result
|
||||||
? new DecimalBigNumber(quotePrices.at(index).result * (10n ** 9n), quoteTokenDecimals)
|
? new DecimalBigNumber(quotePrices.at(index).result * (10n ** 9n), quoteTokenDecimals)
|
||||||
: new DecimalBigNumber(0n, quoteTokenDecimals);
|
: new DecimalBigNumber(0n, quoteTokenDecimals);
|
||||||
@ -194,7 +201,8 @@ export const useLiveBonds = (chainId, chainName) => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}).sort((a, b) => (a.id > b.id ? -1 : 1)) : [];
|
}).sort((a, b) => (a.id > b.id ? -1 : 1)) : [];
|
||||||
return { liveBonds, refetch };
|
|
||||||
|
return { bonds };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useNotes = (chainId, address) => {
|
export const useNotes = (chainId, address) => {
|
||||||
@ -246,11 +254,11 @@ export const useNotes = (chainId, address) => {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const { symbols: quoteTokenSymbols } = useTokenSymbols(chainId, markets?.map(m => m.result?.at(1)));
|
const { symbols: quoteTokenSymbols } = useTokenSymbols(chainId, markets?.map(m => m.result?.at(3)));
|
||||||
|
|
||||||
const notes = indexesFor ? indexesFor.map((noteIndex, index) => {
|
const notes = indexesFor ? indexesFor.map((noteIndex, index) => {
|
||||||
const id = Number(noteIndex);
|
const id = Number(noteIndex);
|
||||||
const quoteTokenAddress = markets?.at(index).result?.at(1) ? markets.at(index).result.at(1) : "";
|
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 : "";
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -15,8 +15,7 @@ const UNSTAKE_ACTION_STAKE = "Unstake";
|
|||||||
const WRAP_ACTION_STAKE = "Wrap";
|
const WRAP_ACTION_STAKE = "Wrap";
|
||||||
const UNWRAP_ACTION_STAKE = "Unwrap";
|
const UNWRAP_ACTION_STAKE = "Unwrap";
|
||||||
|
|
||||||
// TODO: add bond later
|
const POSSIBLE_HISTORY_TYPES = [BRIDGE_IN, BRIDGE_OUT, DEX_ACTION, STAKE_ACTION, BOND_ACTION];
|
||||||
const POSSIBLE_HISTORY_TYPES = [BRIDGE_IN, BRIDGE_OUT, DEX_ACTION, STAKE_ACTION];
|
|
||||||
const DEFAULT_HISTORY_TYPES = [BRIDGE_IN, BRIDGE_OUT];
|
const DEFAULT_HISTORY_TYPES = [BRIDGE_IN, BRIDGE_OUT];
|
||||||
|
|
||||||
const HISTORY_PREFIX = "history";
|
const HISTORY_PREFIX = "history";
|
||||||
@ -34,6 +33,7 @@ const CONSTANTS = {
|
|||||||
bridgeIn: { key: BRIDGE_IN, name: BRIDGE_IN },
|
bridgeIn: { key: BRIDGE_IN, name: BRIDGE_IN },
|
||||||
bridgeOut: { key: BRIDGE_OUT, name: BRIDGE_OUT },
|
bridgeOut: { key: BRIDGE_OUT, name: BRIDGE_OUT },
|
||||||
dex: { key: DEX_ACTION, swap: DEX_ACTION_SWAP, add: DEX_ACTION_ADD },
|
dex: { key: DEX_ACTION, swap: DEX_ACTION_SWAP, add: DEX_ACTION_ADD },
|
||||||
|
bond: { key: BOND_ACTION, name: BOND_ACTION },
|
||||||
stake: {
|
stake: {
|
||||||
key: STAKE_ACTION,
|
key: STAKE_ACTION,
|
||||||
stake: STAKE_ACTION_STAKE,
|
stake: STAKE_ACTION_STAKE,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user