Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class DepositFragment : BaseFragment() {
private val walletViewModel by viewModels<WalletViewModel>()

private val scopeProvider by lazy { AndroidLifecycleScopeProvider.from(this) }
private var assetPrice: String? = null

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -91,12 +92,13 @@ class DepositFragment : BaseFragment() {
) {
super.onViewCreated(view, savedInstanceState)
val asset = requireNotNull(requireArguments().getParcelableCompat(ARGS_ASSET, TokenItem::class.java)) { "required TokenItem can not be null" }
assetPrice = asset.priceUsd
val hideNetworkSwitch = requireArguments().getBoolean(ARGS_HIDE_NETWORK_SWITCH, false)
initView(asset, hideNetworkSwitch)
}

override fun onDestroyView() {
AnalyticsTracker.trackAssetReceiveEnd()
AnalyticsTracker.trackAssetReceiveSuccess(assetPrice)
super.onDestroyView()
_binding = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ object AnalyticsTracker {
}
}

fun trackAssetReceiveEnd() {
logEvent("asset_receive_end")
fun trackAssetReceiveSuccess(price: String?) {
logEvent("asset_receive_success") {
putString("asset_level", getAssetLevel(BigDecimal.ONE, price))
}
}

fun trackAssetSendStart(wallet: String, source: String) {
Expand Down Expand Up @@ -526,20 +528,18 @@ object AnalyticsTracker {
}

fun trackTradeEnd(wallet: String, amountValue: BigDecimal, price: String?) {
val amountUsd = runCatching {
val priceValue = price?.toBigDecimalOrNull() ?: BigDecimal.ZERO
amountValue.multiply(priceValue).toDouble()
}.getOrDefault(0.0)

val tradeAssetLevel = getTradeAssetLevel(amountUsd)

logEvent("trade_end") {
putString("wallet", wallet)
putString("trade_asset_level", tradeAssetLevel)
putString("asset_level", getAssetLevel(amountValue, price))
}
}

private fun getTradeAssetLevel(amountUsd: Double): String {
private fun getAssetLevel(amountValue: BigDecimal, price: String?): String {
val priceValue = price?.toBigDecimalOrNull()?.takeIf { it > BigDecimal.ZERO } ?: return "N/A"
val amountUsd = runCatching {
amountValue.multiply(priceValue).toDouble()
}.getOrNull() ?: return "N/A"

return when {
amountUsd >= 1000000 -> "v1,000,000"
amountUsd >= 100000 -> "v100,000"
Expand Down Expand Up @@ -622,13 +622,9 @@ object AnalyticsTracker {
}

fun trackPerpsOpenPositionEnd(leverage: Int, amountValue: BigDecimal, price: String?) {
val amountUsd = runCatching {
val priceValue = price?.toBigDecimalOrNull() ?: BigDecimal.ZERO
amountValue.multiply(priceValue).toDouble()
}.getOrDefault(0.0)
logEvent("trade_perps_open_position_end") {
putString("leverage", leverage.toString())
putString("trade_asset_level", getTradeAssetLevel(amountUsd))
putString("asset_level", getAssetLevel(amountValue, price))
}
}

Expand Down Expand Up @@ -749,13 +745,9 @@ object AnalyticsTracker {
}

fun trackSpotEnd(wallet: String, amountValue: BigDecimal, price: String?) {
val amountUsd = runCatching {
val priceValue = price?.toBigDecimalOrNull() ?: BigDecimal.ZERO
amountValue.multiply(priceValue).toDouble()
}.getOrDefault(0.0)
logEvent("trade_spot_end") {
putString("wallet", wallet)
putString("trade_asset_level", getTradeAssetLevel(amountUsd))
putString("asset_level", getAssetLevel(amountValue, price))
}
}

Expand Down