Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang committed Apr 22, 2024
1 parent 3c16f80 commit 6ad7541
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
},
Expand Down

0 comments on commit 6ad7541

Please sign in to comment.