Skip to content

Commit fcfd8ae

Browse files
committed
fix: next/image and network switch for mobile
1 parent 24dae02 commit fcfd8ae

1 file changed

Lines changed: 29 additions & 9 deletions

File tree

components/ui/ConnectBtn.tsx

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ConnectButton } from "@rainbow-me/rainbowkit";
22
import { motion } from "framer-motion";
3+
import Image from "next/image";
34

45
function ConnectBtn() {
56
return (
@@ -12,6 +13,8 @@ function ConnectBtn() {
1213
openConnectModal,
1314
mounted,
1415
}) => {
16+
if (!mounted) return null;
17+
1518
const connected = mounted && account && chain;
1619

1720
if (!connected) {
@@ -42,24 +45,45 @@ function ConnectBtn() {
4245

4346
return (
4447
<div className="flex items-center gap-2 font-bold">
45-
{/* Chain Button */}
4648
<motion.button
4749
onClick={openChainModal}
4850
whileHover={{ scale: 1.035 }}
4951
whileTap={{ scale: 0.98 }}
5052
className="hidden items-center gap-1.5 rounded-xl bg-zinc-200 px-3 py-2 text-zinc-800 transition-colors duration-150 hover:bg-zinc-200 sm:flex dark:border-zinc-700 dark:bg-zinc-800 dark:text-white dark:hover:bg-zinc-700"
5153
>
5254
{chain.hasIcon && chain.iconUrl && (
53-
<img
55+
<Image
5456
src={chain.iconUrl}
55-
alt={chain.name}
56-
className="h-6 w-6 shrink-0 rounded-full"
57+
alt={chain.name!}
58+
width={24}
59+
height={24}
60+
unoptimized
61+
className="shrink-0 rounded-full"
5762
/>
5863
)}
59-
{/* Hidden below md, visible md+ */}
6064
<span className="hidden md:inline">{chain.name}</span>
6165
<span className="opacity-70"></span>
6266
</motion.button>
67+
<motion.button
68+
onClick={openChainModal}
69+
whileHover={{ scale: 1.035 }}
70+
whileTap={{ scale: 0.98 }}
71+
className="flex items-center justify-center rounded-xl bg-zinc-200 p-2 text-zinc-800 transition-colors duration-150 hover:bg-zinc-300 sm:hidden dark:bg-zinc-800 dark:text-white dark:hover:bg-zinc-700"
72+
aria-label={`Switch network, current: ${chain.name}`}
73+
>
74+
{chain.hasIcon && chain.iconUrl ? (
75+
<Image
76+
src={chain.iconUrl}
77+
alt={chain.name!}
78+
width={20}
79+
height={20}
80+
unoptimized
81+
className="shrink-0 rounded-full"
82+
/>
83+
) : (
84+
<span className="text-xs"></span>
85+
)}
86+
</motion.button>
6387

6488
{/* Account Button */}
6589
<motion.button
@@ -68,18 +92,14 @@ function ConnectBtn() {
6892
whileTap={{ scale: 0.98 }}
6993
className="flex items-center gap-0 overflow-hidden rounded-xl bg-zinc-300 transition-colors duration-150 dark:border-zinc-700 dark:bg-zinc-800"
7094
>
71-
{/* Balance pill */}
7295
{account.displayBalance && (
7396
<span className="hidden bg-zinc-200 px-3 py-2 text-zinc-800 sm:inline dark:bg-zinc-900 dark:text-zinc-400">
7497
{account.displayBalance}
7598
</span>
7699
)}
77-
78-
{/* Address */}
79100
<span className="px-3 py-2 text-zinc-800 dark:text-white">
80101
{account.displayName}
81102
</span>
82-
83103
<span className="pr-2 text-black opacity-70 dark:text-white">
84104
85105
</span>

0 commit comments

Comments
 (0)