From 6ad7541e65b54085fc350349787d3ea8d39cbef4 Mon Sep 17 00:00:00 2001 From: Rui Date: Mon, 22 Apr 2024 14:25:49 -0700 Subject: [PATCH] Clean up --- .../trigger/DydxTriggerOrderInputViewModel.kt | 1 - .../gainloss/DydxTriggerOrderGainLossViewModel.kt | 14 +++++++------- .../price/DydxTriggerOrderPriceViewModel.kt | 6 +++--- .../size/DydxTriggerOrderSizeViewModel.kt | 6 +++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/DydxTriggerOrderInputViewModel.kt b/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/DydxTriggerOrderInputViewModel.kt index 194cc3c9..294b7f47 100644 --- a/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/DydxTriggerOrderInputViewModel.kt +++ b/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/DydxTriggerOrderInputViewModel.kt @@ -88,7 +88,6 @@ class DydxTriggerOrderInputViewModel @Inject constructor( val firstError = errors?.firstOrNull { it.type == ErrorType.error } val firstWarning = errors?.firstOrNull { it.type == ErrorType.warning } val fieldString = firstError?.fields?.firstOrNull() ?: firstWarning?.fields?.firstOrNull() - print("fieldString: $fieldString") val field: TriggerOrdersInputField? = fieldString?.let { TriggerOrdersInputField.invoke(it) } diff --git a/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/components/inputfields/gainloss/DydxTriggerOrderGainLossViewModel.kt b/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/components/inputfields/gainloss/DydxTriggerOrderGainLossViewModel.kt index 2a3ae0f1..b7618a03 100644 --- a/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/components/inputfields/gainloss/DydxTriggerOrderGainLossViewModel.kt +++ b/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/components/inputfields/gainloss/DydxTriggerOrderGainLossViewModel.kt @@ -83,7 +83,7 @@ open class DydxTriggerOrderGainLossViewModel( ): DydxTriggerOrderGainLossView.ViewState { val marketConfigs = configsAndAsset?.configs val tickSize = marketConfigs?.displayTickSizeDecimals ?: 0 - val firstError = validationErrors?.firstOrNull { it.type == ErrorType.error } + val firstErrorOrWarning = validationErrors?.firstOrNull { it.type == ErrorType.error } ?: validationErrors?.firstOrNull { it.type == ErrorType.warning } fun formatOrder(orderPrice: TriggerPrice) = @@ -130,19 +130,19 @@ open class DydxTriggerOrderGainLossViewModel( }, alertState = when (inputType) { DydxTriggerOrderInputType.TakeProfit -> - if (firstError?.fields?.contains(TriggerOrdersInputField.takeProfitPercentDiff.rawValue) == true || - firstError?.fields?.contains(TriggerOrdersInputField.takeProfitUsdcDiff.rawValue) == true + if (firstErrorOrWarning?.fields?.contains(TriggerOrdersInputField.takeProfitPercentDiff.rawValue) == true || + firstErrorOrWarning?.fields?.contains(TriggerOrdersInputField.takeProfitUsdcDiff.rawValue) == true ) { - firstError.alertState + firstErrorOrWarning.alertState } else { PlatformInputAlertState.None } DydxTriggerOrderInputType.StopLoss -> - if (firstError?.fields?.contains(TriggerOrdersInputField.stopLossPercentDiff.rawValue) == true || - firstError?.fields?.contains(TriggerOrdersInputField.stopLossUsdcDiff.rawValue) == true + if (firstErrorOrWarning?.fields?.contains(TriggerOrdersInputField.stopLossPercentDiff.rawValue) == true || + firstErrorOrWarning?.fields?.contains(TriggerOrdersInputField.stopLossUsdcDiff.rawValue) == true ) { - firstError.alertState + firstErrorOrWarning.alertState } else { PlatformInputAlertState.None } diff --git a/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/components/inputfields/price/DydxTriggerOrderPriceViewModel.kt b/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/components/inputfields/price/DydxTriggerOrderPriceViewModel.kt index 93d569a1..1f58c022 100644 --- a/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/components/inputfields/price/DydxTriggerOrderPriceViewModel.kt +++ b/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/components/inputfields/price/DydxTriggerOrderPriceViewModel.kt @@ -93,7 +93,7 @@ open class DydxTriggerOrderPriceViewModel( ): DydxTriggerOrderPriceView.ViewState { val marketConfigs = configsAndAsset?.configs val tickSize = marketConfigs?.displayTickSizeDecimals ?: 0 - val firstError = validationErrors?.firstOrNull { it.type == ErrorType.error } + val firstErrorOrWarning = validationErrors?.firstOrNull { it.type == ErrorType.error } ?: validationErrors?.firstOrNull { it.type == ErrorType.warning } val state = DydxTriggerOrderPriceView.ViewState( @@ -128,8 +128,8 @@ open class DydxTriggerOrderPriceViewModel( tickSize, ) }, - alertState = if (firstError?.fields?.contains(inputType.abacusInputField.rawValue) == true) { - firstError.alertState + alertState = if (firstErrorOrWarning?.fields?.contains(inputType.abacusInputField.rawValue) == true) { + firstErrorOrWarning.alertState } else { PlatformInputAlertState.None }, diff --git a/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/components/inputfields/size/DydxTriggerOrderSizeViewModel.kt b/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/components/inputfields/size/DydxTriggerOrderSizeViewModel.kt index f661a65a..807f7445 100644 --- a/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/components/inputfields/size/DydxTriggerOrderSizeViewModel.kt +++ b/v4/feature/trade/src/main/java/exchange/dydx/trading/feature/trade/trigger/components/inputfields/size/DydxTriggerOrderSizeViewModel.kt @@ -69,7 +69,7 @@ class DydxTriggerOrderSizeViewModel @Inject constructor( } else { 0.0 } - val firstError = validationErrors?.firstOrNull { it.type == ErrorType.error } + val firstErrorOrWarning = validationErrors?.firstOrNull { it.type == ErrorType.error } ?: validationErrors?.firstOrNull { it.type == ErrorType.warning } return DydxTriggerOrderSizeView.ViewState( @@ -89,8 +89,8 @@ class DydxTriggerOrderSizeViewModel @Inject constructor( label = localizer.localize("APP.GENERAL.AMOUNT"), token = configsAndAsset?.asset?.id, value = formatter.decimalLocaleAgnostic(size, size = stepSize), - alertState = if (firstError?.fields?.contains(TriggerOrdersInputField.size.rawValue) == true) { - firstError.alertState + alertState = if (firstErrorOrWarning?.fields?.contains(TriggerOrdersInputField.size.rawValue) == true) { + firstErrorOrWarning.alertState } else { PlatformInputAlertState.None },