Skip to content

Commit

Permalink
added reporewards and blockscout logo
Browse files Browse the repository at this point in the history
  • Loading branch information
bluntbrain committed Aug 11, 2024
1 parent 4426f43 commit 2c77b72
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 28 deletions.
102 changes: 74 additions & 28 deletions packages/nextjs/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
"use client";

import React, { useCallback, useRef, useState } from "react";
import React, { useRef, useState } from "react";
import Image from "next/image";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { SwitchTheme } from "./SwitchTheme";
import sunny from "./assets/sunny.svg";
import { hardhat } from "viem/chains";
import { useNetwork } from "wagmi";
import { Bars3Icon, MagnifyingGlassIcon } from "@heroicons/react/24/outline";
import { FaucetButton, RainbowKitCustomConnectButton } from "~~/components/scaffold-eth";
import { useOutsideClick } from "~~/hooks/scaffold-eth";
import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork";
import { useDeployedContractInfo, useOutsideClick } from "~~/hooks/scaffold-eth";

type HeaderMenuLink = {
label: string;
href: string;
icon?: React.ReactNode;
image?: string;
};

export const menuLinks: HeaderMenuLink[] = [
Expand All @@ -27,28 +27,75 @@ export const menuLinks: HeaderMenuLink[] = [
label: "Block Explorer",
href: "/blockexplorer",
icon: <MagnifyingGlassIcon className="h-4 w-4" />,
image: "/images/blockscout_logo.png",
},
];

export const HeaderMenuLinks = () => {
const pathname = usePathname();
const { chain } = useNetwork();
const { data: deployedContract } = useDeployedContractInfo("RepoRewards");

console.log("Chain ID:", chain?.id);
console.log("Contract Address:", deployedContract?.address);

const handleBlockExplorerClick = () => {
if (deployedContract?.address) {
let blockscoutUrl = "";

switch (chain?.id) {
case 11155111: // Optimism Sepolia
blockscoutUrl = `https://optimism-sepolia.blockscout.com/address/${deployedContract.address}`;
break;
case 84531: // Base Sepolia
blockscoutUrl = `https://base-sepolia.blockscout.com/address/${deployedContract.address}`;
break;
case 1001: // Mode Testnet
blockscoutUrl = `https://sepolia.explorer.mode.network/address/${deployedContract.address}`;
break;
case 44787: // Celo Alfajores Testnet
blockscoutUrl = `https://explorer.celo.org/alfajores/address/${deployedContract.address}`;
break;
default:
console.warn(`Unhandled chain ID: ${chain?.id}. Falling back to Optimism Sepolia.`);
blockscoutUrl = `https://optimism-sepolia.blockscout.com/address/${deployedContract.address}`;
}

console.log("BlockScout URL:", blockscoutUrl);
window.open(blockscoutUrl, "_blank");
}
};

return (
<>
{menuLinks.map(({ label, href, icon }) => {
{menuLinks.map(({ label, href, icon, image }) => {
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>
{label === "Block Explorer" ? (
<button
onClick={handleBlockExplorerClick}
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>
{image && <img src={image} alt={`${label} icon`} className="h-4 w-4" />}
</button>
) : (
<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}
{image && <img src={image} alt={`${label} icon`} className="h-4 w-4" />}
<span>{label}</span>
</Link>
)}
</li>
);
})}
Expand All @@ -62,12 +109,9 @@ export const HeaderMenuLinks = () => {
export const Header = () => {
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
const burgerMenuRef = useRef<HTMLDivElement>(null);
const { targetNetwork } = useTargetNetwork();
const isLocalNetwork = targetNetwork.id === hardhat.id;
useOutsideClick(
burgerMenuRef,
useCallback(() => setIsDrawerOpen(false), []),
);
const { chain } = useNetwork();
const isLocalNetwork = chain?.id === hardhat.id;
useOutsideClick(burgerMenuRef, () => setIsDrawerOpen(false));

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">
Expand All @@ -76,27 +120,29 @@ export const Header = () => {
<label
tabIndex={0}
className={`ml-1 btn btn-ghost ${isDrawerOpen ? "hover:bg-secondary" : "hover:bg-transparent"}`}
onClick={() => {
setIsDrawerOpen(prevIsOpenState => !prevIsOpenState);
}}
onClick={() => setIsDrawerOpen(prevIsOpenState => !prevIsOpenState)}
>
<Bars3Icon className="h-1/2" />
</label>
{isDrawerOpen && (
<ul
tabIndex={0}
className="menu menu-compact dropdown-content mt-3 p-2 shadow bg-base-100 rounded-box w-52"
onClick={() => {
setIsDrawerOpen(false);
}}
onClick={() => setIsDrawerOpen(false)}
>
<HeaderMenuLinks />
</ul>
)}
</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" src={sunny} />
<Image
alt="SE2 logo"
className="cursor-pointer"
src={"/images/repo_rewards_without_bg.png"}
width={40}
height={40}
/>
</div>
<div className="flex flex-col">
<span className="font-bold leading-tight">Repo Rewards</span>
Expand Down
191 changes: 191 additions & 0 deletions packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,197 @@ const deployedContracts = {
inheritedFunctions: {},
},
},
44787: {
RepoRewards: {
address: "0xACE638d0d36Bd6Cb3f8fEB9739F59492c4e2D13E",
abi: [
{ type: "constructor", stateMutability: "nonpayable", inputs: [] },
{
type: "function",
stateMutability: "payable",
outputs: [],
name: "addFundToRepository",
inputs: [{ type: "uint256", name: "repoId", internalType: "uint256" }],
},
{
type: "function",
stateMutability: "nonpayable",
outputs: [],
name: "addPoolManager",
inputs: [
{ type: "uint256", name: "repoId", internalType: "uint256" },
{ type: "address", name: "poolManager", internalType: "address" },
{ type: "string", name: "username", internalType: "string" },
{ type: "uint256", name: "githubId", internalType: "uint256" },
],
},
{
type: "function",
stateMutability: "view",
outputs: [{ type: "address", name: "", internalType: "address" }],
name: "admin",
inputs: [],
},
{
type: "function",
stateMutability: "nonpayable",
outputs: [],
name: "allocateIssueReward",
inputs: [
{ type: "uint256", name: "repoId", internalType: "uint256" },
{ type: "uint256", name: "issueId", internalType: "uint256" },
{ type: "uint256", name: "reward", internalType: "uint256" },
],
},
{
type: "function",
stateMutability: "view",
outputs: [
{ type: "string", name: "", internalType: "string" },
{ type: "address", name: "", internalType: "address" },
],
name: "checkUserType",
inputs: [{ type: "address", name: "_user", internalType: "address" }],
},
{
type: "function",
stateMutability: "view",
outputs: [{ type: "address", name: "", internalType: "address" }],
name: "contributorAddresses",
inputs: [{ type: "uint256", name: "", internalType: "uint256" }],
},
{
type: "function",
stateMutability: "view",
outputs: [
{ type: "string", name: "username", internalType: "string" },
{ type: "uint256", name: "githubId", internalType: "uint256" },
{ type: "string", name: "worldId", internalType: "string" },
{ type: "address", name: "wallet", internalType: "address" },
],
name: "contributors",
inputs: [{ type: "address", name: "", internalType: "address" }],
},
{
type: "function",
stateMutability: "nonpayable",
outputs: [],
name: "distributeReward",
inputs: [
{ type: "uint256", name: "repoId", internalType: "uint256" },
{ type: "uint256", name: "issueId", internalType: "uint256" },
{ type: "address", name: "contributorAddress", internalType: "address payable" },
],
},
{
type: "function",
stateMutability: "view",
outputs: [
{
type: "tuple",
name: "",
internalType: "struct RepoRewards.Contributor",
components: [
{ type: "string", name: "username", internalType: "string" },
{ type: "uint256", name: "githubId", internalType: "uint256" },
{ type: "string", name: "worldId", internalType: "string" },
{ type: "address", name: "wallet", internalType: "address" },
],
},
],
name: "getContributor",
inputs: [{ type: "address", name: "_wallet", internalType: "address" }],
},
{
type: "function",
stateMutability: "view",
outputs: [
{
type: "tuple",
name: "",
internalType: "struct RepoRewards.PoolManager",
components: [
{ type: "string", name: "username", internalType: "string" },
{ type: "uint256", name: "githubId", internalType: "uint256" },
{ type: "string", name: "worldId", internalType: "string" },
{ type: "address", name: "wallet", internalType: "address" },
],
},
],
name: "getPoolManager",
inputs: [{ type: "address", name: "_wallet", internalType: "address" }],
},
{
type: "function",
stateMutability: "view",
outputs: [
{ type: "address[]", name: "", internalType: "address[]" },
{ type: "address[]", name: "", internalType: "address[]" },
{ type: "uint256", name: "", internalType: "uint256" },
{
type: "tuple[]",
name: "",
internalType: "struct RepoRewards.Issue[]",
components: [
{ type: "uint256", name: "issueId", internalType: "uint256" },
{ type: "uint256", name: "rewardAmount", internalType: "uint256" },
{ type: "string", name: "status", internalType: "string" },
],
},
],
name: "getRepository",
inputs: [{ type: "uint256", name: "_repoId", internalType: "uint256" }],
},
{
type: "function",
stateMutability: "view",
outputs: [{ type: "address", name: "", internalType: "address" }],
name: "getUserWalletByUsername",
inputs: [{ type: "string", name: "username", internalType: "string" }],
},
{
type: "function",
stateMutability: "view",
outputs: [{ type: "address", name: "", internalType: "address" }],
name: "poolManagerAddresses",
inputs: [{ type: "uint256", name: "", internalType: "uint256" }],
},
{
type: "function",
stateMutability: "view",
outputs: [
{ type: "string", name: "username", internalType: "string" },
{ type: "uint256", name: "githubId", internalType: "uint256" },
{ type: "string", name: "worldId", internalType: "string" },
{ type: "address", name: "wallet", internalType: "address" },
],
name: "poolManagers",
inputs: [{ type: "address", name: "", internalType: "address" }],
},
{
type: "function",
stateMutability: "nonpayable",
outputs: [],
name: "registerUser",
inputs: [
{ type: "string", name: "username", internalType: "string" },
{ type: "uint256", name: "githubId", internalType: "uint256" },
{ type: "string", name: "worldId", internalType: "string" },
{ type: "string", name: "typeOfUser", internalType: "string" },
],
},
{
type: "function",
stateMutability: "view",
outputs: [{ type: "uint256", name: "poolRewards", internalType: "uint256" }],
name: "repositories",
inputs: [{ type: "uint256", name: "", internalType: "uint256" }],
},
{ type: "receive", stateMutability: "payable" },
],
inheritedFunctions: {},
},
},
} as const;

export default deployedContracts satisfies GenericContractsDeclaration;
Binary file added packages/nextjs/public/images/blockscout_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2c77b72

Please sign in to comment.