Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix autoConnect when contract not deployed #292

Merged
merged 13 commits into from
Apr 21, 2023
Merged

Conversation

technophile-04
Copy link
Collaborator

Issue :

It seems that due to the below check autoConnect does not work if you use SE-2 that doesn't use deployed contract :
https://github.com/scaffold-eth/se-2/blob/ce83d166df62083a3aac86a6dda1802737a02fa8/packages/nextjs/hooks/scaffold-eth/useAutoConnect.ts#L68

Demo not working :

Selected Mainnet as targetNetwork

Screen.Recording.2023-04-08.at.12.14.00.AM.mov

Fixed by removing the if(contract) from both useAutoConnect & Faucet, it seems that check was added due console getting bloated with errors and warning but I think it was fixed in other commits

checkout OG comment : https://github.com/scaffold-eth/se-2/pull/255/files/43f82e58bab2f624b60f520e68cfff749fe541e7#r1147414048

Demo with only yarn chain runnig and deployed contract is null :

Screen.Recording.2023-04-08.at.12.05.47.AM.mov

Demo with yarn chain not running :

Screen.Recording.2023-04-08.at.12.08.58.AM.mov

@carletex
Copy link
Member

carletex commented Apr 7, 2023

Thanks for the videos and the explanation, Shiv.

Demo with only yarn chain runnig and deployed contract is null :

This one looks good!

Demo with yarn chain not running

I added this one to avoid those errors on projects that don't use contracts. E.g: https://hackathon.buidlguidl.com/

What would be the alternative? Switching targetNetwork to something different than hardhat?

@damianmarti
Copy link
Collaborator

damianmarti commented Apr 10, 2023

Thanks for the videos and the explanation, Shiv.

Really nice explanations and videos to save PR review time!!

Demo with only yarn chain runnig and deployed contract is null :

This one looks good!

Demo with yarn chain not running

I added this one to avoid those errors on projects that don't use contracts. E.g: https://hackathon.buidlguidl.com/

What would be the alternative? Switching targetNetwork to something different than hardhat?

Maybe something like targetNetwork: false?

@sverps
Copy link
Collaborator

sverps commented Apr 10, 2023

Maybe something like targetNetwork: false?

Not a fan of assigning values that don't really match the variable. Would also break some types where targetNetwork is used and expected to be a network.

We could, however, add another config in scaffold.config, something like autoConnect.enabled?

@damianmarti
Copy link
Collaborator

Maybe something like targetNetwork: false?

Not a fan of assigning values that don't really match the variable. Would also break some types where targetNetwork is used and expected to be a network.

We could, however, add another config in scaffold.config, something like autoConnect.enabled?

You are right!

And what about targetNetwork: null? I mean, if you are not using a chain at all, sounds right not to be needed to configure any network. But it's true that if we set it to null, we should take care that the targetNetwork can be null...

Maybe we can just add another config param and that's it!

@technophile-04
Copy link
Collaborator Author

Just summarising the discussion so far:-

Reason for discussion :

We don't want to show a "Cannot connect to the local provider" and other errors if the user wants to build only the frontend app.

Solution discussed :

Giving users a single config option to do so

Question :

Just wanted to know what this option should actually do meaning should it remove "Connecting with wallet" and any other stuff?

The reason I am saying this is because people using SE-2 will surely at least want "Connecting with wallet" functionality be it signing message or other, If they want this functionality it will lead to the user configuring targetNetwork to some network because it will also handle "Switch to right network" and other things

So I see telling people to configure the network to "mainnet" or another network in the README as the best option to get started building only frontend since requires 0 to minimal changes and aslo won't confuse with more options.

I really appreciate the solutions suggested and am happy to explore but had little doubt about what things should we should "turn off" with this configuration option ?

Tysm all

@sverps
Copy link
Collaborator

sverps commented Apr 12, 2023

So I see telling people to configure the network to "mainnet" or another network in the README as the best option to get started building only frontend since requires 0 to minimal changes and aslo won't confuse with more options.

Yeah, lets keep things simple and just explain it in the readme, since the existing config already allows users to resolve the issue. 👍

@damianmarti damianmarti reopened this Apr 13, 2023
@damianmarti
Copy link
Collaborator

So I see telling people to configure the network to "mainnet" or another network in the README as the best option to get started building only frontend since requires 0 to minimal changes and aslo won't confuse with more options.

Yeah, lets keep things simple and just explain it in the readme, since the existing config already allows users to resolve the issue. +1

I agree with that too!

And maybe @carletex can check if setting the network to mainnet fix the issue that he had at https://hackathon.buidlguidl.com/

@technophile-04
Copy link
Collaborator Author

And maybe @carletex can check if setting the network to mainnet fix the issue that he had at https://hackathon.buidlguidl.com/

cc @carletex for review and merge / thoughts

README.md Outdated
@@ -123,6 +123,8 @@ If you want to redeploy to the same production URL you can run `yarn vercel --pr

**Hint**: We recommend connecting the project GitHub repo to Vercel so you the gets automatically deployed when pushing to `main`

**Hint**: If you don't have any contract deployed through SE-2 and plan to just deploy NextJS app maybe only with "connect wallet" functionality you can do so by just setting `targetNetwork : chains.mainnet` or your preferred network in `packages/nextjs/scaffold.config.ts`, rest all instruction remains same as [above](#deploying-your-nextjs-app)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a small hint it can be improved a lot please feel free to suggest idea, aslo was wondering should we create a separate section ? I feel like its not worth it because README.md has really grown alot

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we add a minimal hint in the faucet error, so we don't need to add more stuff here?

Like adding "You can also change your targetNetwork in scaffold.config.ts" below "Did you forget to run yarn chain?".

We could also add some "code" style to the yarn chain and scaffold.config.ts text like we do here:
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the hint text a bit to fit in properly, hope it makes sense :
Screenshot 2023-04-21 at 7 45 10 PM

Before :
Screenshot 2023-04-21 at 7 26 36 PM

The empty space looked weird to me but happy to revert 🙌

Copy link
Member

@carletex carletex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some minor comments @technophile-04 thanks! ;)

README.md Outdated
@@ -123,6 +123,8 @@ If you want to redeploy to the same production URL you can run `yarn vercel --pr

**Hint**: We recommend connecting the project GitHub repo to Vercel so you the gets automatically deployed when pushing to `main`

**Hint**: If you don't have any contract deployed through SE-2 and plan to just deploy NextJS app maybe only with "connect wallet" functionality you can do so by just setting `targetNetwork : chains.mainnet` or your preferred network in `packages/nextjs/scaffold.config.ts`, rest all instruction remains same as [above](#deploying-your-nextjs-app)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we add a minimal hint in the faucet error, so we don't need to add more stuff here?

Like adding "You can also change your targetNetwork in scaffold.config.ts" below "Did you forget to run yarn chain?".

We could also add some "code" style to the yarn chain and scaffold.config.ts text like we do here:
image

@@ -21,22 +20,28 @@ export const Faucet = () => {
const [sendValue, setSendValue] = useState("");

const { chain: ConnectedChain } = useNetwork();
const provider = getLocalProvider(localhost);
const provider = useMemo(() => getLocalProvider(localhost), []);
Copy link
Member

@carletex carletex Apr 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we move this outside/above of the component?

const provider = getLocalProvider(localhost);

export const Faucet = () => { 
//... 
}

Would it have the same effect?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice !! I should have thought about this before using useMemo, this works !

Update at c7ef8b7

@carletex carletex merged commit 0f1eabc into main Apr 21, 2023
@carletex carletex deleted the fix/burner-autoConnect branch April 21, 2023 16:49
kmjones1979 added a commit that referenced this pull request Jul 3, 2023
* Update SE-2 nomenclautre  (#317)

* Fix autoConnect when contract not deployed (#292)

* oxford comma lol

* Fix icon visibility on dark mode in EtherInput (#320)

* Update README: Add Vercel ENV var to disable type/lint checking (#327)

* Fix typo (#334)

Fix typo at code snippet

* README: Updated SE-2 custom hook section (#330)

Co-authored-by: KcPele <fidekg123@gmail.com>
Co-authored-by: Shiv Bhonde <shivbhonde04@gmail.com>
Co-authored-by: Carlos Sánchez <oceanrdn@gmail.com>

* Remove duplicated HINT on README (#335)

* PR and Issue templates (#329)

* Native currency symbol and price as per target network (#322)

* useAppStore => useGlobalState (#338)

* Event history filter type (#333)

* fix: event history filter type

Fixes #332

* fix: make scaffold event history config separate type

* fix: prettier broke due to invalid syntax

* fix: ts error after generating contract

* Indexed prop + example

---------

Co-authored-by: Carlos Sánchez <oceanrdn@gmail.com>

* Update README: custom hooks section (#339)

* fix: assert type as Abi to avoid ts error (#350)

* fix: assert type as Abi to avoid ts error

Fixes #344

* assert type as Abi to avoid ts error on useScaffoldContract

---------

Co-authored-by: Carlos Sánchez <oceanrdn@gmail.com>

* Fix useEffect filter dep on event hook (#349)

* Block confirmation options / callback for useScaffoldContractWrite (#348)

* Patch useLocalStorage setting the right initial value to avoid a hydration error (#356)

Co-authored-by: sverps <sverps@gmail.com>

* Save selected contract to local storage (#326)

* Save selected contract to local storage

* refactor: Replaced native localStorage with useLocalStorage from usehooks-ts

* Fixed empty string parameter error.

* Updated parameter requirements to fix issue.

* Fixed error.

* Fixed parameter assignment error.

* Use useLocalStorage to save selected contract

---------

Co-authored-by: Damian <damianmarti@gmail.com>

* Refactor meta tags into separate component and add default thumbnail / image (#359)

* Hotfix: thumbnail.png => thumbnail.jpg

* Local Block Explorer (#351)

Co-authored-by: Shiv Bhonde <shivbhonde04@gmail.com>

* Fix daisyUI dropdown on IOS (#342)

* allow `overrides` in useScaffoldContractWrite (#345)

* allow overrides for useScaffoldContractWrite

* spread overrides and restConfig separately

* feat: proactively disable read hook when it would result in error (#250)

Fixes #249

Co-authored-by: Shiv Bhonde | shivbhonde.eth <shivbhonde04@gmail.com>

* Size prop on Address component (#365)


Co-authored-by: Carlos Sánchez <oceanrdn@gmail.com>

* Generate TS ABIs from deploy script (#368)

* enable solidity optimizer by default (#360)

* fix(Balance): font-size of symbol should be relative to current font-size, not document root (#375)

* fix(contract.ts): very long abi's now no longer go over type instantiation limit (#377)

Fixes #374

* fix(contract.ts): improve missing config check (#372)

Fixes #371

* fix listner types error when contracts missing (#379)

* zkSyncEra Testnet config (#383)

* Upgrade hardhat-deploy to 0.11.26 where zkSync is supported

* Dependency for @matterlabs/hardhat-zksync-solc

* Add zkSyncEraTestnet to networks

* Import @matterlabs/hardhat-zksync-solc

* Add artifacts-zk and cache-zk to gitignore

* yarn install

* Add zkSync mainnet config

* add hardhat-zksync-verify for contract verification

---------

Co-authored-by: moltam89 <moltam89@gmail.com>
Co-authored-by: Damian <damianmarti@gmail.com>
Co-authored-by: Shiv Bhonde <shivbhonde04@gmail.com>

* allow writeAsync by useScaffoldContractWrite to be called with updated args (#385)

* update wagmi & rainbow for walletConnectV2 (#381)

* meged changes from main, additional configuration in subgraph.yaml

---------

Co-authored-by: Shiv Bhonde | shivbhonde.eth <shivbhonde04@gmail.com>
Co-authored-by: Austin Griffith <austin@ethereum.org>
Co-authored-by: Kevin Joshi <kevinjoshi46b@gmail.com>
Co-authored-by: Carlos Sánchez <oceanrdn@gmail.com>
Co-authored-by: AlehN <natsevsky@gmail.com>
Co-authored-by: Pablo Alayeto <55535804+Pabl0cks@users.noreply.github.com>
Co-authored-by: KcPele <fidekg123@gmail.com>
Co-authored-by: Samuel | solidixen.eth <sverps@gmail.com>
Co-authored-by: Eda Akturk <edakturk96@gmail.com>
Co-authored-by: Tamas Molnar <tamas.molnar@liferay.com>
Co-authored-by: Damian Martinelli <damianmarti@gmail.com>
Co-authored-by: Alexander <a00112699@gmail.com>
Co-authored-by: port <108868128+portdeveloper@users.noreply.github.com>
Co-authored-by: moltam89 <moltam89@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants