From dd8dd7ba97e4785767061b98f8edf2d3b22ff585 Mon Sep 17 00:00:00 2001 From: HashEngineering Date: Wed, 15 Jan 2025 07:57:03 -0800 Subject: [PATCH] feat(dashpay): finish topup feature (ui, backend) (#1338) * refactor: move BaseWorker * feat: add BaseForegroundWorker * feat: add RestoreIdentityWorker * feat: topup backend * feat: topup ui * feat: topup during username request, if necessary * chore: remove unused imports * fix: hide Buy Credits if there is no username * chore: cleanup some constructors, etc * fix: align ui elements and icons * feat: add topup database table * fix: make topup more similar to send tx flow * fix: for topups, show Send to: OP RETURN * fix: improve tx details for topups * fix: improve topup functionality * fix: add isAssetLock to SendCoinViewModel * fix: don't automatically put topup memo * fix: improve tracking of topUp status * fix: remove checkbox on topup confirm * fix: remove use correct amount on Confirm Username Request Dialog * fix: remove the preposition on for Buy Credits fragment --- build.gradle | 2 +- .../common/transactions/TransactionUtils.kt | 17 + .../wallet/common/ui/PaymentHeaderView.kt | 4 +- .../main/res/layout/payment_header_view.xml | 2 +- common/src/main/res/values/strings.xml | 1 + .../ui/dashdirect/PurchaseGiftCardFragment.kt | 2 +- .../main/res/values/strings-explore-dash.xml | 1 - .../wallet/database/DatabaseMigrationTest.kt | 7 +- .../res/drawable/ic_block_home_indicator.xml | 9 + wallet/res/drawable/ic_credits.xml | 9 + .../drawable/ic_info_circle_filled_gray.xml | 9 + wallet/res/drawable/ic_mail_icon.xml | 9 + wallet/res/drawable/ic_profile_icon.xml | 9 + wallet/res/layout/dialog_confirm_topup.xml | 129 +++ wallet/res/layout/dialog_what_are_credits.xml | 139 +++ wallet/res/layout/fragment_tools.xml | 73 +- wallet/res/values/strings-dashpay.xml | 10 + wallet/res/values/strings.xml | 1 + .../15.json | 992 ++++++++++++++++++ .../src/de/schildbach/wallet/Constants.java | 1 + .../schildbach/wallet/database/AppDatabase.kt | 7 +- .../wallet/database/AppDatabaseMigrations.kt | 16 + .../wallet/database/dao/TopUpsDao.kt | 51 + .../wallet/database/entity/TopUp.kt | 21 + .../de/schildbach/wallet/di/DashPayModule.kt | 9 +- .../de/schildbach/wallet/di/DatabaseModule.kt | 8 +- .../wallet/payments/SendCoinsTaskRunner.kt | 21 +- .../service/platform/PlatformSyncService.kt | 85 +- .../service/platform/TopUpRepository.kt | 314 ++++++ .../platform/work/RestoreIdentityOperation.kt | 62 ++ .../platform/work/RestoreIdentityWorker.kt | 357 +++++++ .../platform/work/TopupIdentityOperation.kt | 173 +++ .../platform/work/TopupIdentityWorker.kt | 130 +++ .../service/work/BaseForegroundWorker.kt | 100 ++ .../dashpay => service}/work/BaseWorker.kt | 4 +- .../wallet/ui/TransactionResultViewModel.kt | 12 + .../ui/dashpay/CreateIdentityService.kt | 157 +-- .../wallet/ui/dashpay/PlatformRepo.kt | 69 +- .../wallet/ui/dashpay/utils/DashPayConfig.kt | 9 + .../work/BroadcastIdentityVerifyWorker.kt | 4 +- .../work/BroadcastUsernameVotesOperation.kt | 1 + .../work/BroadcastUsernameVotesWorker.kt | 2 +- .../wallet/ui/dashpay/work/DeriveKeyWorker.kt | 1 + .../work/GetUsernameVotingResultsWorker.kt | 5 +- .../work/SendContactRequestOperation.kt | 1 + .../dashpay/work/SendContactRequestWorker.kt | 2 +- .../ui/dashpay/work/SendInviteOperation.kt | 1 + .../ui/dashpay/work/SendInviteWorker.kt | 1 + .../dashpay/work/SingleWorkStatusLiveData.kt | 1 + .../ui/dashpay/work/UpdateProfileWorker.kt | 1 + .../ui/main/WalletTransactionsFragment.kt | 44 +- .../schildbach/wallet/ui/more/MoreFragment.kt | 6 +- .../wallet/ui/more/ToolsFragment.kt | 24 +- .../wallet/ui/more/ToolsViewModel.kt | 21 +- .../more/tools/ConfirmTopUpDialogFragment.kt | 76 ++ .../more/tools/ConfirmTopupDialogViewModel.kt | 95 ++ .../tools/WhatAreCreditsDialogFragment.kt | 58 + .../wallet/ui/send/BuyCreditsFragment.kt | 122 +-- .../wallet/ui/send/BuyCreditsViewModel.kt | 61 ++ .../wallet/ui/send/SendCoinsActivity.kt | 2 +- .../wallet/ui/send/SendCoinsFragment.kt | 2 +- .../wallet/ui/send/SendCoinsViewModel.kt | 82 +- .../TransactionDetailsDialogFragment.kt | 41 +- .../transactions/TransactionResultActivity.kt | 37 + .../TransactionResultViewBinder.kt | 34 +- .../voting/ConfirmUserNameDialogViewModel.kt | 8 +- .../ConfirmUsernameRequestDialogFragment.kt | 1 + .../voting/RequestUserNameViewModel.kt | 31 +- 68 files changed, 3453 insertions(+), 343 deletions(-) create mode 100644 wallet/res/drawable/ic_block_home_indicator.xml create mode 100644 wallet/res/drawable/ic_credits.xml create mode 100644 wallet/res/drawable/ic_info_circle_filled_gray.xml create mode 100644 wallet/res/drawable/ic_mail_icon.xml create mode 100644 wallet/res/drawable/ic_profile_icon.xml create mode 100644 wallet/res/layout/dialog_confirm_topup.xml create mode 100644 wallet/res/layout/dialog_what_are_credits.xml create mode 100644 wallet/schemas/de.schildbach.wallet.database.AppDatabase/15.json create mode 100644 wallet/src/de/schildbach/wallet/database/dao/TopUpsDao.kt create mode 100644 wallet/src/de/schildbach/wallet/database/entity/TopUp.kt create mode 100644 wallet/src/de/schildbach/wallet/service/platform/TopUpRepository.kt create mode 100644 wallet/src/de/schildbach/wallet/service/platform/work/RestoreIdentityOperation.kt create mode 100644 wallet/src/de/schildbach/wallet/service/platform/work/RestoreIdentityWorker.kt create mode 100644 wallet/src/de/schildbach/wallet/service/platform/work/TopupIdentityOperation.kt create mode 100644 wallet/src/de/schildbach/wallet/service/platform/work/TopupIdentityWorker.kt create mode 100644 wallet/src/de/schildbach/wallet/service/work/BaseForegroundWorker.kt rename wallet/src/de/schildbach/wallet/{ui/dashpay => service}/work/BaseWorker.kt (92%) create mode 100644 wallet/src/de/schildbach/wallet/ui/more/tools/ConfirmTopUpDialogFragment.kt create mode 100644 wallet/src/de/schildbach/wallet/ui/more/tools/ConfirmTopupDialogViewModel.kt create mode 100644 wallet/src/de/schildbach/wallet/ui/more/tools/WhatAreCreditsDialogFragment.kt create mode 100644 wallet/src/de/schildbach/wallet/ui/send/BuyCreditsViewModel.kt diff --git a/build.gradle b/build.gradle index 670a20a8e3..b67bdf8368 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { coroutinesVersion = '1.6.4' ok_http_version = '4.9.1' dashjVersion = '21.1.4' - dppVersion = "1.5.2" + dppVersion = "1.7.0-SNAPSHOT" hiltVersion = '2.51' hiltCompilerVersion = '1.2.0' hiltWorkVersion = '1.0.0' diff --git a/common/src/main/java/org/dash/wallet/common/transactions/TransactionUtils.kt b/common/src/main/java/org/dash/wallet/common/transactions/TransactionUtils.kt index 475a916780..3a2b91c716 100644 --- a/common/src/main/java/org/dash/wallet/common/transactions/TransactionUtils.kt +++ b/common/src/main/java/org/dash/wallet/common/transactions/TransactionUtils.kt @@ -21,6 +21,7 @@ import org.bitcoinj.core.Address import org.bitcoinj.core.Transaction import org.bitcoinj.core.TransactionBag import org.bitcoinj.script.ScriptException +import org.bitcoinj.script.ScriptPattern object TransactionUtils { fun getWalletAddressOfReceived(tx: Transaction, bag: TransactionBag): Address? { @@ -86,6 +87,22 @@ object TransactionUtils { return result } + fun getOpReturnsOfSent(tx: Transaction, bag: TransactionBag): List { + val result = mutableListOf() + + for (output in tx.outputs) { + try { + if (!output.isMine(bag) && ScriptPattern.isOpReturn(output.scriptPubKey)) { + result.add("OP RETURN") + } + } catch (x: ScriptException) { + // swallow + } + } + + return result + } + fun Transaction.isEntirelySelf(bag: TransactionBag): Boolean { for (input in inputs) { val connectedOutput = input.connectedOutput diff --git a/common/src/main/java/org/dash/wallet/common/ui/PaymentHeaderView.kt b/common/src/main/java/org/dash/wallet/common/ui/PaymentHeaderView.kt index 5b1db44488..97d71ab834 100644 --- a/common/src/main/java/org/dash/wallet/common/ui/PaymentHeaderView.kt +++ b/common/src/main/java/org/dash/wallet/common/ui/PaymentHeaderView.kt @@ -70,8 +70,8 @@ class PaymentHeaderView @JvmOverloads constructor( binding.paymentAddressViewBalanceTitle.text = title } - fun setProposition(title: String) { - binding.paymentAddressViewProposition.text = title + fun setPreposition(title: String) { + binding.paymentAddressViewPreposition.text = title } fun setSubtitle(title: String) { diff --git a/common/src/main/res/layout/payment_header_view.xml b/common/src/main/res/layout/payment_header_view.xml index c6edf6584d..9f688b5e28 100644 --- a/common/src/main/res/layout/payment_header_view.xml +++ b/common/src/main/res/layout/payment_header_view.xml @@ -23,7 +23,7 @@ tools:text="@string/to" /> Specify Amount Create Account Submit + Try Again Search diff --git a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/dashdirect/PurchaseGiftCardFragment.kt b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/dashdirect/PurchaseGiftCardFragment.kt index 5d4e23c6b4..69124208e0 100644 --- a/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/dashdirect/PurchaseGiftCardFragment.kt +++ b/features/exploredash/src/main/java/org/dash/wallet/features/exploredash/ui/dashdirect/PurchaseGiftCardFragment.kt @@ -177,7 +177,7 @@ class PurchaseGiftCardFragment : Fragment(R.layout.fragment_purchase_gift_card) private fun setPaymentHeader() { binding.paymentHeaderView.setTitle(getString(R.string.explore_option_buy)) - binding.paymentHeaderView.setProposition(getString(R.string.purchase_gift_card_at)) + binding.paymentHeaderView.setPreposition(getString(R.string.purchase_gift_card_at)) binding.paymentHeaderView.setOnShowHideBalanceClicked { binding.paymentHeaderView.triggerRevealBalance() viewModel.balance.value?.let { balance -> diff --git a/features/exploredash/src/main/res/values/strings-explore-dash.xml b/features/exploredash/src/main/res/values/strings-explore-dash.xml index 2ddb2abfbb..eb0a4638e4 100644 --- a/features/exploredash/src/main/res/values/strings-explore-dash.xml +++ b/features/exploredash/src/main/res/values/strings-explore-dash.xml @@ -220,7 +220,6 @@ Something went wrong! Retry Gift card purchase failed - Try Again Cancel For some reason we were not able to buy a gift card. Please, try again. Accept DashDirect terms and conditions diff --git a/wallet/androidTest/de/schildbach/wallet/database/DatabaseMigrationTest.kt b/wallet/androidTest/de/schildbach/wallet/database/DatabaseMigrationTest.kt index cb081b2076..dde11f7bdc 100644 --- a/wallet/androidTest/de/schildbach/wallet/database/DatabaseMigrationTest.kt +++ b/wallet/androidTest/de/schildbach/wallet/database/DatabaseMigrationTest.kt @@ -54,14 +54,15 @@ open class DatabaseMigrationTest { "Pizza for Bob's party", "" ) - private val address = "yNo1YJcNBoveEHWB7eYmxFZBVEAYQo46Yb" - private val service = ServiceName.CrowdNode + private const val address = "yNo1YJcNBoveEHWB7eYmxFZBVEAYQo46Yb" + private const val service = ServiceName.CrowdNode } private val migrations = arrayOf( AppDatabaseMigrations.migration11To12, AppDatabaseMigrations.migration12To13, - AppDatabaseMigrations.migration13to14 + AppDatabaseMigrations.migration13to14, + AppDatabaseMigrations.migration14to15 ) @Rule diff --git a/wallet/res/drawable/ic_block_home_indicator.xml b/wallet/res/drawable/ic_block_home_indicator.xml new file mode 100644 index 0000000000..d4ac4f840a --- /dev/null +++ b/wallet/res/drawable/ic_block_home_indicator.xml @@ -0,0 +1,9 @@ + + + diff --git a/wallet/res/drawable/ic_credits.xml b/wallet/res/drawable/ic_credits.xml new file mode 100644 index 0000000000..2e6e38b605 --- /dev/null +++ b/wallet/res/drawable/ic_credits.xml @@ -0,0 +1,9 @@ + + + diff --git a/wallet/res/drawable/ic_info_circle_filled_gray.xml b/wallet/res/drawable/ic_info_circle_filled_gray.xml new file mode 100644 index 0000000000..5163ae7752 --- /dev/null +++ b/wallet/res/drawable/ic_info_circle_filled_gray.xml @@ -0,0 +1,9 @@ + + + diff --git a/wallet/res/drawable/ic_mail_icon.xml b/wallet/res/drawable/ic_mail_icon.xml new file mode 100644 index 0000000000..f5e53a292d --- /dev/null +++ b/wallet/res/drawable/ic_mail_icon.xml @@ -0,0 +1,9 @@ + + + diff --git a/wallet/res/drawable/ic_profile_icon.xml b/wallet/res/drawable/ic_profile_icon.xml new file mode 100644 index 0000000000..49534c20bc --- /dev/null +++ b/wallet/res/drawable/ic_profile_icon.xml @@ -0,0 +1,9 @@ + + + diff --git a/wallet/res/layout/dialog_confirm_topup.xml b/wallet/res/layout/dialog_confirm_topup.xml new file mode 100644 index 0000000000..bd4a9583ee --- /dev/null +++ b/wallet/res/layout/dialog_confirm_topup.xml @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +