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 3b8afeef..74536027 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/context/walletContext/walletContext.tsx b/src/context/walletContext/walletContext.tsx index 81ac3de2..0fbdd066 100644 --- a/src/context/walletContext/walletContext.tsx +++ b/src/context/walletContext/walletContext.tsx @@ -11,8 +11,6 @@ import { getUserPreferences, updateUserPreferences, } from '@/utils' -import { identicon } from '@dicebear/collection' -import { createAvatar } from '@dicebear/core' import { useQuery, useQueryClient } from '@tanstack/react-query' import { createContext, ReactNode, useCallback, useContext, useEffect, useMemo, useState } from 'react' import { Chain, erc20Abi, getAddress, parseUnits } from 'viem' @@ -66,23 +64,6 @@ export const WalletProvider = ({ children }: { children: ReactNode }) => { getUserPreferences()?.lastSelectedWallet?.address ) - // generate fallback avatar - const getWalletIcon = useCallback( - (address: string) => { - if (!!connector?.icon) { - return connector?.icon - } - - const avatar = createAvatar(identicon, { - seed: address.toLowerCase(), - size: 128, - }) - - return avatar.toDataUri() - }, - [connector] - ) - const isWalletConnected = useCallback( (wallet: interfaces.IDBWallet): boolean => { if (isPeanut(wallet) && kernelClientAddress) { @@ -134,7 +115,7 @@ export const WalletProvider = ({ children }: { children: ReactNode }) => { 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) @@ -208,6 +189,13 @@ export const WalletProvider = ({ children }: { children: ReactNode }) => { accountIdentifier: address, accountType: interfaces.WalletProviderType.BYOW, userId: user.user.userId as string, + connector: + connector && connector.icon + ? { + iconUrl: connector.icon, + name: connector.name, + } + : undefined, }).catch((error: Error) => { if (error.message.includes('Account already exists')) { toast.error('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 {