From 126bca67312a97ab43baab6d7ce08bbff227d20a Mon Sep 17 00:00:00 2001 From: torof Date: Fri, 8 Nov 2024 11:20:10 +0100 Subject: [PATCH] fix(xswap modal to widget): moved from xswap deprecated modal to widget --- src/app/app/[tab]/AppTabs.tsx | 5 +- src/components/app/xswap/XswapModal.tsx | 110 ----------------------- src/components/app/xswap/XswapWidget.tsx | 14 +++ 3 files changed, 16 insertions(+), 113 deletions(-) delete mode 100644 src/components/app/xswap/XswapModal.tsx create mode 100644 src/components/app/xswap/XswapWidget.tsx diff --git a/src/app/app/[tab]/AppTabs.tsx b/src/app/app/[tab]/AppTabs.tsx index 814fec60..0f5ae68d 100644 --- a/src/app/app/[tab]/AppTabs.tsx +++ b/src/app/app/[tab]/AppTabs.tsx @@ -7,11 +7,10 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui"; import { SwitchAppTabProvider } from "@/contexts/SwitchAppTabContext"; import { useSwitchAppTab } from "@/hooks/useSwitchAppTab"; import { FC } from "react"; -import { twMerge } from "tailwind-merge"; import { AppPreMining } from "@/components/app/pre-mining/AppPreMining"; import { SessionProvider } from "next-auth/react"; import { AppStaking } from "@/components/app/staking/AppStaking"; -import { XPayButton } from "@/components/app/xswap/XswapModal"; +import { XSwapWidget } from "@/components/app/xswap/XswapWidget"; import Link from "next/link"; import { AppAffiliate } from "@/components/app/affiliate/AppAffiliate"; import { AppSwap } from "@/components/app/swap/AppSwap"; @@ -66,7 +65,7 @@ const _AppTabs: FC = () => { Dashboard Affiliate Program Swap - +
diff --git a/src/components/app/xswap/XswapModal.tsx b/src/components/app/xswap/XswapModal.tsx deleted file mode 100644 index 07a93cd8..00000000 --- a/src/components/app/xswap/XswapModal.tsx +++ /dev/null @@ -1,110 +0,0 @@ -import { useAccount, useWalletClient } from 'wagmi'; -import { openTransactionModal, renderTxStatus, Transactions } from "@xswap-link/sdk"; -import { useState, useRef, useEffect } from 'react'; -import { waitForTransactionReceipt } from 'viem/actions'; -import { dstChain, dstToken } from '@/constants/xswap'; - -export const XPayButton = () => { - const { address, chain, connector } = useAccount(); - const { data: walletClient } = useWalletClient(); - const [isHovered, setIsHovered] = useState(false); - const [isLoading, setIsLoading] = useState(false); - const timeoutRef = useRef(null); - - useEffect(() => { - return () => { - if (timeoutRef.current) { - clearTimeout(timeoutRef.current); - } - }; - }, []); - - const handleOpenXPay = async () => { - setIsLoading(true); - - timeoutRef.current = setTimeout(() => { - setIsLoading(false); - }, 5000); - - const integratorId = process.env.NEXT_PUBLIC_INTEGRATOR_ID; - if (!integratorId) { - throw new Error("INTEGRATOR_ID is not set in the .env file"); - } - - if (!address || !chain || !connector || !walletClient) { - throw new Error("Wallet not connected"); - } - - try { - const result = await openTransactionModal({ - integratorId, - dstChain, - dstToken, - returnTransactions: true, - }); - - if (!result) { - throw new Error("No transactions returned from openTransactionModal"); - } - - const transactions: Transactions = result; - - if (timeoutRef.current) { - clearTimeout(timeoutRef.current); - } - setIsLoading(false); - - if (transactions.approve && transactions.approve.to && transactions.approve.data) { - const approveTxHash = await walletClient.sendTransaction({ - to: transactions.approve.to as `0x${string}`, - data: transactions.approve.data as `0x${string}`, - value: BigInt(transactions.approve.value || '0'), - }); - await waitForTransactionReceipt(walletClient, { hash: approveTxHash }); - } - - if (transactions.swap && transactions.swap.to && transactions.swap.data) { - const swapTxHash = await walletClient.sendTransaction({ - to: transactions.swap.to as `0x${string}`, - data: transactions.swap.data as `0x${string}`, - value: BigInt(transactions.swap.value || '0'), - }); - await waitForTransactionReceipt(walletClient, { hash: swapTxHash }); - await renderTxStatus(chain.id.toString(), swapTxHash); - } - } catch (error) { - console.error("Error in openXPay:", error); - } finally { - setIsLoading(false); - } - }; - - return ( - - ); -}; \ No newline at end of file diff --git a/src/components/app/xswap/XswapWidget.tsx b/src/components/app/xswap/XswapWidget.tsx new file mode 100644 index 00000000..b8abf0d9 --- /dev/null +++ b/src/components/app/xswap/XswapWidget.tsx @@ -0,0 +1,14 @@ +import { dstChain, dstToken } from '@/constants/xswap'; +import { TxWidget } from '@xswap-link/sdk'; + +export const XSwapWidget = () => { + return( + + ) +} \ No newline at end of file