@@ -10,6 +10,7 @@ import com.getcode.opencode.model.financial.CurrencyCode
1010import com.getcode.opencode.model.financial.Fiat
1111import com.getcode.opencode.model.financial.LocalFiat
1212import com.getcode.services.flipcash.BuildConfig
13+ import com.getcode.solana.keys.Mint
1314import com.getcode.solana.keys.base58
1415import com.getcode.utils.TraceType
1516import com.getcode.utils.base58
@@ -142,10 +143,40 @@ internal class MixpanelAnalyticsDelegate @Inject constructor(
142143 track(event.name, * properties.toList().toTypedArray())
143144 }
144145
146+ override fun openTokenInfo (from : AnalyticsEvent .OpenTokenInfoEvent , mint : Mint ) {
147+ val properties = from.properties(mint = mint)
148+ track(from.name, * properties.toList().toTypedArray())
149+ }
150+
151+ override fun buy (
152+ method : AnalyticsEvent .TokenTransactionEvent .Purchase ,
153+ amount : Fiat ,
154+ mint : Mint ,
155+ error : Throwable ?
156+ ) {
157+ val properties = method.properties(mint = mint, nativeAmount = amount, error = error)
158+ track(method.name, * properties.toList().toTypedArray())
159+ }
160+
161+ override fun sell (
162+ amount : Fiat ,
163+ feeAmount : Fiat ,
164+ mint : Mint ,
165+ error : Throwable ?
166+ ) {
167+ val event = AnalyticsEvent .TokenTransactionEvent .Sell
168+ val properties = event.properties(mint = mint, nativeAmount = amount, error = error)
169+ track(event.name, * properties.toList().toTypedArray())
170+ }
171+
145172 private fun track (name : String , vararg properties : Pair <String , String >) {
146173 if (BuildConfig .DEBUG ) {
174+ val propsString = properties.joinToString { " ${it.first} => ${it.second} " }
147175 trace(
148- " debug track ${name} , ${properties.joinToString { " ${it.first} => ${it.second} " }} " ,
176+ buildString {
177+ append(" debug track $name " )
178+ if (propsString.isNotEmpty()) append(" , $propsString " )
179+ },
149180 type = TraceType .Silent
150181 )
151182 return
@@ -162,6 +193,8 @@ internal class MixpanelAnalyticsDelegate @Inject constructor(
162193private fun AnalyticsEvent.properties (
163194 localizedAmount : LocalFiat ? = null,
164195 nativeAmount : Fiat ? = null,
196+ feeAmount : Fiat ? = null,
197+ mint : Mint ? = null,
165198 grabTime : Long? = null,
166199 successful : Boolean? = null,
167200 error : Throwable ? = null,
@@ -233,6 +266,17 @@ private fun AnalyticsEvent.properties(
233266 }
234267
235268 is AnalyticsEvent .OnRampOpenEvent -> Unit
269+ is AnalyticsEvent .OpenTokenInfoEvent -> {
270+ put(" Mint" , mint?.base58().orEmpty())
271+ }
272+ is AnalyticsEvent .TokenTransactionEvent -> {
273+ put(" Mint" , mint?.base58().orEmpty())
274+ put(" Fiat" , nativeAmount?.decimalValue.toString())
275+ if (feeAmount != null ) {
276+ put(" Fee" , feeAmount.decimalValue.toString())
277+ }
278+ put(" Currency" , nativeAmount?.currencyCode?.name.orEmpty())
279+ }
236280 is AnalyticsEvent .OnRampVerificationEvent -> Unit
237281 AnalyticsEvent .OnRampPurchaseEvent .Completed -> {
238282 put(" Fiat" , nativeAmount?.decimalValue.toString())
0 commit comments