-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: develop
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for decent-interface-dev ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
mutation: { | ||
onError: () => { | ||
if (chain.id !== walletChainID && !isSubDAO) { | ||
switchChain({ chainId: chain.id }); | ||
} | ||
}, | ||
}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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:
- Connect TP wallet with Ethereum selected.
- Create a DAO in our app. Select "Sepolia" as the network.
- Note, TP shows prompt to change network. If you click "Cancel", it keeps on prompting. Click on "Confirm" now.
- Click "Next"
- 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.
- 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)
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 fromuseNetworkConfigStore
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:
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