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

Ft/smart contracts #7

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add allowed attesters list
  • Loading branch information
hoangvu130301 committed Jun 19, 2024
commit 94b41a1afa16d63f55aa59b080361d3052d85534
8 changes: 8 additions & 0 deletions packages/hardhat/contracts/OnchainShop.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

import "hardhat/console.sol";

contract OnchainShop {
address public immutable sellerAddress;
uint256 public numberOfProducts;
@@ -15,6 +17,8 @@ contract OnchainShop {
Product[] public productArray;
mapping(bytes32 => Product) public products;

mapping(address => bool) public allowedAttesters;

constructor(address _sellerAddress) {
sellerAddress = _sellerAddress;
}
@@ -32,6 +36,10 @@ contract OnchainShop {
uint256 price = products[productId].price;
require(msg.value == price, "Unequal value sent and price");

if (!allowedAttesters[msg.sender]) {
allowedAttesters[msg.sender] = true;
}

(bool sent, ) = sellerAddress.call{ value: price }("");
require(sent, "Failed to send Ether");
}
26 changes: 24 additions & 2 deletions packages/nextjs/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -5,14 +5,15 @@ import Image from "next/image";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useTheme } from "next-themes";
import { Bars3Icon, BugAntIcon } from "@heroicons/react/24/outline";
import { useAccount } from "wagmi";
import { Bars3Icon, BugAntIcon, CheckIcon, XMarkIcon } from "@heroicons/react/24/outline";
import {
BaseFaucetsButton,
FaucetButton,
RainbowKitCustomConnectButton,
SuperchainFaucetButton,
} from "~~/components/scaffold-eth";
import { useOutsideClick } from "~~/hooks/scaffold-eth";
import { useOutsideClick, useScaffoldReadContract } from "~~/hooks/scaffold-eth";

type HeaderMenuLink = {
label: string;
@@ -72,6 +73,14 @@ export const Header = () => {
const { resolvedTheme } = useTheme();
const isDarkMode = resolvedTheme === "dark";

const { address } = useAccount();

const { data: isAllowedAttester } = useScaffoldReadContract({
contractName: "OnchainShop",
functionName: "allowedAttesters",
args: [address],
});

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="navbar-start w-auto lg:w-1/2">
@@ -116,6 +125,19 @@ export const Header = () => {
</ul>
</div>
<div className="navbar-end flex-grow mr-4">
{address ? (
isAllowedAttester ? (
<button className="btn btn-secondary btn-sm px-2 rounded-full">
Allowed Attester
<CheckIcon className="w-6 h-6" />
</button>
) : (
<button className="btn btn-secondary btn-sm px-2 rounded-full">
Allowed Attester
<XMarkIcon className="w-6 h-6" />
</button>
)
) : null}
<RainbowKitCustomConnectButton />
<FaucetButton />
<SuperchainFaucetButton />
19 changes: 19 additions & 0 deletions packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
@@ -50,6 +50,25 @@ const deployedContracts = {
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
name: "allowedAttesters",
outputs: [
{
internalType: "bool",
name: "",
type: "bool",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [
{