fix forceRedeem representation in history; small UI fixes based on the UI revisions
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
parent
d183478e6b
commit
b65ab19873
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ghost-dao-interface",
|
||||
"private": true,
|
||||
"version": "0.8.8",
|
||||
"version": "0.8.9",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@ -26,6 +26,7 @@ import { formatCurrency } from "../../helpers";
|
||||
import { useLocalStorage } from "../../hooks/localstorage";
|
||||
import { useLiveBonds } from "../../hooks/bonds";
|
||||
import { useFtsoPrice } from "../../hooks/prices";
|
||||
import { useTokenSymbol } from "../../hooks/tokens";
|
||||
|
||||
const SLIPPAGE_PREFIX = "bond-slippage";
|
||||
const DECIMALS_PREFIX = "bond-decimals";
|
||||
@ -52,6 +53,8 @@ export const BondModal = ({ bond, chainId, address, config, connect }) => {
|
||||
const [isSettingsOpen, setSettingsOpen] = useState(false);
|
||||
const { useStorageValue, setStorageValue } = useLocalStorage();
|
||||
|
||||
const { symbol } = useTokenSymbol(chainId, "FTSO");
|
||||
|
||||
const { data: slippage } = useStorageValue(chainId, address, SLIPPAGE_PREFIX, "10");
|
||||
const { data: formatDecimals } = useStorageValue(chainId, address, DECIMALS_PREFIX, "5");
|
||||
const { data: recipientAddress } = useStorageValue(chainId, address, RECIPIENT_PREFIX, address);
|
||||
@ -94,21 +97,18 @@ export const BondModal = ({ bond, chainId, address, config, connect }) => {
|
||||
}, [config]);
|
||||
|
||||
const preparedQuoteToken = useMemo(() => {
|
||||
if (isNetworkLegacy(chainId)) {
|
||||
return {
|
||||
address: bond.quoteToken.quoteTokenAddress,
|
||||
chainNames: bond.quoteToken.chainNames,
|
||||
icons: bond.quoteToken.icons,
|
||||
name: bond.quoteToken.name,
|
||||
}
|
||||
return {
|
||||
address: bond.quoteToken.quoteTokenAddress,
|
||||
chainNames: bond.quoteToken.chainNames,
|
||||
icons: bond.quoteToken.icons,
|
||||
name: bond.quoteToken.name,
|
||||
}
|
||||
return { address: undefined, icons: [chainSymbol], name: chainSymbol };
|
||||
}, [bond, chainSymbol, chainId])
|
||||
}, [bond, chainSymbol, chainId]);
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<PageTitle
|
||||
subtitle="We need this one just for alignment"
|
||||
subtitle={`(1, 1) Buy ${symbol} at a treasury-backed discount.`}
|
||||
name={
|
||||
<Box display="flex" flexDirection="row" alignItems="center">
|
||||
<TokenStack
|
||||
|
||||
@ -46,6 +46,8 @@ const BondInputArea = ({
|
||||
const { symbol: ftsoSymbol } = useTokenSymbol(chainId, "FTSO");
|
||||
const { symbol: ghstSymbol } = useTokenSymbol(chainId, "GHST");
|
||||
|
||||
const { balance: ftsoBalance } = useBalance(chainId, "FTSO", address);
|
||||
|
||||
const [amount, setAmount] = useState("");
|
||||
const [confirmOpen, setConfirmOpen] = useState(false);
|
||||
|
||||
@ -132,8 +134,6 @@ const BondInputArea = ({
|
||||
iconNotNeeded
|
||||
UpperSwapCard={
|
||||
<SwapCard
|
||||
maxWidth="390px"
|
||||
inputWidth={isVerySmallScreen ? "100px" : isSemiSmallScreen ? "180px" : "250px"}
|
||||
id="from"
|
||||
token={
|
||||
<TokenStack
|
||||
@ -143,7 +143,7 @@ const BondInputArea = ({
|
||||
/>
|
||||
}
|
||||
tokenName={preparedQuoteToken.name}
|
||||
info={formatCurrency(balance, formatDecimals, preparedQuoteToken.name)}
|
||||
info={(!isSemiSmallScreen ? "Balance: " : "") + formatCurrency(balance, formatDecimals, preparedQuoteToken.name)}
|
||||
endString="Max"
|
||||
endStringOnClick={setMax}
|
||||
value={amount}
|
||||
@ -152,8 +152,6 @@ const BondInputArea = ({
|
||||
/>}
|
||||
LowerSwapCard={
|
||||
<SwapCard
|
||||
maxWidth="390px"
|
||||
inputWidth={isVerySmallScreen ? "100px" : isSemiSmallScreen ? "180px" : "250px"}
|
||||
id="to"
|
||||
token={
|
||||
<TokenStack
|
||||
@ -162,6 +160,7 @@ const BondInputArea = ({
|
||||
sx={{ fontSize: "25px", height: "30px" }}
|
||||
/>
|
||||
}
|
||||
info={(!isSemiSmallScreen ? "Balance: " : "") + formatCurrency(ftsoBalance, formatDecimals, ftsoSymbol)}
|
||||
tokenName={bond.baseToken.name}
|
||||
value={amountInBaseToken.toString({ decimals: 9 })}
|
||||
inputProps={{ "data-testid": "toInput" }}
|
||||
|
||||
@ -67,7 +67,7 @@ const BondSettingsModal = props => {
|
||||
</Box>
|
||||
<Box mt="8px">
|
||||
<Typography variant="body2" color="textSecondary">
|
||||
Choose recipient address. By default, this is your currently connected address
|
||||
Custom recipient address of bonded assets
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
@ -10,7 +10,7 @@ import GhostStyledIcon from "../../components/Icon/GhostIcon";
|
||||
|
||||
import { shorten } from "../../helpers";
|
||||
|
||||
export const BridgeGhostAddressCard = ({ receiver, setReceiver, isCard }) => {
|
||||
export const BridgeGhostAddressCard = ({ receiver, setReceiver, isCard, readOnly = false }) => {
|
||||
const [inputFocused, setInputFocused] = useState(false);
|
||||
const [innerReceiver, setInnerReceiver] = useState(receiver);
|
||||
|
||||
@ -26,9 +26,12 @@ export const BridgeGhostAddressCard = ({ receiver, setReceiver, isCard }) => {
|
||||
}
|
||||
}, [innerReceiver]);
|
||||
|
||||
console.log(readOnly)
|
||||
|
||||
if (isCard) {
|
||||
return (
|
||||
<SwapCard
|
||||
readOnly={readOnly}
|
||||
id={`bridge-token-receiver-card`}
|
||||
inputWidth={"100%"}
|
||||
onBlur={() => setInputFocused(true)}
|
||||
@ -54,6 +57,7 @@ export const BridgeGhostAddressCard = ({ receiver, setReceiver, isCard }) => {
|
||||
return (
|
||||
<FormControl variant="outlined" color="primary" fullWidth>
|
||||
<OutlinedInput
|
||||
readOnly={readOnly}
|
||||
inputProps={{ "data-testid": "custom-destination-input" }}
|
||||
id="custom-destination-input"
|
||||
onBlur={() => setInputFocused(true)}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { useEffect, useState, useMemo, useCallback, useRef } from "react";
|
||||
import { useEffect, useState, useMemo, useCallback } from "react";
|
||||
import { useLocation } from "react-router-dom";
|
||||
import { ss58Decode } from "@polkadot-labs/hdkd-helpers";
|
||||
import { toHex } from "@polkadot-api/utils";
|
||||
@ -28,6 +28,7 @@ import DataRow from "../../components/DataRow/DataRow";
|
||||
import { PrimaryButton } from "../../components/Button";
|
||||
|
||||
import { BridgeInSettingsModal } from "./BridgeSettingsModal";
|
||||
import { BridgeInConfirmationModal } from "./BridgeInConfirmationModal";
|
||||
|
||||
import {
|
||||
ghost,
|
||||
@ -54,12 +55,27 @@ const BridgeStatusCard = ({ progressPercent, totalValidators, pendingValidators,
|
||||
<Box mt="30px" sx={{ mb: { xs: "0px", md: "-30px" }}}>
|
||||
<Box display="flex" justifyContent="space-between" alignItems="center" mt="2px">
|
||||
<Typography variant="caption" fontWeight="bold">
|
||||
{tapestryDraft ? "Round 2: Merkle Root Verification" : "Round 1: Block Consensus"}
|
||||
{tapestryDraft
|
||||
? <Box display="flex" flexDirection="row" gap="5px">
|
||||
<Typography variant="caption" sx={{ fontWeight: "700" }}>Round 2:</Typography>
|
||||
<Typography variant="caption">Merkle Root Verification</Typography>
|
||||
</Box>
|
||||
: <Box display="flex" flexDirection="row" gap="5px">
|
||||
<Typography variant="caption" sx={{ fontWeight: "700" }}>Round 1:</Typography>
|
||||
<Typography variant="caption">Block Consensus</Typography>
|
||||
</Box>
|
||||
}
|
||||
</Typography>
|
||||
<Typography variant="caption">
|
||||
{tapestryDraft
|
||||
? `Block: ${formatNumber(tapestryDraft.median)} (${pendingValidators} out of ${totalValidators} validators)`
|
||||
: `Blocks Pending... (${pendingValidators} out of ${totalValidators} validators)`
|
||||
? <Box display="flex" flexDirection="row" gap="5px">
|
||||
<Typography variant="caption" sx={{ fontWeight: "700" }}>Block:</Typography>
|
||||
<Typography variant="caption">{`${formatNumber(tapestryDraft.median)} (${pendingValidators} out of ${totalValidators} validators)`}</Typography>
|
||||
</Box>
|
||||
: <Box display="flex" flexDirection="row" gap="5px">
|
||||
<Typography variant="caption" sx={{ fontWeight: "700" }}>Blocks:</Typography>
|
||||
<Typography variant="caption">{`Pending... (${pendingValidators} out of ${totalValidators} validators)`}</Typography>
|
||||
</Box>
|
||||
}
|
||||
</Typography>
|
||||
</Box>
|
||||
@ -91,7 +107,7 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
const [msSinceLastBlock, setMsSinceLastBlock] = useState(0);
|
||||
const [nextEraIn, setNextEraIn] = useState(null);
|
||||
const [settingsOpen, setSettingsOpen] = useState(false);
|
||||
const [isPending, setIsPending] = useState(false);
|
||||
const [confirmOpen, setConfirmOpen] = useState(false);
|
||||
const [amount, setAmount] = useState("");
|
||||
const [receiver, setReceiver] = useState(account);
|
||||
const [customReceiver, setCustomReceiver] = useState(account);
|
||||
@ -115,6 +131,25 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
}
|
||||
);
|
||||
|
||||
const { data: accountBalanceRaw } = useSWR(
|
||||
client ? ['accountBalance', client] : null,
|
||||
() => casperApi.query.System.Account.getValue(account),
|
||||
{
|
||||
refreshInterval: 12000,
|
||||
revalidateOnFocus: true
|
||||
}
|
||||
);
|
||||
|
||||
const accountBalance = useMemo(() => {
|
||||
const decimals = chainProperties ? chainProperties.properties.tokenDecimals : 18;
|
||||
if (!accountBalanceRaw) return new DecimalBigNumber(0n, decimals);
|
||||
const balance = accountBalanceRaw.data.free
|
||||
+ accountBalanceRaw.data.frozen
|
||||
+ accountBalanceRaw.data.reserved;
|
||||
|
||||
return new DecimalBigNumber(balance, decimals);
|
||||
}, [accountBalanceRaw, chainProperties]);
|
||||
|
||||
const { data: activeEraStart } = useSWR(
|
||||
casperApi ? ['activeEra', casperApi] : null,
|
||||
() => casperApi.query.Staking.ActiveEra.getValue(),
|
||||
@ -317,28 +352,8 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
const smallAmount = existentialDeposit.gt(preparedAmount);
|
||||
const insufficientAmount = preparedAmount.gt(ghstBalance);
|
||||
|
||||
return isPending || differentGatekeepers || smallAmount || insufficientAmount || !receiverHex
|
||||
}, [isPending, networkData, gatekeeperAddress, existentialDeposit, preparedAmount, ghstBalance, receiverHex]);
|
||||
|
||||
const latestRef = useRef({
|
||||
chainId,
|
||||
address,
|
||||
receiverHex,
|
||||
preparedAmount,
|
||||
tryStoreInHistory,
|
||||
ghstBalanceRefetch
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
latestRef.current = {
|
||||
chainId,
|
||||
address,
|
||||
receiverHex,
|
||||
preparedAmount,
|
||||
tryStoreInHistory,
|
||||
ghstBalanceRefetch
|
||||
};
|
||||
});
|
||||
return differentGatekeepers || smallAmount || insufficientAmount || !receiverHex
|
||||
}, [networkData, gatekeeperAddress, existentialDeposit, preparedAmount, ghstBalance, receiverHex]);
|
||||
|
||||
const setFormatDecimals = useCallback((value) => {
|
||||
if (Number(value) <= 17) {
|
||||
@ -347,38 +362,14 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
}, [chainId, address]);
|
||||
|
||||
const startGhostBridge = async () => {
|
||||
setIsPending(true);
|
||||
|
||||
const {
|
||||
chainId: currentChainId,
|
||||
address: currentAddress,
|
||||
receiverHex: currentReceiverHex,
|
||||
preparedAmount: currentPreparedAmount,
|
||||
tryStoreInHistory: currentTryStoreInHistory,
|
||||
ghstBalanceRefetch: currentGhstBalanceRefetch
|
||||
} = latestRef.current;
|
||||
|
||||
try {
|
||||
const txHash = await ghost(
|
||||
currentChainId,
|
||||
currentAddress,
|
||||
currentReceiverHex,
|
||||
currentPreparedAmount._value
|
||||
);
|
||||
|
||||
const txHash = await ghost(chainId, address, receiverHex, preparedAmount._value);
|
||||
if (txHash) {
|
||||
currentTryStoreInHistory(
|
||||
currentChainId,
|
||||
currentAddress,
|
||||
CONSTANTS.bridgeIn.key,
|
||||
txHash,
|
||||
CONSTANTS.bridgeIn.name
|
||||
);
|
||||
tryStoreInHistory(chainId, address, CONSTANTS.bridgeIn.key, txHash, CONSTANTS.bridgeIn.name);
|
||||
}
|
||||
} finally {
|
||||
await currentGhstBalanceRefetch();
|
||||
await ghstBalanceRefetch();
|
||||
setAmount("");
|
||||
setIsPending(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -412,15 +403,28 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
|
||||
return (
|
||||
<Box minHeight="calc(100vh - 43px)">
|
||||
<PageTitle name="GHOST Bridge-In" subtitle={`${bridgeNumbers()} Bridge-In ${ghstSymbol ? ghstSymbol : "CSPR"} into ${bridgeNumbers()} Stake\u00B2`} />
|
||||
<PageTitle name="GHOST Bridge-In" subtitle={`${bridgeNumbers()} Bridge-In to ${bridgeNumbers()} Stake\u00B2`} />
|
||||
<Container
|
||||
style={{
|
||||
paddingLeft: isSmallScreen || isVerySmallScreen ? "0" : "3.3rem",
|
||||
paddingRight: isSmallScreen || isVerySmallScreen ? "0" : "3.3rem",
|
||||
}}
|
||||
>
|
||||
<BridgeInConfirmationModal
|
||||
isOpen={confirmOpen}
|
||||
onClose={() => setConfirmOpen(false)}
|
||||
preparedAmount={preparedAmount}
|
||||
estimatedOutAmount={estimatedOutAmount}
|
||||
formatDecimals={formatDecimals}
|
||||
ghstSymbol={ghstSymbol}
|
||||
nativeSymbol={nativeSymbol}
|
||||
externalSymbol={chainProperties ? chainProperties.properties.tokenSymbol : "CSPR"}
|
||||
receiver={customReceiver ? customReceiver : receiver}
|
||||
sender={address}
|
||||
startGhostBridge={startGhostBridge}
|
||||
/>
|
||||
<BridgeInSettingsModal
|
||||
isOpen={settingsOpen && !isPending}
|
||||
isOpen={settingsOpen}
|
||||
onClose={() => setSettingsOpen(false)}
|
||||
decimals={formatDecimals}
|
||||
setDecimals={setFormatDecimals}
|
||||
@ -433,9 +437,9 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
enableBackground
|
||||
headerContent={
|
||||
<Box display="flex" gap="5px">
|
||||
<Typography>Next Era in</Typography>
|
||||
<Typography variant="h6">Next Era in</Typography>
|
||||
{nextEraIn
|
||||
? <Typography>{nextEraIn}</Typography>
|
||||
? <Typography sx={{ fontWeight: "700" }} variant="h6">{nextEraIn}</Typography>
|
||||
: <Skeleton width="120px" />
|
||||
}
|
||||
</Box>
|
||||
@ -496,8 +500,6 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
iconNotNeeded
|
||||
UpperSwapCard={
|
||||
<SwapCard
|
||||
maxWidth="390px"
|
||||
inputWidth={isVerySmallScreen ? "100px" : isSemiSmallScreen ? "180px" : "250px"}
|
||||
id="from"
|
||||
token={
|
||||
<TokenStack
|
||||
@ -507,7 +509,7 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
/>
|
||||
}
|
||||
tokenName={ghstSymbol}
|
||||
info={formatCurrency(ghstBalance.toString(), formatDecimals, ghstSymbol)}
|
||||
info={(!isSemiSmallScreen ? "Balance: " : "") + formatCurrency(ghstBalance.toString(), formatDecimals, ghstSymbol)}
|
||||
endString="Max"
|
||||
value={amount}
|
||||
endStringOnClick={() => setAmount(ghstBalance.toString())}
|
||||
@ -516,8 +518,6 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
/>}
|
||||
LowerSwapCard={
|
||||
<SwapCard
|
||||
maxWidth="390px"
|
||||
inputWidth={isVerySmallScreen ? "100px" : isSemiSmallScreen ? "180px" : "250px"}
|
||||
id="to"
|
||||
token={
|
||||
<TokenStack
|
||||
@ -526,6 +526,14 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
sx={{ fontSize: "25px", height: "30px" }}
|
||||
/>
|
||||
}
|
||||
info={
|
||||
(!isSemiSmallScreen ? "Balance: " : "") +
|
||||
formatCurrency(
|
||||
accountBalance.toString(),
|
||||
formatDecimals,
|
||||
chainProperties ? chainProperties.properties.tokenSymbol : "CSPR",
|
||||
)
|
||||
}
|
||||
tokenName={"GHST"}
|
||||
value={estimatedOutAmount}
|
||||
inputProps={{ "data-testid": "toInput" }}
|
||||
@ -542,9 +550,9 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
<PrimaryButton
|
||||
fullWidth
|
||||
disabled={!gatekeepersMatch || actionDisabled}
|
||||
onClick={startGhostBridge}
|
||||
onClick={() => setConfirmOpen(true)}
|
||||
>
|
||||
{isPending ? "Pending..." : "Bridge-In"}
|
||||
Bridge-In
|
||||
</PrimaryButton>
|
||||
</Box>
|
||||
</Paper>
|
||||
|
||||
165
src/containers/Bridge/BridgeInConfirmationModal.jsx
Normal file
165
src/containers/Bridge/BridgeInConfirmationModal.jsx
Normal file
@ -0,0 +1,165 @@
|
||||
import { useState } from "react";
|
||||
import { Box, Typography, Link } from "@mui/material";
|
||||
|
||||
import CloseIcon from '@mui/icons-material/Close';
|
||||
import CheckIcon from '@mui/icons-material/Check';
|
||||
import ContentPasteIcon from '@mui/icons-material/ContentPaste';
|
||||
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
|
||||
|
||||
import GhostStyledIcon from "../../components/Icon/GhostIcon";
|
||||
import Metric from "../../components/Metric/Metric";
|
||||
import Modal from "../../components/Modal/Modal";
|
||||
import TokenStack from "../../components/TokenStack/TokenStack";
|
||||
import DataRow from "../../components/DataRow/DataRow";
|
||||
import { PrimaryButton, SecondaryButton } from "../../components/Button";
|
||||
|
||||
import { formatNumber, shorten } from "../../helpers";
|
||||
|
||||
import { BridgeGhostAddressCard } from "./BridgeGhostAddress";
|
||||
|
||||
export const BridgeInConfirmationModal = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
preparedAmount,
|
||||
estimatedOutAmount,
|
||||
formatDecimals,
|
||||
externalSymbol,
|
||||
ghstSymbol,
|
||||
nativeSymbol,
|
||||
receiver,
|
||||
sender,
|
||||
startGhostBridge
|
||||
}) => {
|
||||
const [isPending, setIsPending] = useState(false);
|
||||
const [copiedIndex, setCopiedIndex] = useState(null);
|
||||
|
||||
const copyToClipboard = (text, index) => {
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
setCopiedIndex(index);
|
||||
setTimeout(() => setCopiedIndex(null) , 800);
|
||||
});
|
||||
};
|
||||
|
||||
const onSubmit = async () => {
|
||||
setIsPending(true);
|
||||
|
||||
try {
|
||||
await startGhostBridge();
|
||||
} finally {
|
||||
setIsPending(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
maxWidth="426px"
|
||||
minHeight="200px"
|
||||
open={isOpen}
|
||||
headerContent={<Typography variant="h4">Confirm Bridge-In</Typography>}
|
||||
onClose={!isPending && onClose}
|
||||
topRight={
|
||||
<GhostStyledIcon
|
||||
viewBox="0 0 23 23"
|
||||
component={CloseIcon}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<Box display="flex" flexDirection="column">
|
||||
<Box display="flex" flexDirection="row" justifyContent="space-between" alignItems="center">
|
||||
<Box display="flex" flexDirection="column">
|
||||
<Metric
|
||||
label="To Bridge"
|
||||
metric={formatNumber(preparedAmount, formatDecimals)}
|
||||
/>
|
||||
<Box
|
||||
sx={{ background: "" }}
|
||||
height="120px"
|
||||
display="flex"
|
||||
flexDirection="column"
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
>
|
||||
<TokenStack
|
||||
parentSx={{
|
||||
height: "80px",
|
||||
"& svg:nth-of-type(2)": {
|
||||
transform: "translate(50%, -30%)",
|
||||
zIndex: 100,
|
||||
}
|
||||
}}
|
||||
sx={{ transform: "scale(1.65)", }}
|
||||
tokens={[ghstSymbol]}
|
||||
chainTokenNames={[nativeSymbol]}
|
||||
/>
|
||||
<Typography>{ghstSymbol}</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
<GhostStyledIcon sx={{ transform: "rotate(-90deg)" }} component={ArrowDropDownIcon} />
|
||||
<Box display="flex" flexDirection="column">
|
||||
<Metric label="To Receive" metric={formatNumber(estimatedOutAmount, formatDecimals)} />
|
||||
<Box
|
||||
sx={{ background: "" }}
|
||||
height="120px"
|
||||
display="flex"
|
||||
flexDirection="column"
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
gap="0"
|
||||
>
|
||||
<TokenStack
|
||||
parentSx={{
|
||||
height: "80px",
|
||||
"& svg:nth-of-type(2)": {
|
||||
transform: "translate(50%, -30%)",
|
||||
zIndex: 100,
|
||||
}
|
||||
}}
|
||||
sx={{ transform: "scale(1.65)", }}
|
||||
tokens={[externalSymbol]}
|
||||
/>
|
||||
<Typography>{externalSymbol}</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
<Box pb="20px" pt="20px" display="flex" flexDirection="column">
|
||||
<Box display="flex" flexDirection="row" justifyContent="space-between">
|
||||
<Typography>Sender Address</Typography>
|
||||
<Link
|
||||
style={{ display: "flex", flexDirection: "row", justifyContent: "center", alignItems: "center" }}
|
||||
onClick={() => copyToClipboard(sender, 0)}
|
||||
>
|
||||
<Typography>{sender ? shorten(sender, 10, -8) : ""}</Typography>
|
||||
<GhostStyledIcon
|
||||
sx={{ marginLeft: "5px", width: "12px", height: "12px" }}
|
||||
viewBox="0 0 25 25"
|
||||
component={copiedIndex === 0 ? CheckIcon : ContentPasteIcon}
|
||||
/>
|
||||
</Link>
|
||||
</Box>
|
||||
<Box display="flex" flexDirection="row" justifyContent="space-between">
|
||||
<Typography>Destination Address</Typography>
|
||||
<Link
|
||||
style={{ display: "flex", flexDirection: "row", justifyContent: "center", alignItems: "center" }}
|
||||
onClick={() => copyToClipboard(receiver, 1)}
|
||||
>
|
||||
<Typography>{receiver ? shorten(receiver, 10, -8) : ""}</Typography>
|
||||
<GhostStyledIcon
|
||||
sx={{ marginLeft: "5px", width: "12px", height: "12px" }}
|
||||
viewBox="0 0 25 25"
|
||||
component={copiedIndex === 1 ? CheckIcon : ContentPasteIcon}
|
||||
/>
|
||||
</Link>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<PrimaryButton
|
||||
fullWidth
|
||||
disabled={isPending}
|
||||
onClick={onSubmit}
|
||||
>
|
||||
{isPending ? "Pending..." : "Confirm"}
|
||||
</PrimaryButton>
|
||||
</Box>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
197
src/containers/History/AddRecordModal.jsx
Normal file
197
src/containers/History/AddRecordModal.jsx
Normal file
@ -0,0 +1,197 @@
|
||||
import { isHash, hexToNumber, decodeEventLog, decodeFunctionData } from 'viem';
|
||||
import { useTransactionReceipt, useBlockNumber, useTransaction } from 'wagmi';
|
||||
import { useState, useMemo } from "react";
|
||||
import { Box, Typography, FormControl, OutlinedInput } from "@mui/material";
|
||||
|
||||
import Modal from "../../components/Modal/Modal";
|
||||
import GhostStyledIcon from "../../components/Icon/GhostIcon";
|
||||
import { PrimaryButton } from "../../components/Button";
|
||||
|
||||
import { shorten } from "../../helpers";
|
||||
import { useLocalStorage } from "../../hooks/localstorage";
|
||||
|
||||
import CheckIcon from '@mui/icons-material/CheckCircle';
|
||||
import PendingIcon from '@mui/icons-material/Pending';
|
||||
import CancelIcon from '@mui/icons-material/Cancel';
|
||||
|
||||
import {
|
||||
STAKING_ADDRESSES,
|
||||
BOND_DEPOSITORY_ADDRESSES,
|
||||
UNISWAP_V2_ROUTER
|
||||
} from "../../constants/addresses";
|
||||
|
||||
import { abi as UniswapV2RouterAbi } from "../../abi/UniswapV2Router.json";
|
||||
import { abi as GhostStakingAbi } from "../../abi/GhostStaking.json"
|
||||
import { abi as GatekeeperAbi } from "../../abi/GhostGatekeeper.json";
|
||||
import { abi as UniswapV2PairAbi } from "../../abi/UniswapV2Pair.json";
|
||||
import { abi as GhostBondDepositoryAbi } from "../../abi/GhostBondDepository.json";
|
||||
import { abi as ERC20TokenAbi } from "../../abi/ERC20.json";
|
||||
|
||||
const ABIS = [GatekeeperAbi, UniswapV2PairAbi, GhostBondDepositoryAbi, ERC20TokenAbi, GhostStakingAbi, UniswapV2RouterAbi]
|
||||
|
||||
const AddRecordModal = ({ chainId, address, isOpen, close }) => {
|
||||
const [txHash, setTxHash] = useState("");
|
||||
const isValidTxHash = isHash(txHash);
|
||||
|
||||
const { tryStoreInHistory, CONSTANTS } = useLocalStorage();
|
||||
|
||||
const { data: txData } = useTransaction({
|
||||
chainId,
|
||||
hash: isValidTxHash ? txHash : null,
|
||||
});
|
||||
|
||||
const { data: receipt } = useTransactionReceipt({
|
||||
hash: isValidTxHash ? txHash : null,
|
||||
query: {
|
||||
enabled: isValidTxHash
|
||||
}
|
||||
});
|
||||
|
||||
const functionCall = useMemo(() => {
|
||||
let functionCall = null;
|
||||
for (const abi of ABIS) {
|
||||
try {
|
||||
const decodedFunction = decodeFunctionData({ abi, data: txData.input });
|
||||
functionCall = {
|
||||
name: decodedFunction.functionName,
|
||||
args: decodedFunction.args,
|
||||
address: txData?.to?.toLowerCase(),
|
||||
};
|
||||
break;
|
||||
} catch (e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return functionCall;
|
||||
}, [receipt, txData]);
|
||||
|
||||
const transactionType = useMemo(() => {
|
||||
switch (functionCall?.name) {
|
||||
case "forceRedeem":
|
||||
if (functionCall?.address !== BOND_DEPOSITORY_ADDRESSES[chainId]?.toLowerCase()) return null;
|
||||
return { key: CONSTANTS.bridgeIn.key, name: CONSTANTS.bridgeIn.name };
|
||||
case "ghost":
|
||||
if (functionCall?.address !== STAKING_ADDRESSES[chainId]?.toLowerCase()) return null;
|
||||
return { key: CONSTANTS.bridgeIn.key, name: CONSTANTS.bridgeIn.name };
|
||||
case "redeem":
|
||||
if (functionCall?.address !== BOND_DEPOSITORY_ADDRESSES[chainId]?.toLowerCase()) return null;
|
||||
return { key: CONSTANTS.bond.key, name: CONSTANTS.bond.claim };
|
||||
case "deposit":
|
||||
if (functionCall?.address !== BOND_DEPOSITORY_ADDRESSES[chainId]?.toLowerCase()) return null;
|
||||
return { key: CONSTANTS.bond.key, name: CONSTANTS.bond.bond };
|
||||
case "stake":
|
||||
if (functionCall?.address !== STAKING_ADDRESSES[chainId]?.toLowerCase()) return null;
|
||||
return { key: CONSTANTS.stake.key, name: CONSTANTS.stake.stake };
|
||||
case "unstake":
|
||||
if (functionCall?.address !== STAKING_ADDRESSES[chainId]?.toLowerCase()) return null;
|
||||
return { key: CONSTANTS.stake.key, name: CONSTANTS.stake.unstake };
|
||||
case "wrap":
|
||||
if (functionCall?.address !== STAKING_ADDRESSES[chainId]?.toLowerCase()) return null;
|
||||
return { key: CONSTANTS.stake.key, name: CONSTANTS.stake.wrap };
|
||||
case "unwrap":
|
||||
if (functionCall?.address !== STAKING_ADDRESSES[chainId]?.toLowerCase()) return null;
|
||||
return { key: CONSTANTS.stake.key, name: CONSTANTS.stake.unwrap };
|
||||
|
||||
case "swapExactETHForTokens":
|
||||
case "swapExactTokensForTokens":
|
||||
case "swapTokensForExactTokens":
|
||||
case "swapTokensForExactETH":
|
||||
case "swapExactTokensForETH":
|
||||
case "swapETHForExactTokens":
|
||||
case "swapExactTokensForTokensSupportingFeeOnTransferTokens":
|
||||
case "swapExactETHForTokensSupportingFeeOnTransferTokens":
|
||||
case "swapExactTokensForETHSupportingFeeOnTransferTokens":
|
||||
if (functionCall?.address !== UNISWAP_V2_ROUTER[chainId]?.toLowerCase()) return null;
|
||||
return { key: CONSTANTS.dex.key, name: CONSTANTS.dex.swap };
|
||||
|
||||
case "addLiquidity":
|
||||
case "addLiquidityETH":
|
||||
if (functionCall?.address !== UNISWAP_V2_ROUTER[chainId]?.toLowerCase()) return null;
|
||||
return { key: CONSTANTS.dex.key, name: CONSTANTS.dex.add };
|
||||
|
||||
case "removeLiquidity":
|
||||
case "removeLiquidityETH":
|
||||
case "removeLiquidityWithPermit":
|
||||
case "removeLiquidityETHWithPermit":
|
||||
case "removeLiquidityETHSupportingFeeOnTransferTokens":
|
||||
case "removeLiquidityETHWithPermitSupportingFeeOnTransferTokens":
|
||||
if (functionCall?.address !== UNISWAP_V2_ROUTER[chainId]?.toLowerCase()) return null;
|
||||
return { key: CONSTANTS.dex.key, name: CONSTANTS.dex.remove };
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}, [functionCall]);
|
||||
|
||||
const submitted = useMemo(() => {
|
||||
if (!txData) return Date.now();
|
||||
const seconds = hexToNumber(txData?.blockTimestamp);
|
||||
const jsTimestamp = seconds * 1000;
|
||||
return new Date(jsTimestamp);
|
||||
}, [txData]);
|
||||
|
||||
const storeRecord = () => {
|
||||
tryStoreInHistory(chainId, address, transactionType.key, txHash, transactionType.name, true);
|
||||
close()
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
key="AddRecordModal"
|
||||
maxWidth="380px"
|
||||
minHeight="200px"
|
||||
open={isOpen}
|
||||
headerText="Add Record"
|
||||
onClose={() => close()}
|
||||
>
|
||||
<Box display="flex" flexDirection="column" justifyContent="space-between" gap="20px">
|
||||
<Box display="flex" flexDirection="column" gap="5px">
|
||||
<Typography>Transaction hash to be used in history</Typography>
|
||||
<FormControl variant="outlined" color="primary" fullWidth>
|
||||
<OutlinedInput
|
||||
inputProps={{ "data-testid": "add-record-tx-hash" }}
|
||||
id="add-record-tx-hash"
|
||||
onChange={event => setTxHash(event.currentTarget.value)}
|
||||
placeholder={isValidTxHash ? shorten(txHash, 17, -14) : "Transaction hash (0x prefixed)"}
|
||||
value={isValidTxHash ? "" : txHash}
|
||||
/>
|
||||
</FormControl>
|
||||
</Box>
|
||||
|
||||
{txData && transactionType &&
|
||||
<>
|
||||
<Box display="flex" flexDirection="column" gap="5px">
|
||||
<Typography>Block Submission Timestamp</Typography>
|
||||
<FormControl variant="outlined" color="primary" fullWidth>
|
||||
<OutlinedInput
|
||||
readOnly
|
||||
inputProps={{ "data-testid": "add-record-submitted" }}
|
||||
id="add-record-submitted"
|
||||
value={submitted.toLocaleString()}
|
||||
/>
|
||||
</FormControl>
|
||||
</Box>
|
||||
|
||||
<Box display="flex" flexDirection="column" gap="5px">
|
||||
<Typography>Transaction Type</Typography>
|
||||
<FormControl variant="outlined" color="primary" fullWidth>
|
||||
<OutlinedInput
|
||||
readOnly
|
||||
inputProps={{ "data-testid": "add-record-submitted" }}
|
||||
id="add-record-submitted"
|
||||
value={`${transactionType.name} / ${transactionType.name}`}
|
||||
/>
|
||||
</FormControl>
|
||||
</Box>
|
||||
</>
|
||||
}
|
||||
|
||||
<PrimaryButton disabled={!txData || !transactionType} fullWidth onClick={storeRecord}>
|
||||
{transactionType ? "Add Record" : "Unknown Transaction"}
|
||||
</PrimaryButton>
|
||||
</Box>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
export default AddRecordModal;
|
||||
@ -20,6 +20,8 @@ import DataRow from "../../components/DataRow/DataRow";
|
||||
import GhostStyledIcon from "../../components/Icon/GhostIcon";
|
||||
import { PrimaryButton } from "../../components/Button";
|
||||
import { abi as GatekeeperAbi } from "../../abi/GhostGatekeeper.json";
|
||||
import { abi as GhostBondDepositoryAbi } from "../../abi/GhostBondDepository.json";
|
||||
import { abi as ERC20TokenAbi } from "../../abi/ERC20.json";
|
||||
|
||||
import { executePapiBareTransaction } from "../../hooks/helpers";
|
||||
import { useWeaverRoot, useWeaverProof, useWeaverSlotValues, useWeaverMaximumSlots } from "../../hooks/staking"
|
||||
@ -57,11 +59,16 @@ const BridgeInModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
||||
|
||||
const functionArgs = useMemo(() => {
|
||||
if (!txData || !chainProperties) return null;
|
||||
const decoded = decodeFunctionData({ abi: GatekeeperAbi, data: txData.input });
|
||||
const prefix = chainProperties.properties.ss58Format;
|
||||
const receiverRaw = decoded?.args.at(0);
|
||||
const receiver = receiverRaw ? ss58Encode(receiverRaw, prefix) : null;
|
||||
return { receiver, amount: decoded?.args.at(1) };
|
||||
|
||||
try {
|
||||
const decoded = decodeFunctionData({ abi: GatekeeperAbi, data: txData.input });
|
||||
const prefix = chainProperties.properties.ss58Format;
|
||||
const receiverRaw = decoded?.args.at(0);
|
||||
const receiver = receiverRaw ? ss58Encode(receiverRaw, prefix) : null;
|
||||
return { receiver, amount: decoded?.args.at(1) };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}, [txData, chainProperties]);
|
||||
|
||||
const { data: networkData } = useSWR(
|
||||
@ -109,20 +116,34 @@ const BridgeInModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
||||
|
||||
return receipt.logs.map((log) => {
|
||||
try {
|
||||
const decoded = decodeEventLog({
|
||||
const decodedERC20 = decodeEventLog({
|
||||
abi: ERC20TokenAbi,
|
||||
data: log.data,
|
||||
topics: log.topics,
|
||||
});
|
||||
|
||||
return {
|
||||
eventName: decodedERC20.eventName,
|
||||
args: decodedERC20.args,
|
||||
address: log.address,
|
||||
};
|
||||
} catch (e) { }
|
||||
|
||||
try {
|
||||
const decodedGatekeeper = decodeEventLog({
|
||||
abi: GatekeeperAbi,
|
||||
data: log.data,
|
||||
topics: log.topics,
|
||||
});
|
||||
|
||||
return {
|
||||
eventName: decoded.eventName,
|
||||
args: decoded.args,
|
||||
address: log.address
|
||||
eventName: decodedGatekeeper.eventName,
|
||||
args: decodedGatekeeper.args,
|
||||
address: log.address,
|
||||
};
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
} catch (e) { }
|
||||
|
||||
return null;
|
||||
}).filter(Boolean);
|
||||
}, [receipt]);
|
||||
|
||||
@ -130,6 +151,10 @@ const BridgeInModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
||||
return allDecodedLogs.find(l => l.eventName === 'ThreadInserted');
|
||||
}, [allDecodedLogs]);
|
||||
|
||||
const transferInfo = useMemo(() => {
|
||||
return allDecodedLogs.find(l => l.eventName === 'Transfer');
|
||||
}, [allDecodedLogs]);
|
||||
|
||||
const { maximumSlots } = useWeaverMaximumSlots(chainId);
|
||||
const { merkleRoot: evmMerkleRoot } = useWeaverRoot(chainId, loomState?.at_block, bridgeInInfo?.args);
|
||||
const { merkleProof } = useWeaverProof(chainId, loomState?.at_block, bridgeInInfo?.args);
|
||||
@ -138,12 +163,20 @@ const BridgeInModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
||||
const localString = new Date(historyRecord.submitted).toLocaleString();
|
||||
|
||||
const bridgedAmount = useMemo(() => {
|
||||
if (!functionArgs) return null;
|
||||
return new DecimalBigNumber(
|
||||
functionArgs.amount,
|
||||
chainProperties?.properties.tokenDecimals ?? 18
|
||||
)
|
||||
}, [functionArgs, chainProperties]);
|
||||
if (functionArgs) {
|
||||
return new DecimalBigNumber(
|
||||
functionArgs.amount,
|
||||
chainProperties?.properties.tokenDecimals ?? 18
|
||||
)
|
||||
} else if (transferInfo) {
|
||||
return new DecimalBigNumber(
|
||||
transferInfo.args.value,
|
||||
chainProperties?.properties.tokenDecimals ?? 18
|
||||
)
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}, [functionArgs, transferInfo, chainProperties]);
|
||||
|
||||
const estimatedFee = useMemo(() => {
|
||||
if (!networkData) return null;
|
||||
@ -151,15 +184,28 @@ const BridgeInModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
||||
}, [networkData]);
|
||||
|
||||
const estimatedReceived = useMemo(() => {
|
||||
if (!functionArgs) return null;
|
||||
if (!networkData || !chainProperties) return null;
|
||||
|
||||
const hundredPercent = 1000000000;
|
||||
const incomingShare = networkData ? networkData.incoming_share : 0;
|
||||
const result = hundredPercent - incomingShare;
|
||||
const hundredPercent = 1000000000n;
|
||||
const incomingShare = networkData ? BigInt(networkData.incoming_share) : 0n;
|
||||
const result = hundredPercent - incomingShare
|
||||
|
||||
const value = Number(functionArgs.amount) * result / hundredPercent;
|
||||
return new DecimalBigNumber(value, chainProperties?.properties.tokenDecimals ?? 18)
|
||||
}, [functionArgs, networkData, chainProperties]);
|
||||
if (functionArgs) {
|
||||
const value = functionArgs.amount * result / hundredPercent;
|
||||
return new DecimalBigNumber(value, chainProperties.properties.tokenDecimals)
|
||||
} else if (transferInfo) {
|
||||
const value = transferInfo.args.value * result / hundredPercent;
|
||||
return new DecimalBigNumber(value, chainProperties.properties.tokenDecimals)
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}, [functionArgs, transferInfo, networkData, chainProperties]);
|
||||
|
||||
const estimatedReceiver = useMemo(() => {
|
||||
if (functionArgs) return functionArgs.receiver;
|
||||
if (transferInfo) return transferInfo.args.from;
|
||||
return null
|
||||
}, [functionArgs, transferInfo]);
|
||||
|
||||
const finalization = useMemo(() => {
|
||||
if (!receipt || !blockNumber || !networkData) return null;
|
||||
@ -313,10 +359,10 @@ const BridgeInModal = ({ chainId, isOpen, close, config, historyRecord }) => {
|
||||
balance={
|
||||
<Link
|
||||
style={{ display: "flex", flexDirection: "row", justifyContent: "center", alignItems: "center" }}
|
||||
onClick={() => functionArgs?.receiver ? copyToClipboard(functionArgs.receiver, 0) : {}}
|
||||
onClick={() => estimatedReceiver ? copyToClipboard(estimatedReceiver, 0) : {}}
|
||||
>
|
||||
<Typography variant="body1">
|
||||
{functionArgs?.receiver ? shorten(functionArgs.receiver, 11, -8) : <Skeleton width="120px" />}
|
||||
{estimatedReceiver ? shorten(estimatedReceiver, 11, -8) : <Skeleton width="120px" />}
|
||||
</Typography>
|
||||
<GhostStyledIcon
|
||||
sx={{ marginLeft: "5px", width: "12px", height: "12px" }}
|
||||
|
||||
@ -44,6 +44,7 @@ import DexViewModal from "./DexViewModal";
|
||||
import StakingViewModal from "./StakingViewModal";
|
||||
import BridgeInModal from "./BridgeInModal";
|
||||
import BondModal from "./BondModal";
|
||||
import AddRecordModal from "./AddRecordModal";
|
||||
|
||||
const HistoryItem = ({ item, chainId, config, currentTime, eraseRecord, setViewModalOpen, isSmallScreen, finalityDelay }) => {
|
||||
const theme = useTheme();
|
||||
@ -96,7 +97,7 @@ const HistoryItem = ({ item, chainId, config, currentTime, eraseRecord, setViewM
|
||||
</Box>
|
||||
|
||||
<Box display="flex" flexDirection="column" alignItems="flex-end">
|
||||
<Typography>{item?.name ?? "Unknown"}</Typography>
|
||||
<Typography>{item?.name ?? "Unknown"}{item?.isCustom ? " (Custom)" : ""}</Typography>
|
||||
{chipStatus}
|
||||
</Box>
|
||||
</Box>
|
||||
@ -116,7 +117,7 @@ const HistoryItem = ({ item, chainId, config, currentTime, eraseRecord, setViewM
|
||||
<Box display="flex" alignItems="center">
|
||||
<TokenStack chainTokenNames={["ETH"]} tokens={["FTSO"]} />
|
||||
<Box ml="10px" display="flex" flexDirection="column" alignItems="flex-start">
|
||||
<Typography>{item?.name ?? "Unknown"}</Typography>
|
||||
<Typography>{item?.name ?? "Unknown"}{item?.isCustom ? " (Custom)" : ""}</Typography>
|
||||
<Link
|
||||
href={`${chainInfo.url}/tx/${item.txHash}`}
|
||||
target="_blank"
|
||||
@ -289,6 +290,7 @@ const History = ({ chainId, config, tryConnectInjected, address }) => {
|
||||
const [erasingIndex, setErasingIndex] = useState(null);
|
||||
const [settingsOpen, setSettingsOpen] = useState(false);
|
||||
const [erasingOpen, setErasingOpen] = useState(false);
|
||||
const [addRecordOpen, setAddRecordOpen] = useState(false);
|
||||
|
||||
const location = useLocation();
|
||||
|
||||
@ -304,7 +306,12 @@ const History = ({ chainId, config, tryConnectInjected, address }) => {
|
||||
} = useLocalStorage();
|
||||
|
||||
const { data: storedHistoryTypes } = useStorageValue(chainId, address, CONSTANTS.historyPrefix, CONSTANTS.defaultHistoryTypes);
|
||||
const { data: storedTransactions } = useStorageValue(chainId, address, storedHistoryTypes[historyTypeIndex], []);
|
||||
const { data: storedTransactions, mutate: storedTransactionsMutate } = useStorageValue(
|
||||
chainId,
|
||||
address,
|
||||
storedHistoryTypes[historyTypeIndex],
|
||||
[]
|
||||
);
|
||||
|
||||
const { data: pendingHistory } = useStorageValue(chainId, address, CONSTANTS.pendingHistoryPrefix, {});
|
||||
|
||||
@ -329,7 +336,7 @@ const History = ({ chainId, config, tryConnectInjected, address }) => {
|
||||
|
||||
return (
|
||||
<Box minHeight="calc(100vh - 43px)">
|
||||
<PageTitle name="History" subtitle="A complete record of your activity on the ghostDAO protocol" />
|
||||
<PageTitle name="History" subtitle="Complete record of your ghostDAO activity" />
|
||||
<Container
|
||||
style={{
|
||||
paddingLeft: isSmallScreen || isVerySmallScreen ? "0" : "3.3rem",
|
||||
@ -347,6 +354,18 @@ const History = ({ chainId, config, tryConnectInjected, address }) => {
|
||||
isAll={erasingIndex === null}
|
||||
/>
|
||||
|
||||
<AddRecordModal
|
||||
chainId={chainId}
|
||||
address={address}
|
||||
key="AddRecordModal"
|
||||
isOpen={addRecordOpen}
|
||||
close={() => {
|
||||
setAddRecordOpen(false);
|
||||
storedTransactionsMutate();
|
||||
clearPendingHistory(chainId, address, storedHistoryTypes.at(historyTypeIndex));
|
||||
}}
|
||||
/>
|
||||
|
||||
<SettingsModal
|
||||
key="SettingsModal"
|
||||
isOpen={settingsOpen}
|
||||
@ -433,13 +452,27 @@ const History = ({ chainId, config, tryConnectInjected, address }) => {
|
||||
})}
|
||||
</Tabs>
|
||||
|
||||
<PrimaryButton
|
||||
fullWidth
|
||||
onClick={() => setErasingOpen(true)}
|
||||
sx={{ maxWidth: isSemiSmallScreen ? "100%" : "350px" }}
|
||||
<Box
|
||||
display="flex"
|
||||
justifyContent="center"
|
||||
gap={isSmallScreen ? "5px" : "20px"}
|
||||
width={isSmallScreen ? "100%" : "380px"}
|
||||
flexDirection={isSmallScreen ? "column" : "row"}
|
||||
>
|
||||
Erase All Records
|
||||
</PrimaryButton>
|
||||
<TertiaryButton
|
||||
fullWidth
|
||||
onClick={() => setAddRecordOpen(true)}
|
||||
>
|
||||
Add Record
|
||||
</TertiaryButton>
|
||||
|
||||
<PrimaryButton
|
||||
fullWidth
|
||||
onClick={() => setErasingOpen(true)}
|
||||
>
|
||||
Erase All Records
|
||||
</PrimaryButton>
|
||||
</Box>
|
||||
</Box>
|
||||
}
|
||||
>
|
||||
|
||||
@ -15,13 +15,13 @@ const SettingsModal = ({ isOpen, close, submit, selectedValues, possibleValues,
|
||||
return (
|
||||
<Modal
|
||||
key="SettingsModal"
|
||||
maxWidth="350px"
|
||||
maxWidth="320px"
|
||||
minHeight="200px"
|
||||
open={isOpen}
|
||||
headerText="History Settings"
|
||||
headerText="Settings"
|
||||
onClose={() => close()}
|
||||
>
|
||||
<Box display="flex" flexDirection="column" justifyContent="space-between" gap="20px">
|
||||
<Box display="flex" flexDirection="column" justifyContent="space-between" gap="5px">
|
||||
{possibleValues.map((type, i) => {
|
||||
const isChecked = selectedValues.includes(type);
|
||||
return (
|
||||
@ -37,7 +37,7 @@ const SettingsModal = ({ isOpen, close, submit, selectedValues, possibleValues,
|
||||
checkedIcon={<CheckBoxOutlined viewBox="0 0 24 24" />}
|
||||
/>
|
||||
}
|
||||
label={<Typography variant="body1">{isChecked ? "Disable" : "Enable"} {type} History Storage</Typography>}
|
||||
label={<Typography variant="body1">{type} History</Typography>}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
|
||||
@ -9,6 +9,7 @@ const BOND_ACTION = "Bond";
|
||||
|
||||
const DEX_ACTION_SWAP = "Swap";
|
||||
const DEX_ACTION_ADD = "Add Liquidity";
|
||||
const DEX_ACTION_REMOVE = "Remove Liquidity";
|
||||
|
||||
const BOND_ACTION_BOND = "Bond";
|
||||
const BOND_ACTION_CLAIM = "Claim";
|
||||
@ -35,7 +36,7 @@ const CONSTANTS = {
|
||||
|
||||
bridgeIn: { key: BRIDGE_IN, name: BRIDGE_IN },
|
||||
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, remove: DEX_ACTION_REMOVE },
|
||||
bond: {
|
||||
key: BOND_ACTION,
|
||||
bond: BOND_ACTION_BOND,
|
||||
@ -86,7 +87,7 @@ export const LocalStorageProvider = ({ children }) => {
|
||||
}
|
||||
}
|
||||
|
||||
const tryStoreInHistory = async (chainId, address, target, txHash, name) => {
|
||||
const tryStoreInHistory = async (chainId, address, target, txHash, name, isCustom = false) => {
|
||||
const historyKey = getStorageKey(chainId, address, HISTORY_PREFIX);
|
||||
const storedHistoryTypes = localStorage.getItem(historyKey);
|
||||
const historyTypes = storedHistoryTypes ? JSON.parse(storedHistoryTypes) : DEFAULT_HISTORY_TYPES;
|
||||
@ -96,7 +97,7 @@ export const LocalStorageProvider = ({ children }) => {
|
||||
const stored = localStorage.getItem(key);
|
||||
const values = stored ? JSON.parse(stored) : [];
|
||||
|
||||
const value = { name, txHash, submitted: Date.now() };
|
||||
const value = { name, txHash, submitted: Date.now(), isCustom };
|
||||
const newValues = [value, ...values];
|
||||
localStorage.setItem(key, JSON.stringify(newValues));
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user