[#1456] runCreateTransactions on lifecycleScope

- Closes #1456
- Also, these changes leverage updated snapshot Zcash SDK version  2.1.2
- Changelog update
This commit is contained in:
Honza Rychnovský 2024-06-03 08:12:07 +02:00 committed by GitHub
parent 030d2e20b0
commit 75e90607d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 10 deletions

View File

@ -15,6 +15,10 @@ directly impact users rather than highlighting other key architectural updates.*
### Changed ### Changed
- The color palette used across the app has been reworked to align with the updated design document - The color palette used across the app has been reworked to align with the updated design document
### Fixed
- An updated snapshot Zcash SDK version has been adopted to improve unstable lightwalletd communication
- Transaction submission has been slightly refactored to improve its stability
## [1.1 (655)] - 2024-05-24 ## [1.1 (655)] - 2024-05-24
### Added ### Added

View File

@ -201,7 +201,11 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
synchronizer synchronizer
.filterNotNull() .filterNotNull()
.map { .map {
WalletAddresses.new(it) runCatching {
WalletAddresses.new(it)
}.onFailure {
Twig.warn { "Wait until the SDK starts providing the addresses" }
}.getOrNull()
}.stateIn( }.stateIn(
viewModelScope, viewModelScope,
SharingStarted.WhileSubscribed(ANDROID_STATE_FLOW_TIMEOUT), SharingStarted.WhileSubscribed(ANDROID_STATE_FLOW_TIMEOUT),

View File

@ -4,7 +4,6 @@ package co.electriccoin.zcash.ui.screen.balances
import android.content.Context import android.content.Context
import android.widget.Toast import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -14,11 +13,13 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.lifecycleScope
import cash.z.ecc.android.sdk.SdkSynchronizer import cash.z.ecc.android.sdk.SdkSynchronizer
import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.Synchronizer
import cash.z.ecc.android.sdk.model.UnifiedSpendingKey import cash.z.ecc.android.sdk.model.UnifiedSpendingKey
import cash.z.ecc.android.sdk.model.Zatoshi import cash.z.ecc.android.sdk.model.Zatoshi
import co.electriccoin.zcash.spackle.Twig import co.electriccoin.zcash.spackle.Twig
import co.electriccoin.zcash.ui.MainActivity
import co.electriccoin.zcash.ui.R import co.electriccoin.zcash.ui.R
import co.electriccoin.zcash.ui.common.compose.BalanceState import co.electriccoin.zcash.ui.common.compose.BalanceState
import co.electriccoin.zcash.ui.common.model.WalletRestoringState import co.electriccoin.zcash.ui.common.model.WalletRestoringState
@ -43,7 +44,7 @@ import org.jetbrains.annotations.VisibleForTesting
@Composable @Composable
internal fun WrapBalances( internal fun WrapBalances(
activity: ComponentActivity, activity: MainActivity,
goSettings: () -> Unit, goSettings: () -> Unit,
goMultiTrxSubmissionFailure: () -> Unit, goMultiTrxSubmissionFailure: () -> Unit,
) { ) {
@ -74,6 +75,7 @@ internal fun WrapBalances(
checkUpdateViewModel = checkUpdateViewModel, checkUpdateViewModel = checkUpdateViewModel,
goSettings = goSettings, goSettings = goSettings,
goMultiTrxSubmissionFailure = goMultiTrxSubmissionFailure, goMultiTrxSubmissionFailure = goMultiTrxSubmissionFailure,
lifecycleScope = activity.lifecycleScope,
spendingKey = spendingKey, spendingKey = spendingKey,
synchronizer = synchronizer, synchronizer = synchronizer,
walletSnapshot = walletSnapshot, walletSnapshot = walletSnapshot,
@ -93,6 +95,7 @@ internal fun WrapBalances(
createTransactionsViewModel: CreateTransactionsViewModel, createTransactionsViewModel: CreateTransactionsViewModel,
goSettings: () -> Unit, goSettings: () -> Unit,
goMultiTrxSubmissionFailure: () -> Unit, goMultiTrxSubmissionFailure: () -> Unit,
lifecycleScope: CoroutineScope,
spendingKey: UnifiedSpendingKey?, spendingKey: UnifiedSpendingKey?,
synchronizer: Synchronizer?, synchronizer: Synchronizer?,
walletSnapshot: WalletSnapshot?, walletSnapshot: WalletSnapshot?,
@ -157,7 +160,7 @@ internal fun WrapBalances(
hideStatusDialog = { showStatusDialog.value = null }, hideStatusDialog = { showStatusDialog.value = null },
snackbarHostState = snackbarHostState, snackbarHostState = snackbarHostState,
onShielding = { onShielding = {
scope.launch { lifecycleScope.launch {
setShieldState(ShieldState.Running) setShieldState(ShieldState.Running)
Twig.debug { "Shielding transparent funds" } Twig.debug { "Shielding transparent funds" }

View File

@ -2,7 +2,6 @@
package co.electriccoin.zcash.ui.screen.home package co.electriccoin.zcash.ui.screen.home
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -104,7 +103,7 @@ internal fun MainActivity.WrapHome(
@Suppress("LongParameterList", "LongMethod") @Suppress("LongParameterList", "LongMethod")
@Composable @Composable
internal fun WrapHome( internal fun WrapHome(
activity: ComponentActivity, activity: MainActivity,
goBack: () -> Unit, goBack: () -> Unit,
goSettings: () -> Unit, goSettings: () -> Unit,
goMultiTrxSubmissionFailure: () -> Unit, goMultiTrxSubmissionFailure: () -> Unit,

View File

@ -16,6 +16,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.lifecycleScope
import cash.z.ecc.android.sdk.SdkSynchronizer import cash.z.ecc.android.sdk.SdkSynchronizer
import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.Synchronizer
import cash.z.ecc.android.sdk.model.Proposal import cash.z.ecc.android.sdk.model.Proposal
@ -44,6 +45,7 @@ import co.electriccoin.zcash.ui.screen.support.viewmodel.SupportViewModel
import co.electriccoin.zcash.ui.util.EmailUtil import co.electriccoin.zcash.ui.util.EmailUtil
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -76,10 +78,11 @@ internal fun MainActivity.WrapSendConfirmation(
activity = this, activity = this,
arguments = arguments, arguments = arguments,
authenticationViewModel = authenticationViewModel, authenticationViewModel = authenticationViewModel,
createTransactionsViewModel = createTransactionsViewModel,
goBack = goBack, goBack = goBack,
goHome = goHome, goHome = goHome,
goSupport = goSupport, goSupport = goSupport,
createTransactionsViewModel = createTransactionsViewModel, lifecycleScope = this.lifecycleScope,
spendingKey = spendingKey, spendingKey = spendingKey,
supportMessage = supportMessage, supportMessage = supportMessage,
synchronizer = synchronizer, synchronizer = synchronizer,
@ -94,10 +97,11 @@ internal fun WrapSendConfirmation(
activity: MainActivity, activity: MainActivity,
arguments: SendConfirmationArguments, arguments: SendConfirmationArguments,
authenticationViewModel: AuthenticationViewModel, authenticationViewModel: AuthenticationViewModel,
createTransactionsViewModel: CreateTransactionsViewModel,
goBack: (clearForm: Boolean) -> Unit, goBack: (clearForm: Boolean) -> Unit,
goHome: () -> Unit, goHome: () -> Unit,
goSupport: () -> Unit, goSupport: () -> Unit,
createTransactionsViewModel: CreateTransactionsViewModel, lifecycleScope: CoroutineScope,
spendingKey: UnifiedSpendingKey?, spendingKey: UnifiedSpendingKey?,
supportMessage: SupportInfo?, supportMessage: SupportInfo?,
synchronizer: Synchronizer?, synchronizer: Synchronizer?,
@ -179,7 +183,7 @@ internal fun WrapSendConfirmation(
}, },
onConfirmation = { onConfirmation = {
// Check and trigger authentication if required, or just submit transactions otherwise // Check and trigger authentication if required, or just submit transactions otherwise
scope.launch { lifecycleScope.launch {
authenticationViewModel.isSendFundsAuthenticationRequired authenticationViewModel.isSendFundsAuthenticationRequired
.filterNotNull() .filterNotNull()
.collect { isProtected -> .collect { isProtected ->
@ -211,7 +215,7 @@ internal fun WrapSendConfirmation(
goSupport() goSupport()
}, },
onSuccess = { onSuccess = {
scope.launch { lifecycleScope.launch {
runSendFundsAction( runSendFundsAction(
createTransactionsViewModel = createTransactionsViewModel, createTransactionsViewModel = createTransactionsViewModel,
goHome = goHome, goHome = goHome,