import ChainCard from '@/components/ChainCard' import SettingsStore from '@/store/SettingsStore' import { truncate } from '@/utils/HelperUtil' import { updateSignClientChainId } from '@/utils/WalletConnectUtil' import { Avatar, Button, Text, Tooltip, Loading } from '@nextui-org/react' import { eip155Wallets } from '@/utils/EIP155WalletUtil' import Image from 'next/image' import { useState, useEffect } from 'react' import { useSnapshot } from 'valtio' import useSmartAccount from '@/hooks/useSmartAccount' interface Props { name: string logo: string rgb: string address: string chainId: string isActiveChain: boolean } export default function SmartAccountCard({ name, logo, rgb, address = '', chainId, isActiveChain }: Props) { const [copied, setCopied] = useState(false) const { activeChainId } = useSnapshot(SettingsStore.state) const { deploy, isDeployed, address: smartAccountAddress, loading, sendTestTransaction, } = useSmartAccount(eip155Wallets[address].getPrivateKey() as `0x${string}`) function onCopy() { navigator?.clipboard?.writeText(address) setCopied(true) setTimeout(() => setCopied(false), 1500) } async function onChainChanged(chainId: string, address: string) { SettingsStore.setActiveChainId(chainId) await updateSignClientChainId(chainId.toString(), address) } async function onCreateSmartAccount() { try { if (!isDeployed) { await deploy() } } catch (error) { console.error(error) } } const getFaucetUrl = () => `https://${name?.toLowerCase()?.replace('ethereum', '')?.trim()}faucet.com` return (
{name} {address ? truncate(address, 19) : ''}
{smartAccountAddress ? ( <> Smart Account: {smartAccountAddress} ) : ( <> )}
) }