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