Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dashpay): add more events #1316

Merged
merged 5 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions wallet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions wallet/src/de/schildbach/wallet/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ 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
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
Expand Down Expand Up @@ -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
Expand Down
48 changes: 43 additions & 5 deletions wallet/src/de/schildbach/wallet/payments/SendCoinsTaskRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -64,15 +67,18 @@ 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"
private val log = LoggerFactory.getLogger(SendCoinsTaskRunner::class.java)
}
private var coinJoinSend = false
private val coroutineScope = CoroutineScope(Dispatchers.IO)

private var firebaseInstallationId: String = ""
init {
coinJoinConfig
.observeMode()
Expand Down Expand Up @@ -319,7 +325,6 @@ class SendCoinsTaskRunner @Inject constructor(
if (checkBalanceConditions) {
checkBalanceConditions(wallet, sendRequest.tx)
}

signSendRequest(sendRequest)

try {
Expand All @@ -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) {
Expand All @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if addedContact was true, then other contacts requests would not be processed until the next time the his function was run (15 seconds later).

log.info("contactRequest: added sent request from ${contactRequest.toUserId}")
}
}
Expand Down Expand Up @@ -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}")
}
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Loading