From d3a430d26da84b7ff2e356df06157a3f277e2632 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Mon, 8 Apr 2024 15:19:42 -0500 Subject: [PATCH 1/4] feat: add custom provider --- packages/nextjs/.env.example | 1 + .../ScaffoldStarkAppWithProviders.tsx | 18 +- .../nextjs/contracts/deployedContracts.ts | 653 ++++++++++-------- packages/nextjs/scaffold.config.ts | 2 + 4 files changed, 373 insertions(+), 301 deletions(-) create mode 100644 packages/nextjs/.env.example diff --git a/packages/nextjs/.env.example b/packages/nextjs/.env.example new file mode 100644 index 00000000..44fea21e --- /dev/null +++ b/packages/nextjs/.env.example @@ -0,0 +1 @@ +NEXT_PUBLIC_PROVIDER_API_KEY= \ No newline at end of file diff --git a/packages/nextjs/components/ScaffoldStarkAppWithProviders.tsx b/packages/nextjs/components/ScaffoldStarkAppWithProviders.tsx index de30fde0..f53b3b54 100644 --- a/packages/nextjs/components/ScaffoldStarkAppWithProviders.tsx +++ b/packages/nextjs/components/ScaffoldStarkAppWithProviders.tsx @@ -5,18 +5,14 @@ import {useEffect, useState} from "react"; import {useTheme} from "next-themes"; import {Toaster} from "react-hot-toast"; import { - StarknetConfig, - publicProvider, - argent, - braavos, - useInjectedConnectors, - starkscan, + StarknetConfig, publicProvider, argent, braavos, useInjectedConnectors, starkscan, jsonRpcProvider, starknetChainId, } from "@starknet-react/core"; import {Header} from "~~/components/Header"; import {Footer} from "~~/components/Footer"; import {ProgressBar} from "~~/components/scaffold-stark/ProgressBar"; import {appChains} from "~~/services/web3/connectors"; import {BurnerConnector} from "~~/services/web3/stark-burner/BurnerConnector"; +import scaffoldConfig from "~~/scaffold.config"; const ScaffoldStarkApp = ({children}: { children: React.ReactNode }) => { return ( @@ -37,6 +33,14 @@ export const ScaffoldStarkAppWithProviders = ({children,}: { const isDarkMode = resolvedTheme === "dark"; const [mounted, setMounted] = useState(false); + const provider = scaffoldConfig.rpcProviderApiKey == "" ? publicProvider() : + jsonRpcProvider({ + rpc: () => ({ + nodeUrl: scaffoldConfig.rpcProviderApiKey, + chainId: starknetChainId(scaffoldConfig.targetNetworks[0].id) + }) + }) + useEffect(() => { setMounted(true); }, []); @@ -49,7 +53,7 @@ export const ScaffoldStarkAppWithProviders = ({children,}: { return ( diff --git a/packages/nextjs/contracts/deployedContracts.ts b/packages/nextjs/contracts/deployedContracts.ts index 91b86e89..9887b5ae 100644 --- a/packages/nextjs/contracts/deployedContracts.ts +++ b/packages/nextjs/contracts/deployedContracts.ts @@ -7,7 +7,7 @@ const deployedContracts = { devnet: { HelloStarknet: { address: - "0x049596cd6bba05027f7928d893b5a204720e59c5591206ea4d957f29f3481a6a", + "0x03cde55282f0c58631a419898569c889b41142438482118c6e50f65c77ebf6fb", abi: [ { type: "impl", @@ -67,39 +67,71 @@ const deployedContracts = { }, ], }, - Challenge0: { + SimpleStorage: { address: - "0x0047466ee4e2950b249a27cc77d6eaecb30e28096d901a2bb1ee94654242d34f", + "0x06aa7ffead51a8bf475cd97b072bd4899e19018b6f0f3c423954b03231237d69", abi: [ { type: "impl", - name: "ERC721MixinImpl", - interface_name: "openzeppelin::token::erc721::interface::ERC721ABI", + name: "SimpleStorageImpl", + interface_name: "contracts::simpleStorage::ISimpleStorage", }, { - type: "struct", - name: "core::integer::u256", - members: [ + type: "interface", + name: "contracts::simpleStorage::ISimpleStorage", + items: [ { - name: "low", - type: "core::integer::u128", + type: "function", + name: "get_name", + inputs: [], + outputs: [ + { + type: "core::felt252", + }, + ], + state_mutability: "view", }, { - name: "high", - type: "core::integer::u128", + type: "function", + name: "set_name", + inputs: [ + { + name: "name", + type: "core::felt252", + }, + ], + outputs: [], + state_mutability: "external", }, ], }, { - type: "struct", - name: "core::array::Span::", - members: [ + type: "constructor", + name: "constructor", + inputs: [ { - name: "snapshot", - type: "@core::array::Array::", + name: "name", + type: "core::felt252", }, ], }, + { + type: "event", + name: "contracts::simpleStorage::SimpleStorage::Event", + kind: "enum", + variants: [], + }, + ], + }, + Vote: { + address: + "0x035e2ca6c323204725495105c23353cd2645e264949fb0f8bce2144fbe695d50", + abi: [ + { + type: "impl", + name: "VoteImpl", + interface_name: "contracts::vote::VoteTrait", + }, { type: "enum", name: "core::bool", @@ -114,344 +146,438 @@ const deployedContracts = { }, ], }, - { - 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: "interface", - name: "openzeppelin::token::erc721::interface::ERC721ABI", + name: "contracts::vote::VoteTrait", items: [ { type: "function", - name: "balance_of", - inputs: [ - { - name: "account", - type: "core::starknet::contract_address::ContractAddress", - }, - ], + name: "get_vote_status", + inputs: [], outputs: [ { - type: "core::integer::u256", + type: "(core::integer::u8, core::integer::u8, core::integer::u8, core::integer::u8)", }, ], state_mutability: "view", }, { type: "function", - name: "owner_of", + name: "voter_can_vote", inputs: [ { - name: "token_id", - type: "core::integer::u256", + name: "user_address", + type: "core::starknet::contract_address::ContractAddress", }, ], outputs: [ { - type: "core::starknet::contract_address::ContractAddress", + type: "core::bool", }, ], state_mutability: "view", }, { type: "function", - name: "safe_transfer_from", + name: "is_voter_registered", inputs: [ { - name: "from", + name: "address", type: "core::starknet::contract_address::ContractAddress", }, + ], + outputs: [ { - name: "to", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "token_id", - type: "core::integer::u256", - }, - { - name: "data", - type: "core::array::Span::", + type: "core::bool", }, ], - outputs: [], - state_mutability: "external", + state_mutability: "view", }, { type: "function", - name: "transfer_from", + name: "vote", inputs: [ { - name: "from", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "to", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "token_id", - type: "core::integer::u256", + name: "vote", + type: "core::integer::u8", }, ], outputs: [], state_mutability: "external", }, + ], + }, + { + type: "constructor", + name: "constructor", + inputs: [ { - type: "function", - name: "approve", - inputs: [ - { - name: "to", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "token_id", - type: "core::integer::u256", - }, - ], - outputs: [], - state_mutability: "external", + name: "voter_1", + type: "core::starknet::contract_address::ContractAddress", }, { - type: "function", - name: "set_approval_for_all", - inputs: [ - { - name: "operator", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "approved", - type: "core::bool", - }, - ], - outputs: [], - state_mutability: "external", + name: "voter_2", + type: "core::starknet::contract_address::ContractAddress", + }, + { + name: "voter_3", + type: "core::starknet::contract_address::ContractAddress", + }, + ], + }, + { + type: "event", + name: "contracts::vote::Vote::VoteCast", + kind: "struct", + members: [ + { + name: "voter", + type: "core::starknet::contract_address::ContractAddress", + kind: "data", + }, + { + name: "vote", + type: "core::integer::u8", + kind: "data", + }, + ], + }, + { + type: "event", + name: "contracts::vote::Vote::UnauthorizedAttempt", + kind: "struct", + members: [ + { + name: "unauthorized_address", + type: "core::starknet::contract_address::ContractAddress", + kind: "data", + }, + ], + }, + { + type: "event", + name: "contracts::vote::Vote::Event", + kind: "enum", + variants: [ + { + name: "VoteCast", + type: "contracts::vote::Vote::VoteCast", + kind: "nested", }, + { + name: "UnauthorizedAttempt", + type: "contracts::vote::Vote::UnauthorizedAttempt", + kind: "nested", + }, + ], + }, + ], + }, + Ownable: { + address: + "0x0133d989c25e6e6237c0b486478470960ae46878e1147ae9d14e9ccf40e88442", + abi: [ + { + type: "impl", + name: "OwnableDataImpl", + interface_name: "contracts::IData", + }, + { + type: "interface", + name: "contracts::IData", + items: [ { type: "function", - name: "get_approved", - inputs: [ - { - name: "token_id", - type: "core::integer::u256", - }, - ], + name: "get_data", + inputs: [], outputs: [ { - type: "core::starknet::contract_address::ContractAddress", + type: "core::integer::u64", }, ], state_mutability: "view", }, { type: "function", - name: "is_approved_for_all", + name: "set_data", inputs: [ { - name: "owner", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "operator", - type: "core::starknet::contract_address::ContractAddress", - }, - ], - outputs: [ - { - type: "core::bool", + name: "new_value", + type: "core::integer::u64", }, ], - state_mutability: "view", + outputs: [], + state_mutability: "external", }, + ], + }, + { + type: "impl", + name: "OwnableImpl", + interface_name: "contracts::IOwnable", + }, + { + type: "interface", + name: "contracts::IOwnable", + items: [ { type: "function", - name: "supports_interface", + name: "transfer_ownership", inputs: [ { - name: "interface_id", - type: "core::felt252", - }, - ], - outputs: [ - { - type: "core::bool", + name: "new_owner", + type: "core::starknet::contract_address::ContractAddress", }, ], - state_mutability: "view", + outputs: [], + state_mutability: "external", }, { type: "function", - name: "name", + name: "owner", inputs: [], outputs: [ { - type: "core::byte_array::ByteArray", + type: "core::starknet::contract_address::ContractAddress", }, ], state_mutability: "view", }, + ], + }, + { + type: "constructor", + name: "constructor", + inputs: [ { - type: "function", - name: "symbol", - inputs: [], - outputs: [ - { - type: "core::byte_array::ByteArray", - }, - ], - state_mutability: "view", + name: "initial_owner", + type: "core::starknet::contract_address::ContractAddress", + }, + ], + }, + { + type: "event", + name: "contracts::ownable_component::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: "data", + }, + ], + }, + { + type: "event", + name: "contracts::ownable_component::Event", + kind: "enum", + variants: [ + { + name: "OwnershipTransferred", + type: "contracts::ownable_component::OwnershipTransferred", + kind: "nested", + }, + ], + }, + { + type: "event", + name: "contracts::Ownable::Event", + kind: "enum", + variants: [ + { + name: "OwnableEvent", + type: "contracts::ownable_component::Event", + kind: "nested", + }, + ], + }, + ], + }, + }, + sepolia: { + HelloStarknet: { + address: + "0x06ebc9ea691324adae48e0ebfd858fb9cdb2052f16fc9337518b6e9ac78b4576", + abi: [ + { + type: "impl", + name: "HelloStarknetImpl", + interface_name: "contracts::helloStarknet::IHelloStarknet", + }, + { + type: "interface", + name: "contracts::helloStarknet::IHelloStarknet", + items: [ { type: "function", - name: "token_uri", + name: "increase_balance", inputs: [ { - name: "token_id", - type: "core::integer::u256", + name: "amount", + type: "core::integer::u32", }, ], + outputs: [], + state_mutability: "external", + }, + { + type: "function", + name: "get_balance", + inputs: [], outputs: [ { - type: "core::byte_array::ByteArray", + type: "core::integer::u32", }, ], state_mutability: "view", }, { type: "function", - name: "balanceOf", + name: "get_balance_increment", inputs: [ { - name: "account", - type: "core::starknet::contract_address::ContractAddress", + name: "amount", + type: "core::integer::u32", }, ], outputs: [ { - type: "core::integer::u256", + type: "core::integer::u32", }, ], state_mutability: "view", }, + ], + }, + { + type: "event", + name: "contracts::helloStarknet::HelloStarknet::Event", + kind: "enum", + variants: [], + }, + ], + }, + SimpleStorage: { + address: + "0x0131e61782d2a33b8c01bbe910ef9434e0d921c58c203ade5a18329e73c43a8f", + abi: [ + { + type: "impl", + name: "SimpleStorageImpl", + interface_name: "contracts::simpleStorage::ISimpleStorage", + }, + { + type: "interface", + name: "contracts::simpleStorage::ISimpleStorage", + items: [ { type: "function", - name: "ownerOf", - inputs: [ - { - name: "tokenId", - type: "core::integer::u256", - }, - ], + name: "get_name", + inputs: [], outputs: [ { - type: "core::starknet::contract_address::ContractAddress", + type: "core::felt252", }, ], state_mutability: "view", }, { type: "function", - name: "safeTransferFrom", + name: "set_name", inputs: [ { - name: "from", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "to", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "tokenId", - type: "core::integer::u256", - }, - { - name: "data", - type: "core::array::Span::", + name: "name", + type: "core::felt252", }, ], outputs: [], state_mutability: "external", }, + ], + }, + { + type: "constructor", + name: "constructor", + inputs: [ { - type: "function", - name: "transferFrom", - inputs: [ - { - name: "from", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "to", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "tokenId", - type: "core::integer::u256", - }, - ], - outputs: [], - state_mutability: "external", + name: "name", + type: "core::felt252", + }, + ], + }, + { + type: "event", + name: "contracts::simpleStorage::SimpleStorage::Event", + kind: "enum", + variants: [], + }, + ], + }, + Vote: { + address: + "0x07e91c1964d3da4166c2cb9a15ed23fd98ed3ff3db2ba94359696f9dffa23e9c", + abi: [ + { + type: "impl", + name: "VoteImpl", + interface_name: "contracts::vote::VoteTrait", + }, + { + type: "enum", + name: "core::bool", + variants: [ + { + name: "False", + type: "()", }, + { + name: "True", + type: "()", + }, + ], + }, + { + type: "interface", + name: "contracts::vote::VoteTrait", + items: [ { type: "function", - name: "setApprovalForAll", - inputs: [ - { - name: "operator", - type: "core::starknet::contract_address::ContractAddress", - }, + name: "get_vote_status", + inputs: [], + outputs: [ { - name: "approved", - type: "core::bool", + type: "(core::integer::u8, core::integer::u8, core::integer::u8, core::integer::u8)", }, ], - outputs: [], - state_mutability: "external", + state_mutability: "view", }, { type: "function", - name: "getApproved", + name: "voter_can_vote", inputs: [ { - name: "tokenId", - type: "core::integer::u256", + name: "user_address", + type: "core::starknet::contract_address::ContractAddress", }, ], outputs: [ { - type: "core::starknet::contract_address::ContractAddress", + type: "core::bool", }, ], state_mutability: "view", }, { type: "function", - name: "isApprovedForAll", + name: "is_voter_registered", inputs: [ { - name: "owner", - type: "core::starknet::contract_address::ContractAddress", - }, - { - name: "operator", + name: "address", type: "core::starknet::contract_address::ContractAddress", }, ], @@ -464,19 +590,15 @@ const deployedContracts = { }, { type: "function", - name: "tokenURI", + name: "vote", inputs: [ { - name: "tokenId", - type: "core::integer::u256", + name: "vote", + type: "core::integer::u8", }, ], - outputs: [ - { - type: "core::byte_array::ByteArray", - }, - ], - state_mutability: "view", + outputs: [], + state_mutability: "external", }, ], }, @@ -485,122 +607,65 @@ const deployedContracts = { name: "constructor", inputs: [ { - name: "recipient", - type: "core::felt252", - }, - ], - }, - { - type: "event", - name: "openzeppelin::token::erc721::erc721::ERC721Component::Transfer", - kind: "struct", - members: [ - { - name: "from", + name: "voter_1", type: "core::starknet::contract_address::ContractAddress", - kind: "key", }, { - name: "to", + name: "voter_2", type: "core::starknet::contract_address::ContractAddress", - kind: "key", }, { - name: "token_id", - type: "core::integer::u256", - kind: "key", + name: "voter_3", + type: "core::starknet::contract_address::ContractAddress", }, ], }, { type: "event", - name: "openzeppelin::token::erc721::erc721::ERC721Component::Approval", + name: "contracts::vote::Vote::VoteCast", kind: "struct", members: [ { - name: "owner", + name: "voter", type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "approved", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", + kind: "data", }, { - name: "token_id", - type: "core::integer::u256", - kind: "key", + name: "vote", + type: "core::integer::u8", + kind: "data", }, ], }, { type: "event", - name: "openzeppelin::token::erc721::erc721::ERC721Component::ApprovalForAll", + name: "contracts::vote::Vote::UnauthorizedAttempt", kind: "struct", members: [ { - name: "owner", + name: "unauthorized_address", type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "operator", - type: "core::starknet::contract_address::ContractAddress", - kind: "key", - }, - { - name: "approved", - type: "core::bool", kind: "data", }, ], }, { type: "event", - name: "openzeppelin::token::erc721::erc721::ERC721Component::Event", + name: "contracts::vote::Vote::Event", kind: "enum", variants: [ { - name: "Transfer", - type: "openzeppelin::token::erc721::erc721::ERC721Component::Transfer", - kind: "nested", - }, - { - name: "Approval", - type: "openzeppelin::token::erc721::erc721::ERC721Component::Approval", + name: "VoteCast", + type: "contracts::vote::Vote::VoteCast", kind: "nested", }, { - name: "ApprovalForAll", - type: "openzeppelin::token::erc721::erc721::ERC721Component::ApprovalForAll", + name: "UnauthorizedAttempt", + type: "contracts::vote::Vote::UnauthorizedAttempt", kind: "nested", }, ], }, - { - type: "event", - name: "openzeppelin::introspection::src5::SRC5Component::Event", - kind: "enum", - variants: [], - }, - { - type: "event", - name: "contracts::challenge0::Challenge0::Event", - kind: "enum", - variants: [ - { - name: "ERC721Event", - type: "openzeppelin::token::erc721::erc721::ERC721Component::Event", - kind: "flat", - }, - { - name: "SRC5Event", - type: "openzeppelin::introspection::src5::SRC5Component::Event", - kind: "flat", - }, - ], - }, ], }, }, diff --git a/packages/nextjs/scaffold.config.ts b/packages/nextjs/scaffold.config.ts index 71377066..9d51683d 100644 --- a/packages/nextjs/scaffold.config.ts +++ b/packages/nextjs/scaffold.config.ts @@ -3,6 +3,7 @@ import * as chains from "@starknet-react/chains"; export type ScaffoldConfig = { targetNetworks: readonly chains.Chain[]; onlyLocalBurnerWallet: boolean; + rpcProviderApiKey: string; walletAutoConnect: boolean; }; @@ -10,6 +11,7 @@ const scaffoldConfig = { targetNetworks: [chains.sepolia], // Only show the Burner Wallet when running on devnet onlyLocalBurnerWallet: false, + rpcProviderApiKey: process.env.NEXT_PUBLIC_PROVIDER_API_KEY || "", /** * Auto connect: * 1. If the user was connected into a wallet before, on page reload reconnect automatically From ef003aba7775e9a1ec6d5844bf4eb587d1e57260 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Mon, 8 Apr 2024 21:03:43 -0500 Subject: [PATCH 2/4] update: custom provider url --- packages/nextjs/.env.example | 2 +- packages/nextjs/components/ScaffoldStarkAppWithProviders.tsx | 4 ++-- packages/nextjs/scaffold.config.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/nextjs/.env.example b/packages/nextjs/.env.example index 44fea21e..49cc1643 100644 --- a/packages/nextjs/.env.example +++ b/packages/nextjs/.env.example @@ -1 +1 @@ -NEXT_PUBLIC_PROVIDER_API_KEY= \ No newline at end of file +NEXT_PUBLIC_PROVIDER_URL= \ No newline at end of file diff --git a/packages/nextjs/components/ScaffoldStarkAppWithProviders.tsx b/packages/nextjs/components/ScaffoldStarkAppWithProviders.tsx index f53b3b54..e04cc12f 100644 --- a/packages/nextjs/components/ScaffoldStarkAppWithProviders.tsx +++ b/packages/nextjs/components/ScaffoldStarkAppWithProviders.tsx @@ -33,10 +33,10 @@ export const ScaffoldStarkAppWithProviders = ({children,}: { const isDarkMode = resolvedTheme === "dark"; const [mounted, setMounted] = useState(false); - const provider = scaffoldConfig.rpcProviderApiKey == "" ? publicProvider() : + const provider = scaffoldConfig.rpcProviderUrl == "" ? publicProvider() : jsonRpcProvider({ rpc: () => ({ - nodeUrl: scaffoldConfig.rpcProviderApiKey, + nodeUrl: scaffoldConfig.rpcProviderUrl, chainId: starknetChainId(scaffoldConfig.targetNetworks[0].id) }) }) diff --git a/packages/nextjs/scaffold.config.ts b/packages/nextjs/scaffold.config.ts index 9d51683d..b57feb3a 100644 --- a/packages/nextjs/scaffold.config.ts +++ b/packages/nextjs/scaffold.config.ts @@ -3,7 +3,7 @@ import * as chains from "@starknet-react/chains"; export type ScaffoldConfig = { targetNetworks: readonly chains.Chain[]; onlyLocalBurnerWallet: boolean; - rpcProviderApiKey: string; + rpcProviderUrl: string; walletAutoConnect: boolean; }; @@ -11,7 +11,7 @@ const scaffoldConfig = { targetNetworks: [chains.sepolia], // Only show the Burner Wallet when running on devnet onlyLocalBurnerWallet: false, - rpcProviderApiKey: process.env.NEXT_PUBLIC_PROVIDER_API_KEY || "", + rpcProviderUrl: process.env.NEXT_PUBLIC_PROVIDER_URL || "", /** * Auto connect: * 1. If the user was connected into a wallet before, on page reload reconnect automatically From b3626e0f5ea45f4b6a10882d6f19269adc6d9023 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Thu, 11 Apr 2024 11:35:18 -0500 Subject: [PATCH 3/4] feat: format code --- package.json | 7 +- .../app/debug/_components/DebugContracts.tsx | 2 +- .../debug/_components/contract/ContractUI.tsx | 2 +- .../contract/ReadOnlyFunctionForm.tsx | 2 +- .../debug/_components/contract/TxReceipt.tsx | 2 +- .../contract/WriteOnlyFunctionForm.tsx | 4 +- .../_components/contract/utilsContract.tsx | 4 +- .../_components/contract/utilsDisplay.tsx | 4 +- packages/nextjs/components/FaucetMenu.tsx | 16 +- packages/nextjs/components/Header.tsx | 8 +- .../ScaffoldStarkAppWithProviders.tsx | 59 +++--- .../components/scaffold-stark/Address.tsx | 2 +- .../components/scaffold-stark/Balance.tsx | 2 +- .../scaffold-stark/BlockieAvatar.tsx | 6 +- .../AddressInfoDropdown.tsx | 29 ++- .../AddressQRCodeModal.tsx | 10 +- .../CustomConnectButton/ConnectModal.tsx | 6 +- .../CustomConnectButton/NetworkOptions.tsx | 26 ++- .../WrongNetworkDropdown.tsx | 12 +- .../CustomConnectButton/index.tsx | 83 ++++---- .../scaffold-stark/Input/InputBase.tsx | 6 +- .../components/scaffold-stark/Input/utils.ts | 2 +- .../components/scaffold-stark/ProgressBar.tsx | 4 +- .../components/scaffold-stark/index.tsx | 2 +- packages/nextjs/hooks/scaffold-stark/index.ts | 2 +- .../hooks/scaffold-stark/useAutoConnect.ts | 14 +- .../scaffold-stark/useDeployedContractInfo.ts | 6 +- .../hooks/scaffold-stark/useNetworkColor.ts | 2 +- .../hooks/scaffold-stark/useOutsideClick.ts | 2 +- .../scaffold-stark/useScaffoldContract.ts | 2 +- .../scaffold-stark/useScaffoldContractRead.ts | 2 +- .../useScaffoldContractWrite.ts | 6 +- .../hooks/scaffold-stark/useSwitchNetwork.ts | 10 +- .../hooks/scaffold-stark/useTargetNetwork.ts | 6 +- .../hooks/scaffold-stark/useTransactor.tsx | 15 +- packages/nextjs/package.json | 4 +- .../web3/stark-burner/BurnerConnector.ts | 4 +- .../stark-burner/BurnerConnectorErrors.ts | 3 +- packages/nextjs/types/utils.ts | 2 +- .../nextjs/utils/scaffold-stark/contract.ts | 47 ++--- .../nextjs/utils/scaffold-stark/networks.ts | 2 +- .../utils/scaffold-stark/notification.tsx | 2 +- packages/snfoundry/package.json | 3 +- yarn.lock | 180 +++++++++--------- 44 files changed, 338 insertions(+), 276 deletions(-) diff --git a/package.json b/package.json index 8013d302..d8b1b085 100644 --- a/package.json +++ b/package.json @@ -17,11 +17,14 @@ "next:lint": "yarn workspace @ss-2/nextjs lint", "next:check-types": "yarn workspace @ss-2/nextjs check-types", "vercel": "yarn workspace @ss-2/nextjs vercel", - "vercel:yolo": "yarn workspace @ss-2/nextjs vercel:yolo" + "vercel:yolo": "yarn workspace @ss-2/nextjs vercel:yolo", + "format": "yarn workspace @ss-2/nextjs format && yarn workspace @ss-2/snfoundry format", + "format:check": "yarn workspace @ss-2/nextjs format:check" }, "packageManager": "yarn@3.2.3", "devDependencies": { - "daisyui": "^4.7.3" + "daisyui": "^4.7.3", + "prettier": "^3.2.5" }, "dependencies": { "postcss": "^8.4.38" diff --git a/packages/nextjs/app/debug/_components/DebugContracts.tsx b/packages/nextjs/app/debug/_components/DebugContracts.tsx index f4f3caa8..a6880dcb 100644 --- a/packages/nextjs/app/debug/_components/DebugContracts.tsx +++ b/packages/nextjs/app/debug/_components/DebugContracts.tsx @@ -15,7 +15,7 @@ export function DebugContracts() { const [selectedContract, setSelectedContract] = useLocalStorage( selectedContractStorageKey, contractNames[0], - { initializeWithValue: false } + { initializeWithValue: false }, ); useEffect(() => { diff --git a/packages/nextjs/app/debug/_components/contract/ContractUI.tsx b/packages/nextjs/app/debug/_components/contract/ContractUI.tsx index 680b3634..0740be52 100644 --- a/packages/nextjs/app/debug/_components/contract/ContractUI.tsx +++ b/packages/nextjs/app/debug/_components/contract/ContractUI.tsx @@ -28,7 +28,7 @@ export const ContractUI = ({ }: ContractUIProps) => { const [refreshDisplayVariables, triggerRefreshDisplayVariables] = useReducer( (value) => !value, - false + false, ); const { targetNetwork } = useTargetNetwork(); const { data: deployedContractData, isLoading: deployedContractLoading } = diff --git a/packages/nextjs/app/debug/_components/contract/ReadOnlyFunctionForm.tsx b/packages/nextjs/app/debug/_components/contract/ReadOnlyFunctionForm.tsx index 7288533b..4aca5677 100644 --- a/packages/nextjs/app/debug/_components/contract/ReadOnlyFunctionForm.tsx +++ b/packages/nextjs/app/debug/_components/contract/ReadOnlyFunctionForm.tsx @@ -32,7 +32,7 @@ export const ReadOnlyFunctionForm = ({ abi, }: ReadOnlyFunctionFormProps) => { const [form, setForm] = useState>(() => - getInitialFormState(abiFunction) + getInitialFormState(abiFunction), ); const [result, setResult] = useState(); diff --git a/packages/nextjs/app/debug/_components/contract/TxReceipt.tsx b/packages/nextjs/app/debug/_components/contract/TxReceipt.tsx index 68d0846f..35d08a85 100644 --- a/packages/nextjs/app/debug/_components/contract/TxReceipt.tsx +++ b/packages/nextjs/app/debug/_components/contract/TxReceipt.tsx @@ -14,7 +14,7 @@ export const TxReceipt = ( | bigint | Record | InvokeTransactionReceiptResponse - | undefined + | undefined, ) => { const [txResultCopied, setTxResultCopied] = useState(false); diff --git a/packages/nextjs/app/debug/_components/contract/WriteOnlyFunctionForm.tsx b/packages/nextjs/app/debug/_components/contract/WriteOnlyFunctionForm.tsx index 5777bb95..71d093cf 100644 --- a/packages/nextjs/app/debug/_components/contract/WriteOnlyFunctionForm.tsx +++ b/packages/nextjs/app/debug/_components/contract/WriteOnlyFunctionForm.tsx @@ -44,7 +44,7 @@ export const WriteOnlyFunctionForm = ({ }: // inheritedFrom, WriteOnlyFunctionFormProps) => { const [form, setForm] = useState>(() => - getInitialFormState(abiFunction) + getInitialFormState(abiFunction), ); const { chain } = useNetwork(); const writeTxn = useTransactor(); @@ -74,7 +74,7 @@ WriteOnlyFunctionFormProps) => { } catch (e: any) { console.error( "⚡️ ~ file: WriteOnlyFunctionForm.tsx:handleWrite ~ error", - e + e, ); } } diff --git a/packages/nextjs/app/debug/_components/contract/utilsContract.tsx b/packages/nextjs/app/debug/_components/contract/utilsContract.tsx index fd4316ae..4f0a2959 100644 --- a/packages/nextjs/app/debug/_components/contract/utilsContract.tsx +++ b/packages/nextjs/app/debug/_components/contract/utilsContract.tsx @@ -6,7 +6,7 @@ import { uint256 } from "starknet"; const getFunctionInputKey = ( functionName: string, input: AbiParameter, - inputIndex: number + inputIndex: number, ): string => { const name = input?.name || `input_${inputIndex}_`; return functionName + "_" + name + "_" + input.type; @@ -113,7 +113,7 @@ const transformAbiFunction = (abiFunction: AbiFunction): AbiFunction => { return { ...abiFunction, inputs: abiFunction.inputs.map((value) => - adjustInput(value as AbiParameter) + adjustInput(value as AbiParameter), ), }; }; diff --git a/packages/nextjs/app/debug/_components/contract/utilsDisplay.tsx b/packages/nextjs/app/debug/_components/contract/utilsDisplay.tsx index 9eb4b5a2..25e70c73 100644 --- a/packages/nextjs/app/debug/_components/contract/utilsDisplay.tsx +++ b/packages/nextjs/app/debug/_components/contract/utilsDisplay.tsx @@ -21,7 +21,7 @@ type DisplayContent = export const displayTxResult = ( displayContent: DisplayContent | DisplayContent[], asText: boolean, - functionOutputs: readonly AbiOutput[] = [] + functionOutputs: readonly AbiOutput[] = [], ): string | ReactElement | number => { if (displayContent == null) { return ""; @@ -71,7 +71,7 @@ export const displayTxResult = ( ["number", "boolean"].includes(typeof v) ? v : displayTxResultAsText(v); const displayable = JSON.stringify( displayContent.map(mostReadable), - replacer + replacer, ); return asText ? ( diff --git a/packages/nextjs/components/FaucetMenu.tsx b/packages/nextjs/components/FaucetMenu.tsx index 9d8d200c..afab5db8 100644 --- a/packages/nextjs/components/FaucetMenu.tsx +++ b/packages/nextjs/components/FaucetMenu.tsx @@ -1,6 +1,6 @@ "use client"; -import { DropdownMenu, Button } from '@radix-ui/themes'; -import { CaretDownIcon } from '@radix-ui/react-icons'; +import { DropdownMenu, Button } from "@radix-ui/themes"; +import { CaretDownIcon } from "@radix-ui/react-icons"; export default function FaucetMenu() { return ( @@ -10,14 +10,14 @@ export default function FaucetMenu() { Faucet - + - Goerli - + Goerli + - Sepolia - + Sepolia + ); -} \ No newline at end of file +} diff --git a/packages/nextjs/components/Header.tsx b/packages/nextjs/components/Header.tsx index 66007487..7d5e1138 100644 --- a/packages/nextjs/components/Header.tsx +++ b/packages/nextjs/components/Header.tsx @@ -4,13 +4,13 @@ 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, BugAntIcon } from "@heroicons/react/24/outline"; // import { // FaucetButton, // RainbowKitCustomConnectButton, // } from "~~/components/scaffold-eth"; import { useOutsideClick } from "~~/hooks/scaffold-stark"; -import {CustomConnectButton} from "~~/components/scaffold-stark/CustomConnectButton"; +import { CustomConnectButton } from "~~/components/scaffold-stark/CustomConnectButton"; type HeaderMenuLink = { label: string; @@ -64,7 +64,7 @@ export const Header = () => { const burgerMenuRef = useRef(null); useOutsideClick( burgerMenuRef, - useCallback(() => setIsDrawerOpen(false), []) + useCallback(() => setIsDrawerOpen(false), []), ); return ( @@ -117,7 +117,7 @@ export const Header = () => {
- +
); diff --git a/packages/nextjs/components/ScaffoldStarkAppWithProviders.tsx b/packages/nextjs/components/ScaffoldStarkAppWithProviders.tsx index e04cc12f..4cee39ec 100644 --- a/packages/nextjs/components/ScaffoldStarkAppWithProviders.tsx +++ b/packages/nextjs/components/ScaffoldStarkAppWithProviders.tsx @@ -1,51 +1,62 @@ "use client"; import React from "react"; -import {useEffect, useState} from "react"; -import {useTheme} from "next-themes"; -import {Toaster} from "react-hot-toast"; +import { useEffect, useState } from "react"; +import { useTheme } from "next-themes"; +import { Toaster } from "react-hot-toast"; import { - StarknetConfig, publicProvider, argent, braavos, useInjectedConnectors, starkscan, jsonRpcProvider, starknetChainId, + StarknetConfig, + publicProvider, + argent, + braavos, + useInjectedConnectors, + starkscan, + jsonRpcProvider, + starknetChainId, } from "@starknet-react/core"; -import {Header} from "~~/components/Header"; -import {Footer} from "~~/components/Footer"; -import {ProgressBar} from "~~/components/scaffold-stark/ProgressBar"; -import {appChains} from "~~/services/web3/connectors"; -import {BurnerConnector} from "~~/services/web3/stark-burner/BurnerConnector"; +import { Header } from "~~/components/Header"; +import { Footer } from "~~/components/Footer"; +import { ProgressBar } from "~~/components/scaffold-stark/ProgressBar"; +import { appChains } from "~~/services/web3/connectors"; +import { BurnerConnector } from "~~/services/web3/stark-burner/BurnerConnector"; import scaffoldConfig from "~~/scaffold.config"; -const ScaffoldStarkApp = ({children}: { children: React.ReactNode }) => { +const ScaffoldStarkApp = ({ children }: { children: React.ReactNode }) => { return ( <>
-
+
{children}
-
+
- + ); }; -export const ScaffoldStarkAppWithProviders = ({children,}: { +export const ScaffoldStarkAppWithProviders = ({ + children, +}: { children: React.ReactNode; }) => { - const {resolvedTheme} = useTheme(); + const { resolvedTheme } = useTheme(); const isDarkMode = resolvedTheme === "dark"; const [mounted, setMounted] = useState(false); - const provider = scaffoldConfig.rpcProviderUrl == "" ? publicProvider() : - jsonRpcProvider({ - rpc: () => ({ - nodeUrl: scaffoldConfig.rpcProviderUrl, - chainId: starknetChainId(scaffoldConfig.targetNetworks[0].id) - }) - }) + const provider = + scaffoldConfig.rpcProviderUrl == "" + ? publicProvider() + : jsonRpcProvider({ + rpc: () => ({ + nodeUrl: scaffoldConfig.rpcProviderUrl, + chainId: starknetChainId(scaffoldConfig.targetNetworks[0].id), + }), + }); useEffect(() => { setMounted(true); }, []); - const {connectors} = useInjectedConnectors({ + const { connectors } = useInjectedConnectors({ // Show these connectors if the user has no connector installed. recommended: [argent(), braavos(), new BurnerConnector()], }); @@ -57,7 +68,7 @@ export const ScaffoldStarkAppWithProviders = ({children,}: { connectors={connectors} explorer={starkscan} > - + {children}
); diff --git a/packages/nextjs/components/scaffold-stark/Address.tsx b/packages/nextjs/components/scaffold-stark/Address.tsx index 070c84f6..6a16f447 100644 --- a/packages/nextjs/components/scaffold-stark/Address.tsx +++ b/packages/nextjs/components/scaffold-stark/Address.tsx @@ -89,7 +89,7 @@ export const Address = ({ const blockExplorerAddressLink = getBlockExplorerAddressLink( targetNetwork, - checkSumAddress + checkSumAddress, ); let displayAddress = checkSumAddress?.slice(0, 6) + "..." + checkSumAddress?.slice(-4); diff --git a/packages/nextjs/components/scaffold-stark/Balance.tsx b/packages/nextjs/components/scaffold-stark/Balance.tsx index 67dc2017..f5fa9eef 100644 --- a/packages/nextjs/components/scaffold-stark/Balance.tsx +++ b/packages/nextjs/components/scaffold-stark/Balance.tsx @@ -29,7 +29,7 @@ export const Balance = ({ address, className = "", usdMode }: BalanceProps) => { }); const [displayUsdMode, setDisplayUsdMode] = useState( - price > 0 ? Boolean(usdMode) : false + price > 0 ? Boolean(usdMode) : false, ); const toggleBalanceMode = () => { diff --git a/packages/nextjs/components/scaffold-stark/BlockieAvatar.tsx b/packages/nextjs/components/scaffold-stark/BlockieAvatar.tsx index cc701877..673bd771 100644 --- a/packages/nextjs/components/scaffold-stark/BlockieAvatar.tsx +++ b/packages/nextjs/components/scaffold-stark/BlockieAvatar.tsx @@ -9,7 +9,11 @@ interface BlockieAvatarProps { } // Custom Avatar for RainbowKit -export const BlockieAvatar = ({ address, ensImage, size }: BlockieAvatarProps) => ( +export const BlockieAvatar = ({ + address, + ensImage, + size, +}: BlockieAvatarProps) => ( // Don't want to use nextJS Image here (and adding remote patterns for the URL) // eslint-disable-next-line @next/next/no-img-element
- + - {isENS(displayName) ? displayName : address?.slice(0, 6) + "..." + address?.slice(-4)} + {isENS(displayName) + ? displayName + : address?.slice(0, 6) + "..." + address?.slice(-4)} @@ -88,13 +93,19 @@ export const AddressInfoDropdown = ({ )}
  • -
  • -
  • ) : null} @@ -125,7 +137,8 @@ export const AddressInfoDropdown = ({ type="button" onClick={() => disconnect()} > - Disconnect + {" "} + Disconnect diff --git a/packages/nextjs/components/scaffold-stark/CustomConnectButton/AddressQRCodeModal.tsx b/packages/nextjs/components/scaffold-stark/CustomConnectButton/AddressQRCodeModal.tsx index a7a082a0..2695205d 100644 --- a/packages/nextjs/components/scaffold-stark/CustomConnectButton/AddressQRCodeModal.tsx +++ b/packages/nextjs/components/scaffold-stark/CustomConnectButton/AddressQRCodeModal.tsx @@ -7,7 +7,10 @@ type AddressQRCodeModalProps = { modalId: string; }; -export const AddressQRCodeModal = ({ address, modalId }: AddressQRCodeModalProps) => { +export const AddressQRCodeModal = ({ + address, + modalId, +}: AddressQRCodeModalProps) => { return ( <>
    @@ -16,7 +19,10 @@ export const AddressQRCodeModal = ({ address, modalId }: AddressQRCodeModalProps