From 3389e6de8fb66a830db360ceb759d7174fd80d88 Mon Sep 17 00:00:00 2001 From: kushagrasarathe <76868364+kushagrasarathe@users.noreply.github.com> Date: Wed, 22 Jan 2025 00:24:39 +0530 Subject: [PATCH] fix: prev conflict messup when merging pr's --- src/app/(mobile-ui)/home/page.tsx | 6 ++++-- src/app/(mobile-ui)/wallet/page.tsx | 25 ++++++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/app/(mobile-ui)/home/page.tsx b/src/app/(mobile-ui)/home/page.tsx index aa2a7ed7..8fda8841 100644 --- a/src/app/(mobile-ui)/home/page.tsx +++ b/src/app/(mobile-ui)/home/page.tsx @@ -43,13 +43,15 @@ export default function Home() { const selectedWalletIndex = rawIndex === -1 ? 0 : rawIndex const [focusedIndex, setFocusedIndex] = useState(selectedWalletIndex) - // update focusedIndex when selectedWallet changes + // update focusedIndex and focused wallet when selectedWallet changes useEffect(() => { const index = wallets.findIndex((wallet) => wallet.address === selectedWallet?.address) if (index !== -1) { setFocusedIndex(index) + // also update the focused wallet when selected wallet changes + dispatch(walletActions.setFocusedWallet(wallets[index])) } - }, [selectedWallet, wallets]) + }, [selectedWallet, wallets, dispatch]) const hasWallets = wallets.length > 0 const { handleLogin, isLoggingIn } = useZeroDev() diff --git a/src/app/(mobile-ui)/wallet/page.tsx b/src/app/(mobile-ui)/wallet/page.tsx index ccf9a884..38e3251d 100644 --- a/src/app/(mobile-ui)/wallet/page.tsx +++ b/src/app/(mobile-ui)/wallet/page.tsx @@ -9,26 +9,25 @@ import NavHeader from '@/components/Global/NavHeader' import { WalletCard } from '@/components/Home/WalletCard' import { useAuth } from '@/context/authContext' import { useWallet } from '@/hooks/wallet/useWallet' -import { IUserBalance, WalletProviderType } from '@/interfaces' +import { IUserBalance } from '@/interfaces' +import { useWalletStore } from '@/redux/hooks' import { formatAmount, getChainName, getUserPreferences, updateUserPreferences } from '@/utils' import { useAppKit, useDisconnect } from '@reown/appkit/react' import { useState } from 'react' import { twMerge } from 'tailwind-merge' const WalletDetailsPage = () => { - const { selectedWallet, isConnected } = useWallet() const { open } = useAppKit() const { disconnect } = useDisconnect() + const { focusedWallet, wallets } = useWalletStore() + const { isConnected } = useWallet() + const { username } = useAuth() const [isBalanceHidden, setIsBalanceHidden] = useState(() => { const prefs = getUserPreferences() return prefs?.balanceHidden ?? false }) - const { username } = useAuth() - const isActiveWalletPW = selectedWallet?.walletProviderType === WalletProviderType.PEANUT - const isActiveWalletBYOW = selectedWallet?.walletProviderType === WalletProviderType.BYOW - - console.log('selectedWallet', selectedWallet) + const walletDetails = wallets.find((wallet) => wallet.address === focusedWallet) const handleToggleBalanceVisibility = (e: React.MouseEvent) => { e.stopPropagation() @@ -46,11 +45,11 @@ const WalletDetailsPage = () => {
- {selectedWallet && ( + {focusedWallet && walletDetails && ( {}} @@ -75,14 +74,14 @@ const WalletDetailsPage = () => {
- {!!selectedWallet?.balances?.length ? ( + {!!walletDetails?.balances?.length ? (
Balance
- {selectedWallet.balances.map((balance: IUserBalance) => ( + {walletDetails.balances.map((balance: IUserBalance) => (