From dce5f3dfd3d523acd4d39ed38343e2062900dd54 Mon Sep 17 00:00:00 2001 From: HashEngineering Date: Fri, 20 Dec 2024 09:48:20 -0800 Subject: [PATCH] fix: problems showing Tx details and going to home screen afterwards --- .../wallet/ui/TransactionResultViewModel.kt | 5 +-- .../TransactionDetailsDialogFragment.kt | 5 --- .../transactions/TransactionResultActivity.kt | 36 +++++++++---------- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/wallet/src/de/schildbach/wallet/ui/TransactionResultViewModel.kt b/wallet/src/de/schildbach/wallet/ui/TransactionResultViewModel.kt index fe77476c3..b18b47f96 100644 --- a/wallet/src/de/schildbach/wallet/ui/TransactionResultViewModel.kt +++ b/wallet/src/de/schildbach/wallet/ui/TransactionResultViewModel.kt @@ -96,8 +96,9 @@ class TransactionResultViewModel @Inject constructor( } } - private suspend fun monitorTransactionMetadata(txId: Sha256Hash) { - withContext(Dispatchers.IO) { + private fun monitorTransactionMetadata(txId: Sha256Hash) { + // this might take some time, so let it run asynchronously + viewModelScope.launch(Dispatchers.IO) { transactionMetadataProvider.importTransactionMetadata(txId) transactionMetadataProvider.observeTransactionMetadata(txId).collect { _transactionMetadata.value = it diff --git a/wallet/src/de/schildbach/wallet/ui/transactions/TransactionDetailsDialogFragment.kt b/wallet/src/de/schildbach/wallet/ui/transactions/TransactionDetailsDialogFragment.kt index 1a133e440..57bc7c544 100644 --- a/wallet/src/de/schildbach/wallet/ui/transactions/TransactionDetailsDialogFragment.kt +++ b/wallet/src/de/schildbach/wallet/ui/transactions/TransactionDetailsDialogFragment.kt @@ -100,11 +100,6 @@ class TransactionDetailsDialogFragment : OffsetDialogFragment(R.layout.transacti viewModel.init(txId) viewModel.transaction.filterNotNull().observe(viewLifecycleOwner) { tx -> // the transactionResultViewBinder.bind is called later -// if (tx == null) { -// // log.error("Transaction not found. TxId: {}", txId) -// return@observe -// } - viewModel.transactionIcon.observe(this) { transactionResultViewBinder.setTransactionIcon(it) diff --git a/wallet/src/de/schildbach/wallet/ui/transactions/TransactionResultActivity.kt b/wallet/src/de/schildbach/wallet/ui/transactions/TransactionResultActivity.kt index 6e312c088..1db2f43de 100644 --- a/wallet/src/de/schildbach/wallet/ui/transactions/TransactionResultActivity.kt +++ b/wallet/src/de/schildbach/wallet/ui/transactions/TransactionResultActivity.kt @@ -40,6 +40,7 @@ import de.schildbach.wallet.util.WalletUtils import de.schildbach.wallet_test.R import de.schildbach.wallet_test.databinding.ActivitySuccessfulTransactionBinding import de.schildbach.wallet_test.databinding.TransactionResultContentBinding +import kotlinx.coroutines.flow.filterNotNull import org.bitcoinj.core.Sha256Hash import org.bitcoinj.core.Transaction import org.dash.wallet.common.services.analytics.AnalyticsConstants @@ -150,27 +151,22 @@ class TransactionResultActivity : LockScreenActivity() { viewModel.init(txId) - viewModel.transaction.observe(this) { tx -> - if (tx != null) { - transactionResultViewBinder.setTransactionIcon(R.drawable.check_animated) - contentBinding.openExplorerCard.setOnClickListener { viewOnExplorer(tx) } - contentBinding.taxCategoryLayout.setOnClickListener { viewOnTaxCategory() } - binding.transactionCloseBtn.setOnClickListener { - onTransactionDetailsDismiss() - } - contentBinding.reportIssueCard.setOnClickListener { - showReportIssue() - } - - viewModel.transactionMetadata.observe(this) { - transactionResultViewBinder.setTransactionMetadata(it) - } - transactionResultViewBinder.setOnRescanTriggered { rescanBlockchain() } - } else { - log.error("Transaction not found. TxId: {}", txId) - finish() - return@observe + viewModel.transaction.filterNotNull().observe(this) { tx -> + transactionResultViewBinder.setTransactionIcon(R.drawable.check_animated) + contentBinding.openExplorerCard.setOnClickListener { viewOnExplorer(tx) } + contentBinding.taxCategoryLayout.setOnClickListener { viewOnTaxCategory() } + binding.transactionCloseBtn.setOnClickListener { + onTransactionDetailsDismiss() + } + contentBinding.reportIssueCard.setOnClickListener { + showReportIssue() + } + + viewModel.transactionMetadata.observe(this) { + transactionResultViewBinder.setTransactionMetadata(it) } + transactionResultViewBinder.setOnRescanTriggered { rescanBlockchain() } + viewModel.transactionMetadata.observe(this) { transactionResultViewBinder.setTransactionMetadata(it)