Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Milan-Cerovsky committed Dec 12, 2024
1 parent 30b50f7 commit 281f327
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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)}..."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -67,7 +65,7 @@ class KeystoneTransactionProgressViewModel(
showBackButton = supportContacted,
onBack = {
if (supportContacted) {
onBackToHomepageAndClearDataRequested()
onBackToHomepageAndClearSendForm()
}
// do nothing
},
Expand All @@ -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)
Expand All @@ -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)
}
}

0 comments on commit 281f327

Please sign in to comment.