Skip to content

Commit

Permalink
fix wallet avatar dropdown on mobile (#1247)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkas authored Nov 12, 2024
1 parent 7f031de commit 3b63bf4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
9 changes: 8 additions & 1 deletion apps/web/app/AppProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TrackingCategory,
TrackingPreference,
} from '@coinbase/cookie-manager';
import { OnchainKitProvider } from '@coinbase/onchainkit';
import { AppConfig, OnchainKitProvider } from '@coinbase/onchainkit';
import { Provider as TooltipProvider } from '@radix-ui/react-tooltip';
import { connectorsForWallets, RainbowKitProvider } from '@rainbow-me/rainbowkit';
import {
Expand Down Expand Up @@ -78,6 +78,12 @@ const config = createConfig({
const queryClient = new QueryClient();
const sprigEnvironmentId = process.env.NEXT_PUBLIC_SPRIG_ENVIRONMENT_ID;

const onchainKitConfig: AppConfig = {
appearance: {
mode: 'light',
},
};

type AppProvidersProps = {
children: React.ReactNode;
};
Expand Down Expand Up @@ -141,6 +147,7 @@ export default function AppProviders({ children }: AppProvidersProps) {
<OnchainKitProvider
chain={isDevelopment ? baseSepolia : base}
apiKey={process.env.NEXT_PUBLIC_ONCHAINKIT_API_KEY}
config={onchainKitConfig}
>
<RainbowKitProvider modalSize="compact">
<TooltipProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import logEvent, {
import sanitizeEventString from 'base-ui/utils/sanitizeEventString';
import classNames from 'classnames';
import { useCallback, useEffect, useState } from 'react';
import { useCopyToClipboard } from 'usehooks-ts';
import { useCopyToClipboard, useMediaQuery } from 'usehooks-ts';
import { useAccount, useSwitchChain } from 'wagmi';
import ChainDropdown from 'apps/web/src/components/ChainDropdown';
import { useSearchParams } from 'next/navigation';
Expand Down Expand Up @@ -93,11 +93,13 @@ export function ConnectWalletButton({
);
}, [openConnectModal]);

const userAddressClasses = classNames('text-lg font-display hidden lg:inline-block', {
const userAddressClasses = classNames('text-lg font-display', {
'text-white': connectWalletButtonVariant === ConnectWalletButtonVariants.BaseOrg,
'text-black': connectWalletButtonVariant === ConnectWalletButtonVariants.Basename,
});

const isDesktop = useMediaQuery('(min-width: 768px)');

if (isConnecting || isReconnecting || !isMounted) {
return <Icon name="spinner" color="currentColor" />;
}
Expand Down Expand Up @@ -141,7 +143,7 @@ export function ConnectWalletButton({
>
<div className="flex items-center gap-2">
<UserAvatar />
<Name chain={basenameChain} className={userAddressClasses} />
{isDesktop && <Name chain={basenameChain} className={userAddressClasses} />}
{showChainSwitcher && <ChainDropdown />}
</div>
</ConnectWallet>
Expand Down
11 changes: 9 additions & 2 deletions apps/web/src/components/ConnectWalletButton/UserAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { mainnet } from 'wagmi/chains';
import useBaseEnsName from 'apps/web/src/hooks/useBaseEnsName';
import ImageWithLoading from 'apps/web/src/components/ImageWithLoading';
import BasenameAvatar from 'apps/web/src/components/Basenames/BasenameAvatar';
import { Basename } from '@coinbase/onchainkit/identity';
import { getBasenameImage } from 'apps/web/src/utils/usernames';
import { StaticImageData } from 'next/image';
import { GetEnsAvatarReturnType } from 'viem';

export function UserAvatar() {
const { address } = useAccount();
Expand Down Expand Up @@ -31,7 +35,6 @@ export function UserAvatar() {
});

const isLoading = ensNameIsLoading || ensAvatarIsLoading || baseEnsNameIsLoading;
const avatar = ensAvatar;

if (baseEnsName) {
return (
Expand All @@ -44,7 +47,11 @@ export function UserAvatar() {
);
}

if (!avatar) return null;
let avatar: GetEnsAvatarReturnType | undefined | StaticImageData = ensAvatar;
// Default to basename avatar if none exists
if (!avatar) {
avatar = getBasenameImage(address as Basename);
}

return (
<ImageWithLoading
Expand Down

0 comments on commit 3b63bf4

Please sign in to comment.