diff --git a/src/app/api/peanut/user/add-account/route.ts b/src/app/api/peanut/user/add-account/route.ts index 19043048..cf3f0866 100644 --- a/src/app/api/peanut/user/add-account/route.ts +++ b/src/app/api/peanut/user/add-account/route.ts @@ -6,7 +6,7 @@ import { cookies } from 'next/headers' export async function POST(request: NextRequest) { try { const body = await request.json() - const { userId, bridgeAccountId, accountType, accountIdentifier } = body + const { userId, bridgeAccountId, accountType, accountIdentifier, connector } = body const apiKey = process.env.PEANUT_API_KEY! @@ -29,6 +29,7 @@ export async function POST(request: NextRequest) { bridgeAccountIdentifier: bridgeAccountId, accountType, accountIdentifier, + connector, }), }) diff --git a/src/components/Global/WalletHeader/index.tsx b/src/components/Global/WalletHeader/index.tsx index 0bcb2f50..af0bd87a 100644 --- a/src/components/Global/WalletHeader/index.tsx +++ b/src/components/Global/WalletHeader/index.tsx @@ -26,7 +26,6 @@ const WalletHeader = () => { const [showModal, setShowModal] = useState(false) const { wallets, selectedWallet, setSelectedWallet, isConnected } = useWallet() const { open: openWeb3Modal } = useAppKit() - const { connector } = useAccount() // sort wallets to add active wallet at the top const sortedWallets = useMemo(() => { @@ -53,14 +52,20 @@ const WalletHeader = () => { > {/* wallet icon container */}
- +
{isConnected ? ( {selectedWallet?.walletProviderType === WalletProviderType.PEANUT ? 'Peanut' - : connector?.name || shortenAddressLong(selectedWallet?.address)} + : selectedWallet?.connector?.name || shortenAddressLong(selectedWallet?.address)} ) : ( 'Connect Wallet' @@ -112,8 +117,8 @@ const WalletEntryCard = ({ wallet, isActive, onClick }: WalletEntryCardProps) => // get wallet icon to display const walletImage = useMemo(() => { - return isPeanutWallet ? PeanutWalletIcon : connector?.icon || PeanutWalletIcon - }, [isPeanutWallet, connector]) + return isPeanutWallet ? PeanutWalletIcon : wallet?.connector?.iconUrl || PeanutWalletIcon + }, [isPeanutWallet, connector, wallet]) return ( diff --git a/src/components/Home/WalletCard.tsx b/src/components/Home/WalletCard.tsx index 5b1b24f7..e5f0ea1f 100644 --- a/src/components/Home/WalletCard.tsx +++ b/src/components/Home/WalletCard.tsx @@ -9,6 +9,8 @@ import { motion } from 'framer-motion' import Image from 'next/image' import { useMemo } from 'react' import CopyToClipboard from '../Global/CopyToClipboard' +import { identicon } from '@dicebear/collection' +import { createAvatar } from '@dicebear/core' const colorArray = ['bg-blue-1', 'bg-yellow-1', 'bg-pink-1'] @@ -67,7 +69,13 @@ export function WalletCard({ type, onClick, ...props }: WalletCardProps) { if (wallet.walletProviderType === WalletProviderType.PEANUT) { return PeanutWalletIcon } - return wallet.walletIcon || PeanutWalletIcon + return ( + wallet.connector?.iconUrl || + createAvatar(identicon, { + seed: wallet.address, + size: 128, + }).toDataUri() + ) }, [wallet]) return ( diff --git a/src/context/authContext.tsx b/src/context/authContext.tsx index b2f35b9b..b1037221 100644 --- a/src/context/authContext.tsx +++ b/src/context/authContext.tsx @@ -21,10 +21,15 @@ interface AuthContextType { accountIdentifier, accountType, userId, + connector, }: { accountIdentifier: string accountType: string userId: string + connector?: { + iconUrl: string + name: string + } }) => Promise isFetchingUser: boolean logoutUser: () => Promise @@ -213,11 +218,16 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { accountType, userId, bridgeAccountId, + connector, }: { accountIdentifier: string accountType: string userId: string bridgeAccountId?: string + connector?: { + iconUrl: string + name: string + } }) => { const response = await fetch('/api/peanut/user/add-account', { method: 'POST', @@ -229,6 +239,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { accountIdentifier, bridgeAccountId, accountType, + connector, }), }) diff --git a/src/hooks/useWallet.ts b/src/hooks/useWallet.ts index 59c11c4f..a8a424da 100644 --- a/src/hooks/useWallet.ts +++ b/src/hooks/useWallet.ts @@ -8,9 +8,7 @@ import * as interfaces from '@/interfaces' import { useAppDispatch, useWalletStore } from '@/redux/hooks' import { walletActions } from '@/redux/slices/wallet-slice' import { areEvmAddressesEqual, backgroundColorFromAddress, fetchWalletBalances } from '@/utils' -import { identicon } from '@dicebear/collection' -import { createAvatar } from '@dicebear/core' -import { useQuery, useQueryClient } from '@tanstack/react-query' +import { useQuery } from '@tanstack/react-query' import { useCallback, useEffect, useMemo } from 'react' import { erc20Abi, getAddress, parseUnits } from 'viem' import { useAccount } from 'wagmi' @@ -31,22 +29,12 @@ const createDefaultDBWallet = (address: string): interfaces.IDBWallet => ({ export const useWallet = () => { const dispatch = useAppDispatch() - const queryClient = useQueryClient() const toast = useToast() const { address: kernelClientAddress, isKernelClientReady } = useZeroDev() const { isConnected: isWagmiConnected, addresses: wagmiAddresses, connector } = useAccount() const { addAccount, user } = useAuth() const { selectedAddress, wallets, signInModalVisible, walletColor } = useWalletStore() - const getWalletIcon = useCallback( - (address: string) => { - if (connector?.icon) return connector.icon - - return createAvatar(identicon, { seed: address.toLowerCase(), size: 128 }).toDataUri() - }, - [connector] - ) - const isWalletConnected = useCallback( (wallet: interfaces.IDBWallet): boolean => { if (isPeanut(wallet) && kernelClientAddress) { @@ -72,7 +60,7 @@ export const useWallet = () => { walletProviderType: account.account_type as unknown as interfaces.WalletProviderType, protocolType: interfaces.WalletProtocolType.EVM, address: account.account_identifier, - walletIcon: getWalletIcon(account.account_identifier), + connector: account.connector, } let balance = BigInt(0) @@ -148,6 +136,13 @@ export const useWallet = () => { accountIdentifier: address, accountType: interfaces.WalletProviderType.BYOW, userId: user.user.userId, + connector: + connector && connector.icon + ? { + iconUrl: connector.icon, + name: connector.name, + } + : undefined, }).catch((error) => { const errorMsg = error.message.includes('Account already exists') ? 'Could not add external wallet, already associated with another account' diff --git a/src/interfaces/interfaces.ts b/src/interfaces/interfaces.ts index ca694d57..5cde23c8 100644 --- a/src/interfaces/interfaces.ts +++ b/src/interfaces/interfaces.ts @@ -400,6 +400,10 @@ interface Account { referred_users_points: number totalReferralPoints: number chain_id: ChainIdType + connector?: { + iconUrl: string + name: string + } } export interface IUserProfile { diff --git a/src/interfaces/wallet.interfaces.ts b/src/interfaces/wallet.interfaces.ts index 64d4e43b..0d3fb3ea 100644 --- a/src/interfaces/wallet.interfaces.ts +++ b/src/interfaces/wallet.interfaces.ts @@ -16,7 +16,10 @@ export interface IDBWallet { walletProviderType: WalletProviderType protocolType: WalletProtocolType address: string - walletIcon?: string + connector?: { + iconUrl: string + name: string + } } export interface IWallet extends IDBWallet {