Loading data from network...
import { usePrivy, useWallets } from '@privy-io/react-auth'
import { useChainId, useSwitchChain } from 'wagmi'
import useWallet from '../hooks/useWallet.js'
import { formatAmount } from '../utils/helpers.js'
import { DEMO_MODE, STABLECOIN_SYMBOL } from '../utils/constants.js'
function DemoWallet() {
const { balance } = useWallet()
return (
<div className="flex items-center gap-3">
<div className="hidden text-right text-xs font-semibold text-ink/60 md:block">
<p>Balance</p>
<p className="text-ink">{formatAmount(balance?.value, balance?.decimals)} {STABLECOIN_SYMBOL}</p>
</div>
<div className="rounded-full bg-ocean px-4 py-2 text-xs font-semibold text-white">Demo Wallet</div>
</div>
)
}
function PrivyWallet() {
const { balance, isConnected } = useWallet()
const { login, logout, ready, authenticated } = usePrivy()
const { wallets } = useWallets()
const chainId = useChainId()
const { switchChain } = useSwitchChain()
const isOnCeloSepolia = chainId === 11142220
return (
<div className="flex items-center gap-3">
{isConnected && (
<div className="hidden text-right text-xs font-semibold text-ink/60 md:block">
<p>Balance</p>
<p className="text-ink">{formatAmount(balance?.value, balance?.decimals)} {STABLECOIN_SYMBOL}</p>
</div>
)}
{!isOnCeloSepolia && authenticated ? (
<button
className="rounded-full bg-ember px-4 py-2 text-xs font-semibold text-white"
onClick={() => switchChain({ chainId: 11142220 })}
type="button"
>
Switch to Celo Sepolia
</button>
) : (
<button
className="rounded-full bg-ocean px-4 py-2 text-xs font-semibold text-white"
onClick={authenticated ? logout : login}
disabled={!ready}
type="button"
>
{authenticated ? 'Disconnect' : 'Connect Wallet'}
</button>
)}
{authenticated && !wallets?.length && (
<span className="hidden text-xs text-ember md:block">Add a wallet in Privy</span>
)}
</div>
)
}
export default function WalletConnect() {
if (DEMO_MODE) return <DemoWallet />
return <PrivyWallet />
}