Updated on 2026-08-14
This commit is contained in:
parent
bd0adfea6f
commit
7d7b6106a0
8 changed files with 134 additions and 8 deletions
|
|
@ -17,6 +17,7 @@ import com.tangem.tap.common.AssetReader
|
|||
import com.tangem.tap.common.analytics.Analytics
|
||||
import com.tangem.tap.common.analytics.AnalyticsHandlersFactory
|
||||
import com.tangem.tap.common.analytics.api.AnalyticsHandlerBuilder
|
||||
import com.tangem.tap.common.analytics.filters.BasicSignInFilter
|
||||
import com.tangem.tap.common.analytics.filters.ShopPurchasedEventFilter
|
||||
import com.tangem.tap.common.analytics.handlers.amplitude.AmplitudeAnalyticsHandler
|
||||
import com.tangem.tap.common.analytics.handlers.appsFlyer.AppsFlyerAnalyticsHandler
|
||||
|
|
@ -125,6 +126,7 @@ class TapApplication : Application(), ImageLoaderFactory {
|
|||
}
|
||||
listOf(
|
||||
ShopPurchasedEventFilter(),
|
||||
BasicSignInFilter(),
|
||||
).forEach { Analytics.addFilter(it) }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package com.tangem.tap.common.analytics.converters
|
||||
|
||||
import com.tangem.common.Converter
|
||||
import com.tangem.common.extensions.isZero
|
||||
import com.tangem.domain.common.ScanResponse
|
||||
import com.tangem.tap.common.analytics.events.AnalyticsParam
|
||||
import com.tangem.tap.common.analytics.events.Basic
|
||||
import com.tangem.tap.domain.tokens.UserWalletId
|
||||
import com.tangem.tap.features.wallet.redux.ProgressState
|
||||
import java.math.BigDecimal
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class BasicSignInEventConverter(
|
||||
private val scanResponse: ScanResponse,
|
||||
private val progressState: ProgressState,
|
||||
private val totalCryptoAmount: BigDecimal,
|
||||
) : Converter<Any?, Basic.SignedIn?> {
|
||||
|
||||
override fun convert(value: Any?): Basic.SignedIn? {
|
||||
if (progressState == ProgressState.Loading || progressState == ProgressState.Refreshing) return null
|
||||
val cardCurrency = ParamCardCurrencyConverter().convert(scanResponse) ?: return null
|
||||
|
||||
val cardState = when {
|
||||
totalCryptoAmount.isZero() -> AnalyticsParam.CardState.Empty
|
||||
else -> AnalyticsParam.CardState.Full
|
||||
}
|
||||
|
||||
return Basic.SignedIn(
|
||||
state = cardState,
|
||||
currency = cardCurrency,
|
||||
batch = scanResponse.card.batchId,
|
||||
).apply {
|
||||
filterData = UserWalletId(scanResponse.card.wallets.first().publicKey).stringValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.tangem.tap.common.analytics.converters
|
||||
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.common.Converter
|
||||
import com.tangem.domain.common.SaltPayWorkaround
|
||||
import com.tangem.domain.common.ScanResponse
|
||||
import com.tangem.domain.common.TapWorkarounds.getTangemNoteBlockchain
|
||||
import com.tangem.tap.common.analytics.events.AnalyticsParam
|
||||
import com.tangem.tap.domain.extensions.isMultiwalletAllowed
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class ParamCardCurrencyConverter : Converter<ScanResponse, AnalyticsParam.CardCurrency?> {
|
||||
|
||||
override fun convert(value: ScanResponse): AnalyticsParam.CardCurrency? {
|
||||
if (value.card.isMultiwalletAllowed) return AnalyticsParam.CardCurrency.MultiCurrency
|
||||
|
||||
val type = when {
|
||||
value.isTangemNote() -> {
|
||||
value.card.getTangemNoteBlockchain()?.let { AnalyticsParam.CurrencyType.Blockchain(it) }
|
||||
}
|
||||
value.isTangemTwins() -> AnalyticsParam.CurrencyType.Blockchain(Blockchain.Bitcoin)
|
||||
value.isSaltPay() -> AnalyticsParam.CurrencyType.Token(SaltPayWorkaround.tokenFrom(Blockchain.SaltPay))
|
||||
value.getPrimaryToken() != null -> AnalyticsParam.CurrencyType.Token(value.getPrimaryToken()!!)
|
||||
else -> null
|
||||
} ?: return null
|
||||
|
||||
return AnalyticsParam.CardCurrency.SingleCurrency(type)
|
||||
}
|
||||
}
|
||||
|
|
@ -7,4 +7,5 @@ sealed class AnalyticsEvent(
|
|||
val category: String,
|
||||
val event: String,
|
||||
val params: Map<String, String> = mapOf(),
|
||||
var filterData: Any? = null,
|
||||
)
|
||||
|
|
@ -8,7 +8,7 @@ sealed class Basic(
|
|||
params: Map<String, String> = mapOf(),
|
||||
) : AnalyticsEvent("Basic", event, params) {
|
||||
|
||||
sealed class SignedIn(
|
||||
class SignedIn(
|
||||
state: AnalyticsParam.CardState,
|
||||
currency: AnalyticsParam.CardCurrency,
|
||||
batch: String,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package com.tangem.tap.common.analytics.filters
|
||||
|
||||
import com.tangem.tap.common.analytics.api.AnalyticsEventFilter
|
||||
import com.tangem.tap.common.analytics.api.AnalyticsEventHandler
|
||||
import com.tangem.tap.common.analytics.events.AnalyticsEvent
|
||||
import com.tangem.tap.common.analytics.events.Basic
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class BasicSignInFilter : AnalyticsEventFilter {
|
||||
|
||||
private val alreadySignedIn = mutableSetOf<String>()
|
||||
|
||||
override fun canBeAppliedTo(event: AnalyticsEvent): Boolean = event is Basic.SignedIn
|
||||
|
||||
override fun canBeSent(event: AnalyticsEvent): Boolean {
|
||||
val userWalletId = event.filterData as? String ?: return false
|
||||
|
||||
val canBeSent = !alreadySignedIn.contains(userWalletId)
|
||||
alreadySignedIn.add(userWalletId)
|
||||
|
||||
return canBeSent
|
||||
}
|
||||
|
||||
override fun canBeConsumedBy(handler: AnalyticsEventHandler, event: AnalyticsEvent): Boolean = true
|
||||
}
|
||||
|
|
@ -17,6 +17,12 @@ fun List<WalletData>.calculateTotalFiatAmount(): BigDecimal {
|
|||
.reduce(BigDecimal::plus)
|
||||
}
|
||||
|
||||
fun List<WalletData>.calculateTotalCryptoAmount(): BigDecimal {
|
||||
return this
|
||||
.map { it.currencyData.amount ?: BigDecimal.ZERO }
|
||||
.reduce(BigDecimal::plus)
|
||||
}
|
||||
|
||||
private fun List<WalletData>.mapToProgressState(): List<ProgressState> {
|
||||
return this.map { wallet ->
|
||||
if (wallet.fiatRate == null) ProgressState.Error
|
||||
|
|
@ -25,12 +31,15 @@ private fun List<WalletData>.mapToProgressState(): List<ProgressState> {
|
|||
BalanceStatus.VerifiedOnline,
|
||||
BalanceStatus.SameCurrencyTransactionInProgress,
|
||||
BalanceStatus.TransactionInProgress,
|
||||
BalanceStatus.NoAccount -> ProgressState.Done
|
||||
BalanceStatus.NoAccount,
|
||||
-> ProgressState.Done
|
||||
BalanceStatus.Unreachable,
|
||||
BalanceStatus.EmptyCard,
|
||||
BalanceStatus.UnknownBlockchain -> ProgressState.Error
|
||||
BalanceStatus.UnknownBlockchain,
|
||||
-> ProgressState.Error
|
||||
BalanceStatus.Loading,
|
||||
null -> ProgressState.Loading
|
||||
null,
|
||||
-> ProgressState.Loading
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -41,20 +50,24 @@ private infix fun ProgressState.or(newState: ProgressState): ProgressState {
|
|||
ProgressState.Loading,
|
||||
ProgressState.Refreshing,
|
||||
ProgressState.Error,
|
||||
ProgressState.Done -> this
|
||||
ProgressState.Done,
|
||||
-> this
|
||||
}
|
||||
ProgressState.Done,
|
||||
ProgressState.Error -> when (newState) {
|
||||
ProgressState.Error,
|
||||
-> when (newState) {
|
||||
ProgressState.Loading,
|
||||
ProgressState.Refreshing,
|
||||
ProgressState.Error -> newState
|
||||
ProgressState.Error,
|
||||
-> newState
|
||||
ProgressState.Done -> this
|
||||
}
|
||||
ProgressState.Refreshing -> when (newState) {
|
||||
ProgressState.Loading -> this
|
||||
ProgressState.Refreshing,
|
||||
ProgressState.Error,
|
||||
ProgressState.Done -> newState
|
||||
ProgressState.Done,
|
||||
-> newState
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ import coil.size.Scale
|
|||
import com.tangem.domain.common.TapWorkarounds.isSaltPay
|
||||
import com.tangem.tap.MainActivity
|
||||
import com.tangem.tap.common.analytics.Analytics
|
||||
import com.tangem.tap.common.analytics.converters.BasicSignInEventConverter
|
||||
import com.tangem.tap.common.analytics.events.MainScreen
|
||||
import com.tangem.tap.common.analytics.events.Portfolio
|
||||
import com.tangem.tap.common.extensions.show
|
||||
|
|
@ -33,6 +34,7 @@ import com.tangem.tap.features.wallet.redux.ErrorType
|
|||
import com.tangem.tap.features.wallet.redux.ProgressState
|
||||
import com.tangem.tap.features.wallet.redux.WalletAction
|
||||
import com.tangem.tap.features.wallet.redux.WalletState
|
||||
import com.tangem.tap.features.wallet.redux.reducers.calculateTotalCryptoAmount
|
||||
import com.tangem.tap.features.wallet.ui.adapters.WarningMessagesAdapter
|
||||
import com.tangem.tap.features.wallet.ui.wallet.MultiWalletView
|
||||
import com.tangem.tap.features.wallet.ui.wallet.SaltPaySingleWalletView
|
||||
|
|
@ -119,6 +121,7 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<Walle
|
|||
override fun newState(state: WalletState) {
|
||||
if (activity == null || view == null) return
|
||||
|
||||
handleBasicAnalyticsEvent(state)
|
||||
val isSaltPay = store.state.globalState.scanResponse?.card?.isSaltPay == true
|
||||
|
||||
when {
|
||||
|
|
@ -226,4 +229,15 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), StoreSubscriber<Walle
|
|||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
if (store.state.walletState.shouldShowDetails) inflater.inflate(R.menu.menu_wallet, menu)
|
||||
}
|
||||
|
||||
private fun handleBasicAnalyticsEvent(state: WalletState) {
|
||||
if (state.walletsData.isEmpty()) return
|
||||
val scanResponse = store.state.globalState.scanResponse ?: return
|
||||
val totalBalanceState = state.totalBalance?.state ?: return
|
||||
|
||||
val totalCryptoAmount = state.walletsData.calculateTotalCryptoAmount()
|
||||
BasicSignInEventConverter(scanResponse, totalBalanceState, totalCryptoAmount).convert(null)?.let {
|
||||
Analytics.send(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue