Skip to content

Commit afcfd5b

Browse files
authored
Merge pull request #712 from code-payments/chore/add-coinbase-events
chore(onramp): add analytics events for purchases with Coinbase
2 parents e73d42f + 83eed95 commit afcfd5b

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

apps/flipcash/features/onramp/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies {
1818

1919
implementation(project(":apps:flipcash:shared:onramp:coinbase"))
2020
implementation(project(":apps:flipcash:shared:onramp:deeplinks"))
21+
implementation(project(":apps:flipcash:shared:analytics"))
2122
implementation(project(":apps:flipcash:shared:router"))
2223

2324
implementation(project(":libs:crypto:solana"))

apps/flipcash/features/onramp/src/main/kotlin/com/flipcash/app/onramp/internal/OnRampViewModel.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.flipcash.app.onramp.internal
22

33
import androidx.lifecycle.viewModelScope
4+
import com.flipcash.app.analytics.Analytics
5+
import com.flipcash.app.analytics.FlipcashAnalyticsService
46
import com.flipcash.app.core.extensions.mapResult
57
import com.flipcash.app.core.extensions.onResult
68
import com.flipcash.app.core.ui.CurrencyHolder
@@ -81,6 +83,7 @@ internal class OnRampViewModel @Inject constructor(
8183
tokenController: TokenController,
8284
transactionController: TransactionOperations,
8385
dispatchers: DispatcherProvider,
86+
analytics: FlipcashAnalyticsService,
8487
) : BaseViewModel2<OnRampViewModel.State, OnRampViewModel.Event>(
8588
initialState = State(),
8689
updateStateForEvent = updateStateForEvent,
@@ -344,8 +347,15 @@ internal class OnRampViewModel @Inject constructor(
344347
amount = selectedAmount.localFiat.underlyingTokenAmount,
345348
token = token,
346349
verifiedFiat = selectedAmount,
347-
).onFailure { error ->
350+
).onSuccess {
351+
analytics.buy(
352+
method = Analytics.PurchaseMethod.Coinbase,
353+
amount = selectedAmount.localFiat.nativeAmount,
354+
mint = token.address,
355+
)
356+
}.onFailure { error ->
348357
dispatchEvent(Event.UpdateConfirmingAmountState())
358+
349359
when (error) {
350360
is OnRampAuthError.CoinbasePhoneVerificationRequired -> {
351361
dispatchEvent(Event.OnVerificationNeeded(phone = true))
@@ -375,6 +385,13 @@ internal class OnRampViewModel @Inject constructor(
375385
}
376386

377387
else -> {
388+
analytics.buy(
389+
method = Analytics.PurchaseMethod.Coinbase,
390+
amount = selectedAmount.localFiat.nativeAmount,
391+
mint = token.address,
392+
error = error
393+
)
394+
378395
BottomBarManager.showError(
379396
title = "Something Went Wrong",
380397
message = error.message ?: "Please try again",

0 commit comments

Comments
 (0)