From 281f327145f720e543aaf44c17ec55f4fbb19e9c Mon Sep 17 00:00:00 2001 From: Milan Cerovsky Date: Thu, 12 Dec 2024 14:09:33 +0100 Subject: [PATCH] Code cleanup --- .../CancelKeystoneProposalFlowUseCase.kt | 6 ++-- ...iveKeystoneAccountUnifiedAddressUseCase.kt | 13 ++++---- .../ReviewKeystoneTransactionViewModel.kt | 6 ++-- .../KeystoneTransactionProgressViewModel.kt | 32 +++++++++---------- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/CancelKeystoneProposalFlowUseCase.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/CancelKeystoneProposalFlowUseCase.kt index f8e00a277..82914e92c 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/CancelKeystoneProposalFlowUseCase.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/CancelKeystoneProposalFlowUseCase.kt @@ -8,9 +8,11 @@ class CancelKeystoneProposalFlowUseCase( private val navigationRouter: NavigationRouter, private val observeClearSend: ObserveClearSendUseCase ) { - operator fun invoke() { + operator fun invoke(clearSendForm: Boolean = true) { keystoneProposalRepository.clear() - observeClearSend.requestClear() + if (clearSendForm) { + observeClearSend.requestClear() + } navigationRouter.backToRoot() } } diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/DeriveKeystoneAccountUnifiedAddressUseCase.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/DeriveKeystoneAccountUnifiedAddressUseCase.kt index eb131df55..6c2479a70 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/DeriveKeystoneAccountUnifiedAddressUseCase.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/usecase/DeriveKeystoneAccountUnifiedAddressUseCase.kt @@ -1,17 +1,18 @@ package co.electriccoin.zcash.ui.common.usecase +import cash.z.ecc.android.sdk.tool.DerivationTool import co.electriccoin.zcash.ui.common.provider.PersistableWalletProvider +import co.electriccoin.zcash.ui.screen.addressbook.viewmodel.ADDRESS_MAX_LENGTH import com.keystone.module.ZcashAccount class DeriveKeystoneAccountUnifiedAddressUseCase( private val persistableWalletProvider: PersistableWalletProvider ) { suspend operator fun invoke(account: ZcashAccount): String { - // TODO keystone derivation - // return DerivationTool.getInstance().deriveUnifiedAddress( - // viewingKey = account.ufvk, - // network = persistableWalletProvider.getPersistableWallet().network - // ) - return "placeholder because sdk crashes" // TODO keystone + val address = DerivationTool.getInstance().deriveUnifiedAddress( + viewingKey = account.ufvk, + network = persistableWalletProvider.getPersistableWallet().network + ) + return "${address.take(ADDRESS_MAX_LENGTH)}..." } } 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 8ea2ea598..ce083cf8f 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 @@ -10,6 +10,7 @@ import co.electriccoin.zcash.ui.common.model.WalletAccount import co.electriccoin.zcash.ui.common.repository.RegularTransactionProposal import co.electriccoin.zcash.ui.common.repository.SendTransactionProposal import co.electriccoin.zcash.ui.common.repository.Zip321TransactionProposal +import co.electriccoin.zcash.ui.common.usecase.CancelKeystoneProposalFlowUseCase import co.electriccoin.zcash.ui.common.usecase.GetLoadedExchangeRateUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveContactByAddressUseCase import co.electriccoin.zcash.ui.common.usecase.ObserveKeystoneSendTransactionProposalUseCase @@ -34,6 +35,7 @@ class ReviewKeystoneTransactionViewModel( observeContactByAddress: ObserveContactByAddressUseCase, observeSelectedWalletAccount: ObserveSelectedWalletAccountUseCase, observeKeystoneSendTransactionProposal: ObserveKeystoneSendTransactionProposalUseCase, + private val cancelKeystoneProposalFlow: CancelKeystoneProposalFlowUseCase, private val getLoadedExchangeRate: GetLoadedExchangeRateUseCase, private val navigationRouter: NavigationRouter, ) : ViewModel() { @@ -193,11 +195,11 @@ class ReviewKeystoneTransactionViewModel( } private fun onBack() { - navigationRouter.backToRoot() + cancelKeystoneProposalFlow(clearSendForm = false) } private fun onCancelClick() { - navigationRouter.backToRoot() + cancelKeystoneProposalFlow(clearSendForm = false) } private fun onConfirmClick() { diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/transactionprogress/KeystoneTransactionProgressViewModel.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/transactionprogress/KeystoneTransactionProgressViewModel.kt index b3f845888..1bcd0de9c 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/transactionprogress/KeystoneTransactionProgressViewModel.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/transactionprogress/KeystoneTransactionProgressViewModel.kt @@ -3,7 +3,6 @@ package co.electriccoin.zcash.ui.screen.transactionprogress import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import cash.z.ecc.sdk.ANDROID_STATE_FLOW_TIMEOUT -import co.electriccoin.zcash.ui.NavigationRouter import co.electriccoin.zcash.ui.common.repository.KeystoneProposalRepository import co.electriccoin.zcash.ui.common.repository.SendTransactionProposal import co.electriccoin.zcash.ui.common.repository.ShieldTransactionProposal @@ -26,7 +25,6 @@ import kotlinx.coroutines.launch class KeystoneTransactionProgressViewModel( private val getSelectedWalletAccount: GetSelectedWalletAccountUseCase, private val keystoneProposalRepository: KeystoneProposalRepository, - private val navigationRouter: NavigationRouter, private val copyToClipboardUseCase: CopyToClipboardUseCase, private val sendEmailUseCase: SendEmailUseCase, private val cancelKeystoneProposalFlow: CancelKeystoneProposalFlowUseCase @@ -67,7 +65,7 @@ class KeystoneTransactionProgressViewModel( showBackButton = supportContacted, onBack = { if (supportContacted) { - onBackToHomepageAndClearDataRequested() + onBackToHomepageAndClearSendForm() } // do nothing }, @@ -88,27 +86,23 @@ class KeystoneTransactionProgressViewModel( private fun createGrpcFailureTransactionState() = GrpcFailureTransactionState( - onBack = ::onBackToHomepageAndClearDataRequested, - onCloseClick = ::onBackToHomepageAndClearDataRequested + onBack = ::onBackToHomepageAndClearSendForm, + onCloseClick = ::onBackToHomepageAndClearSendForm ) private suspend fun createSuccessfulTransactionState() = SuccessfulTransactionState( - onBack = ::onBackToHomepageAndClearDataRequested, - onViewTransactionClick = ::onBackToHomepageAndClearDataRequested, - onCloseClick = ::onBackToHomepageAndClearDataRequested, + onBack = ::onBackToHomepageAndClearSendForm, + onViewTransactionClick = ::onBackToHomepageAndClearSendForm, + onCloseClick = ::onBackToHomepageAndClearSendForm, address = getAddressAbbreviated() ) private fun createFailureTransactionState(result: SubmitResult.SimpleTrxFailure) = FailureTransactionState( - onBack = { - navigationRouter.back() - }, - onCloseClick = { - navigationRouter.back() - }, - onViewTransactionClick = ::onBackToHomepageAndClearDataRequested, + onBack = ::onBackToHomepage, + onCloseClick = ::onBackToHomepage, + onViewTransactionClick = ::onBackToHomepageAndClearSendForm, onReportClick = { viewModelScope.launch { sendEmailUseCase(result) @@ -135,7 +129,11 @@ class KeystoneTransactionProgressViewModel( return "${address.take(ADDRESS_MAX_LENGTH)}..." } - private fun onBackToHomepageAndClearDataRequested() { - cancelKeystoneProposalFlow() + private fun onBackToHomepageAndClearSendForm() { + cancelKeystoneProposalFlow(clearSendForm = true) + } + + private fun onBackToHomepage() { + cancelKeystoneProposalFlow(clearSendForm = false) } }