From b65ab1987322aef26a6f87831f8849b85afa1b84 Mon Sep 17 00:00:00 2001 From: Uncle Fatso Date: Wed, 11 Nov 2026 17:12:10 +0300 Subject: [PATCH] fix forceRedeem representation in history; small UI fixes based on the UI revisions Signed-off-by: Uncle Fatso --- package.json | 2 +- src/containers/Bond/BondModal.jsx | 20 +- .../Bond/components/BondInputArea.jsx | 9 +- .../Bond/components/BondSettingsModal.jsx | 2 +- src/containers/Bridge/BridgeGhostAddress.jsx | 6 +- src/containers/Bridge/BridgeIn.jsx | 138 ++++++------ .../Bridge/BridgeInConfirmationModal.jsx | 165 +++++++++++++++ src/containers/History/AddRecordModal.jsx | 197 ++++++++++++++++++ src/containers/History/BridgeInModal.jsx | 100 ++++++--- src/containers/History/History.jsx | 53 ++++- src/containers/History/SettingsModal.jsx | 8 +- src/hooks/localstorage/index.jsx | 7 +- 12 files changed, 580 insertions(+), 127 deletions(-) create mode 100644 src/containers/Bridge/BridgeInConfirmationModal.jsx create mode 100644 src/containers/History/AddRecordModal.jsx diff --git a/package.json b/package.json index 0bf80db..96af63d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ghost-dao-interface", "private": true, - "version": "0.8.8", + "version": "0.8.9", "type": "module", "scripts": { "dev": "vite", diff --git a/src/containers/Bond/BondModal.jsx b/src/containers/Bond/BondModal.jsx index 880fadb..ff2f661 100644 --- a/src/containers/Bond/BondModal.jsx +++ b/src/containers/Bond/BondModal.jsx @@ -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 ( } 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={ } + info={(!isSemiSmallScreen ? "Balance: " : "") + formatCurrency(ftsoBalance, formatDecimals, ftsoSymbol)} tokenName={bond.baseToken.name} value={amountInBaseToken.toString({ decimals: 9 })} inputProps={{ "data-testid": "toInput" }} diff --git a/src/containers/Bond/components/BondSettingsModal.jsx b/src/containers/Bond/components/BondSettingsModal.jsx index 09b6e83..ed92c38 100644 --- a/src/containers/Bond/components/BondSettingsModal.jsx +++ b/src/containers/Bond/components/BondSettingsModal.jsx @@ -67,7 +67,7 @@ const BondSettingsModal = props => { - Choose recipient address. By default, this is your currently connected address + Custom recipient address of bonded assets diff --git a/src/containers/Bridge/BridgeGhostAddress.jsx b/src/containers/Bridge/BridgeGhostAddress.jsx index fe75baa..4caa775 100644 --- a/src/containers/Bridge/BridgeGhostAddress.jsx +++ b/src/containers/Bridge/BridgeGhostAddress.jsx @@ -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 ( setInputFocused(true)} @@ -54,6 +57,7 @@ export const BridgeGhostAddressCard = ({ receiver, setReceiver, isCard }) => { return ( setInputFocused(true)} diff --git a/src/containers/Bridge/BridgeIn.jsx b/src/containers/Bridge/BridgeIn.jsx index 3c059d1..eba5149 100644 --- a/src/containers/Bridge/BridgeIn.jsx +++ b/src/containers/Bridge/BridgeIn.jsx @@ -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, - {tapestryDraft ? "Round 2: Merkle Root Verification" : "Round 1: Block Consensus"} + {tapestryDraft + ? + Round 2: + Merkle Root Verification + + : + Round 1: + Block Consensus + + } {tapestryDraft - ? `Block: ${formatNumber(tapestryDraft.median)} (${pendingValidators} out of ${totalValidators} validators)` - : `Blocks Pending... (${pendingValidators} out of ${totalValidators} validators)` + ? + Block: + {`${formatNumber(tapestryDraft.median)} (${pendingValidators} out of ${totalValidators} validators)`} + + : + Blocks: + {`Pending... (${pendingValidators} out of ${totalValidators} validators)`} + } @@ -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 ( - + + 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} + /> setSettingsOpen(false)} decimals={formatDecimals} setDecimals={setFormatDecimals} @@ -433,9 +437,9 @@ const BridgeIn = ({ chainId, address, config, connect }) => { enableBackground headerContent={ - Next Era in + Next Era in {nextEraIn - ? {nextEraIn} + ? {nextEraIn} : } @@ -496,8 +500,6 @@ const BridgeIn = ({ chainId, address, config, connect }) => { iconNotNeeded UpperSwapCard={ { /> } 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={ { 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 }) => { setConfirmOpen(true)} > - {isPending ? "Pending..." : "Bridge-In"} + Bridge-In diff --git a/src/containers/Bridge/BridgeInConfirmationModal.jsx b/src/containers/Bridge/BridgeInConfirmationModal.jsx new file mode 100644 index 0000000..43ad5f3 --- /dev/null +++ b/src/containers/Bridge/BridgeInConfirmationModal.jsx @@ -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 ( + Confirm Bridge-In} + onClose={!isPending && onClose} + topRight={ + + } + > + + + + + + + {ghstSymbol} + + + + + + + + {externalSymbol} + + + + + + Sender Address + copyToClipboard(sender, 0)} + > + {sender ? shorten(sender, 10, -8) : ""} + + + + + Destination Address + copyToClipboard(receiver, 1)} + > + {receiver ? shorten(receiver, 10, -8) : ""} + + + + + + + {isPending ? "Pending..." : "Confirm"} + + + + ) +} diff --git a/src/containers/History/AddRecordModal.jsx b/src/containers/History/AddRecordModal.jsx new file mode 100644 index 0000000..996e286 --- /dev/null +++ b/src/containers/History/AddRecordModal.jsx @@ -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 ( + close()} + > + + + Transaction hash to be used in history + + setTxHash(event.currentTarget.value)} + placeholder={isValidTxHash ? shorten(txHash, 17, -14) : "Transaction hash (0x prefixed)"} + value={isValidTxHash ? "" : txHash} + /> + + + + {txData && transactionType && + <> + + Block Submission Timestamp + + + + + + + Transaction Type + + + + + + } + + + {transactionType ? "Add Record" : "Unknown Transaction"} + + + + ) +} + +export default AddRecordModal; diff --git a/src/containers/History/BridgeInModal.jsx b/src/containers/History/BridgeInModal.jsx index f5928da..4bf6d8d 100644 --- a/src/containers/History/BridgeInModal.jsx +++ b/src/containers/History/BridgeInModal.jsx @@ -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={ functionArgs?.receiver ? copyToClipboard(functionArgs.receiver, 0) : {}} + onClick={() => estimatedReceiver ? copyToClipboard(estimatedReceiver, 0) : {}} > - {functionArgs?.receiver ? shorten(functionArgs.receiver, 11, -8) : } + {estimatedReceiver ? shorten(estimatedReceiver, 11, -8) : } { const theme = useTheme(); @@ -96,7 +97,7 @@ const HistoryItem = ({ item, chainId, config, currentTime, eraseRecord, setViewM - {item?.name ?? "Unknown"} + {item?.name ?? "Unknown"}{item?.isCustom ? " (Custom)" : ""} {chipStatus} @@ -116,7 +117,7 @@ const HistoryItem = ({ item, chainId, config, currentTime, eraseRecord, setViewM - {item?.name ?? "Unknown"} + {item?.name ?? "Unknown"}{item?.isCustom ? " (Custom)" : ""} { 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 ( - + { isAll={erasingIndex === null} /> + { + setAddRecordOpen(false); + storedTransactionsMutate(); + clearPendingHistory(chainId, address, storedHistoryTypes.at(historyTypeIndex)); + }} + /> + { })} - setErasingOpen(true)} - sx={{ maxWidth: isSemiSmallScreen ? "100%" : "350px" }} + - Erase All Records - + setAddRecordOpen(true)} + > + Add Record + + + setErasingOpen(true)} + > + Erase All Records + + } > diff --git a/src/containers/History/SettingsModal.jsx b/src/containers/History/SettingsModal.jsx index 5c2fd91..9b1c28e 100644 --- a/src/containers/History/SettingsModal.jsx +++ b/src/containers/History/SettingsModal.jsx @@ -15,13 +15,13 @@ const SettingsModal = ({ isOpen, close, submit, selectedValues, possibleValues, return ( close()} > - + {possibleValues.map((type, i) => { const isChecked = selectedValues.includes(type); return ( @@ -37,7 +37,7 @@ const SettingsModal = ({ isOpen, close, submit, selectedValues, possibleValues, checkedIcon={} /> } - label={{isChecked ? "Disable" : "Enable"} {type} History Storage} + label={{type} History} /> ) })} diff --git a/src/hooks/localstorage/index.jsx b/src/hooks/localstorage/index.jsx index 25607e4..c4f3a25 100644 --- a/src/hooks/localstorage/index.jsx +++ b/src/hooks/localstorage/index.jsx @@ -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));