WalletConnect / WalletConnectSwift

WalletConnect Swift SDK
MIT License
344 stars 167 forks source link

Connecting to Wallet #68

Open frankynines opened 3 years ago

frankynines commented 3 years ago

Using this SDK

After I call open URL it redirects to the MetaMask then does nothing. Is there a missing step to have it connect and return to the parent app?

frankynines commented 3 years ago

WCURL Has to be encoded. Should add to documentation.

j-cimb-barker commented 3 years ago

Can you add to the documentation how this should be done, please...? I am facing the same problem.

j-cimb-barker commented 3 years ago

Can you add to the documentation how this should be done, please...? I am facing the same problem.

I worked out how to do this. See : https://github.com/WalletConnect/WalletConnectSwift/issues/70

sche commented 3 years ago

Here you can find information on how to encode universal links: https://docs.walletconnect.org/mobile-linking#for-ios

peoplewhite commented 3 years ago

Hello @j-cimb-barker

I'm facing same problem here. I checked repo be mentioned what you post #70, and implemented it. But issue still existed.

Here's Url what i encoded before using UIApplication.shared.open to open it.

https://metamask.app.link/wc?uri=wc%3AAD5C58F5%2D28D5%2D499B%2DB81F%2DD8C79FE169E8%401%3Fbridge%3Dhttps%253A%252F%252Fj%2Ebridge%2Ewalletconnect%2Eorg%26key%3D726172697479d1ecfd0fa2f16c523fa33fcb887f8c98a0b5919f835298563094

Here's bridge server I used.

https://j.bridge.walletconnect.org

I still hanging in metamash iOS app without popup from bottom which's asking me to connect with. Is this issue caused on encoded url, or bridge server url depends on your experience?

Appreciate it.

sche commented 3 years ago

@peoplewhite It seems that your URL looks fine. Could you try using a different bridge server?

peoplewhite commented 3 years ago

@sche Thanks for checking. 😊

I tried these bridge servers, but fail... Sometimes work, sometimes fail.

https://safe-walletconnect.gnosis.io
https://wcbridge.zerion.io
https://j.bridge.walletconnect.org
https://bridge.walletconnect.org

Would you provide any suggestions?

Do I need to build a "bridge server" for my app?

kohlivarun5 commented 3 years ago

I saw similar issues. Trust wallet worked fine, but Metamask did not respond to any of the bridges I tried

sche commented 3 years ago

@peoplewhite @kohlivarun5 bridge servers might be not very responsive sometimes. If it worked at least once with MetaMask, then the universal link is correct.

kohlivarun5 commented 3 years ago

Thanks @sche, Do you have any recommendations on how to debug such things? Is creating and running a custom bridge the way to go for it?

sche commented 3 years ago

@kohlivarun5 no need to create a custom bridge. If MetaMask never worked for you, probably you are doing smth wrong. Here is a link to code that works for us with MetaMask, Trust, Rainbow, Ledger Live (other wallets I did not test yet) https://github.com/gnosis/safe-ios/blob/40a50dc8e6b3c007c8b3279cab0c202bef06d4a1/Multisig/UI/Settings/OwnerKeyManagement/WalletConnectOwnerKey/ConnectWalletViewController.swift#L112

j-cimb-barker commented 3 years ago

Hello @j-cimb-barker

I'm facing same problem here. I checked repo be mentioned what you post #70, and implemented it. But issue still existed.

Here's Url what i encoded before using UIApplication.shared.open to open it.

https://metamask.app.link/wc?uri=wc%3AAD5C58F5%2D28D5%2D499B%2DB81F%2DD8C79FE169E8%401%3Fbridge%3Dhttps%253A%252F%252Fj%2Ebridge%2Ewalletconnect%2Eorg%26key%3D726172697479d1ecfd0fa2f16c523fa33fcb887f8c98a0b5919f835298563094

Here's bridge server I used.

https://j.bridge.walletconnect.org

I still hanging in metamash iOS app without popup from bottom which's asking me to connect with. Is this issue caused on encoded url, or bridge server url depends on your experience?

Appreciate it.

I would suggest building and running the Gnosis Safe App on a Test Device and then looking at how they did it. Generally if you don't get a response from MetaMask it's due to the encoded url not being correct.

sche commented 3 years ago

Generally if you don't get a response from MetaMask it's due to the encoded url not being correct.

Or due to not enough time to actually send the handshake request to MetaMask before opening it.

rndhacker commented 3 years ago

I am encountering the same problem, where the URL works and stops working randomly, even using all of the different servers recommended before. Are the servers down? or do they have a limit of requests per device which would case to suddenly stop working without any code changes?

@sche Thanks for checking. 😊

I tried these bridge servers, but fail... Sometimes work, sometimes fail.

https://safe-walletconnect.gnosis.io
https://wcbridge.zerion.io
https://j.bridge.walletconnect.org
https://bridge.walletconnect.org

Would you provide any suggestions?

Do I need to build a "bridge server" for my app?

peoplewhite commented 3 years ago

Actually I still be stuck in this problem.

Sometimes I get wallet address succeed, then be stuck in personal_sign proceed in MetaMask iOS app (with wallet address & nonce message from app server).

I'm wondering why there's no such problem for using Rarible iOS app. Maybe they using their owned bridge server I guess...

Still seeking for solutions here...🙏

rndhacker commented 3 years ago

I think it has to do with the way it works with Metamask. When it wasn't working for Metamask, I tried connecting with Trust Wallet and it was working perfectly.

sche commented 3 years ago

With Metamask I recommend cleaning open WalletConnect sessions from time to time in advanced settings of mobile MetaMask. If some requests work with MetaMask, but not always, 99% that this is an issue with that MetaMask can not receive your request sometimes. This might happen due to

You can try to test similar scenarios with Gnosis Safe App where the code is open source and works well with MetaMask https://github.com/gnosis/safe-ios Also, you can try to connect to MetaMask via a QR code (not a deep link) and to check how it behaves. Here you can use Example apps in the WalletConnectSwift repo.

duycao2506 commented 3 years ago

Hi team, I found that we should wait until the bridge has been connected then we can navigate to the wallet via universal link.

Specifically, wait for this method to be called:

func client(_ client: Client, didConnect url: WCURL)

The bridge I used: https://safe-walletconnect.gnosis.io

mataide commented 3 years ago

To solve this problem, you need to implement a local bridge server. The Android SDK has a built local server.

BrettRosen commented 3 years ago

To solve this problem, you need to implement a local bridge server. The Android SDK has a built local server.

Are you sure? Is this what gnosis safe does? Others say it works just fine in their opensource app

elrid commented 2 years ago

After checking out gnosis-safe client implementation, i've figured out two parts of a solution for everyone who got stuck:

Correct way to create universal link (example for metamask, similar idea works with trust, but Rainbow wallet is not working) URL(string: "https://metamask.app.link/wc?uri=\(wcURL.absoluteString.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? "")")

For Rainbow client you shoud use .controlCharacters instead: URL(string: "https://rnbwapp.com/wc?uri=\(wcURL.absoluteString.addingPercentEncoding(withAllowedCharacters: .controlCharacters) ?? "")")

Best bridge: https://safe-walletconnect.gnosis.io walletconnect bridges are not responding at the time of writing.

Everything here is relevant for 1.6.0 client, and may not work in 2.0 client

sotrosh commented 2 years ago

works great with @elrid solution!

tommychavez commented 2 years ago

Thank you! @elrid

ahumay commented 2 years ago

.

DmitryBespalov commented 2 years ago

@ahumay check out OpenSea mobile app, it's there but not sure what libs they use. I know it's written with Flutter though