WalletConnect / kotlin-walletconnect-lib

library to use WalletConnect with Kotlin or Java
MIT License
147 stars 100 forks source link

WCSessionStore APIs are not async friendly. #66

Open prashanOS opened 2 years ago

prashanOS commented 2 years ago

Hi from OpenSea! We have found an issue when enabling Android's StrictMode. It fails because FileWCSessionStore is doing file I/O on the main thread.

The WCSessionStore's methods are all synchronous, but a store (unless it is purely in-memory) is by nature asynchronous. In general, this means implementations would have to block the current thread while doing either file or network I/O. store() and remove() methods could maybe be implemented as fire-and-forget methods, but then we lose access to Kotlin's built-in structured concurrency.

With the provided FileWCSessionStore implementation, this means we are blocking the main thread while doing file I/O whenever these methods are called. FileWCSessionStore is also doing file I/O on the main thread in its' init block.

The proposed solution would be to make these methods suspend functions. Then, consumers can use their own coroutine scope to run these methods. This does mean that WCSession would need to take in a coroutine scope to launch these new suspend functions from.

jemshit commented 1 year ago

@prashanOS try this, let me know if you have issues

jemshit commented 1 year ago

Hey guys, i see you're trying to improve this library, i have written it from scratch using coroutines, you could try it instead. We're already using it in prod.

@prashanOS @mhernand40 @matthewrkula