Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the bug by using conditional rendering and by defining checkWal… #84

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions client/app/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import React from "react";
import React, { useState, useEffect } from "react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { motion } from "framer-motion";
Expand All @@ -9,7 +9,7 @@ import {
UserIcon,
HomeIcon,
} from "@heroicons/react/24/outline";
import Web3Connect from "../Helper/Web3Connect";
import Web3Connect from "../Helper/Web3Connect"; // Assuming this is your wallet connection logic
import Image from "next/image";

const menuItems = [
Expand All @@ -20,6 +20,30 @@ const menuItems = [

const Header = () => {
const pathname = usePathname();
const [isWalletConnected, setIsWalletConnected] = useState(false);

// Function to simulate wallet connection
const connectWallet = async () => {
try {
// Call your wallet connection logic here
// For example, using Web3Connect or any other method
await Web3Connect(); // Assuming this function connects the wallet
setIsWalletConnected(true);
} catch (error) {
console.error("Failed to connect wallet:", error);
}
};

// Optional: Function to check wallet connection status
const checkWalletConnection = async () => {
// Logic to check if the wallet is connected
const connected = /* your logic here to check if wallet is connected */;
setIsWalletConnected(connected);
};

useEffect(() => {
checkWalletConnection();
}, []);

return (
<motion.header
Expand All @@ -44,7 +68,7 @@ const Header = () => {
</Link>

<nav className="flex items-center space-x-4">
{menuItems.map((item) => (
{isWalletConnected && menuItems.map((item) => (
<Link key={item.name} href={item.href} className="relative">
<motion.button
className={`inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md ${
Expand All @@ -69,12 +93,16 @@ const Header = () => {
)}
</Link>
))}
<Web3Connect />
{!isWalletConnected && (
<button onClick={connectWallet} className="px-4 py-2 text-sm font-medium text-white bg-indigo-600 rounded-md hover:bg-indigo-700">
Connect Wallet
</button>
)}
</nav>
</div>
</div>
</motion.header>
);
};

export default Header;
export default Header;