From 9ae240ce29c134d97597b28c5b367127e3d1b43f Mon Sep 17 00:00:00 2001 From: Milan Cerovsky Date: Wed, 18 Dec 2024 08:13:05 +0100 Subject: [PATCH] Transparent address on sign transaction screen during shielding --- .../co/electriccoin/zcash/di/UseCaseModule.kt | 4 ++-- ...e.kt => ObserveTransactionProposalUseCase.kt} | 6 ++++-- .../ReviewKeystoneTransactionViewModel.kt | 6 +++--- .../SignKeystoneTransactionViewModel.kt | 16 ++++++++++++++-- 4 files changed, 23 insertions(+), 9 deletions(-) rename ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/{ObserveKeystoneSendTransactionProposalUseCase.kt => ObserveTransactionProposalUseCase.kt} (82%) diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/di/UseCaseModule.kt b/ui-lib/src/main/java/co/electriccoin/zcash/di/UseCaseModule.kt index 44008ded..4599e7c9 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/di/UseCaseModule.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/di/UseCaseModule.kt @@ -30,11 +30,11 @@ import co.electriccoin.zcash.ui.common.usecase.ObserveContactPickedUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveCurrentTransactionsUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveFastestServersUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveIsFlexaAvailableUseCase -import co.electriccoin.zcash.ui.common.usecase.ObserveKeystoneSendTransactionProposalUseCase import co.electriccoin.zcash.ui.common.usecase.ObservePersistableWalletUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveSelectedEndpointUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveSelectedWalletAccountUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveSynchronizerUseCase +import co.electriccoin.zcash.ui.common.usecase.ObserveTransactionProposalUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveWalletAccountsUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveWalletStateUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveZashiAccountUseCase @@ -119,7 +119,7 @@ val useCaseModule = factoryOf(::ParseKeystonePCZTUseCase) factoryOf(::ParseKeystoneSignInRequestUseCase) factoryOf(::CancelKeystoneProposalFlowUseCase) - factoryOf(::ObserveKeystoneSendTransactionProposalUseCase) + factoryOf(::ObserveTransactionProposalUseCase) factoryOf(::SharePCZTUseCase) factoryOf(::CreateKeystoneProposalPCZTEncoderUseCase) } diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/ObserveKeystoneSendTransactionProposalUseCase.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/ObserveTransactionProposalUseCase.kt similarity index 82% rename from ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/ObserveKeystoneSendTransactionProposalUseCase.kt rename to ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/ObserveTransactionProposalUseCase.kt index 21459c7a..5f20e5ee 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/ObserveKeystoneSendTransactionProposalUseCase.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/ObserveTransactionProposalUseCase.kt @@ -8,10 +8,12 @@ import co.electriccoin.zcash.ui.common.repository.KeystoneProposalRepository import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map -class ObserveKeystoneSendTransactionProposalUseCase( +class ObserveTransactionProposalUseCase( private val keystoneProposalRepository: KeystoneProposalRepository, ) { - operator fun invoke(): Flow = + operator fun invoke() = keystoneProposalRepository.transactionProposal + + fun filterSendTransactions(): Flow = keystoneProposalRepository.transactionProposal.map { when (it) { is RegularTransactionProposal -> it diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/reviewtransaction/ReviewKeystoneTransactionViewModel.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/reviewtransaction/ReviewKeystoneTransactionViewModel.kt index 659697e4..6043283f 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/reviewtransaction/ReviewKeystoneTransactionViewModel.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/reviewtransaction/ReviewKeystoneTransactionViewModel.kt @@ -14,8 +14,8 @@ import co.electriccoin.zcash.ui.common.model.WalletAccount import co.electriccoin.zcash.ui.common.usecase.CancelKeystoneProposalFlowUseCase import co.electriccoin.zcash.ui.common.usecase.GetExchangeRateUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveContactByAddressUseCase -import co.electriccoin.zcash.ui.common.usecase.ObserveKeystoneSendTransactionProposalUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveSelectedWalletAccountUseCase +import co.electriccoin.zcash.ui.common.usecase.ObserveTransactionProposalUseCase import co.electriccoin.zcash.ui.common.wallet.ExchangeRateState import co.electriccoin.zcash.ui.design.component.ButtonState import co.electriccoin.zcash.ui.design.component.ZashiChipButtonState @@ -39,7 +39,7 @@ import kotlinx.coroutines.flow.update class ReviewKeystoneTransactionViewModel( observeContactByAddress: ObserveContactByAddressUseCase, observeSelectedWalletAccount: ObserveSelectedWalletAccountUseCase, - observeKeystoneSendTransactionProposal: ObserveKeystoneSendTransactionProposalUseCase, + observeKeystoneSendTransactionProposal: ObserveTransactionProposalUseCase, private val cancelKeystoneProposalFlow: CancelKeystoneProposalFlowUseCase, private val getExchangeRate: GetExchangeRateUseCase, private val navigationRouter: NavigationRouter, @@ -60,7 +60,7 @@ class ReviewKeystoneTransactionViewModel( val state = combine( observeSelectedWalletAccount.require(), - observeKeystoneSendTransactionProposal(), + observeKeystoneSendTransactionProposal.filterSendTransactions(), isReceiverExpanded, exchangeRate, ) { wallet, zecSend, isReceiverExpanded, exchangeRate -> diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/signkeystonetransaction/viewmodel/SignKeystoneTransactionViewModel.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/signkeystonetransaction/viewmodel/SignKeystoneTransactionViewModel.kt index bcb38551..a7225e25 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/signkeystonetransaction/viewmodel/SignKeystoneTransactionViewModel.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/signkeystonetransaction/viewmodel/SignKeystoneTransactionViewModel.kt @@ -6,9 +6,11 @@ import cash.z.ecc.sdk.ANDROID_STATE_FLOW_TIMEOUT import co.electriccoin.zcash.ui.BuildConfig import co.electriccoin.zcash.ui.NavigationRouter import co.electriccoin.zcash.ui.R +import co.electriccoin.zcash.ui.common.datasource.ShieldTransactionProposal import co.electriccoin.zcash.ui.common.usecase.CancelKeystoneProposalFlowUseCase import co.electriccoin.zcash.ui.common.usecase.CreateKeystoneProposalPCZTEncoderUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveSelectedWalletAccountUseCase +import co.electriccoin.zcash.ui.common.usecase.ObserveTransactionProposalUseCase import co.electriccoin.zcash.ui.common.usecase.SharePCZTUseCase import co.electriccoin.zcash.ui.design.component.ButtonState import co.electriccoin.zcash.ui.design.util.stringRes @@ -28,6 +30,7 @@ import kotlinx.coroutines.launch class SignKeystoneTransactionViewModel( observeSelectedWalletAccount: ObserveSelectedWalletAccountUseCase, + observeTransactionProposalUseCase: ObserveTransactionProposalUseCase, private val navigationRouter: NavigationRouter, private val createKeystoneProposalPCZTEncoder: CreateKeystoneProposalPCZTEncoderUseCase, private val cancelKeystoneProposalFlow: CancelKeystoneProposalFlowUseCase, @@ -38,13 +41,22 @@ class SignKeystoneTransactionViewModel( private val currentQrPart = MutableStateFlow(null) val state: StateFlow = - combine(observeSelectedWalletAccount.require(), currentQrPart) { wallet, qrData -> + combine( + observeTransactionProposalUseCase(), + observeSelectedWalletAccount.require(), + currentQrPart + ) { proposal, wallet, qrData -> SignKeystoneTransactionState( accountInfo = ZashiAccountInfoListItemState( icon = R.drawable.ic_settings_info, title = wallet.name, - subtitle = stringRes("${wallet.unified.address.address.take(ADDRESS_MAX_LENGTH)}...") + subtitle = + if (proposal is ShieldTransactionProposal) { + stringRes("${wallet.transparent.address.address.take(ADDRESS_MAX_LENGTH)}...") + } else { + stringRes("${wallet.unified.address.address.take(ADDRESS_MAX_LENGTH)}...") + } ), generateNextQrCode = { currentQrPart.update { encoder?.nextPart() } }, qrData = qrData,