chore: improve performance #41
@@ -29,16 +29,14 @@ class UniversalSigner(initialSigner: AsyncNostrSigner) : AsyncNostrSigner {
|
||||
/**
|
||||
* Switch to a new signer.
|
||||
*/
|
||||
suspend fun switch(newSigner: AsyncNostrSigner) = mutex.withLock {
|
||||
val pubkey = try {
|
||||
withTimeoutOrNull(20.seconds) {
|
||||
newSigner.getPublicKeyAsync()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
throw IllegalStateException("Failed to get public key from signer", e)
|
||||
suspend fun switch(newSigner: AsyncNostrSigner) {
|
||||
val pubkey = withTimeoutOrNull(20.seconds) { newSigner.getPublicKeyAsync() }
|
||||
?: throw IllegalStateException("Failed to get public key from signer")
|
||||
|
||||
mutex.withLock {
|
||||
signer = newSigner
|
||||
_publicKeyFlow.value = pubkey
|
||||
}
|
||||
signer = newSigner
|
||||
_publicKeyFlow.value = pubkey
|
||||
}
|
||||
|
||||
override suspend fun getPublicKeyAsync(): PublicKey? {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package su.reya.coop.viewmodel
|
||||
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
@@ -145,6 +146,8 @@ class ChatViewModel(
|
||||
rooms.forEach { room -> newMap[room.id] = room }
|
||||
currentState.copy(rooms = newMap)
|
||||
}
|
||||
} catch (e: CancellationException) {
|
||||
throw e
|
||||
} catch (e: Exception) {
|
||||
showError("Error: ${e.message}")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user