Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Android reliability #2250

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import io.parity.signer.uniffi.*
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collectLatest
import java.lang.RuntimeException

/**
* Wrapper for uniffi calls into rust. Made for centralized handling errors
Expand Down Expand Up @@ -373,6 +374,22 @@ fun <T> UniffiResult<T>.mapError(): T? {
}
}

/**
* Dangerous cast to non error so we can see a reason in crash logs
*/
@Deprecated("Handle error state")
fun <T> UniffiResult<T>.mapErrorForce(): T {
return when (this) {
is UniffiResult.Error -> {
throw RuntimeException("uniffi interaction exception $error")
}

is UniffiResult.Success -> {
result
}
}
}

fun <T> UniffiResult<T>.toOperationResult(): OperationResult<T, ErrorDisplayed> {
return when (this) {
is UniffiResult.Error -> OperationResult.Err(this.error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package io.parity.signer.domain.usecases
import io.parity.signer.domain.NetworkModel
import io.parity.signer.domain.backend.UniffiInteractor
import io.parity.signer.domain.backend.mapError
import io.parity.signer.domain.backend.mapErrorForce
import kotlinx.coroutines.runBlocking


class AllNetworksUseCase(val uniffiInteractor: UniffiInteractor) {
private var allNetworks: List<NetworkModel> = runBlocking { getNetworks() }!!
private var allNetworks: List<NetworkModel> = runBlocking { getNetworks() }

fun updateCache(): Unit {
allNetworks = runBlocking { getNetworks() }!!
allNetworks = runBlocking { getNetworks() }
}

fun getAllNetworks(): List<NetworkModel> = allNetworks
Expand All @@ -20,7 +21,7 @@ class AllNetworksUseCase(val uniffiInteractor: UniffiInteractor) {
fun getDefaultPreselectedNetworks(): List<NetworkModel> = allNetworks
.filter { preselectedkeys.contains(it.title) }

private suspend fun getNetworks(): List<NetworkModel>? {
return uniffiInteractor.getAllNetworks().mapError()
private suspend fun getNetworks(): List<NetworkModel> {
return uniffiInteractor.getAllNetworks().mapErrorForce()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import io.parity.signer.domain.backend.toOperationResult
import io.parity.signer.domain.popUpToTop
import io.parity.signer.screens.error.handleErrorAppState
import io.parity.signer.screens.keysets.create.backupstepscreens.NewKeySetBackupBottomSheet
import io.parity.signer.screens.keysets.create.backupstepscreens.NewKeySetBackupScreen
import io.parity.signer.screens.keysets.create.backupstepscreens.NewKeySetSelectNetworkScreen
Expand All @@ -37,10 +39,7 @@ fun NewKeysetSubgraph(
mutableStateOf("")
}
val seedPhrase = rememberSaveable() {
vm.createNewSeedPhrase() ?: run {
coreNavController.popBackStack()
""
}
vm.createNewSeedPhrase().toOperationResult().handleErrorAppState(coreNavController) ?: ""
}

NavHost(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.parity.signer.screens.keysets.create

import androidx.lifecycle.ViewModel
import io.parity.signer.dependencygraph.ServiceLocator
import io.parity.signer.domain.backend.mapError
import io.parity.signer.domain.backend.UniffiResult
import kotlinx.coroutines.runBlocking


Expand All @@ -13,9 +13,9 @@ class NewKeysetNameViewModel : ViewModel() {
val seedNames =
ServiceLocator.seedStorage.lastKnownSeedNames

fun createNewSeedPhrase(): String? {
fun createNewSeedPhrase(): UniffiResult<String> {
return runBlocking {
uniffi.createNewSeedPhrase().mapError()
uniffi.createNewSeedPhrase()
}
}
}
Loading