WalletConnect / web3modal-swift

Apache License 2.0
56 stars 28 forks source link

Web3Modal uses wrong session when selecting a different chain #88

Open marctatham opened 4 weeks ago

marctatham commented 4 weeks ago

Describe the bug Web3Modal determines the session by simply grabbing the first available session from getSessions(). This works when the only session is the connected wallet, it does NOT work when we are managing multiple sessions (such as in the case when you are using both Web3Modal to connect a wallet and connecting dApps as well)

SDK Version

To Reproduce

  1. Connect a wallet using web3modal
  2. Connect a dApp to the same application using Pair.instance.pair(...)
  3. Attempt to change network using Web3Modal.selectChain() , this will fail as the requests are being routed to the wrong session

Expected behaviour The change network request should be sent to the wallet session. The web3Modal should manage its connected wallet session correctly.

Screenshots N/A

Device:

Additional context The exact problem can be found in how the session is determined here: https://github.com/WalletConnect/web3modal-swift/blob/2d94ebc9065d1602ddc7eb60dab34a853afb4186/Sources/Web3Modal/Core/Web3Modal.swift#L37-L48

mrktrace commented 1 day ago

Good morning,

I'm experiencing the same issue, I think it would be super useful to be able to perform web3 options sending a the sessionId.

Maybe it could be an optional string with a default nil value, and if the topicId is nil it could use the first session.

WDYT?

Thank you!