From 5ef16ea500abf69376c74f9c258dd9603c24bad6 Mon Sep 17 00:00:00 2001 From: bluecco Date: Wed, 15 Jan 2025 16:01:46 +0100 Subject: [PATCH 1/7] chore: create .env.example file --- .env.example | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..534d414 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +NEXT_PUBLIC_ARGENT_WEBWALLET_URL=https://web.argent.xyz +NEXT_PUBLIC_ARGENT_SESSION_SERVICE_BASE_URL=https://cloud.argent-api.com/v1 +NEXT_PUBLIC_CHAIN_ID=SN_MAIN + From 56d0432001ba54b578314965d82867debe9ce06a Mon Sep 17 00:00:00 2001 From: Dhruv Kelawala Date: Wed, 22 Jan 2025 23:50:08 +0000 Subject: [PATCH 2/7] feat: add declare --- src/components/StarknetDapp.tsx | 23 ++- .../sections/Declare/DeclareContract.tsx | 163 ++++++++++++++++++ src/components/sections/types.ts | 1 + src/helpers/upperFirst.ts | 3 + 4 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 src/components/sections/Declare/DeclareContract.tsx create mode 100644 src/helpers/upperFirst.ts diff --git a/src/components/StarknetDapp.tsx b/src/components/StarknetDapp.tsx index c5e43fe..725a198 100644 --- a/src/components/StarknetDapp.tsx +++ b/src/components/StarknetDapp.tsx @@ -2,7 +2,7 @@ import { SignMessage } from "@/components/sections/SignMessage" import { Transactions } from "@/components/sections/Transactions/Transactions" import { useAccount } from "@starknet-react/core" -import { useState } from "react" +import { useEffect, useState } from "react" import { Connect } from "./connect/Connect" import { Header } from "./Header" import { GithubLogo } from "./icons/GithubLogo" @@ -13,11 +13,23 @@ import { SectionButton } from "./sections/SectionButton" import { SectionLayout } from "./sections/SectionLayout" import { SessionKeysSign } from "./sections/SessionKeys/SessionKeysSign" import { Section } from "./sections/types" +import { DeclareContract } from "./sections/Declare/DeclareContract" +import { useSearchParams } from "next/navigation" +import { upperFirst } from "@/helpers/upperFirst" const StarknetDapp = () => { const [section, setSection] = useState
(undefined) const { isConnected } = useAccount() + const searchParams = useSearchParams() + + useEffect(() => { + const section = searchParams.get("section") + if (section) { + setSection(upperFirst(section) as Section) + } + }, [searchParams]) + return (
@@ -99,6 +111,14 @@ const StarknetDapp = () => { selected={section === "SessionKeys"} disabled={!isConnected} className={`${!section ? "flex" : section === "SessionKeys" ? "flex" : "md:flex hidden"}`} + />{" "} +
@@ -117,6 +137,7 @@ const StarknetDapp = () => { {section === "Network" && } {section === "ERC20" && } {section === "SessionKeys" && } + {section === "Declare" && } diff --git a/src/components/sections/Declare/DeclareContract.tsx b/src/components/sections/Declare/DeclareContract.tsx new file mode 100644 index 0000000..e443856 --- /dev/null +++ b/src/components/sections/Declare/DeclareContract.tsx @@ -0,0 +1,163 @@ +// import { useAccount, useDeclareContract } from "@starknet-react/core" +import { useState } from "react" +import { SectionLayout } from "../SectionLayout" +import { Button } from "@/components/ui/Button" +import { useAccount, useDeclareContract } from "@starknet-react/core" +import { hash } from "starknet" +import { isMainnet, toHexChainid } from "@/helpers/chainId" + +const DeclareContract = () => { + const { account, address, chainId } = useAccount() + const { declareAsync } = useDeclareContract({}) + const [contractJson, setContractJson] = useState(null) + const [compiledClassHashJson, setCompiledClassHashJson] = useState< + string | null + >(null) + const [declaredClassHash, setDeclaredClassHash] = useState() + const [txHash, setTxHash] = useState() + const [error, setError] = useState() + + if (!account || !address) { + return null + } + + const handleContractChange = (e: React.ChangeEvent) => { + if (e.target.files && e.target.files.length > 0) { + const file = e.target.files[0] + const reader = new FileReader() + reader.onload = () => { + setContractJson(reader.result as string) + } + reader.readAsText(file) + } + } + + const handleCompiledClassHashChange = ( + e: React.ChangeEvent, + ) => { + if (e.target.files && e.target.files.length > 0) { + const file = e.target.files[0] + const reader = new FileReader() + reader.onload = () => { + setCompiledClassHashJson(reader.result as string) + } + reader.readAsText(file) + } + } + + const onDeclare = async () => { + try { + const { class_hash, transaction_hash } = await declareAsync({ + contract_class: JSON.parse(contractJson || ""), + compiled_class_hash: hash.computeCompiledClassHash( + JSON.parse(compiledClassHashJson || ""), + ), + }) + + setDeclaredClassHash(class_hash) + setTxHash(transaction_hash) + } catch (e) { + setError((e as Error).message) + } + } + const openTxOnVoyager = () => { + const hexChainId = toHexChainid(chainId) + + window.open( + isMainnet(hexChainId) + ? `https://voyager.online/tx/${txHash}` + : `https://sepolia.voyager.online/tx/${txHash}`, + "_blank", + ) + } + + const openClassHashOnVoyager = () => { + const hexChainId = toHexChainid(chainId) + window.open( + isMainnet(hexChainId) + ? `https://voyager.online/class/${declaredClassHash}` + : `https://sepolia.voyager.online/class/${declaredClassHash}`, + "_blank", + ) + } + + return ( + +
+
+ + Upload Contract Files + +
+
+ + +
+
+ + +
+
+
+
+ + {error && ( +
+ Error + {error} +
+ )} + + {declaredClassHash && txHash && ( +
+
+ + Declared Contract Hash + + + {declaredClassHash} + +
+
+ + Transaction Hash + + + {txHash} + +
+
+ )} + +
+ +
+
+ ) +} + +export { DeclareContract } diff --git a/src/components/sections/types.ts b/src/components/sections/types.ts index 3b4746d..e1c85ca 100644 --- a/src/components/sections/types.ts +++ b/src/components/sections/types.ts @@ -6,3 +6,4 @@ export type Section = | "Network" | "ERC20" | "SessionKeys" + | "Declare" diff --git a/src/helpers/upperFirst.ts b/src/helpers/upperFirst.ts new file mode 100644 index 0000000..3fcf8a7 --- /dev/null +++ b/src/helpers/upperFirst.ts @@ -0,0 +1,3 @@ +export const upperFirst = (str: string) => { + return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase() +} From caaff6730c2df32a7afd275ced010ea6ad250cea Mon Sep 17 00:00:00 2001 From: Dhruv Kelawala Date: Thu, 23 Jan 2025 17:46:04 +0000 Subject: [PATCH 3/7] feat: improve initial connection --- src/components/StarknetDapp.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/StarknetDapp.tsx b/src/components/StarknetDapp.tsx index 725a198..d4e6cac 100644 --- a/src/components/StarknetDapp.tsx +++ b/src/components/StarknetDapp.tsx @@ -18,17 +18,17 @@ import { useSearchParams } from "next/navigation" import { upperFirst } from "@/helpers/upperFirst" const StarknetDapp = () => { - const [section, setSection] = useState
(undefined) + const [section, setSection] = useState
("Connection") const { isConnected } = useAccount() const searchParams = useSearchParams() useEffect(() => { const section = searchParams.get("section") - if (section) { + if (section && isConnected) { setSection(upperFirst(section) as Section) } - }, [searchParams]) + }, [searchParams, isConnected]) return (
From 314e898fb48525152274d56918f94ea5ae75285f Mon Sep 17 00:00:00 2001 From: Dhruv Kelawala Date: Thu, 23 Jan 2025 17:46:43 +0000 Subject: [PATCH 4/7] fix: add cursor-pointer --- src/components/sections/Declare/DeclareContract.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/sections/Declare/DeclareContract.tsx b/src/components/sections/Declare/DeclareContract.tsx index e443856..f79473c 100644 --- a/src/components/sections/Declare/DeclareContract.tsx +++ b/src/components/sections/Declare/DeclareContract.tsx @@ -125,13 +125,13 @@ const DeclareContract = () => { )} {declaredClassHash && txHash && ( -
+
Declared Contract Hash {declaredClassHash} From aa6c61ecd59ea76e1f810e2b31a218934b447f4d Mon Sep 17 00:00:00 2001 From: Dhruv Kelawala Date: Fri, 24 Jan 2025 16:34:58 +0000 Subject: [PATCH 5/7] fix: add suspense --- src/components/StarknetDapp.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/StarknetDapp.tsx b/src/components/StarknetDapp.tsx index d4e6cac..4cef6bf 100644 --- a/src/components/StarknetDapp.tsx +++ b/src/components/StarknetDapp.tsx @@ -2,7 +2,7 @@ import { SignMessage } from "@/components/sections/SignMessage" import { Transactions } from "@/components/sections/Transactions/Transactions" import { useAccount } from "@starknet-react/core" -import { useEffect, useState } from "react" +import { useEffect, useState, Suspense } from "react" import { Connect } from "./connect/Connect" import { Header } from "./Header" import { GithubLogo } from "./icons/GithubLogo" @@ -17,10 +17,9 @@ import { DeclareContract } from "./sections/Declare/DeclareContract" import { useSearchParams } from "next/navigation" import { upperFirst } from "@/helpers/upperFirst" -const StarknetDapp = () => { +const StarknetDappContent = () => { const [section, setSection] = useState
("Connection") const { isConnected } = useAccount() - const searchParams = useSearchParams() useEffect(() => { @@ -156,4 +155,12 @@ const StarknetDapp = () => { ) } +const StarknetDapp = () => { + return ( + + + + ) +} + export { StarknetDapp } From 4aaca9bb5c9478bb524934e49a262b9946945c31 Mon Sep 17 00:00:00 2001 From: Dhruv Kelawala Date: Wed, 29 Jan 2025 16:09:51 +0000 Subject: [PATCH 6/7] chore: add review --- src/components/StarknetDapp.tsx | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/components/StarknetDapp.tsx b/src/components/StarknetDapp.tsx index 4cef6bf..57f2750 100644 --- a/src/components/StarknetDapp.tsx +++ b/src/components/StarknetDapp.tsx @@ -2,7 +2,7 @@ import { SignMessage } from "@/components/sections/SignMessage" import { Transactions } from "@/components/sections/Transactions/Transactions" import { useAccount } from "@starknet-react/core" -import { useEffect, useState, Suspense } from "react" +import { useState, Suspense } from "react" import { Connect } from "./connect/Connect" import { Header } from "./Header" import { GithubLogo } from "./icons/GithubLogo" @@ -14,20 +14,18 @@ import { SectionLayout } from "./sections/SectionLayout" import { SessionKeysSign } from "./sections/SessionKeys/SessionKeysSign" import { Section } from "./sections/types" import { DeclareContract } from "./sections/Declare/DeclareContract" -import { useSearchParams } from "next/navigation" -import { upperFirst } from "@/helpers/upperFirst" const StarknetDappContent = () => { const [section, setSection] = useState
("Connection") const { isConnected } = useAccount() - const searchParams = useSearchParams() + // const searchParams = useSearchParams() - useEffect(() => { - const section = searchParams.get("section") - if (section && isConnected) { - setSection(upperFirst(section) as Section) - } - }, [searchParams, isConnected]) + // useEffect(() => { + // const section = searchParams.get("section") + // if (section && isConnected) { + // setSection(upperFirst(section) as Section) + // } + // }, [searchParams, isConnected]) return (
@@ -110,7 +108,7 @@ const StarknetDappContent = () => { selected={section === "SessionKeys"} disabled={!isConnected} className={`${!section ? "flex" : section === "SessionKeys" ? "flex" : "md:flex hidden"}`} - />{" "} + /> Date: Fri, 7 Feb 2025 10:21:54 +0100 Subject: [PATCH 7/7] fix: section as undefined --- src/components/StarknetDapp.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/StarknetDapp.tsx b/src/components/StarknetDapp.tsx index 57f2750..a0856b6 100644 --- a/src/components/StarknetDapp.tsx +++ b/src/components/StarknetDapp.tsx @@ -16,7 +16,7 @@ import { Section } from "./sections/types" import { DeclareContract } from "./sections/Declare/DeclareContract" const StarknetDappContent = () => { - const [section, setSection] = useState
("Connection") + const [section, setSection] = useState
(undefined) const { isConnected } = useAccount() // const searchParams = useSearchParams()