WalletConnect / walletconnect-utils

Javascript Utilities for WalletConnect
MIT License
65 stars 56 forks source link

fix: Cast WS Connection Origin to undefined #175

Closed ugur-eren closed 2 months ago

ugur-eren commented 3 months ago

Fix: Cast WS Connection Origin to undefined

URLSearchParams.get method returns null for params that are not defined, this results in the origin variable to be null, which leads to a crash in the React Native app when using sign client with the following error:

NSInvalidArgumentException: -[NSNull length]: unrecognized selector sent to instance 0x7ff84002f610

The crash only occured on only iOS devices with only specific builds, but still, this causes a crash.

This change ensures that the origin is undefined if not provided and prevents the app from crashing due to the null value.

ignaciosantise commented 2 months ago

hey @ugur-eren 👋 i see you are using the sign-sdk directly (instead of Appkit) and that's why the origin is undefined.

Can you try installing @walletconnect/react-native-compat in your app and check if it solves the crash?

ugur-eren commented 2 months ago

Hi @ignaciosantise I've tried @walletconnect/react-native-compat before debugging and finding the issue. AFAIK there is no problem origin being not defined. But it returns null when it is not defined, and it causes the error. I've locally built and tested my app with my changes, it works without a problem when casted to undefined instead of null.

ugur-eren commented 2 months ago

Hi @ignaciosantise I've created an example snack, you can try it on your iOS device with Expo Go: https://snack.expo.dev/@truetiem/747c9a

ignaciosantise commented 2 months ago

@ugur-eren yes, the socket connection works without origin, but im wondering why is it null in your case. If you already installed @walletconnect/react-native-compat and run pod install then origin shouldnt be null 🤔 are you using expo?

ugur-eren commented 2 months ago

Hi @ignaciosantise Sorry for inconvenience, I don't know what happened when I tried out the @walletconnect/react-native-compat for the first time (probably forgot to import it...). But I've tried again now, and it totally works!