From 00c0bdb5f68a125438dc3a957a1cd28f5f7eacd3 Mon Sep 17 00:00:00 2001 From: HashEngineering Date: Tue, 22 Oct 2024 08:46:10 -0700 Subject: [PATCH] feat(dashpay): add more events and release v11.0.1 (#1316) * feat: add firebase events for some dashpay related actions * fix: change order of operands to ensure execution * fix: use dashj 21.1.2 * chore: v11.0.1 * fix: remove unnecessary firebase id in SendCoinsTaskRunner --- build.gradle | 2 +- .../services/analytics/AnalyticsConstants.kt | 3 ++ wallet/build.gradle | 4 +- .../src/de/schildbach/wallet/di/AppModule.kt | 9 +++- .../wallet/payments/SendCoinsTaskRunner.kt | 48 +++++++++++++++++-- .../service/platform/PlatformSyncService.kt | 8 ++-- .../wallet/ui/dashpay/EditProfileViewModel.kt | 1 + 7 files changed, 61 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index b6ce137df..e1f5061c7 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { kotlin_version = '1.9.23' coroutinesVersion = '1.6.4' ok_http_version = '4.9.1' - dashjVersion = '21.1.1' + dashjVersion = '21.1.2' dppVersion = "1.3-SNAPSHOT" hiltVersion = '2.51' hiltCompilerVersion = '1.2.0' diff --git a/common/src/main/java/org/dash/wallet/common/services/analytics/AnalyticsConstants.kt b/common/src/main/java/org/dash/wallet/common/services/analytics/AnalyticsConstants.kt index fbd2b9c35..112899d22 100644 --- a/common/src/main/java/org/dash/wallet/common/services/analytics/AnalyticsConstants.kt +++ b/common/src/main/java/org/dash/wallet/common/services/analytics/AnalyticsConstants.kt @@ -87,6 +87,8 @@ object AnalyticsConstants { } object SendReceive { + const val SEND_TX = "send_tx" // also include amount sent + const val SEND_TX_CONTACT = "send_tx_to_contact" // also include amount sent const val SCAN_TO_SEND = "send_scan_to_send" const val SEND_TO_ADDRESS = "send_to_address" const val SHOW_QR_CODE = "receive_show_qr_code" @@ -175,6 +177,7 @@ object AnalyticsConstants { const val PROFILE_NAME_LENGTH = "profile_display_name_length" const val PROFILE_CHANGE_ABOUT_ME = "profile_change_about_me" const val PROFILE_ABOUT_ME_LENGTH = "profile_about_me_length" + const val PROFILE_CHANGE_PICTURE = "profile_change_picture" const val PROFILE_CHANGE_PICTURE_GRAVATAR = "profile_change_picture_gravatar" const val PROFILE_CHANGE_PICTURE_PUBLIC_URL = "profile_change_picture_public_url" const val PROFILE_CHANGE_PICTURE_CAMERA = "profile_change_picture_camera_photo" diff --git a/wallet/build.gradle b/wallet/build.gradle index a5532ed6a..68a393e38 100644 --- a/wallet/build.gradle +++ b/wallet/build.gradle @@ -207,8 +207,8 @@ android { compileSdk 34 minSdkVersion 24 targetSdkVersion 34 - versionCode project.hasProperty('versionCode') ? project.property('versionCode') as int : 110043 - versionName project.hasProperty('versionName') ? project.property('versionName') : "11.0-beta" + versionCode project.hasProperty('versionCode') ? project.property('versionCode') as int : 110060 + versionName project.hasProperty('versionName') ? project.property('versionName') : "11.0.1" multiDexEnabled true generatedDensities = ['hdpi', 'xhdpi'] vectorDrawables.useSupportLibrary = true diff --git a/wallet/src/de/schildbach/wallet/di/AppModule.kt b/wallet/src/de/schildbach/wallet/di/AppModule.kt index c548e3bd7..d6578e12e 100644 --- a/wallet/src/de/schildbach/wallet/di/AppModule.kt +++ b/wallet/src/de/schildbach/wallet/di/AppModule.kt @@ -30,6 +30,7 @@ import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent import de.schildbach.wallet.WalletApplication import de.schildbach.wallet.data.CoinJoinConfig +import de.schildbach.wallet.database.entity.BlockchainIdentityConfig import de.schildbach.wallet.payments.ConfirmTransactionLauncher import de.schildbach.wallet.payments.SendCoinsTaskRunner import de.schildbach.wallet.security.SecurityFunctions @@ -37,6 +38,7 @@ import de.schildbach.wallet.service.* import de.schildbach.wallet.service.AndroidActionsService import de.schildbach.wallet.service.AppRestartService import de.schildbach.wallet.service.RestartService +import de.schildbach.wallet.ui.dashpay.PlatformRepo import de.schildbach.wallet.ui.more.tools.ZenLedgerApi import de.schildbach.wallet.ui.more.tools.ZenLedgerClient import de.schildbach.wallet.ui.notifications.NotificationManagerWrapper @@ -105,9 +107,12 @@ abstract class AppModule { walletApplication: WalletApplication, securityFunctions: SecurityFunctions, packageInfoProvider: PackageInfoProvider, - coinJoinConfig: CoinJoinConfig + analyticsService: AnalyticsService, + identityConfig: BlockchainIdentityConfig, + coinJoinConfig: CoinJoinConfig, + platformRepo: PlatformRepo ): SendPaymentService { - val realService = SendCoinsTaskRunner(walletData, walletApplication, securityFunctions, packageInfoProvider, coinJoinConfig) + val realService = SendCoinsTaskRunner(walletData, walletApplication, securityFunctions, packageInfoProvider, analyticsService, identityConfig, coinJoinConfig, platformRepo) return if (BuildConfig.FLAVOR.lowercase() == "prod") { realService diff --git a/wallet/src/de/schildbach/wallet/payments/SendCoinsTaskRunner.kt b/wallet/src/de/schildbach/wallet/payments/SendCoinsTaskRunner.kt index 894e56ca7..085b37f09 100644 --- a/wallet/src/de/schildbach/wallet/payments/SendCoinsTaskRunner.kt +++ b/wallet/src/de/schildbach/wallet/payments/SendCoinsTaskRunner.kt @@ -17,17 +17,18 @@ package de.schildbach.wallet.payments import androidx.annotation.VisibleForTesting -import androidx.lifecycle.viewModelScope import de.schildbach.wallet.WalletApplication import de.schildbach.wallet.data.CoinJoinConfig import de.schildbach.wallet.data.PaymentIntent +import de.schildbach.wallet.database.entity.BlockchainIdentityConfig +import de.schildbach.wallet.database.entity.BlockchainIdentityConfig.Companion.IDENTITY_ID import de.schildbach.wallet.payments.parsers.PaymentIntentParser import de.schildbach.wallet.security.SecurityFunctions import de.schildbach.wallet.security.SecurityGuard import de.schildbach.wallet.service.CoinJoinMode import de.schildbach.wallet.service.PackageInfoProvider +import de.schildbach.wallet.ui.dashpay.PlatformRepo import kotlinx.coroutines.* -import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -52,6 +53,8 @@ import org.dash.wallet.common.WalletDataProvider import org.dash.wallet.common.services.DirectPayException import org.dash.wallet.common.services.LeftoverBalanceException import org.dash.wallet.common.services.SendPaymentService +import org.dash.wallet.common.services.analytics.AnalyticsConstants +import org.dash.wallet.common.services.analytics.AnalyticsService import org.dash.wallet.common.transactions.ByAddressCoinSelector import org.dash.wallet.common.util.Constants import org.dash.wallet.common.util.call @@ -64,7 +67,10 @@ class SendCoinsTaskRunner @Inject constructor( private val walletApplication: WalletApplication, private val securityFunctions: SecurityFunctions, private val packageInfoProvider: PackageInfoProvider, - coinJoinConfig: CoinJoinConfig + private val analyticsService: AnalyticsService, + private val identityConfig: BlockchainIdentityConfig, + coinJoinConfig: CoinJoinConfig, + private val platformRepo: PlatformRepo ) : SendPaymentService { companion object { private const val WALLET_EXCEPTION_MESSAGE = "this method can't be used before creating the wallet" @@ -72,7 +78,7 @@ class SendCoinsTaskRunner @Inject constructor( } private var coinJoinSend = false private val coroutineScope = CoroutineScope(Dispatchers.IO) - + private var firebaseInstallationId: String = "" init { coinJoinConfig .observeMode() @@ -319,7 +325,6 @@ class SendCoinsTaskRunner @Inject constructor( if (checkBalanceConditions) { checkBalanceConditions(wallet, sendRequest.tx) } - signSendRequest(sendRequest) try { @@ -334,6 +339,7 @@ class SendCoinsTaskRunner @Inject constructor( val transaction = sendRequest.tx log.info("send successful, transaction committed: {}", transaction.txId.toString()) walletApplication.broadcastTransaction(transaction) + logSendTxEvent(transaction, wallet) transaction } catch (ex: Exception) { when (ex) { @@ -349,6 +355,38 @@ class SendCoinsTaskRunner @Inject constructor( } } + private suspend fun logSendTxEvent( + transaction: Transaction, + wallet: Wallet + ) { + identityConfig.get(IDENTITY_ID)?.let { + val valueSent: Long = transaction.outputs.filter { + !it.isMine(wallet) + }.sumOf { + it.value.value + } + val isSentToContact = try { + platformRepo.blockchainIdentity.getContactForTransaction(transaction) != null + } catch (e: Exception) { + false + } + analyticsService.logEvent( + AnalyticsConstants.SendReceive.SEND_TX, + mapOf( + AnalyticsConstants.Parameter.VALUE to valueSent + ) + ) + if (isSentToContact) { + analyticsService.logEvent( + AnalyticsConstants.SendReceive.SEND_TX_CONTACT, + mapOf( + AnalyticsConstants.Parameter.VALUE to valueSent + ) + ) + } + } + } + fun signSendRequest(sendRequest: SendRequest) { val wallet = walletData.wallet ?: throw RuntimeException("this method can't be used before creating the wallet") diff --git a/wallet/src/de/schildbach/wallet/service/platform/PlatformSyncService.kt b/wallet/src/de/schildbach/wallet/service/platform/PlatformSyncService.kt index 74819afe0..5292df3dd 100644 --- a/wallet/src/de/schildbach/wallet/service/platform/PlatformSyncService.kt +++ b/wallet/src/de/schildbach/wallet/service/platform/PlatformSyncService.kt @@ -300,7 +300,7 @@ class PlatformSynchronizationService @Inject constructor( dashPayContactRequestDao.insert(dashPayContactRequest) // add our receiving from this contact keychain if it doesn't exist - addedContact = addedContact || checkAndAddSentRequest(userId, contactRequest) + addedContact = checkAndAddSentRequest(userId, contactRequest) || addedContact log.info("contactRequest: added sent request from ${contactRequest.toUserId}") } } @@ -328,7 +328,7 @@ class PlatformSynchronizationService @Inject constructor( dashPayContactRequestDao.insert(dashPayContactRequest) // add the sending to contact keychain if it doesn't exist - addedContact = addedContact || checkAndAddReceivedRequest(userId, contactRequest) + addedContact = checkAndAddReceivedRequest(userId, contactRequest) || addedContact log.info("contactRequest: added received request from ${contactRequest.ownerId}") } } @@ -477,9 +477,9 @@ class PlatformSynchronizationService @Inject constructor( myEncryptionKey = platformRepo.walletApplication.wallet!!.keyCrypter!!.deriveKey(password) } - platformRepo.blockchainIdentity.addContactPaymentKeyChain( + platformRepo.blockchainIdentity.addPaymentKeyChainToContact( contactIdentity!!, - contactRequest.document, + contactRequest, myEncryptionKey!! ) return true diff --git a/wallet/src/de/schildbach/wallet/ui/dashpay/EditProfileViewModel.kt b/wallet/src/de/schildbach/wallet/ui/dashpay/EditProfileViewModel.kt index 2f424d1a1..f657d1217 100644 --- a/wallet/src/de/schildbach/wallet/ui/dashpay/EditProfileViewModel.kt +++ b/wallet/src/de/schildbach/wallet/ui/dashpay/EditProfileViewModel.kt @@ -398,6 +398,7 @@ class EditProfileViewModel @Inject constructor( } if (avatarUrl != dashPayProfile.value!!.avatarUrl) { + analytics.logEvent(AnalyticsConstants.UsersContacts.PROFILE_CHANGE_PICTURE, mapOf()) when (pictureSource) { "gravatar" -> analytics.logEvent(AnalyticsConstants.UsersContacts.PROFILE_CHANGE_PICTURE_GRAVATAR, mapOf()) "public_url" -> analytics.logEvent(AnalyticsConstants.UsersContacts.PROFILE_CHANGE_PICTURE_PUBLIC_URL, mapOf())