From 4013dd6f5bee6b441d75cc36dd082bae9cf26e14 Mon Sep 17 00:00:00 2001 From: dipanshuhappy Date: Tue, 12 Nov 2024 17:55:59 +0700 Subject: [PATCH] feat: improve wallet handling in ConnectButton and ensure proper logout flow in WalletProfile --- components/global/connect-button.tsx | 9 +++++++-- components/global/wallet-profile.tsx | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/components/global/connect-button.tsx b/components/global/connect-button.tsx index 0136977..496250b 100644 --- a/components/global/connect-button.tsx +++ b/components/global/connect-button.tsx @@ -24,13 +24,17 @@ const ConnectButton = () => { const { login } = useLogin({ onComplete: async (user) => { console.log("user logged in...", user); - - if (user.wallet?.address && ready) { + const wallet = user.linkedAccounts.filter(a=>a.type === "wallet")[0] + console.log("wallet", wallet); + if (wallet.address) { console.log("wallets", wallets); const newActiveWallet = wallets.find( (wallet) => wallet.address === user.wallet?.address, ); if (newActiveWallet) { + console.log("newActiveWallet", newActiveWallet); + console.log("chainId", newActiveWallet.chainId); + await setActiveWallet(newActiveWallet); const chainId = newActiveWallet.chainId; if (chainId !== DEFAULT_CHAIN_ID.toString()) { @@ -40,6 +44,7 @@ const ConnectButton = () => { } setIsLogin(true); }, + onError: (error) => { console.log("error while logging in...", error); setIsLogin(false); diff --git a/components/global/wallet-profile.tsx b/components/global/wallet-profile.tsx index c54043d..c826aa3 100644 --- a/components/global/wallet-profile.tsx +++ b/components/global/wallet-profile.tsx @@ -119,8 +119,9 @@ const WalletProfile = ({ { - await logout.logout(); await disconnectAsync(); + await logout.logout(); + }} > Disconnect