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

[Eng 50] | Dao creation network switch #2645

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

Da-Colon
Copy link
Contributor

@Da-Colon Da-Colon commented Dec 20, 2024

Closes https://linear.app/decent-labs/issue/ENG-50/dev-error-creating-an-nft-dao

So the problem is that I placed the useEffect within the EstablishEssentials form rather than higher up.

This move makes it if the User switches there network at some point later in the process, the app switches it back keeping the user on the selected network.

I did attempt to move this selection and network check to the button, but with the current setup within useBuildDAOTx where it pulls contracts from useNetworkConfigStore in which is set to the current network.

A future refactor will be needed to confirm to a new pattern of more fine control over what network the DAO is deployed on.

Testing:

  • Enter Create DAO workflow
  • Select Different network from etherem
  • Go to end of which DAO creation workflow you are on.
  • Before deploying, open wallet and manually switch wallet network
  • Go back to page (focus on page), go back to wallet and network should be back to the originally selected network.

Basically our now app now prevents the user from manually switching thier network via wallet during this workflow. Not ideal to be so connected to that network. but without some refactoring how the contracts for deployment are chosen this is the most effective method to ensure proper deployment

Copy link

linear bot commented Dec 20, 2024

Copy link

netlify bot commented Dec 20, 2024

Deploy Preview for decent-interface-dev ready!

Name Link
🔨 Latest commit 96b63e3
🔍 Latest deploy log https://app.netlify.com/sites/decent-interface-dev/deploys/6765990956b3260008f9b6c0
😎 Deploy Preview https://deploy-preview-2645.app.dev.decentdao.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +46 to +52
mutation: {
onError: () => {
if (chain.id !== walletChainID && !isSubDAO) {
switchChain({ chainId: chain.id });
}
},
},
Copy link
Member

Choose a reason for hiding this comment

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

@Da-Colon can you explain what this mutation is and why it's needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So my understanding is that Metamask doesn't require that popup permission to switch networks anymore. Network permission are done within Metamask and if its listed then its available.

So when switchchain is called if the network is allowed then switch should happen. BUT for some reason this doesn't happen as it should. I looked into this before and mentioned a while back that I believe this error is occurs in
the current version of Viem.

So during testing. I found that this pattern 'brute' forces past the error and switches the network. Didn't see this problem in Frame (didn't reach the error).

There are two ways to get rid of this need more than likely.

  • Update viem to latest, but requires some changes in the app as they change Address typing to string for whatever reason.
  • We could also create our own wallet client to use in the app. I attempted to set this up here. but requires a bit more thought, a little refactor and additional testing for how network config (contracts) is used in this workflow.

Copy link
Contributor Author

@Da-Colon Da-Colon Dec 20, 2024

Choose a reason for hiding this comment

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

As far as what the mutation, it taps into the internal tanstack query parameters and I chose to use the onError from there.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Da-Colon Does this work with other wallet extensions? Major ones are Coinbase Wallet and TokenPocket.

Copy link
Contributor

Choose a reason for hiding this comment

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

I will do some testing with CB and TP. Please hold on until testing is done.

Copy link
Contributor

@johnqh johnqh left a comment

Choose a reason for hiding this comment

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

Tested against Coinbase and TokenPocket wallet extensions. CB works fine because when the app request the wallet to change network, it just does it. TP has a little problem.

Steps:

  1. Connect TP wallet with Ethereum selected.
  2. Create a DAO in our app. Select "Sepolia" as the network.
  3. Note, TP shows prompt to change network. If you click "Cancel", it keeps on prompting. Click on "Confirm" now.
  4. Click "Next"
  5. In TP, switch network back to "Ethereum". Note, immediately, it shows a badge with "1" label. If you click on it, it is asking you to switch back to Sepolia. However, the badge is not super obvious and user may miss it.
  6. Create NFT DAO with 0x31408f226E37FBF8715CA6eE45aaB4Ea213bA7A5 as address (this issue should happen with ERC-20 DAO too). You will see the address is red with error because it is now using Ethereum mainNet to check the address.

Conclusion, there are many wallet variations and different network switching flows, that may still cause two source of truth in our app.

I think we should ignore the wallet network selection during our flow, and only prompt the wallet to switch network at signing (so only one source of truth with user selected network in the app)

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.

3 participants