-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOB-441 add TP/SL display to market screen
- Loading branch information
Showing
17 changed files
with
960 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...ge/dydx/trading/feature/trade/trigger/components/inputfields/DydxTriggerOrderInputType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package exchange.dydx.trading.feature.trade.trigger.components.inputfields | ||
|
||
enum class DydxTriggerOrderInputType { | ||
TakeProfit, | ||
StopLoss, | ||
} | ||
enum class DydxTriggerOrderPriceInputType { | ||
TakeProfit, | ||
StopLoss, | ||
TakeProfitLimit, | ||
StopLossLimit, | ||
} |
133 changes: 133 additions & 0 deletions
133
...ing/feature/trade/trigger/components/inputfields/gainloss/DydxTriggerOrderGainLossView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package exchange.dydx.trading.feature.trade.trigger.components.inputfields.gainloss | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import exchange.dydx.abacus.protocols.LocalizerProtocol | ||
import exchange.dydx.platformui.components.buttons.PlatformAccessoryButton | ||
import exchange.dydx.platformui.components.menus.PlatformDropdownMenu | ||
import exchange.dydx.platformui.components.menus.PlatformMenuItem | ||
import exchange.dydx.platformui.designSystem.theme.ThemeColor | ||
import exchange.dydx.platformui.designSystem.theme.ThemeFont | ||
import exchange.dydx.platformui.designSystem.theme.ThemeShapes | ||
import exchange.dydx.platformui.designSystem.theme.dydxDefault | ||
import exchange.dydx.platformui.designSystem.theme.themeColor | ||
import exchange.dydx.platformui.designSystem.theme.themeFont | ||
import exchange.dydx.trading.common.component.DydxComponent | ||
import exchange.dydx.trading.common.compose.collectAsStateWithLifecycle | ||
import exchange.dydx.trading.common.theme.DydxThemedPreviewSurface | ||
import exchange.dydx.trading.common.theme.MockLocalizer | ||
import exchange.dydx.trading.feature.shared.scarfolds.InputFieldScarfold | ||
import exchange.dydx.trading.feature.shared.views.LabeledSelectionInput | ||
import exchange.dydx.trading.feature.shared.views.LabeledTextInput | ||
import exchange.dydx.trading.feature.trade.trigger.components.inputfields.DydxTriggerOrderInputType | ||
|
||
@Preview | ||
@Composable | ||
fun Preview_DydxTriggerOrderGainLossView() { | ||
DydxThemedPreviewSurface { | ||
DydxTriggerOrderGainLossView.Content( | ||
Modifier, | ||
DydxTriggerOrderGainLossView.ViewState.preview, | ||
) | ||
} | ||
} | ||
|
||
object DydxTriggerOrderGainLossView : DydxComponent { | ||
data class ViewState( | ||
val localizer: LocalizerProtocol, | ||
val labeledTextInput: LabeledTextInput.ViewState? = null, | ||
val labeledSelectionInput: LabeledSelectionInput.ViewState? = null, | ||
) { | ||
companion object { | ||
val preview = ViewState( | ||
localizer = MockLocalizer(), | ||
labeledTextInput = LabeledTextInput.ViewState.preview, | ||
labeledSelectionInput = LabeledSelectionInput.ViewState.preview, | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
override fun Content(modifier: Modifier) { | ||
Content(modifier, DydxTriggerOrderInputType.TakeProfit) | ||
} | ||
|
||
@Composable | ||
fun Content(modifier: Modifier, inputType: DydxTriggerOrderInputType) { | ||
when (inputType) { | ||
DydxTriggerOrderInputType.TakeProfit -> { | ||
val viewModel: DydxTriggerOrderGainLossTakeProfitViewModel = hiltViewModel() | ||
val state = viewModel.state.collectAsStateWithLifecycle(initialValue = null).value | ||
Content(modifier, state) | ||
} | ||
DydxTriggerOrderInputType.StopLoss -> { | ||
val viewModel: DydxTriggerOrderGainLossStopLossViewModel = hiltViewModel() | ||
val state = viewModel.state.collectAsStateWithLifecycle(initialValue = null).value | ||
Content(modifier, state) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun Content(modifier: Modifier, state: ViewState?) { | ||
if (state == null) { | ||
return | ||
} | ||
|
||
val expanded: MutableState<Boolean> = remember { | ||
mutableStateOf(false) | ||
} | ||
|
||
InputFieldScarfold(modifier) { | ||
Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
LabeledTextInput.Content( | ||
modifier = Modifier.weight(1f), | ||
state = state.labeledTextInput, | ||
) | ||
|
||
Box { | ||
PlatformAccessoryButton( | ||
modifier = Modifier, | ||
action = { expanded.value = !expanded.value }, | ||
) { | ||
Text( | ||
modifier = Modifier.padding(ThemeShapes.InputPaddingValues), | ||
text = state.labeledSelectionInput?.options?.getOrNull( | ||
state.labeledSelectionInput?.selectedIndex ?: 0, | ||
) ?: "", | ||
style = TextStyle.dydxDefault | ||
.themeFont(fontSize = ThemeFont.FontSize.small) | ||
.themeColor(ThemeColor.SemanticColor.text_primary), | ||
) | ||
} | ||
|
||
PlatformDropdownMenu( | ||
expanded = expanded, | ||
items = state.labeledSelectionInput?.options?.mapIndexed { index, option -> | ||
PlatformMenuItem( | ||
text = option, | ||
onClick = { | ||
expanded.value = false | ||
state.labeledSelectionInput?.onSelectionChanged?.invoke(index) | ||
}, | ||
) | ||
} ?: listOf(), | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.