From 7151ce6f334c551485c1aa306eeecef7c629f228 Mon Sep 17 00:00:00 2001 From: aforaleka Date: Thu, 9 May 2024 20:02:10 -0400 Subject: [PATCH] nit --- .../state/manager/StateManagerAdaptor.kt | 2 +- .../state/manager/V4StateManagerAdaptor.kt | 8 +++++--- .../state/v2/supervisor/NetworkSupervisor.kt | 6 ++++-- .../state/v2/supervisor/SubaccountSupervisor.kt | 12 +++++++----- .../exchange.dydx.abacus/utils/AnalyticsUtils.kt | 4 ++-- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/StateManagerAdaptor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/StateManagerAdaptor.kt index ffae672b3..03cfce228 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/StateManagerAdaptor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/StateManagerAdaptor.kt @@ -2366,7 +2366,7 @@ open class StateManagerAdaptor( ) } - internal open fun tracking(eventName: String, params: IMap?) { + internal open fun tracking(eventName: String, params: IMap? = null) { val paramsAsString = jsonEncoder.encode(params) ioImplementations.threading?.async(ThreadingType.main) { ioImplementations.tracking?.log(eventName, paramsAsString) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt index 2ed3b4312..9a44ad236 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt @@ -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 @@ -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?) { - val additionalParams = apiStateParams() - val paramsAsString = this.jsonEncoder.encode(params?.let { ParsingHelper.merge(it as IMap, 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) } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkSupervisor.kt index 8c4b09311..19ff87cbf 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkSupervisor.kt @@ -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 @@ -83,9 +84,10 @@ internal open class NetworkSupervisor( } } - internal fun tracking(eventName: String, params: IMap?) { + internal fun tracking(eventName: String, params: IMap?) { 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) } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt index ed608d590..a69b1c514 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/SubaccountSupervisor.kt @@ -356,6 +356,12 @@ internal class SubaccountSupervisor( ) } + private fun trackingParams(interval: Double): IMap { + return iMapOf( + "roundtripMs" to interval, + ) + } + private fun didSetCancelOrderRecords() { parseOrdersToMatchPlaceOrdersAndCancelOrders() } @@ -398,10 +404,6 @@ internal class SubaccountSupervisor( } } - private fun trackingParams(interval: Double? = null): IMap { - return interval?.let { iMapOf("roundtripMs" to it) } ?: iMapOf() - } - fun closePosition( data: String?, type: ClosePositionInputField, @@ -671,7 +673,7 @@ internal class SubaccountSupervisor( } private fun trackOrderClick( - analyticsPayload: IMap?, + analyticsPayload: IMap?, analyticsEvent: AnalyticsEvent, ): Double { val uiClickTimeMs = Clock.System.now().toEpochMilliseconds().toDouble() diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt b/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt index 2c03ffc50..5ae5970ac 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt @@ -30,7 +30,7 @@ class AnalyticsUtils { */ fun triggerOrdersAnalyticsPayload( payload: HumanReadableTriggerOrdersPayload, - ): IMap? { + ): IMap? { val placeOrderPayloads = payload.placeOrderPayloads val cancelOrderPayloads = payload.cancelOrderPayloads @@ -84,7 +84,7 @@ class AnalyticsUtils { "takeProfitOrderAction" to takeProfitOrderAction?.rawValue, "takeProfitOrderCancelClientId" to takeProfitOrderCancelClientId, "takeProfitOrderPlaceClientId" to takeProfitOrderPlaceClientId, - ) as IMap? + ) } /**