From 4dd50df4aea05155242981421b6599e9d5d94f3e Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Mon, 15 Apr 2024 16:32:38 +0700 Subject: [PATCH 01/17] Feat: Update preset-erc1155 --- packages/snfoundry/contracts/Scarb.toml | 4 +++ packages/snfoundry/contracts/src/lib.cairo | 2 +- .../{challenge2.cairo => presetERC1155.cairo} | 25 +++++++++++++------ packages/snfoundry/scripts_js/deploy.js | 20 +++++++-------- 4 files changed, 33 insertions(+), 18 deletions(-) rename packages/snfoundry/contracts/src/{challenge2.cairo => presetERC1155.cairo} (70%) diff --git a/packages/snfoundry/contracts/Scarb.toml b/packages/snfoundry/contracts/Scarb.toml index 2c315c76..d851aaae 100644 --- a/packages/snfoundry/contracts/Scarb.toml +++ b/packages/snfoundry/contracts/Scarb.toml @@ -12,3 +12,7 @@ openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", ta [[target.starknet-contract]] casm = true + + +[tool.fmt] +sort-module-level-items = true diff --git a/packages/snfoundry/contracts/src/lib.cairo b/packages/snfoundry/contracts/src/lib.cairo index 4290cbfd..a5a7cd46 100644 --- a/packages/snfoundry/contracts/src/lib.cairo +++ b/packages/snfoundry/contracts/src/lib.cairo @@ -3,7 +3,7 @@ mod simpleStorage; mod vote; mod challenge0; mod challenge1; -mod challenge2; +mod presetERC1155; mod challenge3; use starknet::ContractAddress; diff --git a/packages/snfoundry/contracts/src/challenge2.cairo b/packages/snfoundry/contracts/src/presetERC1155.cairo similarity index 70% rename from packages/snfoundry/contracts/src/challenge2.cairo rename to packages/snfoundry/contracts/src/presetERC1155.cairo index 050ae7c8..e67b7fdb 100644 --- a/packages/snfoundry/contracts/src/challenge2.cairo +++ b/packages/snfoundry/contracts/src/presetERC1155.cairo @@ -1,5 +1,6 @@ #[starknet::contract] -mod Challenge2 { +mod PresetERC1155 { + use core::num::traits::zero::Zero; use openzeppelin::introspection::src5::SRC5Component; use openzeppelin::token::erc1155::ERC1155Component; use starknet::ContractAddress; @@ -13,8 +14,7 @@ mod Challenge2 { #[abi(embed_v0)] impl ERC1155MetadataURIImpl = ERC1155Component::ERC1155MetadataURIImpl; - #[abi(embed_v0)] - impl ERC1155Camel = ERC1155Component::ERC1155CamelImpl; + impl ERC1155InternalImpl = ERC1155Component::InternalImpl; // SRC5 @@ -47,8 +47,19 @@ mod Challenge2 { values: Span ) { self.erc1155.initializer(base_uri); - self - .erc1155 - .batch_mint_with_acceptance_check(recipient, token_ids, values, array![].span()); + self.batch_mint(recipient, token_ids, values); //unsafe_batch_mint() + } + + #[generate_trait] + impl InternalImpl of InternalTrait { + fn batch_mint( + ref self: ContractState, + recipient: ContractAddress, + token_ids: Span, + values: Span + ) { + assert(recipient.is_non_zero(), ERC1155Component::Errors::INVALID_RECEIVER); + self.erc1155.update(Zero::zero(), recipient, token_ids, values); + } } -} \ No newline at end of file +} diff --git a/packages/snfoundry/scripts_js/deploy.js b/packages/snfoundry/scripts_js/deploy.js index 7b5612a4..e82efcaa 100644 --- a/packages/snfoundry/scripts_js/deploy.js +++ b/packages/snfoundry/scripts_js/deploy.js @@ -156,16 +156,16 @@ const deployScript = async () => { // "Challenge1" // ); - // await deployContract( - // { - // base_uri: CallData.byteArrayFromString("https://example.com/"), - // // recipient: - // // "0x06072Bb27d275a0bC1deBf1753649b8721CF845B681A48443Ac46baF45769f8E", - // // token_ids: 2, - // // values: 100, - // }, - // "Challenge2" - // ); + await deployContract( + { + base_uri: "https://example.com/", + recipient: + "0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691", + token_ids: [2], + values: [100], + }, + "PresetERC1155" + ); // await deployContract( // { From c4153763b0f648bf8ddfc1b80a5b48e5c986787a Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Tue, 16 Apr 2024 16:27:44 +0700 Subject: [PATCH 02/17] Feat(Challenge-1): Add basic smart contrac, fn stake() --- .../snfoundry/contracts/src/challenge1.cairo | 76 ++++++++++++------- packages/snfoundry/contracts/src/lib.cairo | 1 + .../snfoundry/contracts/src/presetERC20.cairo | 39 ++++++++++ packages/snfoundry/scripts_js/deploy.js | 25 +++--- 4 files changed, 100 insertions(+), 41 deletions(-) create mode 100644 packages/snfoundry/contracts/src/presetERC20.cairo diff --git a/packages/snfoundry/contracts/src/challenge1.cairo b/packages/snfoundry/contracts/src/challenge1.cairo index 3b367d74..61499402 100644 --- a/packages/snfoundry/contracts/src/challenge1.cairo +++ b/packages/snfoundry/contracts/src/challenge1.cairo @@ -1,39 +1,57 @@ -#[starknet::contract] -mod Challenge1 { - use openzeppelin::token::erc20::ERC20Component; - use starknet::ContractAddress; +use starknet::ContractAddress; - component!(path: ERC20Component, storage: erc20, event: ERC20Event); +#[starknet::interface] +pub trait IChallenge1 { + fn stake(ref self: T, amount: u256); + //fn withdraw(ref self: TContractState, shares: u256); + fn balances(self: @T, account: ContractAddress) -> u256; + fn total_balance(self: @T) -> u256; + fn deadline(self: @T) -> u64; + fn threshold(self: @T) -> u256; +} - // ERC20Mixin - #[abi(embed_v0)] - impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl; - impl InternalImpl = ERC20Component::InternalImpl; +#[starknet::contract] +mod Challenge1 { + use super::{ContractAddress, IChallenge1}; + use starknet::{get_block_timestamp, get_caller_address, get_contract_address}; + pub const THRESHOLD: u256 = 100000000000000000; // ONE_ETH_IN_WEI: 10 ^ 18; #[storage] struct Storage { - #[substorage(v0)] - erc20: ERC20Component::Storage + balances: LegacyMap, + deadline: u64, } - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ERC20Event: ERC20Component::Event + #[constructor] + fn constructor(ref self: ContractState) { + self.deadline.write(get_block_timestamp() + 45); } - /// Sets the token `name` and `symbol`. - /// Mints `fixed_supply` tokens to `recipient`. - #[constructor] - fn constructor( - ref self: ContractState, - name: ByteArray, - symbol: ByteArray, - fixed_supply: u256, - recipient: ContractAddress - ) { - self.erc20.initializer(name, symbol); - self.erc20._mint(recipient, fixed_supply); + #[abi(embed_v0)] + impl Challenge1Impl of IChallenge1 { + fn stake(ref self: ContractState, amount: u256) { + assert(get_block_timestamp() < self.deadline.read(), 'Staking priod has ended'); + let sender = get_caller_address(); + let contract_address = get_contract_address(); + let sender_current_amount = self.balances.read(sender); + self.balances.write(sender, sender_current_amount + amount); + self.balances.write(contract_address, self.balances.read(contract_address) + amount); + } + + fn balances(self: @ContractState, account: ContractAddress) -> u256 { + self.balances.read(account) + } + + fn total_balance(self: @ContractState) -> u256 { + self.balances.read(get_contract_address()) + } + + fn deadline(self: @ContractState) -> u64 { + self.deadline.read() + } + + fn threshold(self: @ContractState) -> u256 { + THRESHOLD + } } -} \ No newline at end of file +} diff --git a/packages/snfoundry/contracts/src/lib.cairo b/packages/snfoundry/contracts/src/lib.cairo index 4290cbfd..d49f5607 100644 --- a/packages/snfoundry/contracts/src/lib.cairo +++ b/packages/snfoundry/contracts/src/lib.cairo @@ -5,6 +5,7 @@ mod challenge0; mod challenge1; mod challenge2; mod challenge3; +mod presetERC20; use starknet::ContractAddress; diff --git a/packages/snfoundry/contracts/src/presetERC20.cairo b/packages/snfoundry/contracts/src/presetERC20.cairo new file mode 100644 index 00000000..cd05528b --- /dev/null +++ b/packages/snfoundry/contracts/src/presetERC20.cairo @@ -0,0 +1,39 @@ +#[starknet::contract] +mod PresertERC20 { + use openzeppelin::token::erc20::ERC20Component; + use starknet::ContractAddress; + + component!(path: ERC20Component, storage: erc20, event: ERC20Event); + + // ERC20Mixin + #[abi(embed_v0)] + impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl; + impl InternalImpl = ERC20Component::InternalImpl; + + #[storage] + struct Storage { + #[substorage(v0)] + erc20: ERC20Component::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + ERC20Event: ERC20Component::Event + } + + /// Sets the token `name` and `symbol`. + /// Mints `fixed_supply` tokens to `recipient`. + #[constructor] + fn constructor( + ref self: ContractState, + name: ByteArray, + symbol: ByteArray, + fixed_supply: u256, + recipient: ContractAddress + ) { + self.erc20.initializer(name, symbol); + self.erc20._mint(recipient, fixed_supply); + } +} diff --git a/packages/snfoundry/scripts_js/deploy.js b/packages/snfoundry/scripts_js/deploy.js index 384be09f..20343c02 100644 --- a/packages/snfoundry/scripts_js/deploy.js +++ b/packages/snfoundry/scripts_js/deploy.js @@ -13,25 +13,26 @@ const deployScript = async () => { // "SimpleStorage" // ); - await deployContract( - { - owner: - "0x4b3f4ba8c00a02b66142a4b1dd41a4dfab4f92650922a3280977b0f03c75ee1", - }, // last account in devnet accounts - "Challenge0" - ); - // await deployContract( // { - // name: 1, - // symbol: 2, + // owner: + // "0x4b3f4ba8c00a02b66142a4b1dd41a4dfab4f92650922a3280977b0f03c75ee1", + // }, // last account in devnet accounts + // "Challenge0" + // ); + + await deployContract(null,"Challenge1"); + + // await deployContract( + // { + // name: "Marquis", + // symbol: "MRQ", // fixed_supply: 10, // recipient: // "0x06072Bb27d275a0bC1deBf1753649b8721CF845B681A48443Ac46baF45769f8E", // }, - // "Challenge1" + // "PresetERC20" // ); - // await deployContract( // { // base_uri: CallData.byteArrayFromString("https://example.com/"), From c7f0b906b70278272ca916be54f432ff4a250f2c Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Tue, 16 Apr 2024 23:40:43 +0700 Subject: [PATCH 03/17] Feat: Add fn execute(), fn withdraw() --- .../snfoundry/contracts/src/challenge1.cairo | 88 +++++++++++++++++-- .../src/exampleExternalContract.cairo | 25 ++++++ packages/snfoundry/contracts/src/lib.cairo | 1 + packages/snfoundry/scripts_js/deploy.js | 8 +- 4 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 packages/snfoundry/contracts/src/exampleExternalContract.cairo diff --git a/packages/snfoundry/contracts/src/challenge1.cairo b/packages/snfoundry/contracts/src/challenge1.cairo index 61499402..d497e45c 100644 --- a/packages/snfoundry/contracts/src/challenge1.cairo +++ b/packages/snfoundry/contracts/src/challenge1.cairo @@ -1,17 +1,24 @@ use starknet::ContractAddress; - #[starknet::interface] pub trait IChallenge1 { fn stake(ref self: T, amount: u256); - //fn withdraw(ref self: TContractState, shares: u256); + fn withdraw(ref self: T); fn balances(self: @T, account: ContractAddress) -> u256; - fn total_balance(self: @T) -> u256; + fn execute(ref self: T); + fn completed(self: @T) -> bool; fn deadline(self: @T) -> u64; + fn example_external_contract(self: @T) -> ContractAddress; + fn open_for_withdraw(self: @T) -> bool; fn threshold(self: @T) -> u256; + fn total_balance(self: @T) -> u256; + fn time_left(self: @T) -> u64; } #[starknet::contract] mod Challenge1 { + use contracts::exampleExternalContract::{ + IExampleExternalContractDispatcher, IExampleExternalContractDispatcherTrait + }; use super::{ContractAddress, IChallenge1}; use starknet::{get_block_timestamp, get_caller_address, get_contract_address}; @@ -20,17 +27,21 @@ mod Challenge1 { struct Storage { balances: LegacyMap, deadline: u64, + open_for_withdraw: bool, + external_contract_address: ContractAddress, } #[constructor] - fn constructor(ref self: ContractState) { - self.deadline.write(get_block_timestamp() + 45); + fn constructor(ref self: ContractState, external_contract_address: ContractAddress) { + self.deadline.write(get_block_timestamp() + 45); // 45 seconds + self.external_contract_address.write(external_contract_address); } #[abi(embed_v0)] impl Challenge1Impl of IChallenge1 { fn stake(ref self: ContractState, amount: u256) { - assert(get_block_timestamp() < self.deadline.read(), 'Staking priod has ended'); + self._not_completed(); + assert(get_block_timestamp() < self.deadline.read(), 'Staking period has ended'); let sender = get_caller_address(); let contract_address = get_contract_address(); let sender_current_amount = self.balances.read(sender); @@ -38,6 +49,29 @@ mod Challenge1 { self.balances.write(contract_address, self.balances.read(contract_address) + amount); } + // Function to execute the transfer or allow withdrawals after the deadline + fn execute(ref self: ContractState) { + self._not_completed(); + assert(get_block_timestamp() >= self.deadline.read(), 'Staking period has not ended'); + let contract_address = get_contract_address(); + let contract_amount = self.balances.read(contract_address); + if (contract_amount >= THRESHOLD) { + self._complete_transfer(contract_amount, self.external_contract_address.read()); + } else { + self.open_for_withdraw.write(true); + } + } + + fn withdraw(ref self: ContractState) { + assert(self.open_for_withdraw.read(), 'Withdrawal not allowed'); + let sender = get_caller_address(); + let sender_amount = self.balances.read(sender); + assert(sender_amount > 0, 'No balance to withdraw'); + let contract_amount = self.balances.read(get_contract_address()); + self.balances.write(sender, 0); + self.balances.write(get_contract_address(), contract_amount - sender_amount); + } + fn balances(self: @ContractState, account: ContractAddress) -> u256 { self.balances.read(account) } @@ -53,5 +87,47 @@ mod Challenge1 { fn threshold(self: @ContractState) -> u256 { THRESHOLD } + + fn open_for_withdraw(self: @ContractState) -> bool { + self.open_for_withdraw.read() + } + + fn example_external_contract(self: @ContractState) -> ContractAddress { + self.external_contract_address.read() + } + + fn completed(self: @ContractState) -> bool { + let external_contract = IExampleExternalContractDispatcher { + contract_address: self.external_contract_address.read() + }; + external_contract.completed() + } + + fn time_left(self: @ContractState) -> u64 { + let current_time = get_block_timestamp(); + let deadline = self.deadline.read(); + if current_time < deadline { + deadline - current_time + } else { + 0 + } + } + } + + #[generate_trait] + impl InternalImpl of InternalTrait { + fn _complete_transfer( + ref self: ContractState, amount: u256, external_contract_address: ContractAddress + ) { + let external_contract = IExampleExternalContractDispatcher { + contract_address: external_contract_address + }; + self.balances.write(get_contract_address(), 0); + external_contract.complete(amount); + } + + fn _not_completed(ref self: ContractState) { + assert(!self.completed(), 'Action already completed'); + } } } diff --git a/packages/snfoundry/contracts/src/exampleExternalContract.cairo b/packages/snfoundry/contracts/src/exampleExternalContract.cairo new file mode 100644 index 00000000..edc5b498 --- /dev/null +++ b/packages/snfoundry/contracts/src/exampleExternalContract.cairo @@ -0,0 +1,25 @@ +#[starknet::interface] +pub trait IExampleExternalContract { + fn complete(ref self: T, amount: u256); + fn completed(ref self: T) -> bool; +} + +#[starknet::contract] +mod ExampleExternalContract { + #[storage] + struct Storage { + completed: bool, + balance: u256, + } + + #[abi(embed_v0)] + impl ExampleExternalContractImpl of super::IExampleExternalContract { + fn complete(ref self: ContractState, amount: u256) { + self.completed.write(true); + self.balance.write(self.balance.read() + amount); + } + fn completed(ref self: ContractState) -> bool { + self.completed.read() + } + } +} diff --git a/packages/snfoundry/contracts/src/lib.cairo b/packages/snfoundry/contracts/src/lib.cairo index d49f5607..36d30407 100644 --- a/packages/snfoundry/contracts/src/lib.cairo +++ b/packages/snfoundry/contracts/src/lib.cairo @@ -6,6 +6,7 @@ mod challenge1; mod challenge2; mod challenge3; mod presetERC20; +mod exampleExternalContract; use starknet::ContractAddress; diff --git a/packages/snfoundry/scripts_js/deploy.js b/packages/snfoundry/scripts_js/deploy.js index 20343c02..b11d0af4 100644 --- a/packages/snfoundry/scripts_js/deploy.js +++ b/packages/snfoundry/scripts_js/deploy.js @@ -21,7 +21,13 @@ const deployScript = async () => { // "Challenge0" // ); - await deployContract(null,"Challenge1"); + const values = { + classHash: helloStarknetClassHash, + abi: helloStarknetAbi, + address: ContractAddress, + } = await deployContract(null, "ExampleExternalContract"); + await deployContract({ external_contract_address: values.address } + , "Challenge1"); // await deployContract( // { From 5b6089f853aa8de248d448143ffaf5f7c139b0cf Mon Sep 17 00:00:00 2001 From: gianalarcon Date: Wed, 17 Apr 2024 17:19:18 +0700 Subject: [PATCH 04/17] Add dummy transferEthContract --- packages/snfoundry/contracts/src/lib.cairo | 1 + .../snfoundry/contracts/src/transferETH.cairo | 44 +++++++++++++++++++ packages/snfoundry/scripts_js/deploy.js | 15 ++++--- 3 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 packages/snfoundry/contracts/src/transferETH.cairo diff --git a/packages/snfoundry/contracts/src/lib.cairo b/packages/snfoundry/contracts/src/lib.cairo index 36d30407..61a6e0ce 100644 --- a/packages/snfoundry/contracts/src/lib.cairo +++ b/packages/snfoundry/contracts/src/lib.cairo @@ -7,6 +7,7 @@ mod challenge2; mod challenge3; mod presetERC20; mod exampleExternalContract; +mod transferETH; use starknet::ContractAddress; diff --git a/packages/snfoundry/contracts/src/transferETH.cairo b/packages/snfoundry/contracts/src/transferETH.cairo new file mode 100644 index 00000000..ffce3cee --- /dev/null +++ b/packages/snfoundry/contracts/src/transferETH.cairo @@ -0,0 +1,44 @@ +use starknet::ContractAddress; +#[starknet::interface] +trait ITransferETH { + fn read_balance_contract(self: @T) -> u256; + fn read_balance_caller(self: @T) -> u256; + fn caller_and_contract(self: @T) -> (ContractAddress, ContractAddress); +} + +#[starknet::contract] +mod TransferETH { + use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; + use starknet::{get_caller_address, get_contract_address, ContractAddress}; + #[storage] + struct Storage { + token: IERC20Dispatcher, + } + + #[constructor] + fn constructor(ref self: ContractState //, external_contract_address: ContractAddress + ) { + self + .token + .write( + IERC20Dispatcher { + contract_address: 0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 + .try_into() + .unwrap() + } + ); + } + + #[abi(embed_v0)] + impl TransferETHImpl of super::ITransferETH { + fn read_balance_contract(self: @ContractState) -> u256 { + self.token.read().balance_of(get_contract_address()) + } + fn read_balance_caller(self: @ContractState) -> u256 { + self.token.read().balance_of(get_caller_address()) + } + fn caller_and_contract(self: @ContractState) -> (ContractAddress, ContractAddress) { + (get_caller_address(), get_contract_address()) + } + } +} diff --git a/packages/snfoundry/scripts_js/deploy.js b/packages/snfoundry/scripts_js/deploy.js index b11d0af4..736c1581 100644 --- a/packages/snfoundry/scripts_js/deploy.js +++ b/packages/snfoundry/scripts_js/deploy.js @@ -21,14 +21,15 @@ const deployScript = async () => { // "Challenge0" // ); - const values = { - classHash: helloStarknetClassHash, - abi: helloStarknetAbi, - address: ContractAddress, - } = await deployContract(null, "ExampleExternalContract"); - await deployContract({ external_contract_address: values.address } - , "Challenge1"); + // const values = { + // classHash: helloStarknetClassHash, + // abi: helloStarknetAbi, + // address: ContractAddress, + // } = await deployContract(null, "ExampleExternalContract"); + // await deployContract({ external_contract_address: values.address } + // , "Challenge1"); + await deployContract(null, "TransferETH"); // await deployContract( // { // name: "Marquis", From 7527c221e09155cd7b266ca1493de09ce5810c56 Mon Sep 17 00:00:00 2001 From: jrcarlos2000 Date: Wed, 17 Apr 2024 18:51:20 +0800 Subject: [PATCH 05/17] fix contract --- packages/snfoundry/contracts/src/transferETH.cairo | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/snfoundry/contracts/src/transferETH.cairo b/packages/snfoundry/contracts/src/transferETH.cairo index ffce3cee..80f67683 100644 --- a/packages/snfoundry/contracts/src/transferETH.cairo +++ b/packages/snfoundry/contracts/src/transferETH.cairo @@ -8,11 +8,11 @@ trait ITransferETH { #[starknet::contract] mod TransferETH { - use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; + use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait}; use starknet::{get_caller_address, get_contract_address, ContractAddress}; #[storage] struct Storage { - token: IERC20Dispatcher, + token: IERC20CamelDispatcher, } #[constructor] @@ -21,7 +21,7 @@ mod TransferETH { self .token .write( - IERC20Dispatcher { + IERC20CamelDispatcher { contract_address: 0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 .try_into() .unwrap() @@ -32,10 +32,10 @@ mod TransferETH { #[abi(embed_v0)] impl TransferETHImpl of super::ITransferETH { fn read_balance_contract(self: @ContractState) -> u256 { - self.token.read().balance_of(get_contract_address()) + self.token.read().balanceOf(get_contract_address()) } fn read_balance_caller(self: @ContractState) -> u256 { - self.token.read().balance_of(get_caller_address()) + self.token.read().balanceOf(get_caller_address()) } fn caller_and_contract(self: @ContractState) -> (ContractAddress, ContractAddress) { (get_caller_address(), get_contract_address()) From 10be81a6cae65be52a39034481ae1020901dde06 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Wed, 17 Apr 2024 13:23:44 -0500 Subject: [PATCH 06/17] fix: render on every input --- .../_components/contract/ReadOnlyFunctionForm.tsx | 15 +++++++-------- .../nextjs/hooks/scaffold-stark/useAutoConnect.ts | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/nextjs/app/debug/_components/contract/ReadOnlyFunctionForm.tsx b/packages/nextjs/app/debug/_components/contract/ReadOnlyFunctionForm.tsx index cc6d167e..18510850 100644 --- a/packages/nextjs/app/debug/_components/contract/ReadOnlyFunctionForm.tsx +++ b/packages/nextjs/app/debug/_components/contract/ReadOnlyFunctionForm.tsx @@ -32,13 +32,13 @@ export const ReadOnlyFunctionForm = ({ const [form, setForm] = useState>(() => getInitialFormState(abiFunction), ); - const [result, setResult] = useState(); + const [inputValue, setInputValue] = useState(); - const { isLoading, isFetching, refetch } = useContractRead({ + const { isLoading, isFetching, data } = useContractRead({ address: contractAddress, functionName: abiFunction.name, abi: [...abi], - args: getParsedContractFunctionArgs(form), + args: inputValue, enabled: false, // TODO : notify when failed - add error blockIdentifier: "pending" as BlockNumber, }); @@ -49,7 +49,7 @@ export const ReadOnlyFunctionForm = ({ { - setResult(undefined); + setInputValue(undefined); setForm(updatedFormValue); }} form={form} @@ -68,11 +68,11 @@ export const ReadOnlyFunctionForm = ({ {inputElements}
- {result !== null && result !== undefined && ( + {data !== null && data !== undefined && (

Result:

-                {displayTxResult(result, false, abiFunction?.outputs)}
+                {displayTxResult(data, false, abiFunction?.outputs)}
               
)} @@ -80,8 +80,7 @@ export const ReadOnlyFunctionForm = ({