From 77b47434c8e897827286fad2d155fb2e46d5ee5d Mon Sep 17 00:00:00 2001 From: mulan xia Date: Tue, 30 Apr 2024 16:30:03 -0400 Subject: [PATCH] review comments --- .../state/manager/StateManagerAdaptor.kt | 7 +++---- .../state/manager/V4StateManagerAdaptor.kt | 2 +- .../state/v2/supervisor/NetworkSupervisor.kt | 2 +- .../state/v2/supervisor/SubaccountSupervisor.kt | 7 +++---- .../exchange.dydx.abacus/utils/AnalyticsUtils.kt | 13 ++++--------- 5 files changed, 12 insertions(+), 19 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 29c12e751..6fa4398a6 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/StateManagerAdaptor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/StateManagerAdaptor.kt @@ -1876,10 +1876,9 @@ open class StateManagerAdaptor( fun triggerOrdersPayload(): HumanReadableTriggerOrdersPayload { val placeOrderPayloads = mutableListOf() val cancelOrderPayloads = mutableListOf() - val triggerOrders = stateMachine.state?.input?.triggerOrders - - val marketId = triggerOrders?.marketId ?: throw Exception("marketId is null") + val triggerOrders = requireNotNull(stateMachine.state?.input?.triggerOrders) { "triggerOrders input was null" } + val marketId = requireNotNull(triggerOrders.marketId) { "triggerOrders.marektId was null" } val subaccountNumber = connectedSubaccountNumber ?: throw Exception("subaccountNumber is null") val subaccount = stateMachine.state?.subaccount(subaccountNumber) ?: throw Exception("subaccount is null") val position = subaccount.openPositions?.find { it.id == marketId } @@ -2307,7 +2306,7 @@ open class StateManagerAdaptor( ) } - internal fun tracking(eventName: String, params: IMap?) { + internal fun tracking(eventName: String, params: IMap?) { 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 6ead8fad2..b779c1952 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt @@ -1130,7 +1130,7 @@ class V4StateManagerAdaptor( } 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/state/v2/supervisor/NetworkSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/NetworkSupervisor.kt index 8748551d4..475a8a847 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 @@ -81,7 +81,7 @@ internal open class NetworkSupervisor( } } - internal fun tracking(eventName: String, params: IMap?) { + internal fun tracking(eventName: String, params: IMap?) { val paramsAsString = helper.jsonEncoder.encode(params) 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 ad0f5b3c8..663f2fe1c 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 @@ -651,7 +651,7 @@ internal class SubaccountSupervisor( } private fun trackOrderClick( - analyticsPayload: IMap?, + analyticsPayload: IMap?, analyticsEvent: AnalyticsEvent, ): Double { val uiClickTimeMs = Clock.System.now().toEpochMilliseconds().toDouble() @@ -1019,10 +1019,9 @@ internal class SubaccountSupervisor( fun triggerOrdersPayload(currentHeight: Int?): HumanReadableTriggerOrdersPayload { val placeOrderPayloads = mutableListOf() val cancelOrderPayloads = mutableListOf() - val triggerOrders = stateMachine.state?.input?.triggerOrders - - val marketId = triggerOrders?.marketId ?: throw Exception("marketId is null") + val triggerOrders = requireNotNull(stateMachine.state?.input?.triggerOrders) { "triggerOrders input was null" } + val marketId = requireNotNull(triggerOrders.marketId) { "triggerOrders.marketId was null" } val subaccount = stateMachine.state?.subaccount(subaccountNumber) val position = subaccount?.openPositions?.find { it.id == marketId } val positionSize = position?.size?.current diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt b/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt index 8079afd79..c64b73ee0 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/utils/AnalyticsUtils.kt @@ -16,11 +16,6 @@ enum class TriggerOrderAction(val rawValue: String) { CANCEL("CANCEL"), CREATE("CREATE"), ; - - companion object { - operator fun invoke(rawValue: String?) = - TriggerOrderAction.values().firstOrNull { it.rawValue == rawValue } - } } class AnalyticsUtils { @@ -35,7 +30,7 @@ class AnalyticsUtils { */ fun triggerOrdersAnalyticsPayload( payload: HumanReadableTriggerOrdersPayload, - ): IMap? { + ): IMap? { val placeOrderPayloads = payload.placeOrderPayloads val cancelOrderPayloads = payload.cancelOrderPayloads @@ -51,7 +46,7 @@ class AnalyticsUtils { var takeProfitOrderAction: TriggerOrderAction? = null placeOrderPayloads.forEach { placePayload -> - val orderType = OrderType.invoke(placePayload.type) + val orderType = OrderType(placePayload.type) if (stopLossOrderTypes.contains(orderType)) { stopLossOrderPlaceClientId = placePayload.clientId stopLossOrderAction = TriggerOrderAction.CREATE @@ -62,7 +57,7 @@ class AnalyticsUtils { } cancelOrderPayloads.forEach { cancelPayload -> - val orderType = OrderType.invoke(cancelPayload.type) + val orderType = OrderType(cancelPayload.type) if (stopLossOrderTypes.contains(orderType)) { stopLossOrderCancelClientId = cancelPayload.clientId stopLossOrderAction = if (stopLossOrderAction == null) { @@ -89,7 +84,7 @@ class AnalyticsUtils { "takeProfitOrderAction" to takeProfitOrderAction?.rawValue, "takeProfitOrderCancelClientId" to takeProfitOrderCancelClientId, "takeProfitOrderPlaceClientId" to takeProfitOrderPlaceClientId, - ) as IMap? + ) } /**