Skip to content

Commit

Permalink
nit
Browse files Browse the repository at this point in the history
  • Loading branch information
aforaleka committed May 10, 2024
1 parent 1eefcde commit 7151ce6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2366,7 +2366,7 @@ open class StateManagerAdaptor(
)
}

internal open fun tracking(eventName: String, params: IMap<String, Any?>?) {
internal open fun tracking(eventName: String, params: IMap<String, Any?>? = null) {
val paramsAsString = jsonEncoder.encode(params)
ioImplementations.threading?.async(ThreadingType.main) {
ioImplementations.tracking?.log(eventName, paramsAsString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import exchange.dydx.abacus.utils.Logger
import exchange.dydx.abacus.utils.Numeric
import exchange.dydx.abacus.utils.ParsingHelper
import exchange.dydx.abacus.utils.UIImplementations
import exchange.dydx.abacus.utils.filterNotNull
import exchange.dydx.abacus.utils.iMapOf
import exchange.dydx.abacus.utils.isAddressValid
import exchange.dydx.abacus.utils.mutableMapOf
Expand Down Expand Up @@ -1585,13 +1586,14 @@ class V4StateManagerAdaptor(

private fun trackApiStateIfNeeded(apiState: ApiState?, oldValue: ApiState?) {
if (apiState?.abnormalState() == true || oldValue?.abnormalState() == true) {
tracking(AnalyticsEvent.NetworkStatus.rawValue, null)
tracking(AnalyticsEvent.NetworkStatus.rawValue)
}
}

override fun tracking(eventName: String, params: IMap<String, Any?>?) {
val additionalParams = apiStateParams()
val paramsAsString = this.jsonEncoder.encode(params?.let { ParsingHelper.merge(it as IMap<String, Any>, additionalParams) } ?: additionalParams)
val requiredParams = this.validatorUrl?.let { iMapOf("validatorUrl" to it) } ?: iMapOf()
val mergedParams = params?.let { ParsingHelper.merge(params.filterNotNull(), requiredParams) } ?: requiredParams
val paramsAsString = this.jsonEncoder.encode(mergedParams)
this.ioImplementations.threading?.async(ThreadingType.main) {
this.ioImplementations.tracking?.log(eventName, paramsAsString)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import exchange.dydx.abacus.state.model.TradingStateMachine
import exchange.dydx.abacus.utils.AnalyticsUtils
import exchange.dydx.abacus.utils.IMap
import exchange.dydx.abacus.utils.ParsingHelper
import exchange.dydx.abacus.utils.filterNotNull
import exchange.dydx.abacus.utils.iMapOf
import kollections.iListOf

Expand Down Expand Up @@ -83,9 +84,10 @@ internal open class NetworkSupervisor(
}
}

internal fun tracking(eventName: String, params: IMap<String, Any>?) {
internal fun tracking(eventName: String, params: IMap<String, Any?>?) {
val requiredParams = helper.validatorUrl?.let { iMapOf("validatorUrl" to it) } ?: iMapOf()
val paramsAsString = helper.jsonEncoder.encode(params?.let { ParsingHelper.merge(it, requiredParams) } ?: requiredParams)
val mergedParams = params?.let { ParsingHelper.merge(params.filterNotNull(), requiredParams) } ?: requiredParams
val paramsAsString = helper.jsonEncoder.encode(mergedParams)
helper.ioImplementations.threading?.async(ThreadingType.main) {
helper.ioImplementations.tracking?.log(eventName, paramsAsString)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ internal class SubaccountSupervisor(
)
}

private fun trackingParams(interval: Double): IMap<String, Any> {
return iMapOf(
"roundtripMs" to interval,
)
}

private fun didSetCancelOrderRecords() {
parseOrdersToMatchPlaceOrdersAndCancelOrders()
}
Expand Down Expand Up @@ -398,10 +404,6 @@ internal class SubaccountSupervisor(
}
}

private fun trackingParams(interval: Double? = null): IMap<String, Any> {
return interval?.let { iMapOf("roundtripMs" to it) } ?: iMapOf()
}

fun closePosition(
data: String?,
type: ClosePositionInputField,
Expand Down Expand Up @@ -671,7 +673,7 @@ internal class SubaccountSupervisor(
}

private fun trackOrderClick(
analyticsPayload: IMap<String, Any>?,
analyticsPayload: IMap<String, Any?>?,
analyticsEvent: AnalyticsEvent,
): Double {
val uiClickTimeMs = Clock.System.now().toEpochMilliseconds().toDouble()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AnalyticsUtils {
*/
fun triggerOrdersAnalyticsPayload(
payload: HumanReadableTriggerOrdersPayload,
): IMap<String, Any>? {
): IMap<String, Any?>? {
val placeOrderPayloads = payload.placeOrderPayloads
val cancelOrderPayloads = payload.cancelOrderPayloads

Expand Down Expand Up @@ -84,7 +84,7 @@ class AnalyticsUtils {
"takeProfitOrderAction" to takeProfitOrderAction?.rawValue,
"takeProfitOrderCancelClientId" to takeProfitOrderCancelClientId,
"takeProfitOrderPlaceClientId" to takeProfitOrderPlaceClientId,
) as IMap<String, Any>?
)
}

/**
Expand Down

0 comments on commit 7151ce6

Please sign in to comment.