// import React, { useEffect } from "react"; // import { motion, AnimatePresence } from "framer-motion"; // import * as RadixDialog from "@radix-ui/react-dialog"; // import * as RadixSlider from "@radix-ui/react-slider"; // import * as RadixTooltip from "@radix-ui/react-tooltip"; // import { // FiSettings, // FiRefreshCw, // FiChevronDown, // FiArrowDown, // } from "react-icons/fi"; // import { useTheme } from "@/context"; // import { useThorswap, useMoonTokenManager } from "@/hooks"; // import { Transaction } from "@/components/Web3/Transactions/transactions"; // import { useMoonAccount } from "@/hooks"; // import { formatUnits } from "ethers"; // import { Button } from "@/components"; // import { ChainSelectorModal } from "@/components/Web3/Chains/ChainSelectors/ChainSelectorModal"; // import { useQueryClient } from "@tanstack/react-query"; // import { safelyParseUnits } from "../../../utils"; // import { useDebounceValue } from "usehooks-ts"; // const converyGasTokenAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; // type ButtonStatus = // | "Estimate" // | "Estimating..." // | "Swapping..." // | "Swap" // | "Insufficient Balance"; // interface TokenSelectorProps { // tokens: any[]; // selectedToken: any; // onSelect: (token: any) => void; // } // const TokenSelector: React.FC = ({ // tokens, // selectedToken, // onSelect, // }) => { // const [isOpen, setIsOpen] = React.useState(false); // const [searchTerm, setSearchTerm] = React.useState(""); // const theme = useTheme(); // const filteredTokens = tokens.filter( // (token) => // token.symbol.toLowerCase().includes(searchTerm.toLowerCase()) || // token.name.toLowerCase().includes(searchTerm.toLowerCase()), // ); // return ( // // // // // // {isOpen && ( // // // // // // // // Select a token // // setSearchTerm(e.target.value)} // className={`w-full p-2 mb-4 rounded-md bg-${theme.backgroundColorSecondary} text-${theme.textColor}`} // /> //
// {filteredTokens.map((token) => ( // // ))} //
//
//
//
// )} //
//
// ); // }; export const ThorswapSwap = () => { // const theme = useTheme(); // const { getQuote, swap } = useThorswap(); // const { tokensWithGasToken: tokenList, chain } = useMoonTokenManager(); // const { account } = useMoonAccount(); // const queryClient = useQueryClient(); // const [fromToken, setFromToken] = React.useState(null); // const [toToken, setToToken] = React.useState(null); // const [fromAmount, setFromAmount] = React.useState(""); // const [toAmount, setToAmount] = React.useState(""); // const [slippage, setSlippage] = React.useState(0.5); // const [estimateResult, setEstimateResult] = React.useState(null); // const [buttonStatus, setButtonStatus] = // React.useState("Estimate"); // const [debouncedFromAmount] = useDebounceValue(fromAmount, 500); // const tokensFilteredForChain = tokenList.filter( // (token) => token.chainId === chain?.chain_id, // ); // useEffect(() => { // if (fromToken && toToken && debouncedFromAmount) { // handleEstimate(); // } // }, [fromToken, toToken, debouncedFromAmount, slippage]); // const handleEstimate = async () => { // if (!fromToken || !toToken || !debouncedFromAmount) return; // setButtonStatus("Estimating..."); // const bigAmountWei = safelyParseUnits( // debouncedFromAmount, // fromToken.decimals, // ); // try { // const quoteParams = { // fromChain: chain?.chain_id?.toString() || "", // toChain: chain?.chain_id?.toString() || "", // fromToken: fromToken.address, // toToken: toToken.address, // fromAddress: account || "", // toAddress: account || "", // amount: bigAmountWei.toString(), // slippage: slippage.toString(), // buyAsset: toToken.symbol, // chainId: chain?.chain_id?.toString() || "", // recipientAddress: account || "", // sellAmount: bigAmountWei.toString(), // sellAsset: fromToken.symbol, // senderAddress: account || "", // }; // const estimateResult = await getQuote(quoteParams); // setEstimateResult(estimateResult); // setToAmount( // estimateResult?.expectedAmountOut // ? formatUnits(estimateResult.expectedAmountOut, toToken.decimals) // : "0", // ); // setButtonStatus("Swap"); // } catch (error) { // console.error("Estimate failed:", error); // setButtonStatus("Estimate"); // } // }; // const handleSwap = async () => { // if (!fromToken || !toToken || !fromAmount || !toAmount || !account) return; // setButtonStatus("Swapping..."); // const bigAmountWei = safelyParseUnits(fromAmount, fromToken.decimals); // try { // const swapParams = { // fromChain: chain?.chain_id?.toString() || "", // toChain: chain?.chain_id?.toString() || "", // fromToken: fromToken.address, // toToken: toToken.address, // fromAddress: account, // toAddress: account, // amount: bigAmountWei.toString(), // slippage: slippage.toString(), // }; // const result = await swap(swapParams); // queryClient.invalidateQueries({ queryKey: ["erc20TokenBalances"] }); // console.log("Swap executed:", result); // setButtonStatus("Estimate"); // } catch (error) { // console.error("Swap failed:", error); // setButtonStatus("Swap"); // } // }; // return ( //
// //
// // setFromToken( // token.isGasToken // ? { ...token, address: converyGasTokenAddress } // : token, // ) // } // /> // setFromAmount(e.target.value)} // placeholder="0.0" // className={`w-full mt-2 p-2 rounded-md bg-${theme.backgroundColor} text-${theme.textColor} text-right text-2xl`} // /> //

// Balance: {fromToken?.balance || 0} //

//
//
// //
//
// // setToToken( // token.isGasToken // ? { ...token, address: converyGasTokenAddress } // : token, // ) // } // /> // //

// Balance: {toToken?.balance || 0} //

//
// // // // // // //
Slippage Tolerance
// setSlippage(value[0])} // max={5} // step={0.1} // > // // // // // //
{slippage.toFixed(1)}%
//
//
//
// {estimateResult && ( //
//

Swap Details

//
// Rate // // 1 {fromToken.symbol} ={" "} // {(parseFloat(toAmount) / parseFloat(fromAmount)).toFixed(6)}{" "} // {toToken.symbol} // //
//
// Minimum received // // {(parseFloat(toAmount) * (1 - slippage / 100)).toFixed(6)}{" "} // {toToken.symbol} // //
//
// )} // // {estimateResult && ( //
// //
// )} //
// ); return null; }; export default ThorswapSwap;