Skip to content

Commit

Permalink
Header v1.0 (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
carletex authored Aug 14, 2024
1 parent a413fd8 commit e86fb89
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 201 deletions.
59 changes: 0 additions & 59 deletions packages/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,69 +1,10 @@
"use client";

import Link from "next/link";
import type { NextPage } from "next";
import { useAccount } from "wagmi";
import { BugAntIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline";
import { Faq } from "~~/components/extensions-hackathon/Faq";
import { Address } from "~~/components/scaffold-eth";

const Home: NextPage = () => {
const { address: connectedAddress } = useAccount();

return (
<>
<div className="flex items-center flex-col flex-grow pt-10">
<div className="px-5">
<h1 className="text-center">
<span className="block text-2xl mb-2">Welcome to</span>
<span className="block text-4xl font-bold">Scaffold-ETH 2</span>
</h1>
<div className="flex justify-center items-center space-x-2 flex-col sm:flex-row">
<p className="my-2 font-medium">Connected Address:</p>
<Address address={connectedAddress} />
</div>
<p className="text-center text-lg">
Get started by editing{" "}
<code className="italic bg-base-300 text-base font-bold max-w-full break-words break-all inline-block">
packages/nextjs/app/page.tsx
</code>
</p>
<p className="text-center text-lg">
Edit your smart contract{" "}
<code className="italic bg-base-300 text-base font-bold max-w-full break-words break-all inline-block">
YourContract.sol
</code>{" "}
in{" "}
<code className="italic bg-base-300 text-base font-bold max-w-full break-words break-all inline-block">
packages/hardhat/contracts
</code>
</p>
</div>

<div className="flex-grow bg-base-300 w-full mt-16 px-8 py-12">
<div className="flex justify-center items-center gap-12 flex-col sm:flex-row">
<div className="flex flex-col bg-base-100 px-10 py-10 text-center items-center max-w-xs rounded-3xl">
<BugAntIcon className="h-8 w-8 fill-secondary" />
<p>
Tinker with your smart contract using the{" "}
<Link href="/debug" passHref className="link">
Debug Contracts
</Link>{" "}
tab.
</p>
</div>
<div className="flex flex-col bg-base-100 px-10 py-10 text-center items-center max-w-xs rounded-3xl">
<MagnifyingGlassIcon className="h-8 w-8 fill-secondary" />
<p>
Explore your local transactions with the{" "}
<Link href="/blockexplorer" passHref className="link">
Block Explorer
</Link>{" "}
tab.
</p>
</div>
</div>
</div>
<Faq />
</div>
</>
Expand Down
2 changes: 0 additions & 2 deletions packages/nextjs/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Link from "next/link";
import { hardhat } from "viem/chains";
import { CurrencyDollarIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline";
import { HeartIcon } from "@heroicons/react/24/outline";
import { SwitchTheme } from "~~/components/SwitchTheme";
import { BuidlGuidlLogo } from "~~/components/assets/BuidlGuidlLogo";
import { Faucet } from "~~/components/scaffold-eth";
import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork";
Expand Down Expand Up @@ -40,7 +39,6 @@ export const Footer = () => {
</>
)}
</div>
<SwitchTheme className={`pointer-events-auto ${isLocalNetwork ? "self-end md:self-auto" : ""}`} />
</div>
</div>
<div className="w-full">
Expand Down
83 changes: 32 additions & 51 deletions packages/nextjs/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import React, { useCallback, useRef, useState } from "react";
import Image from "next/image";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { Bars3Icon, BugAntIcon, LockClosedIcon } from "@heroicons/react/24/outline";
import { FaucetButton, RainbowKitCustomConnectButton } from "~~/components/scaffold-eth";
import { Bars3Icon, ChatBubbleLeftEllipsisIcon, LockClosedIcon } from "@heroicons/react/24/outline";
import { RainbowKitCustomConnectButton } from "~~/components/scaffold-eth";
import { useOutsideClick } from "~~/hooks/scaffold-eth";
import { useAuthSession } from "~~/hooks/useAuthSession";

Expand All @@ -16,62 +15,51 @@ type HeaderMenuLink = {
};

export const menuLinks: HeaderMenuLink[] = [
{
label: "Home",
href: "/",
},
{
label: "Submit",
href: "/submit",
},
{
label: "Admin",
href: "/admin",
icon: <LockClosedIcon className="h-4 w-4" />,
},
{
label: "Siwe",
href: "/siwe",
},
{
label: "Debug Contracts",
href: "/debug",
icon: <BugAntIcon className="h-4 w-4" />,
label: "Join Telegram",
// TODO: Real TG link
href: "https://t.me/ToDo",
icon: <ChatBubbleLeftEllipsisIcon className="h-4 w-4" />,
},
];

export const HeaderMenuLinks = () => {
const pathname = usePathname();
const { isAdmin, data: session, isAuthenticated } = useAuthSession();
const { isAdmin } = useAuthSession();

return (
<>
{menuLinks.map(({ label, href, icon }) => {
if (!session && label !== "Siwe") {
return null;
}

if (isAuthenticated && label === "Siwe") {
return null;
}

if (label === "Admin" && !isAdmin) {
return null;
}

const isActive = pathname === href;
return (
<li key={href}>
<Link
href={href}
passHref
className={`${
isActive ? "bg-secondary shadow-md" : ""
} hover:bg-secondary hover:shadow-md focus:!bg-secondary active:!text-neutral py-1.5 px-3 text-sm rounded-full gap-2 grid grid-flow-col`}
>
{icon}
<span>{label}</span>
</Link>
{href.startsWith("http") ? (
<a
href={href}
target="_blank"
rel="noreferrer noopener"
className="hover:underline flex items-center align-center active:!text-neutral py-1.5 px-3 text-lg gap-2"
>
{icon}
<span>{label}</span>
</a>
) : (
<Link
href={href}
passHref
className="hover:underline flex items-center align-center active:!text-neutral py-1.5 px-3 text-lg gap-2"
>
{icon}
<span>{label}</span>
</Link>
)}
</li>
);
})}
Expand All @@ -91,7 +79,7 @@ export const Header = () => {
);

return (
<div className="sticky lg:static top-0 navbar bg-base-100 min-h-0 flex-shrink-0 justify-between z-20 shadow-md shadow-secondary px-0 sm:px-2">
<div className="sticky lg:static top-0 navbar bg-base-100 min-h-0 flex-shrink-0 justify-between z-20 sm:px-6 py-6">
<div className="navbar-start w-auto lg:w-1/2">
<div className="lg:hidden dropdown" ref={burgerMenuRef}>
<label
Expand All @@ -116,21 +104,14 @@ export const Header = () => {
)}
</div>
<Link href="/" passHref className="hidden lg:flex items-center gap-2 ml-4 mr-6 shrink-0">
<div className="flex relative w-10 h-10">
<Image alt="SE2 logo" className="cursor-pointer" fill src="/logo.svg" />
</div>
<div className="flex flex-col">
<span className="font-bold leading-tight">Scaffold-ETH</span>
<span className="text-xs">Ethereum dev stack</span>
</div>
<Image alt="SE2 logo" className="cursor-pointer" width={205} height={54} src="/logo.svg" />
</Link>
<ul className="hidden lg:flex lg:flex-nowrap menu menu-horizontal px-1 gap-2">
<HeaderMenuLinks />
</ul>
</div>
<div className="navbar-end flex-grow mr-4">
<ul className="hidden lg:flex lg:flex-nowrap px-1 gap-2 pr-4">
<HeaderMenuLinks />
</ul>
<RainbowKitCustomConnectButton />
<FaucetButton />
</div>
</div>
);
Expand Down
17 changes: 2 additions & 15 deletions packages/nextjs/components/ScaffoldEthAppWithProviders.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"use client";

import { useEffect, useState } from "react";
import { RainbowKitProvider, darkTheme, lightTheme } from "@rainbow-me/rainbowkit";
import { RainbowKitProvider, lightTheme } from "@rainbow-me/rainbowkit";
import { RainbowKitSiweNextAuthProvider } from "@rainbow-me/rainbowkit-siwe-next-auth";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { SessionProvider } from "next-auth/react";
import { useTheme } from "next-themes";
import { Toaster } from "react-hot-toast";
import { WagmiProvider } from "wagmi";
import { Footer } from "~~/components/Footer";
Expand Down Expand Up @@ -39,24 +37,13 @@ export const queryClient = new QueryClient({
});

export const ScaffoldEthAppWithProviders = ({ children }: { children: React.ReactNode }) => {
const { resolvedTheme } = useTheme();
const isDarkMode = resolvedTheme === "dark";
const [mounted, setMounted] = useState(false);

useEffect(() => {
setMounted(true);
}, []);

return (
<WagmiProvider config={wagmiConfig}>
<SessionProvider>
<QueryClientProvider client={queryClient}>
<ProgressBar />
<RainbowKitSiweNextAuthProvider>
<RainbowKitProvider
avatar={BlockieAvatar}
theme={mounted ? (isDarkMode ? darkTheme() : lightTheme()) : lightTheme()}
>
<RainbowKitProvider avatar={BlockieAvatar} theme={lightTheme()}>
<ScaffoldEthApp>{children}</ScaffoldEthApp>
</RainbowKitProvider>
</RainbowKitSiweNextAuthProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ export const AddressInfoDropdown = ({
return (
<>
<details ref={dropdownRef} className="dropdown dropdown-end leading-3">
<summary tabIndex={0} className="btn btn-secondary btn-sm pl-0 pr-2 shadow-md dropdown-toggle gap-0 !h-auto">
<summary
tabIndex={0}
className="btn btn-outline btn-sm shadow-md dropdown-toggle gap-0 !h-auto p-2 font-normal"
>
<BlockieAvatar address={checkSumAddress} size={30} ensImage={ensAvatar} />
<span className="ml-2 mr-1">
{isENS(displayName) ? displayName : checkSumAddress?.slice(0, 6) + "..." + checkSumAddress?.slice(-4)}
</span>
<ChevronDownIcon className="h-6 w-4 ml-2 sm:ml-0" />
</summary>
<ul
tabIndex={0}
className="dropdown-content menu z-[2] p-2 mt-2 shadow-center shadow-accent bg-base-200 rounded-box gap-1"
>
<ul tabIndex={0} className="dropdown-content menu z-[2] p-2 mt-2 shadow-center shadow-accent gap-1">
<NetworkOptions hidden={!selectingNetwork} />
<li className={selectingNetwork ? "hidden" : ""}>
{addressCopied ? (
<div className="btn-sm !rounded-xl flex gap-3 py-3">
<div className="btn-sm flex gap-3 py-3">
<CheckCircleIcon
className="text-xl font-normal h-6 w-4 cursor-pointer ml-2 sm:ml-0"
aria-hidden="true"
Expand All @@ -80,7 +80,7 @@ export const AddressInfoDropdown = ({
}, 800);
}}
>
<div className="btn-sm !rounded-xl flex gap-3 py-3">
<div className="btn-sm flex gap-3 py-3">
<DocumentDuplicateIcon
className="text-xl font-normal h-6 w-4 cursor-pointer ml-2 sm:ml-0"
aria-hidden="true"
Expand All @@ -91,13 +91,13 @@ export const AddressInfoDropdown = ({
)}
</li>
<li className={selectingNetwork ? "hidden" : ""}>
<label htmlFor="qrcode-modal" className="btn-sm !rounded-xl flex gap-3 py-3">
<label htmlFor="qrcode-modal" className="btn-sm flex gap-3 py-3">
<QrCodeIcon className="h-6 w-4 ml-2 sm:ml-0" />
<span className="whitespace-nowrap">View QR Code</span>
</label>
</li>
<li className={selectingNetwork ? "hidden" : ""}>
<button className="menu-item btn-sm !rounded-xl flex gap-3 py-3" type="button">
<button className="menu-item btn-sm flex gap-3 py-3" type="button">
<ArrowTopRightOnSquareIcon className="h-6 w-4 ml-2 sm:ml-0" />
<a
target="_blank"
Expand All @@ -112,7 +112,7 @@ export const AddressInfoDropdown = ({
{allowedNetworks.length > 1 ? (
<li className={selectingNetwork ? "hidden" : ""}>
<button
className="btn-sm !rounded-xl flex gap-3 py-3"
className="btn-sm flex gap-3 py-3"
type="button"
onClick={() => {
setSelectingNetwork(true);
Expand All @@ -124,7 +124,7 @@ export const AddressInfoDropdown = ({
) : null}
<li className={selectingNetwork ? "hidden" : ""}>
<button
className="menu-item text-error btn-sm !rounded-xl flex gap-3 py-3"
className="menu-item text-error btn-sm flex gap-3 py-3"
type="button"
onClick={() => {
disconnect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

// @refresh reset
import { useEffect } from "react";
import { Balance } from "../Balance";
import { AddressInfoDropdown } from "./AddressInfoDropdown";
import { AddressQRCodeModal } from "./AddressQRCodeModal";
import { WrongNetworkDropdown } from "./WrongNetworkDropdown";
import { ConnectButton } from "@rainbow-me/rainbowkit";
import { signOut } from "next-auth/react";
import { Address } from "viem";
import { useAccount } from "wagmi";
import { useNetworkColor } from "~~/hooks/scaffold-eth";
import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork";
import { useAuthSession } from "~~/hooks/useAuthSession";
import { getBlockExplorerAddressLink } from "~~/utils/scaffold-eth";
Expand All @@ -19,7 +17,6 @@ import { getBlockExplorerAddressLink } from "~~/utils/scaffold-eth";
* Custom Wagmi Connect Button (watch balance + custom design)
*/
export const RainbowKitCustomConnectButton = ({ fullWidth }: { fullWidth?: boolean }) => {
const networkColor = useNetworkColor();
const { targetNetwork } = useTargetNetwork();
const { address, isConnected } = useAccount();
const { address: sessionAddress } = useAuthSession();
Expand All @@ -44,11 +41,11 @@ export const RainbowKitCustomConnectButton = ({ fullWidth }: { fullWidth?: boole
if (!connected) {
return (
<button
className={`btn btn-primary btn-sm${fullWidth ? " w-full" : ""}`}
className={`btn btn-outline text-lg font-normal${fullWidth ? " w-full" : ""}`}
onClick={openConnectModal}
type="button"
>
Connect Wallet
Connect
</button>
);
}
Expand All @@ -59,12 +56,6 @@ export const RainbowKitCustomConnectButton = ({ fullWidth }: { fullWidth?: boole

return (
<>
<div className="flex flex-col items-center mr-1">
<Balance address={account.address as Address} className="min-h-0 h-auto" />
<span className="text-xs" style={{ color: networkColor }}>
{chain.name}
</span>
</div>
<AddressInfoDropdown
address={account.address as Address}
displayName={account.displayName}
Expand Down
Loading

0 comments on commit e86fb89

Please sign in to comment.