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

Update main page #24

Merged
merged 8 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
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
1,552 changes: 1,552 additions & 0 deletions .deps/npm/hardhat/console.sol

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ To help you make the most of your BuidlGuidl Batch experience, we've gathered so
- **PR Guide**: For a detailed understanding of the pull request process, our guide is a great resource. You can find it [here](https://gist.github.com/ZakGriffith/69d1eb8baebddd7d370b87a65a7e3ec0).

The Scaffold-ETH2 and PR guides are a great place to start, but you may have to mold the instructions to suit your needs!

Greetings Address: 0x521365831caCE9B65F8636f598396ff95B9aEFD9
86 changes: 86 additions & 0 deletions packages/hardhat/contracts/Greetings.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

// Useful for debugging. Remove when deploying to a live network.
import "hardhat/console.sol";
// Use openzeppelin to inherit battle-tested implementations (ERC20, ERC721, etc)
// import "@openzeppelin/contracts/access/Ownable.sol";

/**
* A smart contract that allows changing a state variable of the contract and tracking the changes
* It also allows the owner to withdraw the Ether in the contract
* @author BuidlGuidl
*/
contract Greetings {
// State Variables
address public immutable owner;
string public greeting = "Batch 6 welcomes you";
bool public premium = false;
uint256 public totalCounter = 0;
mapping(address => uint) public userGreetingCounter;

// Events: a way to emit log statements from smart contract that can be listened to by external parties
event GreetingChange(
address greetingSetter,
string newGreeting,
bool premium,
uint256 value
);

// Constructor: Called once on contract deployment
// Check packages/hardhat/deploy/00_deploy_your_contract.ts
constructor(address _owner) {
owner = _owner;
}

// Modifier: used to define a set of rules that must be met before or after a function is executed
// Check the withdraw() function
modifier isOwner() {
// msg.sender: predefined variable that represents address of the account that called the current function
require(msg.sender == owner, "Not the Owner");
_;
}

/**
* Function that allows anyone to change the state variable "greeting" of the contract and increase the counters
*
* @param _newGreeting (string memory) - new greeting to save on the contract
*/
function setGreeting(string memory _newGreeting) public payable {
// Print data to the hardhat chain console. Remove when deploying to a live network.
console.log(
"Setting new greeting '%s' from %s",
_newGreeting,
msg.sender
);

// Change state variables
greeting = _newGreeting;
totalCounter += 1;
userGreetingCounter[msg.sender] += 1;

// msg.value: built-in global variable that represents the amount of ether sent with the transaction
if (msg.value > 0) {
premium = true;
} else {
premium = false;
}

// emit: keyword used to trigger an event
emit GreetingChange(msg.sender, _newGreeting, msg.value > 0, 0);
}

/**
* Function that allows the owner to withdraw all the Ether in the contract
* The function can only be called by the owner of the contract as defined by the isOwner modifier
*/
function withdraw() public isOwner {
(bool success, ) = owner.call{ value: address(this).balance }("");
require(success, "Failed to send Ether");
}

/**
* Function that allows the contract to receive ETH
*/
receive() external payable {}
}
20 changes: 17 additions & 3 deletions packages/hardhat/deploy/00_deploy_your_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn
const { deployer } = await hre.getNamedAccounts();
const { deploy } = hre.deployments;

await deploy("BatchRegistry", {
// await deploy("BatchRegistry", {
// from: deployer,
// // Contract constructor arguments
// args: [deployer],
// log: true,
// // autoMine: can be passed to the deploy function to make the deployment process faster on local networks by
// // automatically mining the contract deployment transaction. There is no effect on live networks.
// autoMine: true,
// });

// // Get the deployed contract to interact with it after deploying.
// const batchRegistry = await hre.ethers.getContract<Contract>("BatchRegistry", deployer);
// console.log("BatchRegistry deployed to:", await batchRegistry.getAddress());

await deploy("Greetings", {
from: deployer,
// Contract constructor arguments
args: [deployer],
Expand All @@ -33,8 +47,8 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn
});

// Get the deployed contract to interact with it after deploying.
const batchRegistry = await hre.ethers.getContract<Contract>("BatchRegistry", deployer);
console.log("BatchRegistry deployed to:", await batchRegistry.getAddress());
const greetings = await hre.ethers.getContract<Contract>("Greetings", deployer);
console.log("Greetings deployed to:", await greetings.getAddress());
};

export default deployYourContract;
Expand Down
162 changes: 158 additions & 4 deletions packages/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,174 @@
"use client";

import { useState } from "react";
import Link from "next/link";
import { LucideArrowRight } from "lucide-react";
import type { NextPage } from "next";
import { parseEther } from "viem";
import { BugAntIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline";
import { useScaffoldReadContract } from "~~/hooks/scaffold-eth";
import { ContractData } from "~~/components/assets/ContractData";
import { useScaffoldReadContract, useScaffoldWriteContract } from "~~/hooks/scaffold-eth";

const Home: NextPage = () => {
const [newGreeting, setNewGreeting] = useState("");

const { writeContractAsync: writeGreetingGreetingAsync, isPending } = useScaffoldWriteContract("Greetings");

const handleSendGreeting = async () => {
try {
await writeGreetingGreetingAsync({
functionName: "setGreeting",
args: [newGreeting],
value: parseEther("0.1"),
});
} catch (e) {
console.error("Error setting greeting:", e);
}
};

const checkedInCounter = useScaffoldReadContract({
contractName: "BatchRegistry",
functionName: "checkedInCounter",
});

return (
<>
<div className="flex items-center flex-col flex-grow pt-10">
<div className="px-5">
<div className="relative bg-gradient-to-bl from-blue-100 via-transparent dark:from-blue-950 dark:via-transparent flex flex-row flex-grow lg:grid lg:grid-cols-2">
<div className="bg-orange-10 flex-1 flex flex-col p-8">
<Link
href={"/blockexplorer"}
title="transaction explorer"
className="btn absolute right-8 flex flex-row items-center gap-x-4 w-full max-w-xs bg-base-100 border-base-300 ring-1 rounded-full p-0 z-30"
>
<MagnifyingGlassIcon className="h-8 w-8 fill-secondary" />
<span>Click here to see your transactions</span>
</Link>

<div className="stats px-4 py-4 dark:bg-transparent">
<div className="stat">
<div className="stat-title text-lg">Welcome to</div>
<div className="stat-value">
<span className="inline-block text-5xl font-bold bg-clip-text bg-gradient-to-l from-blue-600 to-violet-500 text-transparent dark:from-blue-400 dark:to-violet-400">
Batch 6
</span>
</div>
<div className="stat-actions">
<div className="flex justify-start">
<Link
className="inline-flex items-center gap-x-2 bg-white border border-gray-200 font-medium text-md text-gray-600 p-3 px-3 rounded-full transition hover:border-gray-300 dark:bg-base-300 dark:border-0 dark:hover:border-neutral-600 dark:text-neutral-400"
href="/builders"
>
See our batch builders 😎
<span className="flex items-center gap-x-1">
<span className="flex flex-row items-center border-s border-gray-200 font-bold text-md text-blue-600 ps-3 px-3 dark:text-blue-500 dark:border-neutral-700">
{!checkedInCounter.isFetched ? (
<span className="loading loading-lg loading-ring" />
) : (
<span>{checkedInCounter?.data?.toString() || 0} builders</span>
)}
</span>
<svg
className="hidden border-s border-gray-200 flex-shrink-0 size-4 text-blue-600 dark:text-blue-500 dark:border-neutral-700"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="m9 18 6-6-6-6" />
</svg>
</span>
</Link>
</div>
</div>
</div>
</div>

<div className="relative w-full max-w-[85rem] mx-auto px-4 sm:px-6 lg:px-8 py-10 sm:py-16 mt-8 rounded-3xl bg-base-100">
<div className="relative flex flex-row items-center font-bold text-7xl">Write a Shoutout 📣</div>
<div className="relative flex flex-row items-center font-bold text-md p-3 bg-clip-text bg-gradient-to-l from-blue-600 to-violet-500 text-transparent dark:from-blue-400 dark:to-violet-400">
and we will display it for you
</div>

<div className="mt-2 sm:mt-6 mx-auto relative">
<div>
<div className="relative z-10 flex items-center space-x-3 p-3 border rounded-box shadow-lg bg-base-300 dark:border-0">
<div className="flex-[1_0_0%] ">
<label
htmlFor="hs-search-article-1"
className="block text-sm text-gray-700 font-medium dark:text-white"
>
<span className="sr-only">Type your shoutout</span>
</label>
<input
type="text"
id="hs-search-article-1"
className="py-4 px-6 block w-full text-3xl border-transparent rounded-box outline-0 focus:border-blue-500 focus:ring-blue-500 bg-base-200"
placeholder="Type your shoutout"
onChange={e => setNewGreeting(e.target.value)}
/>
</div>
<div className="flex-[0_0_auto] ">
<button
className={`btn btn-primary border border-transparent bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50 disabled:pointer-events-none ${
isPending ? "disabled" : ""
}`}
onClick={handleSendGreeting}
>
{isPending ? <span className="loading loading-spinner"></span> : <LucideArrowRight />}
</button>
</div>
</div>
</div>
<div className="font-medium text-md my-4">Fee: 0.01 ETH + Gas</div>

<div className="hidden md:block absolute bottom-0 start-0 translate-y-10 -translate-x-32">
<svg
className="w-40 h-auto text-cyan-500"
width="347"
height="188"
viewBox="0 0 347 188"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M4 82.4591C54.7956 92.8751 30.9771 162.782 68.2065 181.385C112.642 203.59 127.943 78.57 122.161 25.5053C120.504 2.2376 93.4028 -8.11128 89.7468 25.5053C85.8633 61.2125 130.186 199.678 180.982 146.248L214.898 107.02C224.322 95.4118 242.9 79.2851 258.6 107.02C274.299 134.754 299.315 125.589 309.861 117.539L343 93.4426"
stroke="currentColor"
strokeWidth="7"
strokeLinecap="round"
/>
</svg>
</div>
</div>
</div>
</div>

<ContractData />

<div className="hidden w-full p-6">
<h1 className="text-left">
<span className="block text-2xl mb-2">Welcome to</span>
{/* <span className="block text-5xl font-bold">Batch 6</span> */}
<span className="inline-block text-6xl font-bold bg-clip-text bg-gradient-to-l from-blue-600 to-violet-500 text-transparent dark:from-blue-400 dark:to-violet-400">
Batch 6
</span>
</h1>
<p className="text-left text-lg">Get started by taking a look at your batch GitHub repository.</p>
<p className="text-lg flex gap-2 justify-center">
<span className="font-bold">Checked in builders count:</span>
{!checkedInCounter.isFetched ? (
<span className="loading" />
) : (
<span>{checkedInCounter?.data?.toString() || 0}</span>
)}
</p>
</div>

<div className="hidden px-5">
<h1 className="text-center">
<span className="block text-2xl mb-2">Welcome to</span>
<span className="block text-4xl font-bold">Batch 6</span>
Expand All @@ -30,7 +184,7 @@ const Home: NextPage = () => {
</p>
</div>

<div className="flex-grow bg-base-300 w-full mt-16 px-8 py-12">
<div className="hidden 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" />
Expand Down
Loading
Loading