WalletConnect / Web3ModalUnity

WalletConnect AppKit: a single Web3 provider solution for all Wallets
Apache License 2.0
7 stars 2 forks source link

iOS Runtime Errors - WalletConnect Not Working #26

Open brian-kryptomon opened 2 weeks ago

brian-kryptomon commented 2 weeks ago

Describe the bug Our WalletConnect integration isn't working on iOS builds and I see an error in the logs:

ArgumentNullException: Value cannot be null.
Parameter name: method
  at Newtonsoft.Json.Utilities.LateBoundReflectionDelegateFactory.CreateParameterizedConstructor (System.Reflection.MethodBase method) [0x00000] in <00000000000000000000000000000000>:0 
  at Newtonsoft.Json.Serialization.JsonDictionaryContract.CreateWrapper (System.Object dictionary) [0x00000] in <00000000000000000000000000000000>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewDictionary (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonDictionaryContract contract, System.Boolean& createdFromNonDefaultCreator) [0x00000] in <00000000000000000000000000000000>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00000] in <00000000000000000000000000000000>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x00000] in <00000000000000000000000000000000>:0 
  at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <00000000000000000000000000000000>:0 
  at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <00000000000000000000000000000000>:0 
  at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <00000000000000000000000000000000>:0 
  at WalletConnectSharp.Storage.FileSystemStorage.Load () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0 
--- End of stack trace from previous location where exception was thrown ---

at WalletConnectSharp.Storage.FileSystemStorage.Init () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.Threading.ContextCallback callback, System.Object state, System.Threading.Tasks.Task& currentTask) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.TrySetException (System.Object exceptionObject) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.Task.TrySetException (System.Object exceptionObject) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].SetException (System.Exception exception) [0x00000] in <00000000000000000000000000000000>:0 
  at WalletConnectSharp.Storage.FileSystemStorage.Load () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0 
--- End of stack trace from previous location where exception was thrown ---

To Reproduce I just added the modal to the build and then ran the build like I normally would.

Expected behavior No errors and WalletConnect modal should show up.

Screenshots If applicable, add screenshots to help explain your problem.

Environment

Is this happening in Unity Editor or on a player like Android, iOS, Windows? Only happens on iOS - prompt works on windows and android.

Wallets used for testing N/A - can't even get to that point.

Additional context Add any other context about the problem here.

brian-kryptomon commented 2 weeks ago

And obviously this is the error I get when I try to open the modal:


Exception: Web3Modal not initialized
  at WalletConnect.Web3Modal.Web3Modal.OpenModal (WalletConnect.Web3Modal.ViewType viewType) [0x00000] in <00000000000000000000000000000000>:0 
  at PinkMoon.World.Blockchain.WalletConnectWalletProviderService.Connect () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0 
  at PinkMoon.World.Blockchain.WalletConnectWalletProviderService.Connect () [0x00000] in <00000000000000000000000000000000>:0 
  at PinkMoon.World.Blockchain.BlockchainClientService.Connect (PinkMoon.World.Accounts.WalletType walletType, System.String emailAddress) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0 
  at PinkMoon.World.Blockchain.BlockchainClientService.Connect (PinkMoon.World.Accounts.WalletType walletType, System.String emailAddress) [0x00000] in <00000000000000000000000000000000>:0 
  at PinkMoon.World.Login.LoginCreateAccountView.ExternalWalletToggleChanged (System.Boolean isOn) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0 ```
skibitsky commented 2 weeks ago

Hello!

Have you set Managed Code Stripping to Minimal in the Player settings?

brian-kryptomon commented 2 weeks ago

Hello!

Have you set Managed Code Stripping to Minimal in the Player settings?

@skibitsky Thanks this did solve the issue on the start on both android and iOS so now the modal comes up but I am getting this error now:

[websocket-connection-197952ff-48fa-417b-b31a-8b1bf22a9a60] Error: Unable to connect to the remote server
NativeWebSocket.<Connect>d__32:MoveNext()
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Runtime.CompilerServices.MoveNextRunner:Run()
UnityEngine.WorkRequest:Invoke()
UnityEngine.UnitySynchronizationContext:Exec()

I have attached the larger log file with the relevant WalletConnect lines.

logs.txt

brian-kryptomon commented 2 weeks ago

Also I have metamask already installed on the device and its up to date on the latest patch and it doesn't open the wallet and just shows this - not sure if its related: image

skibitsky commented 2 weeks ago

Error: Unable to connect to the remote server

Could you please try changing the relay url in the WalletConnectProjectConfig scriptable asset from wss://relay.walletconnect.com to wss://relay.walletconnect.org?

Also I have metamask already installed on the device and its up to date on the latest patch and it doesn't open the wallet and just shows this

The SDK needs to connect to the WalletConnect relay before establishing a connection with any wallet. So, it's probably related to the first issue.

Also, based on the screenshot, it seems you're running the game in the Editor with iOS/Android as the target platform. In this case, the Web3Modal UI and user flow will be the same as on mobile. However, since there’s no desktop MetaMask app, you’ll need to use another desktop wallet (e.g. Ledger Live or Zerion) or scan QR code with your phone. In the mobile Web3Modal UI, the QR code button can be found next to the search input field on the "All wallets" screen.

brian-kryptomon commented 2 weeks ago

@skibitsky I tried updating it to the URL but still no luck? any ideas on how I can get you more info to help troubleshoot? That error is pretty vague.

brian-kryptomon commented 2 weeks ago

@skibitsky a little more info - i am getting this in the Unity editor as well when I'm on android or iOS platforms but not on Windows.

brian-kryptomon commented 2 weeks ago

Also interestingly enough - our other library that is using web sockets is also failing on android / ios. I'm trying to see if there's something specific that needs to be done on Android/iOS for web sockets.

UPDATE: I fixed the other library and its working but WalletConnect still wont connect. I saw some stuff about headers being missing or even this link that talks about wss not working on some android versions:

https://github.com/sta/websocket-sharp/issues/312#issuecomment-286339095

Let me know if I can get you more info somehow.

skibitsky commented 2 weeks ago

This is very strange, especially that it doesn't work in the Editor with some platforms. Have you tried exiting Unity, deleting Library folder, and opening Unity again?

brian-kryptomon commented 2 weeks ago

This is very strange, especially that it doesn't work in the Editor with some platforms. Have you tried exiting Unity, deleting Library folder, and opening Unity again?

@skibitsky is there something more targeted? If I delete the library folder i'll be here for 3 days waiting for Unity to import everything.

The only platform it seems to work on consistently is PC other than that I can't get it to work on any mobile platforms - as builds or in editor.

skibitsky commented 2 weeks ago

is there something more targeted?

Library/Bee? We only use WebGL preprocessor directive in the WebSocketConnection and WebSocket scripts, so I think there's a high chance that it's a Unity bug, or there's another tool in your project that causes this behaviour. Moreover, we haven't received similar reports from other developers.

I saw some stuff about headers being missing

We use query parameters instead of headers for higher compatibility.