diff --git a/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsParam.kt b/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsParam.kt index 093769910b..fd070196c9 100644 --- a/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsParam.kt +++ b/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsParam.kt @@ -131,7 +131,7 @@ sealed class AnalyticsParam { companion object Key { const val BLOCKCHAIN = "blockchain" - const val TOKEN = "Token" + const val TOKEN_PARAM = "Token" const val SOURCE = "Source" const val BALANCE = "Balance" const val STATE = "State" @@ -152,5 +152,12 @@ sealed class AnalyticsParam { const val VALIDATION = "Validation" const val BLOCKCHAIN_EXCEPTION_HOST = "exception_host" const val BLOCKCHAIN_SELECTED_HOST = "selected_host" + + // region swap + const val TOKEN_CATEGORY = "Token" + const val STATUS = "Status" + const val PROVIDER = "Provider" + const val PLACE = "Place" + // } } \ No newline at end of file diff --git a/core/analytics/models/src/main/java/com/tangem/core/analytics/models/Basic.kt b/core/analytics/models/src/main/java/com/tangem/core/analytics/models/Basic.kt index 9f39ae5bdd..6fb52dfe29 100644 --- a/core/analytics/models/src/main/java/com/tangem/core/analytics/models/Basic.kt +++ b/core/analytics/models/src/main/java/com/tangem/core/analytics/models/Basic.kt @@ -55,7 +55,7 @@ sealed class Basic( this[AnalyticsParam.SOURCE] = sentFrom.value if (sentFrom is AnalyticsParam.TxData) { this[AnalyticsParam.BLOCKCHAIN] = sentFrom.blockchain - this[AnalyticsParam.TOKEN] = sentFrom.token + this[AnalyticsParam.TOKEN_PARAM] = sentFrom.token this[AnalyticsParam.FEE_TYPE] = sentFrom.feeType.value } if (sentFrom is AnalyticsParam.TxSentFrom.Approve) { diff --git a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/analytics/TokenExchangeAnalyticsEvent.kt b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/analytics/TokenExchangeAnalyticsEvent.kt index b89306aded..ae26e772f5 100644 --- a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/analytics/TokenExchangeAnalyticsEvent.kt +++ b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/analytics/TokenExchangeAnalyticsEvent.kt @@ -1,34 +1,43 @@ package com.tangem.domain.tokens.model.analytics import com.tangem.core.analytics.models.AnalyticsEvent +import com.tangem.core.analytics.models.AnalyticsParam.Key.PLACE +import com.tangem.core.analytics.models.AnalyticsParam.Key.PROVIDER +import com.tangem.core.analytics.models.AnalyticsParam.Key.STATUS +import com.tangem.core.analytics.models.AnalyticsParam.Key.TOKEN_CATEGORY +import com.tangem.core.analytics.models.AnalyticsParam.Key.TOKEN_PARAM class TokenExchangeAnalyticsEvent( event: String, params: Map = mapOf(), -) : AnalyticsEvent("Token", event, params, null) { +) : AnalyticsEvent(TOKEN_CATEGORY, event, params, null) { class CexTxStatusOpened(token: String) : TokenScreenAnalyticsEvent( event = "Swap Status Opened", - params = mapOf("Token" to token), + params = mapOf(TOKEN_PARAM to token), ) - class CexTxStatusChanged(token: String, status: String) : TokenScreenAnalyticsEvent( + class CexTxStatusChanged(token: String, status: String, provider: String) : TokenScreenAnalyticsEvent( event = "Swap Status", - params = mapOf("Token" to token, "Status" to status), + params = mapOf( + TOKEN_PARAM to token, + STATUS to status, + PROVIDER to provider, + ), ) class GoToProviderStatus(token: String) : TokenScreenAnalyticsEvent( event = "Button - Go To Provider", - params = mapOf("Token" to token, "Place" to "Status"), + params = mapOf(TOKEN_PARAM to token, PLACE to "Status"), ) class GoToProviderKYC(token: String) : TokenScreenAnalyticsEvent( event = "Button - Go To Provider", - params = mapOf("Token" to token, "Place" to "KYC"), + params = mapOf(TOKEN_PARAM to token, PLACE to "KYC"), ) class GoToProviderFail(token: String) : TokenScreenAnalyticsEvent( event = "Button - Go To Provider", - params = mapOf("Token" to token, "Place" to "Fail"), + params = mapOf(TOKEN_PARAM to token, PLACE to "Fail"), ) } \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/analytics/SendAnalyticEvents.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/analytics/SendAnalyticEvents.kt index c4ce202599..03fb73beab 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/analytics/SendAnalyticEvents.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/analytics/SendAnalyticEvents.kt @@ -5,7 +5,7 @@ import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.analytics.models.AnalyticsParam.Key.BLOCKCHAIN import com.tangem.core.analytics.models.AnalyticsParam.Key.FEE_TYPE import com.tangem.core.analytics.models.AnalyticsParam.Key.SOURCE -import com.tangem.core.analytics.models.AnalyticsParam.Key.TOKEN +import com.tangem.core.analytics.models.AnalyticsParam.Key.TOKEN_PARAM import com.tangem.core.analytics.models.AnalyticsParam.Key.TYPE import com.tangem.core.analytics.models.AnalyticsParam.Key.VALIDATION import com.tangem.core.analytics.models.AnalyticsParam.OnOffState @@ -105,7 +105,7 @@ internal sealed class SendAnalyticEvents( ) : SendAnalyticEvents( event = "Transaction Sent Screen Opened", params = mapOf( - TOKEN to token, + TOKEN_PARAM to token, FEE_TYPE to feeType.value, ), ) @@ -119,13 +119,13 @@ internal sealed class SendAnalyticEvents( /** If not enough fee notification is present */ data class NoticeNotEnoughFee(val token: String, val blockchain: String) : SendAnalyticEvents( event = "Notice - Not Enough Fee", - params = mapOf(TOKEN to token, BLOCKCHAIN to blockchain), + params = mapOf(TOKEN_PARAM to token, BLOCKCHAIN to blockchain), ) /** If transaction delays notification is present */ data class NoticeTransactionDelays(val token: String) : SendAnalyticEvents( event = "Notice - Transaction Delays Are Possible", - params = mapOf(TOKEN to token), + params = mapOf(TOKEN_PARAM to token), ) data object NoticeFeeCoverage : SendAnalyticEvents( @@ -135,7 +135,7 @@ internal sealed class SendAnalyticEvents( /** If error occurs during send transactions */ data class TransactionError(val token: String) : SendAnalyticEvents( event = "Error - Transaction Rejected", - params = mapOf(TOKEN to token), + params = mapOf(TOKEN_PARAM to token), ) // endregion } diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/ExchangeStatusFactory.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/ExchangeStatusFactory.kt index 67920c922a..aa63ffd144 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/ExchangeStatusFactory.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/ExchangeStatusFactory.kt @@ -13,10 +13,7 @@ import com.tangem.domain.wallets.models.UserWalletId import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase import com.tangem.feature.swap.domain.SwapTransactionRepository import com.tangem.feature.swap.domain.api.SwapRepository -import com.tangem.feature.swap.domain.models.domain.ExchangeProviderType -import com.tangem.feature.swap.domain.models.domain.ExchangeStatus -import com.tangem.feature.swap.domain.models.domain.ExchangeStatusModel -import com.tangem.feature.swap.domain.models.domain.SavedSwapTransactionListModel +import com.tangem.feature.swap.domain.models.domain.* import com.tangem.feature.tokendetails.presentation.tokendetails.state.SwapTransactionsState import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsState import com.tangem.feature.tokendetails.presentation.tokendetails.state.factory.TokenDetailsSwapTransactionsStateConverter @@ -109,7 +106,7 @@ internal class ExchangeStatusFactory( suspend fun updateSwapTxStatuses(swapTxList: PersistentList) = withContext(dispatchers.io) { swapTxList.map { tx -> async { - val statusModel = getExchangeStatus(tx.txId) + val statusModel = getExchangeStatus(tx.txId, tx.provider) val isRefundTerminalStatus = statusModel?.refundNetwork == null && statusModel?.refundContractAddress == null && tx.provider.type != ExchangeProviderType.DEX_BRIDGE @@ -130,26 +127,26 @@ internal class ExchangeStatusFactory( .toPersistentList() } - private suspend fun getExchangeStatus(txId: String): ExchangeStatusModel? { + private suspend fun getExchangeStatus(txId: String, provider: SwapProvider): ExchangeStatusModel? { return swapRepository.getExchangeStatus(txId) .fold( ifLeft = { null }, ifRight = { statusModel -> - sendStatusUpdateAnalytics(statusModel) + sendStatusUpdateAnalytics(statusModel, provider) swapTransactionRepository.storeTransactionState(txId, statusModel) statusModel }, ) } - private suspend fun sendStatusUpdateAnalytics(statusModel: ExchangeStatusModel) { + private suspend fun sendStatusUpdateAnalytics(statusModel: ExchangeStatusModel, provider: SwapProvider) { val txId = statusModel.txId ?: return val status = toAnalyticStatus(statusModel.status) ?: return val savedStatus = swapTransactionStatusStore.getTransactionStatus(txId) if (savedStatus != status) { analyticsEventsHandlerProvider().send( - TokenExchangeAnalyticsEvent.CexTxStatusChanged(cryptoCurrency.symbol, status.value), + TokenExchangeAnalyticsEvent.CexTxStatusChanged(cryptoCurrency.symbol, status.value, provider.name), ) swapTransactionStatusStore.setTransactionStatus(txId, status) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/WalletScreenAnalyticsEvent.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/WalletScreenAnalyticsEvent.kt index de6ddf8b1b..c0021f5d7e 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/WalletScreenAnalyticsEvent.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/WalletScreenAnalyticsEvent.kt @@ -43,7 +43,7 @@ sealed class WalletScreenAnalyticsEvent { event = "Token Balance", params = mapOf( AnalyticsParam.STATE to balance.value, - AnalyticsParam.TOKEN to token, + AnalyticsParam.TOKEN_PARAM to token, ), ) }