Skip to content

Commit

Permalink
web app basic working
Browse files Browse the repository at this point in the history
  • Loading branch information
bluntbrain committed Sep 21, 2024
1 parent 4f04085 commit 0f8722a
Show file tree
Hide file tree
Showing 12 changed files with 322 additions and 74 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
},
"packageManager": "[email protected]",
"devDependencies": {
"@types/canvas-confetti": "^1.6.4",
"husky": "^8.0.1",
"lint-staged": "^13.0.3"
},
"engines": {
"node": ">=18.17.0"
},
"dependencies": {
"axios": "^1.7.7"
"axios": "^1.7.7",
"canvas-confetti": "^1.9.3"
}
}
4 changes: 2 additions & 2 deletions packages/chrome-extension/contentScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ function injectAiAuditButton() {
const aiAuditButton = document.createElement('button');
aiAuditButton.textContent = '✨ AI Audit';
aiAuditButton.style.cssText = `
background-color: #6A0DAD;
background-color: #334155;
border: none;
color: white;
color: #F8FAFC;
padding: 5px 10px;
font-size: 12px;
margin-left: 10px;
Expand Down
26 changes: 15 additions & 11 deletions packages/chrome-extension/styles.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
body {
width: 400px;
background-color: #1e1e1e;
color: #e0e0e0;
background-color: #111827;
color: #F8FAFC;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
Expand Down Expand Up @@ -115,7 +115,7 @@ body {
}

.link {
color: #4caf50;
color: #009C59;
text-decoration: none;
}

Expand All @@ -138,23 +138,27 @@ body {
}

.ai-review.low-risk {
background-color: #e6ffe6;
border: 1px solid #4CAF50;
background-color: #DCFCE7;
border: 1px solid #009C59;
color: #1F2937;
}

.ai-review.moderate-risk {
background-color: #ffffcc;
border: 1px solid #FFD700;
background-color: #FEFCE8;
border: 1px solid #FFB310;
color: #1F2937;
}

.ai-review.high-risk {
background-color: #ffe6e6;
border: 1px solid #FF0000;
background-color: #FEE2E2;
border: 1px solid #B91C1C;
color: #1F2937;
}

.ai-review.neutral {
background-color: #f0f0f0;
border: 1px solid #808080;
background-color: #E2E8F0;
border: 1px solid #334155;
color: #1F2937;
}

.hidden {
Expand Down
58 changes: 49 additions & 9 deletions packages/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,62 @@
"use client";

import { useRouter } from "next/navigation";
import { useState } from "react";
import { useRouter, useSearchParams } from "next/navigation";
import { Address } from "viem";
import { useAccount } from "wagmi";
import ReviewPage from "~~/components/inspectorAiComponents/ReviewPage";
import { AddressInput } from "~~/components/scaffold-eth";
import { RainbowKitCustomConnectButton } from "~~/components/scaffold-eth";

// Expected URL structure: /?address=0x1234...5678&chain=ethereum
// Example: http://localhost:3000/?address=0x1234567890123456789012345678901234567890&chain=ethereum

export default function Home() {
const router = useRouter();
const { isConnected } = useAccount();
const router = useRouter();
const searchParams = useSearchParams();

const [inputAddress, setInputAddress] = useState<Address>();

console.log("page: Home component rendered, isConnected:", isConnected);

const address = searchParams.get("address");
const chain = searchParams.get("chain") || "ethereum";

if (!isConnected) {
router.push("/wallet-connection");
} else {
router.push("/world-id-verification");
}
const handleAddressSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (inputAddress) {
router.push(`/?address=${inputAddress}&chain=${chain}`);
}
};

return (
<main className="flex min-h-screen flex-col items-center justify-center p-24">
<h1 className="text-4xl font-bold mb-8">Welcome to PumpInspector</h1>
<p>Loading...</p>
{isConnected ? (
address ? (
<ReviewPage address={address} chain={chain} />
) : (
<div className="text-center w-full max-w-2xl">
<h1 className="text-4xl font-bold mb-8">Review a Contract</h1>
<form onSubmit={handleAddressSubmit} className="space-y-4">
<AddressInput
value={inputAddress || ""}
onChange={value => setInputAddress(value as Address)}
placeholder="Enter contract address to review"
/>
<button type="submit" className="btn btn-primary">
Review Contract
</button>
</form>
</div>
)
) : (
<div className="text-center">
<h1 className="text-4xl font-bold mb-4">Welcome to Inspector AI</h1>
<p className="mb-4">Please connect your wallet to continue.</p>
<RainbowKitCustomConnectButton />
</div>
)}
</main>
);
}
21 changes: 4 additions & 17 deletions packages/nextjs/components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
import React from "react";
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";
import { useGlobalState } from "~~/services/store/store";

/**
* Site footer
*/
export const Footer = () => {
const nativeCurrencyPrice = useGlobalState(state => state.nativeCurrency.price);
const { targetNetwork } = useTargetNetwork();
const isLocalNetwork = targetNetwork.id === hardhat.id;

return (
<div className="min-h-0 py-5 px-1 mb-11 lg:mb-0">
<div>
<div className="fixed flex justify-between items-center w-full z-10 p-4 bottom-0 left-0 pointer-events-none">
{/* <div className="fixed flex justify-between items-center w-full z-10 p-4 bottom-0 left-0 pointer-events-none">
<div className="flex flex-col md:flex-row gap-2 pointer-events-auto">
{nativeCurrencyPrice > 0 && (
<div>
Expand All @@ -41,9 +28,9 @@ export const Footer = () => {
)}
</div>
<SwitchTheme className={`pointer-events-auto ${isLocalNetwork ? "self-end md:self-auto" : ""}`} />
</div>
</div> */}
</div>
<div className="w-full">
{/* <div className="w-full">
<ul className="menu menu-horizontal w-full">
<div className="flex justify-center items-center gap-2 text-sm w-full">
<div className="text-center">
Expand Down Expand Up @@ -74,7 +61,7 @@ export const Footer = () => {
</div>
</div>
</ul>
</div>
</div> */}
</div>
);
};
22 changes: 9 additions & 13 deletions packages/nextjs/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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 } from "@heroicons/react/24/outline";
import { Bars3Icon } from "@heroicons/react/24/outline";
import { FaucetButton, RainbowKitCustomConnectButton } from "~~/components/scaffold-eth";
import { useOutsideClick } from "~~/hooks/scaffold-eth";

Expand All @@ -19,11 +19,11 @@ export const menuLinks: HeaderMenuLink[] = [
label: "Home",
href: "/",
},
{
label: "Debug Contracts",
href: "/debug",
icon: <BugAntIcon className="h-4 w-4" />,
},
// {
// label: "Debug Contracts",
// href: "/debug",
// icon: <BugAntIcon className="h-4 w-4" />,
// },
];

export const HeaderMenuLinks = () => {
Expand Down Expand Up @@ -64,7 +64,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-primary 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">
<div className="lg:hidden dropdown" ref={burgerMenuRef}>
<label
Expand All @@ -89,12 +89,8 @@ 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 className="flex relative w-40 h-8">
<Image alt="Inspector AI logo" className="cursor-pointer" fill src="/logo_with_name.png" />
</div>
</Link>
<ul className="hidden lg:flex lg:flex-nowrap menu menu-horizontal px-1 gap-2">
Expand Down
138 changes: 138 additions & 0 deletions packages/nextjs/components/inspectorAiComponents/ReviewPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
"use client";

import { useEffect, useState } from "react";
import { IDKitWidget, ISuccessResult, VerificationLevel } from "@worldcoin/idkit";
import { useInspectorAI } from "~~/hooks/scaffold-eth/useInspectorAI";

interface ReviewPageProps {
address: string;
chain: string;
}

export default function ReviewPage({ address, chain }: ReviewPageProps) {
console.log("ReviewPage: Rendering with props:", { address, chain });

const [isVerified, setIsVerified] = useState(false);
const [rating, setRating] = useState<number>(0);
const [comment, setComment] = useState<string>("");
const { addReview, loadReviews, reviews, isAddingReview } = useInspectorAI(address);

console.log("ReviewPage: Hook values:", { reviews, isAddingReview });

useEffect(() => {
console.log("ReviewPage: useEffect - Loading reviews");
loadReviews();
}, [loadReviews]);

const handleVerification = () => {
console.log("ReviewPage: Verification successful");
setIsVerified(true);
};

const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
console.log("ReviewPage: Submitting review", { rating, comment });
await addReview(rating, comment);
setRating(0);
setComment("");
};

const verifyProof = async (proof: ISuccessResult) => {
console.log("ReviewPage: Proof received:", proof);
handleVerification();
};

console.log("ReviewPage: Current state", { isVerified, rating, comment, reviews });

return (
<div className="container mx-auto p-4 bg-background text-textDark">
<div className="card bg-primary shadow-xl max-w-md mx-auto">
<div className="card-body bg-card rounded-md">
<h2 className="card-title text-background">Review Contract</h2>
<p className="text-sm opacity-70 text-background">Chain: {chain}</p>
<p className="text-sm opacity-70 text-background">Address: {address}</p>
<form onSubmit={handleSubmit}>
<div className="form-control">
<div className="rating rating-lg">
{[1, 2, 3, 4, 5].map(star => (
<input
key={star}
type="radio"
name="rating"
className="mask mask-star-2 bg-warningDark"
checked={rating === star}
onChange={() => setRating(star)}
/>
))}
</div>
</div>
<div className="form-control mt-5">
<textarea
className={`textarea textarea-bordered h-24 bg-card text-black border-1 ${
comment ? "border-primary" : "border-gray-300"
} rounded-md`}
placeholder="Write your review here..."
value={comment}
onChange={e => setComment(e.target.value)}
></textarea>
</div>
<div className="form-control mt-4">
<IDKitWidget
app_id="app_staging_1b80c195333c350add4fda2d1e29d3f5"
action="verifyidentity"
onSuccess={verifyProof}
verification_level={VerificationLevel.Device}
>
{({ open }) => (
<button type="button" className="btn bg-primary text-textDark" onClick={open}>
Verify with WorldID (Optional)
</button>
)}
</IDKitWidget>
</div>
<div className="form-control mt-6">
<button
type="submit"
className={`btn bg-primary text-textDark hover:bg-primary-focus ${
isAddingReview || rating === 0 || comment.trim() === "" ? "bg-gray-600" : ""
}`}
disabled={isAddingReview || rating === 0 || comment.trim() === ""}
>
{isAddingReview ? "Submitting..." : "Submit Review"}
</button>
</div>
</form>
</div>
</div>

<div className="mt-8">
<h3 className="text-2xl font-bold mb-4 text-textDark">Reviews</h3>
{reviews.length > 0 ? (
<ul className="space-y-4">
{reviews.map((review, index) => (
<li key={index} className="bg-primary p-4 rounded-lg">
<div className="flex items-center mb-2">
<div className="rating rating-sm">
{[1, 2, 3, 4, 5].map(star => (
<input
key={star}
type="radio"
className="mask mask-star-2 bg-warningDark"
checked={review.rating === star}
readOnly
/>
))}
</div>
<span className="ml-2 text-sm opacity-70 text-textDark">by {review.reviewer}</span>
</div>
<p className="text-textDark">{review.comment}</p>
</li>
))}
</ul>
) : (
<p className="text-textDark">No reviews yet.</p>
)}
</div>
</div>
);
}
Loading

0 comments on commit 0f8722a

Please sign in to comment.