reown-com / appkit

The full stack toolkit to build onchain app UX
https://reown.com/appkit
Apache License 2.0
4.91k stars 1.4k forks source link

'Connection Declined' error after wallet successfully connects in beta.10 / rc.1 #799

Closed kwebster2 closed 1 year ago

kwebster2 commented 1 year ago

When calling the open function, the modal displays an error showing 'Connection Declined.', despite the wagmi useAccount hook correctly returning the connected wallet's address and isConnected as true. If you reload the page, the hook continues to return data suggesting the wallet is connected, but upon calling the open function, it shows the web3modal as if no wallet is connected. At this point the useAccount hook returns isConnected as false and no longer returns the connected wallet's address.

SDK Version 2.0.0-rc.1

I have a repo that reproduces the bug issue here: https://github.com/kwebster2/web3modal-bug-demo

  1. Connect metamask wallet and observe address displayed in place of Connect button (useAccount correctly returning isConnected and address)
  2. Click the address to call the open function of the useWeb3Modal hook
  3. An error is displayed
  4. Reload the page, and note that the useAccount hook is still continuing to return the correct data
  5. Click the address once again, and note that the web3modal appears as if the wallet is not connected. Attempting to connect again results in the same 'Connection Declined' error

Expected behavior When the wallet is connected and you call the open function, the modal should display the screen with the wallet details and show that the wallet is connected

Screenshots

Screen Shot 2022-12-25 at 12 53 16

Desktop (please complete the following information):

Additional context This error was not happening with 2.0.0-beta.9. I searched the changelog for beta.10 and rc.1 and did not immediately see anything that might cause this. I did see the fallback provider change and tried adding a fallback InfuraProvider when configuring the chains since I am currently using Görli and mumbai testnets, but that did not work.

xzilja commented 1 year ago

@kwebster2 Does it work if you provide other rpc providers instead or alongside walletConnectProvider. Some changes were made between beta.9 and beta.10 in that area where we now fall back to rpc's defined in chain configs if our one doesn't support it. Although walletConnectProvider should support both of the chains that you use, so perhaps there is an error on our end here (do you see any info in console perhaps)?

One way or another, you can probably unblock yourself by defining custom rpc in wagmi config for now (https://wagmi.sh/react/providers/jsonRpc)

I will deep dive into this issue next week (team is currently on holiday break).

Saszr commented 1 year ago

@0xAsimetriq I encountered the same problem in version 2.0.0-rc.1. I don't think it's a problem on the walletConnectProvider, my custom one uses the wagmi publicProvider. const { open } = useWeb3Modal(); Custom button to call open event, resulting in Connection Declined. https://github.com/WalletConnect/web3modal/blob/V2/examples/react/src/pages/index.tsx There is no custom button involved that is called again after the connection is established.

image
xzilja commented 1 year ago

@Saszr Does this happen for all the chains or only specific ones i.e. if you just configure it with Ethereum mainnet, can you replicate the issue? Public provider in wagmi is also limited on amount of chains they support. Also if you have any further info i.e. repo or errors logged in the console would appreciate if you post them here, will make it easier to pinpoint once I start investigating this.

If it is all rpc related, I will try to at least throw a useful error to make this more clear.

Saszr commented 1 year ago

@0xAsimetriq I tried the following combinations: [mainnet, bsc] + publicProvider() ; [mainnet] + publicProvider() ; [mainnet, bsc] + walletConnectProvider({ projectId }) ; [mainnet] + walletConnectProvider({ projectId }); Unfortunately, there is no related error display in the console.

image
xzilja commented 1 year ago

@kwebster2 @Saszr Found the issue, I think you can work around this via open({ route: 'Account' }) for now. Possible routes to open modal are 'Account' | 'ConnectWallet' | 'Help' | 'SelectNetwork' and you need to manage them atm to open correct one based on users connection. (I will add handling for default when no route is provided in rc.2)

Ty for the info 👍

xzilja commented 1 year ago

TODO's for myself

  1. Document open method options
  2. Add logic to opening correct view based on acc state / standalone modal etc. if route option was not provided / default custom button behaviour
kwebster2 commented 1 year ago

Hi @0xAsimetriq ! Thank you for the response! I'll try this workaround. And no worries - hope the team enjoys the holiday! Loving the progress on this project - v2 is looking great