From dd800cf87cda5901836f44c2a2bd7b594aa6b979 Mon Sep 17 00:00:00 2001 From: "DESKTOP-APEQLA2\\NOSEL" Date: Fri, 21 Jun 2024 13:32:03 +0700 Subject: [PATCH] fix reconnect --- src/app/get-aura/deposit.tsx | 9 +++++++++ src/app/get-aura/wallet-connect.tsx | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/app/get-aura/deposit.tsx b/src/app/get-aura/deposit.tsx index 1248914..45f5fe5 100644 --- a/src/app/get-aura/deposit.tsx +++ b/src/app/get-aura/deposit.tsx @@ -11,6 +11,7 @@ import { useBalance, useWaitForTransactionReceipt, BaseError, + useReconnect, } from "wagmi"; import TableHistory from "./table"; import { stringToHex, parseEther, parseUnits, formatUnits } from "viem"; @@ -131,6 +132,14 @@ function Deposit() { getActivityHistory(address?.toLowerCase() || ""); } }, [address]); + const { reconnect } = useReconnect(); + + useEffect(() => { + if (!isConnected) { + reconnect(); + console.log('-----------reconnect') + } + }, [isConnected]); if (isDisconnected) { redirect("/get-aura"); diff --git a/src/app/get-aura/wallet-connect.tsx b/src/app/get-aura/wallet-connect.tsx index 9424606..8d55be5 100644 --- a/src/app/get-aura/wallet-connect.tsx +++ b/src/app/get-aura/wallet-connect.tsx @@ -1,10 +1,16 @@ import { ConnectButton } from "@rainbow-me/rainbowkit"; -import { useAccount, useAccountEffect, useDisconnect } from "wagmi"; +import { + useAccount, + useAccountEffect, + useDisconnect, + useReconnect, +} from "wagmi"; import copyLogo from "@/assets/images/img_copy_logo.svg"; import Image from "next/image"; import { Tooltip } from "react-tooltip"; import "./style.css"; import { toast } from "react-toastify"; +import { useEffect } from "react"; function WalletConnectEVM() { const { isConnected, address } = useAccount(); const { disconnect } = useDisconnect(); @@ -18,6 +24,14 @@ function WalletConnectEVM() { toastDisconnect(); }, }); + const { reconnect } = useReconnect(); + useEffect(() => { + if (!isConnected) { + reconnect(); + console.log("-----------reconnect"); + } + }, [isConnected]); + return (