From 0cadd7b21ad32e59ea1b53ac0b7e4228ebc18a4e Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Mon, 14 Oct 2024 22:24:45 +0700 Subject: [PATCH 01/18] hotfix: remove console log [skip ci] --- packages/snfoundry/scripts-ts/helpers/deploy-wrapper.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/snfoundry/scripts-ts/helpers/deploy-wrapper.ts b/packages/snfoundry/scripts-ts/helpers/deploy-wrapper.ts index ad3aa5e02..4b94355d5 100644 --- a/packages/snfoundry/scripts-ts/helpers/deploy-wrapper.ts +++ b/packages/snfoundry/scripts-ts/helpers/deploy-wrapper.ts @@ -22,8 +22,6 @@ const argv = yargs(process.argv.slice(2)) }) .parseSync() as CommandLineOptions; -console.log(argv); - // Set the NETWORK environment variable based on the --network argument process.env.NETWORK = argv.network || "devnet"; process.env.FEE_TOKEN = argv.fee || "eth"; From a6e739c94dd9a5288c18e189217523bfb7b57fa6 Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Tue, 19 Nov 2024 17:59:13 +0700 Subject: [PATCH 02/18] wip: fix on starknet id address to name resolution --- package.json | 3 +- .../components/scaffold-stark/Address.tsx | 22 ++++++---- .../hooks/useConditionalStarkProfile.tsx | 44 ++++++++++++++++--- packages/nextjs/scaffold.config.ts | 2 +- yarn.lock | 11 +++++ 5 files changed, 65 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 50e613a8c..7d0162486 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "prettier": "^3.2.5" }, "dependencies": { - "postcss": "^8.4.38" + "postcss": "^8.4.38", + "starknetid.js": "^4.0.1" } } diff --git a/packages/nextjs/components/scaffold-stark/Address.tsx b/packages/nextjs/components/scaffold-stark/Address.tsx index c23f99e9f..486f18a7b 100644 --- a/packages/nextjs/components/scaffold-stark/Address.tsx +++ b/packages/nextjs/components/scaffold-stark/Address.tsx @@ -1,6 +1,6 @@ "use client"; -import { useMemo, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import Link from "next/link"; import { CopyToClipboard } from "react-copy-to-clipboard"; import { Address as AddressType } from "@starknet-react/chains"; @@ -51,7 +51,11 @@ export const Address = ({ const [addressCopied, setAddressCopied] = useState(false); const { targetNetwork } = useTargetNetwork(); - const { data: profile } = useConditionalStarkProfile(address); + const { data: fetchedProfile } = useConditionalStarkProfile(address); + + useEffect(() => { + console.debug({ profile: fetchedProfile }); + }, [fetchedProfile]); const checkSumAddress = useMemo(() => { if (!address) return undefined; @@ -94,8 +98,8 @@ export const Address = ({ let displayAddress = checkSumAddress?.slice(0, 6) + "..." + checkSumAddress?.slice(-4); - if (ens) { - displayAddress = ens; + if (!!fetchedProfile) { + displayAddress = fetchedProfile.name; } else if (format === "long") { displayAddress = checkSumAddress; } @@ -103,10 +107,10 @@ export const Address = ({ return (
- {getStarknetPFPIfExists(profile?.profilePicture) ? ( + {getStarknetPFPIfExists(fetchedProfile?.profilePicture) ? ( //eslint-disable-next-line @next/next/no-img-element Profile Picture {disableAddressLink ? ( - {profile?.name || displayAddress} + {fetchedProfile?.name || displayAddress} ) : targetNetwork.network === devnet.network ? ( - {profile?.name || displayAddress} + {fetchedProfile?.name || displayAddress} ) : ( @@ -137,7 +141,7 @@ export const Address = ({ href={blockExplorerAddressLink} rel="noopener noreferrer" > - {profile?.name || displayAddress} + {fetchedProfile?.name || displayAddress} )} {addressCopied ? ( diff --git a/packages/nextjs/hooks/useConditionalStarkProfile.tsx b/packages/nextjs/hooks/useConditionalStarkProfile.tsx index e13b39333..6a3c87d5d 100644 --- a/packages/nextjs/hooks/useConditionalStarkProfile.tsx +++ b/packages/nextjs/hooks/useConditionalStarkProfile.tsx @@ -1,16 +1,48 @@ -import { useStarkProfile } from "@starknet-react/core"; +import { + useProvider, + useStarkName, + useStarkProfile, +} from "@starknet-react/core"; import * as chains from "@starknet-react/chains"; import scaffoldConfig from "~~/scaffold.config"; +import { useEffect, useMemo, useState } from "react"; +import { constants, Provider, StarkProfile } from "starknet"; +import { StarknetIdNavigator } from "starknetid.js"; const useConditionalStarkProfile = (address: chains.Address | undefined) => { const shouldUseProfile = scaffoldConfig.targetNetworks[0].id !== chains.devnet.id; + + const [profile, setProfile] = useState(); + // Conditional hooks are not recommended, but in this case, it's the best approach to avoid issues on devnet. - const profile = shouldUseProfile - ? // eslint-disable-next-line react-hooks/rules-of-hooks - useStarkProfile({ address }) - : { data: undefined }; - return profile; + + const { provider } = useProvider(); + + // // eslint-disable-next-line react-hooks/exhaustive-deps + // const profile = shouldUseProfile + // ? // eslint-disable-next-line react-hooks/rules-of-hooks + // useStarkProfile({ address }) + // : { data: undefined }; + + // const name = useStarkName({ address }); + + useEffect(() => { + const wrappedProvider = new StarknetIdNavigator( + provider as any, + constants.StarknetChainId.SN_MAIN, + ); + if (shouldUseProfile && !!address) + wrappedProvider.getStarkProfiles([address]).then((profileData) => { + if (profileData.length > 0) setProfile(profileData[0]); + }); + }, [address, provider, shouldUseProfile]); + + useEffect(() => { + console.log({ profile, address }); + }, [profile, address]); + + return { data: profile }; }; export default useConditionalStarkProfile; diff --git a/packages/nextjs/scaffold.config.ts b/packages/nextjs/scaffold.config.ts index 84b2b526e..aa4cd43d4 100644 --- a/packages/nextjs/scaffold.config.ts +++ b/packages/nextjs/scaffold.config.ts @@ -10,7 +10,7 @@ export type ScaffoldConfig = { }; const scaffoldConfig = { - targetNetworks: [chains.devnet], + targetNetworks: [chains.mainnet], // Only show the Burner Wallet when running on devnet onlyLocalBurnerWallet: false, rpcProviderUrl: process.env.NEXT_PUBLIC_PROVIDER_URL || "", diff --git a/yarn.lock b/yarn.lock index be9666fb3..8b1cf6d05 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8727,6 +8727,7 @@ __metadata: pinst: ^3.0.0 postcss: ^8.4.38 prettier: ^3.2.5 + starknetid.js: ^4.0.1 languageName: unknown linkType: soft @@ -8766,6 +8767,16 @@ __metadata: languageName: node linkType: hard +"starknetid.js@npm:^4.0.1": + version: 4.0.1 + resolution: "starknetid.js@npm:4.0.1" + peerDependencies: + "@babel/core": ^7.0.0-0 + starknet: ^6.9.0 + checksum: ece8a56b322fbf2ef60f476bfa3c3932a205cde60046ea1577059e559c2c83c468ee2697792e559693d45b6d75d6e8f42552249bb65c657b0ca884f6b4d4f0ae + languageName: node + linkType: hard + "stat-mode@npm:0.3.0": version: 0.3.0 resolution: "stat-mode@npm:0.3.0" From cd20722dd97073eccfc29f2850c5dcf3465448f1 Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Thu, 21 Nov 2024 22:51:10 +0700 Subject: [PATCH 03/18] fix: svg config --- .../components/scaffold-stark/Address.tsx | 65 ++++++++----------- .../hooks/useConditionalStarkProfile.tsx | 28 ++++---- packages/nextjs/next.config.mjs | 12 ++++ 3 files changed, 55 insertions(+), 50 deletions(-) diff --git a/packages/nextjs/components/scaffold-stark/Address.tsx b/packages/nextjs/components/scaffold-stark/Address.tsx index 486f18a7b..31e3079af 100644 --- a/packages/nextjs/components/scaffold-stark/Address.tsx +++ b/packages/nextjs/components/scaffold-stark/Address.tsx @@ -19,6 +19,7 @@ import { getBlockExplorerAddressLink } from "~~/utils/scaffold-stark"; import { BlockieAvatar } from "~~/components/scaffold-stark/BlockieAvatar"; import { getStarknetPFPIfExists } from "~~/utils/profile"; import useConditionalStarkProfile from "~~/hooks/useConditionalStarkProfile"; +import Image from "next/image"; type AddressProps = { address?: AddressType; @@ -46,34 +47,34 @@ export const Address = ({ format, size = "base", }: AddressProps) => { - const [ens, setEns] = useState(); const [ensAvatar, setEnsAvatar] = useState(); const [addressCopied, setAddressCopied] = useState(false); + const [isUseBlockie, setIsUseBlockie] = useState(false); const { targetNetwork } = useTargetNetwork(); const { data: fetchedProfile } = useConditionalStarkProfile(address); - useEffect(() => { - console.debug({ profile: fetchedProfile }); - }, [fetchedProfile]); - const checkSumAddress = useMemo(() => { if (!address) return undefined; return getChecksumAddress(address); }, [address]); - // const checkSumAddress = address ? address : undefined; + const blockExplorerAddressLink = getBlockExplorerAddressLink( + targetNetwork, + checkSumAddress || address || "", + ); - // TODO add starkprofile | not working on devnet now - //const { data: fetchedProfile } = useStarkProfile({ address }); + const [displayAddress, setDisplayAddress] = useState( + checkSumAddress?.slice(0, 6) + "..." + checkSumAddress?.slice(-4), + ); - // We need to apply this pattern to avoid Hydration errors. - // useEffect(() => { - // if (fetchedProfile) { - // setEns(fetchedProfile.name); - // setEnsAvatar(fetchedProfile.profilePicture); - // } - // }, [fetchedProfile]); + useEffect(() => { + if (!!fetchedProfile) { + setDisplayAddress(fetchedProfile.name || ""); + } else if (format === "long") { + setDisplayAddress(checkSumAddress || address || ""); + } + }, [fetchedProfile, checkSumAddress, address, format]); // Skeleton UI if (!checkSumAddress) { @@ -91,36 +92,26 @@ export const Address = ({ return Wrong address; } - const blockExplorerAddressLink = getBlockExplorerAddressLink( - targetNetwork, - checkSumAddress, - ); - let displayAddress = - checkSumAddress?.slice(0, 6) + "..." + checkSumAddress?.slice(-4); - - if (!!fetchedProfile) { - displayAddress = fetchedProfile.name; - } else if (format === "long") { - displayAddress = checkSumAddress; - } - return (
- {getStarknetPFPIfExists(fetchedProfile?.profilePicture) ? ( - //eslint-disable-next-line @next/next/no-img-element + {isUseBlockie ? ( + + ) : ( + // eslint-disable-next-line @next/next/no-img-element Profile Picture - ) : ( - { + setIsUseBlockie(true); + }} /> )}
diff --git a/packages/nextjs/hooks/useConditionalStarkProfile.tsx b/packages/nextjs/hooks/useConditionalStarkProfile.tsx index 6a3c87d5d..c30f71970 100644 --- a/packages/nextjs/hooks/useConditionalStarkProfile.tsx +++ b/packages/nextjs/hooks/useConditionalStarkProfile.tsx @@ -6,36 +6,38 @@ import { import * as chains from "@starknet-react/chains"; import scaffoldConfig from "~~/scaffold.config"; import { useEffect, useMemo, useState } from "react"; -import { constants, Provider, StarkProfile } from "starknet"; +import { constants, Provider, RpcProvider, StarkProfile } from "starknet"; import { StarknetIdNavigator } from "starknetid.js"; +import { useTargetNetwork } from "./scaffold-stark/useTargetNetwork"; +// this hook is a workaround, basically a re-implement of the starknet react hook with conditional rendering. const useConditionalStarkProfile = (address: chains.Address | undefined) => { const shouldUseProfile = scaffoldConfig.targetNetworks[0].id !== chains.devnet.id; + const [isLoading, setIsLoading] = useState(false); const [profile, setProfile] = useState(); + const { targetNetwork } = useTargetNetwork(); + const publicNodeUrl = targetNetwork.rpcUrls.public.http[0]; - // Conditional hooks are not recommended, but in this case, it's the best approach to avoid issues on devnet. - - const { provider } = useProvider(); - - // // eslint-disable-next-line react-hooks/exhaustive-deps - // const profile = shouldUseProfile - // ? // eslint-disable-next-line react-hooks/rules-of-hooks - // useStarkProfile({ address }) - // : { data: undefined }; - - // const name = useStarkName({ address }); + const provider = useMemo(() => { + return new RpcProvider({ + nodeUrl: publicNodeUrl, + }); + }, [publicNodeUrl]); useEffect(() => { const wrappedProvider = new StarknetIdNavigator( provider as any, constants.StarknetChainId.SN_MAIN, ); - if (shouldUseProfile && !!address) + if (shouldUseProfile && !!address) { + setIsLoading(true); wrappedProvider.getStarkProfiles([address]).then((profileData) => { if (profileData.length > 0) setProfile(profileData[0]); + setIsLoading(false); }); + } }, [address, provider, shouldUseProfile]); useEffect(() => { diff --git a/packages/nextjs/next.config.mjs b/packages/nextjs/next.config.mjs index 6c1dd362a..81029d49b 100644 --- a/packages/nextjs/next.config.mjs +++ b/packages/nextjs/next.config.mjs @@ -1,6 +1,18 @@ /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, + images: { + // make sure no one injects anything funny in svg + dangerouslyAllowSVG: true, + remotePatterns: [ + // we might need to add more links. this is just from the starknet ID identicon + { + protocol: "https", + hostname: "identicon.starknet.id", + pathname: "/**", // Allows all paths under this domain + }, + ], + }, typescript: { ignoreBuildErrors: process.env.NEXT_PUBLIC_IGNORE_BUILD_ERROR === "true", }, From 41ec244b4ee0eea36830d24ff6d519df02312945 Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Thu, 21 Nov 2024 22:55:37 +0700 Subject: [PATCH 04/18] chore: revert scaffold config --- packages/nextjs/scaffold.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/scaffold.config.ts b/packages/nextjs/scaffold.config.ts index aa4cd43d4..84b2b526e 100644 --- a/packages/nextjs/scaffold.config.ts +++ b/packages/nextjs/scaffold.config.ts @@ -10,7 +10,7 @@ export type ScaffoldConfig = { }; const scaffoldConfig = { - targetNetworks: [chains.mainnet], + targetNetworks: [chains.devnet], // Only show the Burner Wallet when running on devnet onlyLocalBurnerWallet: false, rpcProviderUrl: process.env.NEXT_PUBLIC_PROVIDER_URL || "", From 26d418181e07e40d202ef223f6068db9164324a9 Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Thu, 21 Nov 2024 23:04:57 +0700 Subject: [PATCH 05/18] chore: move dependencies to next js package --- package.json | 3 +-- packages/nextjs/package.json | 1 + yarn.lock | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 7d0162486..50e613a8c 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "prettier": "^3.2.5" }, "dependencies": { - "postcss": "^8.4.38", - "starknetid.js": "^4.0.1" + "postcss": "^8.4.38" } } diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index d4a3b3f34..630786f85 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -37,6 +37,7 @@ "react-dom": "^18", "react-hot-toast": "^2.4.1", "starknet": "6.12.1", + "starknetid.js": "^4.0.1", "type-fest": "^4.6.0", "usehooks-ts": "^2.13.0", "zustand": "^4.1.2" diff --git a/yarn.lock b/yarn.lock index 8b1cf6d05..3af4bb014 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2257,6 +2257,7 @@ __metadata: react-dom: ^18 react-hot-toast: ^2.4.1 starknet: 6.12.1 + starknetid.js: ^4.0.1 tailwindcss: ^3.3.0 type-fest: ^4.6.0 typescript: ^5 @@ -8727,7 +8728,6 @@ __metadata: pinst: ^3.0.0 postcss: ^8.4.38 prettier: ^3.2.5 - starknetid.js: ^4.0.1 languageName: unknown linkType: soft From 45a8307001f888eecea3c3d32f086fad6fbd1dc7 Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Fri, 22 Nov 2024 00:13:39 +0700 Subject: [PATCH 06/18] fix: point to correct network in the sdk --- packages/nextjs/hooks/useConditionalStarkProfile.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nextjs/hooks/useConditionalStarkProfile.tsx b/packages/nextjs/hooks/useConditionalStarkProfile.tsx index c30f71970..72eec10ba 100644 --- a/packages/nextjs/hooks/useConditionalStarkProfile.tsx +++ b/packages/nextjs/hooks/useConditionalStarkProfile.tsx @@ -29,7 +29,9 @@ const useConditionalStarkProfile = (address: chains.Address | undefined) => { useEffect(() => { const wrappedProvider = new StarknetIdNavigator( provider as any, - constants.StarknetChainId.SN_MAIN, + targetNetwork.id === chains.sepolia.id + ? constants.StarknetChainId.SN_SEPOLIA + : constants.StarknetChainId.SN_MAIN, ); if (shouldUseProfile && !!address) { setIsLoading(true); @@ -38,7 +40,7 @@ const useConditionalStarkProfile = (address: chains.Address | undefined) => { setIsLoading(false); }); } - }, [address, provider, shouldUseProfile]); + }, [address, provider, shouldUseProfile, targetNetwork.id]); useEffect(() => { console.log({ profile, address }); From 28c15ef51f2aec2d6406a2f485c271318f53082d Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Fri, 6 Dec 2024 21:18:07 +0700 Subject: [PATCH 07/18] fix(starknetid): sepolia resolver --- .../hooks/useConditionalStarkProfile.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/nextjs/hooks/useConditionalStarkProfile.tsx b/packages/nextjs/hooks/useConditionalStarkProfile.tsx index 72eec10ba..500ba4f6d 100644 --- a/packages/nextjs/hooks/useConditionalStarkProfile.tsx +++ b/packages/nextjs/hooks/useConditionalStarkProfile.tsx @@ -13,7 +13,8 @@ import { useTargetNetwork } from "./scaffold-stark/useTargetNetwork"; // this hook is a workaround, basically a re-implement of the starknet react hook with conditional rendering. const useConditionalStarkProfile = (address: chains.Address | undefined) => { const shouldUseProfile = - scaffoldConfig.targetNetworks[0].id !== chains.devnet.id; + // @ts-expect-error program thinks this is a constant but its changed at code level + scaffoldConfig.targetNetworks[0].network !== chains.devnet.network; const [isLoading, setIsLoading] = useState(false); const [profile, setProfile] = useState(); @@ -27,20 +28,25 @@ const useConditionalStarkProfile = (address: chains.Address | undefined) => { }, [publicNodeUrl]); useEffect(() => { + if (!shouldUseProfile) { + return; + } + const wrappedProvider = new StarknetIdNavigator( provider as any, - targetNetwork.id === chains.sepolia.id + targetNetwork.network === chains.sepolia.network ? constants.StarknetChainId.SN_SEPOLIA : constants.StarknetChainId.SN_MAIN, ); - if (shouldUseProfile && !!address) { + + if (!!address) { setIsLoading(true); - wrappedProvider.getStarkProfiles([address]).then((profileData) => { - if (profileData.length > 0) setProfile(profileData[0]); + wrappedProvider.getProfileData(address).then((profileData) => { + setProfile(profileData); setIsLoading(false); }); } - }, [address, provider, shouldUseProfile, targetNetwork.id]); + }, [address, provider, shouldUseProfile, targetNetwork]); useEffect(() => { console.log({ profile, address }); From 6252964716ac4ea6aaf3fc442470dd089e23d887 Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Fri, 6 Dec 2024 21:25:51 +0700 Subject: [PATCH 08/18] chore(starknetid): rename and move hooks --- packages/nextjs/components/scaffold-stark/Address.tsx | 4 ++-- .../CustomConnectButton/AddressInfoDropdown.tsx | 4 ++-- .../useScaffoldStarkProfile.tsx} | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) rename packages/nextjs/hooks/{useConditionalStarkProfile.tsx => scaffold-stark/useScaffoldStarkProfile.tsx} (86%) diff --git a/packages/nextjs/components/scaffold-stark/Address.tsx b/packages/nextjs/components/scaffold-stark/Address.tsx index 31e3079af..4101198c2 100644 --- a/packages/nextjs/components/scaffold-stark/Address.tsx +++ b/packages/nextjs/components/scaffold-stark/Address.tsx @@ -18,7 +18,7 @@ import { useTargetNetwork } from "~~/hooks/scaffold-stark/useTargetNetwork"; import { getBlockExplorerAddressLink } from "~~/utils/scaffold-stark"; import { BlockieAvatar } from "~~/components/scaffold-stark/BlockieAvatar"; import { getStarknetPFPIfExists } from "~~/utils/profile"; -import useConditionalStarkProfile from "~~/hooks/useConditionalStarkProfile"; +import useScaffoldStarkProfile from "~~/hooks/scaffold-stark/useScaffoldStarkProfile"; import Image from "next/image"; type AddressProps = { @@ -52,7 +52,7 @@ export const Address = ({ const [isUseBlockie, setIsUseBlockie] = useState(false); const { targetNetwork } = useTargetNetwork(); - const { data: fetchedProfile } = useConditionalStarkProfile(address); + const { data: fetchedProfile } = useScaffoldStarkProfile(address); const checkSumAddress = useMemo(() => { if (!address) return undefined; diff --git a/packages/nextjs/components/scaffold-stark/CustomConnectButton/AddressInfoDropdown.tsx b/packages/nextjs/components/scaffold-stark/CustomConnectButton/AddressInfoDropdown.tsx index ef73586e5..7f1495b35 100644 --- a/packages/nextjs/components/scaffold-stark/CustomConnectButton/AddressInfoDropdown.tsx +++ b/packages/nextjs/components/scaffold-stark/CustomConnectButton/AddressInfoDropdown.tsx @@ -21,7 +21,7 @@ import { burnerAccounts } from "~~/utils/devnetAccounts"; import { Address } from "@starknet-react/chains"; import { useDisconnect, useNetwork, useConnect } from "@starknet-react/core"; import { getStarknetPFPIfExists } from "~~/utils/profile"; -import useConditionalStarkProfile from "~~/hooks/useConditionalStarkProfile"; +import useScaffoldStarkProfile from "~~/hooks/scaffold-stark/useScaffoldStarkProfile"; import { useTheme } from "next-themes"; import { default as NextImage } from "next/image"; @@ -42,7 +42,7 @@ export const AddressInfoDropdown = ({ }: AddressInfoDropdownProps) => { const { disconnect } = useDisconnect(); const [addressCopied, setAddressCopied] = useState(false); - const { data: profile } = useConditionalStarkProfile(address); + const { data: profile } = useScaffoldStarkProfile(address); const { chain } = useNetwork(); const [showBurnerAccounts, setShowBurnerAccounts] = useState(false); const [selectingNetwork, setSelectingNetwork] = useState(false); diff --git a/packages/nextjs/hooks/useConditionalStarkProfile.tsx b/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx similarity index 86% rename from packages/nextjs/hooks/useConditionalStarkProfile.tsx rename to packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx index 78a30b8cb..1d7e01999 100644 --- a/packages/nextjs/hooks/useConditionalStarkProfile.tsx +++ b/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx @@ -8,7 +8,7 @@ import scaffoldConfig from "~~/scaffold.config"; import { useEffect, useMemo, useState } from "react"; import { constants, Provider, RpcProvider, StarkProfile } from "starknet"; import { StarknetIdNavigator } from "starknetid.js"; -import { useTargetNetwork } from "./scaffold-stark/useTargetNetwork"; +import { useTargetNetwork } from "./useTargetNetwork"; const shouldUseProfile = () => { const set = new Set(["mainnet", "sepolia"]); @@ -20,7 +20,7 @@ const shouldUseProfile = () => { }; // this hook is a workaround, basically a re-implement of the starknet react hook with conditional rendering. -const useConditionalStarkProfile = (address: chains.Address | undefined) => { +const useScaffoldStarkProfile = (address: chains.Address | undefined) => { const [isLoading, setIsLoading] = useState(false); const [profile, setProfile] = useState(); const { targetNetwork } = useTargetNetwork(); @@ -51,13 +51,13 @@ const useConditionalStarkProfile = (address: chains.Address | undefined) => { setIsLoading(false); }); } - }, [address, provider, shouldUseProfile, targetNetwork]); + }, [address, provider, targetNetwork]); useEffect(() => { console.log({ profile, address }); }, [profile, address]); - return { data: profile }; + return { data: profile, isLoading }; }; -export default useConditionalStarkProfile; +export default useScaffoldStarkProfile; From 96e638e741f9dd2ab7093a2583dd8966af3db144 Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Fri, 6 Dec 2024 21:35:14 +0700 Subject: [PATCH 09/18] chore: code cleanup --- .../nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx b/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx index 1d7e01999..8a25b29b6 100644 --- a/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx +++ b/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx @@ -14,7 +14,6 @@ const shouldUseProfile = () => { const set = new Set(["mainnet", "sepolia"]); return ( set.has(scaffoldConfig.targetNetworks[0].network) && - // @ts-expect-error we use network here since devnet and sepolia has the same id, and this will silence the compiler since it thinks constant will always be false when it fact its changed at code level scaffoldConfig.targetNetworks[0].network !== chains.devnet.network ); }; @@ -53,10 +52,6 @@ const useScaffoldStarkProfile = (address: chains.Address | undefined) => { } }, [address, provider, targetNetwork]); - useEffect(() => { - console.log({ profile, address }); - }, [profile, address]); - return { data: profile, isLoading }; }; From 1957eb45a65296ce7727284ee3658557c4285c8c Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Sun, 8 Dec 2024 04:55:54 +0700 Subject: [PATCH 10/18] refactor: use starknet id api instead to remove rate limit contract call issues --- .../components/scaffold-stark/Address.tsx | 24 +++--- .../useScaffoldStarkProfile.tsx | 80 ++++++++++++------- packages/nextjs/package.json | 1 - yarn.lock | 11 --- 4 files changed, 61 insertions(+), 55 deletions(-) diff --git a/packages/nextjs/components/scaffold-stark/Address.tsx b/packages/nextjs/components/scaffold-stark/Address.tsx index 4101198c2..b99e54150 100644 --- a/packages/nextjs/components/scaffold-stark/Address.tsx +++ b/packages/nextjs/components/scaffold-stark/Address.tsx @@ -4,11 +4,7 @@ import { useEffect, useMemo, useState } from "react"; import Link from "next/link"; import { CopyToClipboard } from "react-copy-to-clipboard"; import { Address as AddressType } from "@starknet-react/chains"; -import { - getChecksumAddress, - validateAndParseAddress, - validateChecksumAddress, -} from "starknet"; +import { getChecksumAddress, validateChecksumAddress } from "starknet"; import { devnet } from "@starknet-react/chains"; import { CheckCircleIcon, @@ -17,9 +13,7 @@ import { import { useTargetNetwork } from "~~/hooks/scaffold-stark/useTargetNetwork"; import { getBlockExplorerAddressLink } from "~~/utils/scaffold-stark"; import { BlockieAvatar } from "~~/components/scaffold-stark/BlockieAvatar"; -import { getStarknetPFPIfExists } from "~~/utils/profile"; import useScaffoldStarkProfile from "~~/hooks/scaffold-stark/useScaffoldStarkProfile"; -import Image from "next/image"; type AddressProps = { address?: AddressType; @@ -52,7 +46,7 @@ export const Address = ({ const [isUseBlockie, setIsUseBlockie] = useState(false); const { targetNetwork } = useTargetNetwork(); - const { data: fetchedProfile } = useScaffoldStarkProfile(address); + const { data: fetchedProfile, isLoading } = useScaffoldStarkProfile(address); const checkSumAddress = useMemo(() => { if (!address) return undefined; @@ -69,15 +63,21 @@ export const Address = ({ ); useEffect(() => { - if (!!fetchedProfile) { - setDisplayAddress(fetchedProfile.name || ""); + const addressWithFallback = checkSumAddress || address || ""; + + if (fetchedProfile?.name) { + setDisplayAddress(fetchedProfile.name); } else if (format === "long") { - setDisplayAddress(checkSumAddress || address || ""); + setDisplayAddress(addressWithFallback || ""); + } else { + setDisplayAddress( + addressWithFallback.slice(0, 6) + "..." + addressWithFallback.slice(-4), + ); } }, [fetchedProfile, checkSumAddress, address, format]); // Skeleton UI - if (!checkSumAddress) { + if (!checkSumAddress || isLoading) { return (
diff --git a/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx b/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx index 8a25b29b6..95bd3fbe8 100644 --- a/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx +++ b/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx @@ -1,56 +1,74 @@ -import { - useProvider, - useStarkName, - useStarkProfile, -} from "@starknet-react/core"; import * as chains from "@starknet-react/chains"; import scaffoldConfig from "~~/scaffold.config"; -import { useEffect, useMemo, useState } from "react"; -import { constants, Provider, RpcProvider, StarkProfile } from "starknet"; -import { StarknetIdNavigator } from "starknetid.js"; -import { useTargetNetwork } from "./useTargetNetwork"; +import { useEffect, useState } from "react"; +import { StarkProfile } from "starknet"; const shouldUseProfile = () => { const set = new Set(["mainnet", "sepolia"]); return ( set.has(scaffoldConfig.targetNetworks[0].network) && + // @ts-expect-error program thinks this is constant scaffoldConfig.targetNetworks[0].network !== chains.devnet.network ); }; +const starknetIdApiBaseUrl = + // @ts-expect-error program thinks this is constant + scaffoldConfig.targetNetworks[0].network === chains.mainnet.network + ? "https://api.starknet.id" + : "https://sepolia.api.starknet.id"; + +const fetchProfileFromApi = async (address: string) => { + const addrToDomainRes = await fetch( + `${starknetIdApiBaseUrl}/addr_to_domain?addr=${address}`, + ); + + const addrToDomainJson = await addrToDomainRes.json(); + + const domain = addrToDomainJson.domain; + + const profileRes = await fetch( + `${starknetIdApiBaseUrl}/domain_to_data?domain=${domain}`, + ); + + const profileData = await profileRes.json(); + + return { + name: profileData.domain.domain, + + // TODO: figure out where these go in case we have PFP, because its a bit complex to parse the data + // profilePicture?: string; + // discord?: string; + // twitter?: string; + // github?: string; + // proofOfPersonhood?: boolean; + }; +}; + // this hook is a workaround, basically a re-implement of the starknet react hook with conditional rendering. const useScaffoldStarkProfile = (address: chains.Address | undefined) => { const [isLoading, setIsLoading] = useState(false); const [profile, setProfile] = useState(); - const { targetNetwork } = useTargetNetwork(); - const publicNodeUrl = targetNetwork.rpcUrls.public.http[0]; - - const provider = useMemo(() => { - return new RpcProvider({ - nodeUrl: publicNodeUrl, - }); - }, [publicNodeUrl]); + const isEnabled = shouldUseProfile(); useEffect(() => { - if (!shouldUseProfile()) { + if (!isEnabled || !address) { + setProfile(undefined); return; } - const wrappedProvider = new StarknetIdNavigator( - provider as any, - targetNetwork.network === chains.sepolia.network - ? constants.StarknetChainId.SN_SEPOLIA - : constants.StarknetChainId.SN_MAIN, - ); - - if (!!address) { - setIsLoading(true); - wrappedProvider.getProfileData(address).then((profileData) => { - setProfile(profileData); + setIsLoading(true); + + fetchProfileFromApi(address) + .then((data) => { + setProfile(data); + }) + .finally(() => { setIsLoading(false); }); - } - }, [address, provider, targetNetwork]); + + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [address, isEnabled]); return { data: profile, isLoading }; }; diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index 689f3d26d..4281d063d 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -37,7 +37,6 @@ "react-dom": "^18", "react-hot-toast": "^2.4.1", "starknet": "6.12.1", - "starknetid.js": "^4.0.1", "type-fest": "^4.6.0", "usehooks-ts": "^2.13.0", "zustand": "^4.1.2" diff --git a/yarn.lock b/yarn.lock index bf2c100fc..286e7889d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2271,7 +2271,6 @@ __metadata: react-dom: ^18 react-hot-toast: ^2.4.1 starknet: 6.12.1 - starknetid.js: ^4.0.1 tailwindcss: ^3.3.0 type-fest: ^4.6.0 typescript: ^5 @@ -8801,16 +8800,6 @@ __metadata: languageName: node linkType: hard -"starknetid.js@npm:^4.0.1": - version: 4.0.1 - resolution: "starknetid.js@npm:4.0.1" - peerDependencies: - "@babel/core": ^7.0.0-0 - starknet: ^6.9.0 - checksum: ece8a56b322fbf2ef60f476bfa3c3932a205cde60046ea1577059e559c2c83c468ee2697792e559693d45b6d75d6e8f42552249bb65c657b0ca884f6b4d4f0ae - languageName: node - linkType: hard - "stat-mode@npm:0.3.0": version: 0.3.0 resolution: "stat-mode@npm:0.3.0" From 854da912bc5dde2db34f1374db4ef08942deb9eb Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Sun, 8 Dec 2024 15:54:10 +0700 Subject: [PATCH 11/18] fix: json parse error --- .../hooks/scaffold-stark/useScaffoldStarkProfile.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx b/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx index 95bd3fbe8..83babaf53 100644 --- a/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx +++ b/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx @@ -23,6 +23,10 @@ const fetchProfileFromApi = async (address: string) => { `${starknetIdApiBaseUrl}/addr_to_domain?addr=${address}`, ); + if (!addrToDomainRes.ok) { + throw new Error(await addrToDomainRes.text()); + } + const addrToDomainJson = await addrToDomainRes.json(); const domain = addrToDomainJson.domain; @@ -31,6 +35,8 @@ const fetchProfileFromApi = async (address: string) => { `${starknetIdApiBaseUrl}/domain_to_data?domain=${domain}`, ); + if (!profileRes.ok) throw new Error(await profileRes.text()); + const profileData = await profileRes.json(); return { @@ -63,11 +69,13 @@ const useScaffoldStarkProfile = (address: chains.Address | undefined) => { .then((data) => { setProfile(data); }) + .catch((e) => { + console.dir(e); + console.error(`[useScaffoldStarkProfile] ` + e); + }) .finally(() => { setIsLoading(false); }); - - // eslint-disable-next-line react-hooks/exhaustive-deps }, [address, isEnabled]); return { data: profile, isLoading }; From 99ca5562ed7e661893abecc3b4750088fab0d70f Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Sun, 8 Dec 2024 16:01:29 +0700 Subject: [PATCH 12/18] chore: format --- packages/nextjs/.env.example | 2 +- packages/nextjs/app/page.tsx | 2 + .../nextjs/contracts/deployedContracts.ts | 519 +++++++++++++++++- packages/nextjs/scaffold.config.ts | 2 +- 4 files changed, 522 insertions(+), 3 deletions(-) diff --git a/packages/nextjs/.env.example b/packages/nextjs/.env.example index a207edc11..b469dd895 100644 --- a/packages/nextjs/.env.example +++ b/packages/nextjs/.env.example @@ -1 +1 @@ -NEXT_PUBLIC_PROVIDER_URL=https://starknet-sepolia.public.blastapi.io/rpc/v0_7 +NEXT_PUBLIC_PROVIDER_URL=https://starknet-sepolia.blastapi.io/64168c77-3fa5-4e1e-9fe4-41675d212522/rpc/v0_7 diff --git a/packages/nextjs/app/page.tsx b/packages/nextjs/app/page.tsx index 35d15b797..aba819511 100644 --- a/packages/nextjs/app/page.tsx +++ b/packages/nextjs/app/page.tsx @@ -1,6 +1,7 @@ import Link from "next/link"; import Image from "next/image"; import { ConnectedAddress } from "~~/components/ConnectedAddress"; +import { Address } from "~~/components/scaffold-stark"; const Home = () => { return ( @@ -11,6 +12,7 @@ const Home = () => { Scaffold-Stark 2 +

Edit your smart contract{" "} diff --git a/packages/nextjs/contracts/deployedContracts.ts b/packages/nextjs/contracts/deployedContracts.ts index 25751cee0..b3f7f8406 100644 --- a/packages/nextjs/contracts/deployedContracts.ts +++ b/packages/nextjs/contracts/deployedContracts.ts @@ -3,6 +3,523 @@ * You should not edit it manually or your changes might be overwritten. */ -const deployedContracts = {} as const; +const deployedContracts = { + devnet: { + YourContract: { + address: + "0x790b5bcf4678f1a052d22e1f9205e26aa772cf6976db981c63c9a7e6179e737", + abi: [ + { + type: "impl", + name: "YourContractImpl", + interface_name: "contracts::YourContract::IYourContract", + }, + { + type: "struct", + name: "core::byte_array::ByteArray", + members: [ + { + name: "data", + type: "core::array::Array::", + }, + { + name: "pending_word", + type: "core::felt252", + }, + { + name: "pending_word_len", + type: "core::integer::u32", + }, + ], + }, + { + type: "struct", + name: "core::integer::u256", + members: [ + { + name: "low", + type: "core::integer::u128", + }, + { + name: "high", + type: "core::integer::u128", + }, + ], + }, + { + type: "enum", + name: "core::bool", + variants: [ + { + name: "False", + type: "()", + }, + { + name: "True", + type: "()", + }, + ], + }, + { + type: "interface", + name: "contracts::YourContract::IYourContract", + items: [ + { + type: "function", + name: "greeting", + inputs: [], + outputs: [ + { + type: "core::byte_array::ByteArray", + }, + ], + state_mutability: "view", + }, + { + type: "function", + name: "set_greeting", + inputs: [ + { + name: "new_greeting", + type: "core::byte_array::ByteArray", + }, + { + name: "amount_eth", + type: "core::integer::u256", + }, + ], + outputs: [], + state_mutability: "external", + }, + { + type: "function", + name: "withdraw", + inputs: [], + outputs: [], + state_mutability: "external", + }, + { + type: "function", + name: "premium", + inputs: [], + outputs: [ + { + type: "core::bool", + }, + ], + state_mutability: "view", + }, + ], + }, + { + type: "impl", + name: "OwnableImpl", + interface_name: "openzeppelin_access::ownable::interface::IOwnable", + }, + { + type: "interface", + name: "openzeppelin_access::ownable::interface::IOwnable", + items: [ + { + type: "function", + name: "owner", + inputs: [], + outputs: [ + { + type: "core::starknet::contract_address::ContractAddress", + }, + ], + state_mutability: "view", + }, + { + type: "function", + name: "transfer_ownership", + inputs: [ + { + name: "new_owner", + type: "core::starknet::contract_address::ContractAddress", + }, + ], + outputs: [], + state_mutability: "external", + }, + { + type: "function", + name: "renounce_ownership", + inputs: [], + outputs: [], + state_mutability: "external", + }, + ], + }, + { + type: "constructor", + name: "constructor", + inputs: [ + { + name: "owner", + type: "core::starknet::contract_address::ContractAddress", + }, + ], + }, + { + type: "event", + name: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferred", + kind: "struct", + members: [ + { + name: "previous_owner", + type: "core::starknet::contract_address::ContractAddress", + kind: "key", + }, + { + name: "new_owner", + type: "core::starknet::contract_address::ContractAddress", + kind: "key", + }, + ], + }, + { + type: "event", + name: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferStarted", + kind: "struct", + members: [ + { + name: "previous_owner", + type: "core::starknet::contract_address::ContractAddress", + kind: "key", + }, + { + name: "new_owner", + type: "core::starknet::contract_address::ContractAddress", + kind: "key", + }, + ], + }, + { + type: "event", + name: "openzeppelin_access::ownable::ownable::OwnableComponent::Event", + kind: "enum", + variants: [ + { + name: "OwnershipTransferred", + type: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferred", + kind: "nested", + }, + { + name: "OwnershipTransferStarted", + type: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferStarted", + kind: "nested", + }, + ], + }, + { + type: "event", + name: "contracts::YourContract::YourContract::GreetingChanged", + kind: "struct", + members: [ + { + name: "greeting_setter", + type: "core::starknet::contract_address::ContractAddress", + kind: "key", + }, + { + name: "new_greeting", + type: "core::byte_array::ByteArray", + kind: "key", + }, + { + name: "premium", + type: "core::bool", + kind: "data", + }, + { + name: "value", + type: "core::integer::u256", + kind: "data", + }, + ], + }, + { + type: "event", + name: "contracts::YourContract::YourContract::Event", + kind: "enum", + variants: [ + { + name: "OwnableEvent", + type: "openzeppelin_access::ownable::ownable::OwnableComponent::Event", + kind: "flat", + }, + { + name: "GreetingChanged", + type: "contracts::YourContract::YourContract::GreetingChanged", + kind: "nested", + }, + ], + }, + ], + classHash: + "0x2900465e2b29becd029ba2d0cecfb799528347bd2259eb5c6aa2489a8de19f5", + }, + }, + sepolia: { + YourContract: { + address: + "0x7104bd4816c4a2858c4bff6d5b2bf03582bf03d576174f9db565d6583e2d83e", + abi: [ + { + type: "impl", + name: "YourContractImpl", + interface_name: "contracts::YourContract::IYourContract", + }, + { + type: "struct", + name: "core::byte_array::ByteArray", + members: [ + { + name: "data", + type: "core::array::Array::", + }, + { + name: "pending_word", + type: "core::felt252", + }, + { + name: "pending_word_len", + type: "core::integer::u32", + }, + ], + }, + { + type: "struct", + name: "core::integer::u256", + members: [ + { + name: "low", + type: "core::integer::u128", + }, + { + name: "high", + type: "core::integer::u128", + }, + ], + }, + { + type: "enum", + name: "core::bool", + variants: [ + { + name: "False", + type: "()", + }, + { + name: "True", + type: "()", + }, + ], + }, + { + type: "interface", + name: "contracts::YourContract::IYourContract", + items: [ + { + type: "function", + name: "greeting", + inputs: [], + outputs: [ + { + type: "core::byte_array::ByteArray", + }, + ], + state_mutability: "view", + }, + { + type: "function", + name: "set_greeting", + inputs: [ + { + name: "new_greeting", + type: "core::byte_array::ByteArray", + }, + { + name: "amount_eth", + type: "core::integer::u256", + }, + ], + outputs: [], + state_mutability: "external", + }, + { + type: "function", + name: "withdraw", + inputs: [], + outputs: [], + state_mutability: "external", + }, + { + type: "function", + name: "premium", + inputs: [], + outputs: [ + { + type: "core::bool", + }, + ], + state_mutability: "view", + }, + ], + }, + { + type: "impl", + name: "OwnableImpl", + interface_name: "openzeppelin_access::ownable::interface::IOwnable", + }, + { + type: "interface", + name: "openzeppelin_access::ownable::interface::IOwnable", + items: [ + { + type: "function", + name: "owner", + inputs: [], + outputs: [ + { + type: "core::starknet::contract_address::ContractAddress", + }, + ], + state_mutability: "view", + }, + { + type: "function", + name: "transfer_ownership", + inputs: [ + { + name: "new_owner", + type: "core::starknet::contract_address::ContractAddress", + }, + ], + outputs: [], + state_mutability: "external", + }, + { + type: "function", + name: "renounce_ownership", + inputs: [], + outputs: [], + state_mutability: "external", + }, + ], + }, + { + type: "constructor", + name: "constructor", + inputs: [ + { + name: "owner", + type: "core::starknet::contract_address::ContractAddress", + }, + ], + }, + { + type: "event", + name: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferred", + kind: "struct", + members: [ + { + name: "previous_owner", + type: "core::starknet::contract_address::ContractAddress", + kind: "key", + }, + { + name: "new_owner", + type: "core::starknet::contract_address::ContractAddress", + kind: "key", + }, + ], + }, + { + type: "event", + name: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferStarted", + kind: "struct", + members: [ + { + name: "previous_owner", + type: "core::starknet::contract_address::ContractAddress", + kind: "key", + }, + { + name: "new_owner", + type: "core::starknet::contract_address::ContractAddress", + kind: "key", + }, + ], + }, + { + type: "event", + name: "openzeppelin_access::ownable::ownable::OwnableComponent::Event", + kind: "enum", + variants: [ + { + name: "OwnershipTransferred", + type: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferred", + kind: "nested", + }, + { + name: "OwnershipTransferStarted", + type: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferStarted", + kind: "nested", + }, + ], + }, + { + type: "event", + name: "contracts::YourContract::YourContract::GreetingChanged", + kind: "struct", + members: [ + { + name: "greeting_setter", + type: "core::starknet::contract_address::ContractAddress", + kind: "key", + }, + { + name: "new_greeting", + type: "core::byte_array::ByteArray", + kind: "key", + }, + { + name: "premium", + type: "core::bool", + kind: "data", + }, + { + name: "value", + type: "core::integer::u256", + kind: "data", + }, + ], + }, + { + type: "event", + name: "contracts::YourContract::YourContract::Event", + kind: "enum", + variants: [ + { + name: "OwnableEvent", + type: "openzeppelin_access::ownable::ownable::OwnableComponent::Event", + kind: "flat", + }, + { + name: "GreetingChanged", + type: "contracts::YourContract::YourContract::GreetingChanged", + kind: "nested", + }, + ], + }, + ], + classHash: + "0x2a83f388c1c7e7f23b0c5df034bb4c36ed36eff65513760954c4d1effaa2074", + }, + }, +} as const; export default deployedContracts; diff --git a/packages/nextjs/scaffold.config.ts b/packages/nextjs/scaffold.config.ts index 4b80eee2c..1446a0c38 100644 --- a/packages/nextjs/scaffold.config.ts +++ b/packages/nextjs/scaffold.config.ts @@ -11,7 +11,7 @@ export type ScaffoldConfig = { }; const scaffoldConfig = { - targetNetworks: [chains.devnet], + targetNetworks: [chains.sepolia], // Only show the Burner Wallet when running on devnet onlyLocalBurnerWallet: false, rpcProviderUrl: process.env.NEXT_PUBLIC_PROVIDER_URL || "", From 06ea2aa1f684693bff241adb0be6cf8f639bad43 Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Sun, 8 Dec 2024 16:33:12 +0700 Subject: [PATCH 13/18] fix: remove debug address --- packages/nextjs/app/page.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/nextjs/app/page.tsx b/packages/nextjs/app/page.tsx index aba819511..9e7aa9e42 100644 --- a/packages/nextjs/app/page.tsx +++ b/packages/nextjs/app/page.tsx @@ -12,7 +12,6 @@ const Home = () => { Scaffold-Stark 2 -

Edit your smart contract{" "} From 03c5677a0e968bb6c23a84517828bcfd5558c8e4 Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Sun, 8 Dec 2024 16:34:44 +0700 Subject: [PATCH 14/18] chore: revert config to devnet --- packages/nextjs/scaffold.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/scaffold.config.ts b/packages/nextjs/scaffold.config.ts index 1446a0c38..4b80eee2c 100644 --- a/packages/nextjs/scaffold.config.ts +++ b/packages/nextjs/scaffold.config.ts @@ -11,7 +11,7 @@ export type ScaffoldConfig = { }; const scaffoldConfig = { - targetNetworks: [chains.sepolia], + targetNetworks: [chains.devnet], // Only show the Burner Wallet when running on devnet onlyLocalBurnerWallet: false, rpcProviderUrl: process.env.NEXT_PUBLIC_PROVIDER_URL || "", From 703085a75ec773cda28d68088d0aaad8f04361dd Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Sun, 8 Dec 2024 16:35:21 +0700 Subject: [PATCH 15/18] chore: revert deployed contracts --- .../nextjs/contracts/deployedContracts.ts | 519 +----------------- 1 file changed, 1 insertion(+), 518 deletions(-) diff --git a/packages/nextjs/contracts/deployedContracts.ts b/packages/nextjs/contracts/deployedContracts.ts index b3f7f8406..25751cee0 100644 --- a/packages/nextjs/contracts/deployedContracts.ts +++ b/packages/nextjs/contracts/deployedContracts.ts @@ -3,523 +3,6 @@ * You should not edit it manually or your changes might be overwritten. */ -const deployedContracts = { - devnet: { - YourContract: { - address: - "0x790b5bcf4678f1a052d22e1f9205e26aa772cf6976db981c63c9a7e6179e737", - abi: [ - { - type: "impl", - name: "YourContractImpl", - interface_name: "contracts::YourContract::IYourContract", - }, - { - type: "struct", - name: "core::byte_array::ByteArray", - members: [ - { - name: "data", - type: "core::array::Array::", - }, - { - name: "pending_word", - type: "core::felt252", - }, - { - name: "pending_word_len", - type: "core::integer::u32", - }, - ], - }, - { - type: "struct", - name: "core::integer::u256", - members: [ - { - name: "low", - type: "core::integer::u128", - }, - { - name: "high", - type: "core::integer::u128", - }, - ], - }, - { - type: "enum", - name: "core::bool", - variants: [ - { - name: "False", - type: "()", - }, - { - name: "True", - type: "()", - }, - ], - }, - { - type: "interface", - name: "contracts::YourContract::IYourContract", - items: [ - { - type: "function", - name: "greeting", - inputs: [], - outputs: [ - { - type: "core::byte_array::ByteArray", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "set_greeting", - inputs: [ - { - name: "new_greeting", - type: "core::byte_array::ByteArray", - }, - { - name: "amount_eth", - type: "core::integer::u256", - }, - ], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "withdraw", - inputs: [], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "premium", - inputs: [], - outputs: [ - { - type: "core::bool", - }, - ], - state_mutability: "view", - }, - ], - }, - { - type: "impl", - name: "OwnableImpl", - interface_name: "openzeppelin_access::ownable::interface::IOwnable", - }, - { - type: "interface", - name: "openzeppelin_access::ownable::interface::IOwnable", - items: [ - { - type: "function", - name: "owner", - inputs: [], - outputs: [ - { - type: "core::starknet::contract_address::ContractAddress", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "transfer_ownership", - inputs: [ - { - name: "new_owner", - type: "core::starknet::contract_address::ContractAddress", - }, - ], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "renounce_ownership", - inputs: [], - outputs: [], - state_mutability: "external", - }, - ], - }, - { - type: "constructor", - name: "constructor", - inputs: [ - { - name: "owner", - type: "core::starknet::contract_address::ContractAddress", - }, - ], - }, - { - type: "event", - name: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferred", - kind: "struct", - members: [ - { - name: "previous_owner", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "new_owner", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - ], - }, - { - type: "event", - name: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferStarted", - kind: "struct", - members: [ - { - name: "previous_owner", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "new_owner", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - ], - }, - { - type: "event", - name: "openzeppelin_access::ownable::ownable::OwnableComponent::Event", - kind: "enum", - variants: [ - { - name: "OwnershipTransferred", - type: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferred", - kind: "nested", - }, - { - name: "OwnershipTransferStarted", - type: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferStarted", - kind: "nested", - }, - ], - }, - { - type: "event", - name: "contracts::YourContract::YourContract::GreetingChanged", - kind: "struct", - members: [ - { - name: "greeting_setter", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "new_greeting", - type: "core::byte_array::ByteArray", - kind: "key", - }, - { - name: "premium", - type: "core::bool", - kind: "data", - }, - { - name: "value", - type: "core::integer::u256", - kind: "data", - }, - ], - }, - { - type: "event", - name: "contracts::YourContract::YourContract::Event", - kind: "enum", - variants: [ - { - name: "OwnableEvent", - type: "openzeppelin_access::ownable::ownable::OwnableComponent::Event", - kind: "flat", - }, - { - name: "GreetingChanged", - type: "contracts::YourContract::YourContract::GreetingChanged", - kind: "nested", - }, - ], - }, - ], - classHash: - "0x2900465e2b29becd029ba2d0cecfb799528347bd2259eb5c6aa2489a8de19f5", - }, - }, - sepolia: { - YourContract: { - address: - "0x7104bd4816c4a2858c4bff6d5b2bf03582bf03d576174f9db565d6583e2d83e", - abi: [ - { - type: "impl", - name: "YourContractImpl", - interface_name: "contracts::YourContract::IYourContract", - }, - { - type: "struct", - name: "core::byte_array::ByteArray", - members: [ - { - name: "data", - type: "core::array::Array::", - }, - { - name: "pending_word", - type: "core::felt252", - }, - { - name: "pending_word_len", - type: "core::integer::u32", - }, - ], - }, - { - type: "struct", - name: "core::integer::u256", - members: [ - { - name: "low", - type: "core::integer::u128", - }, - { - name: "high", - type: "core::integer::u128", - }, - ], - }, - { - type: "enum", - name: "core::bool", - variants: [ - { - name: "False", - type: "()", - }, - { - name: "True", - type: "()", - }, - ], - }, - { - type: "interface", - name: "contracts::YourContract::IYourContract", - items: [ - { - type: "function", - name: "greeting", - inputs: [], - outputs: [ - { - type: "core::byte_array::ByteArray", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "set_greeting", - inputs: [ - { - name: "new_greeting", - type: "core::byte_array::ByteArray", - }, - { - name: "amount_eth", - type: "core::integer::u256", - }, - ], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "withdraw", - inputs: [], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "premium", - inputs: [], - outputs: [ - { - type: "core::bool", - }, - ], - state_mutability: "view", - }, - ], - }, - { - type: "impl", - name: "OwnableImpl", - interface_name: "openzeppelin_access::ownable::interface::IOwnable", - }, - { - type: "interface", - name: "openzeppelin_access::ownable::interface::IOwnable", - items: [ - { - type: "function", - name: "owner", - inputs: [], - outputs: [ - { - type: "core::starknet::contract_address::ContractAddress", - }, - ], - state_mutability: "view", - }, - { - type: "function", - name: "transfer_ownership", - inputs: [ - { - name: "new_owner", - type: "core::starknet::contract_address::ContractAddress", - }, - ], - outputs: [], - state_mutability: "external", - }, - { - type: "function", - name: "renounce_ownership", - inputs: [], - outputs: [], - state_mutability: "external", - }, - ], - }, - { - type: "constructor", - name: "constructor", - inputs: [ - { - name: "owner", - type: "core::starknet::contract_address::ContractAddress", - }, - ], - }, - { - type: "event", - name: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferred", - kind: "struct", - members: [ - { - name: "previous_owner", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "new_owner", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - ], - }, - { - type: "event", - name: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferStarted", - kind: "struct", - members: [ - { - name: "previous_owner", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "new_owner", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - ], - }, - { - type: "event", - name: "openzeppelin_access::ownable::ownable::OwnableComponent::Event", - kind: "enum", - variants: [ - { - name: "OwnershipTransferred", - type: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferred", - kind: "nested", - }, - { - name: "OwnershipTransferStarted", - type: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferStarted", - kind: "nested", - }, - ], - }, - { - type: "event", - name: "contracts::YourContract::YourContract::GreetingChanged", - kind: "struct", - members: [ - { - name: "greeting_setter", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "new_greeting", - type: "core::byte_array::ByteArray", - kind: "key", - }, - { - name: "premium", - type: "core::bool", - kind: "data", - }, - { - name: "value", - type: "core::integer::u256", - kind: "data", - }, - ], - }, - { - type: "event", - name: "contracts::YourContract::YourContract::Event", - kind: "enum", - variants: [ - { - name: "OwnableEvent", - type: "openzeppelin_access::ownable::ownable::OwnableComponent::Event", - kind: "flat", - }, - { - name: "GreetingChanged", - type: "contracts::YourContract::YourContract::GreetingChanged", - kind: "nested", - }, - ], - }, - ], - classHash: - "0x2a83f388c1c7e7f23b0c5df034bb4c36ed36eff65513760954c4d1effaa2074", - }, - }, -} as const; +const deployedContracts = {} as const; export default deployedContracts; From 6450ca31841b4f38dc515a519a8c3812c955a931 Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Sun, 8 Dec 2024 16:43:22 +0700 Subject: [PATCH 16/18] fix: changing account should change profile state --- .../nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx b/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx index 83babaf53..2f9a19c9e 100644 --- a/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx +++ b/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx @@ -70,8 +70,8 @@ const useScaffoldStarkProfile = (address: chains.Address | undefined) => { setProfile(data); }) .catch((e) => { - console.dir(e); - console.error(`[useScaffoldStarkProfile] ` + e); + console.error(`[useScaffoldStarkProfile] ` + e.message); + setProfile(undefined); }) .finally(() => { setIsLoading(false); From 3a41bfdb454dff2b9e92f1a0f64b56a64cedc2ca Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Sun, 8 Dec 2024 16:50:01 +0700 Subject: [PATCH 17/18] chore: remove unused ts expect error --- packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx b/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx index 2f9a19c9e..32e6e9496 100644 --- a/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx +++ b/packages/nextjs/hooks/scaffold-stark/useScaffoldStarkProfile.tsx @@ -7,7 +7,6 @@ const shouldUseProfile = () => { const set = new Set(["mainnet", "sepolia"]); return ( set.has(scaffoldConfig.targetNetworks[0].network) && - // @ts-expect-error program thinks this is constant scaffoldConfig.targetNetworks[0].network !== chains.devnet.network ); }; From 8c09ea9483beed6e6e1594ac0bf5a884031dcb69 Mon Sep 17 00:00:00 2001 From: metalboyrick Date: Sun, 8 Dec 2024 17:01:13 +0700 Subject: [PATCH 18/18] chore: remove unused imports --- packages/nextjs/app/page.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/nextjs/app/page.tsx b/packages/nextjs/app/page.tsx index 9e7aa9e42..35d15b797 100644 --- a/packages/nextjs/app/page.tsx +++ b/packages/nextjs/app/page.tsx @@ -1,7 +1,6 @@ import Link from "next/link"; import Image from "next/image"; import { ConnectedAddress } from "~~/components/ConnectedAddress"; -import { Address } from "~~/components/scaffold-stark"; const Home = () => { return (