Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOB-445 Add TP | SL button to market info page when there are open positions for the market #82

Merged
merged 32 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
067cc5c
Wire up input data
ruixhuang Apr 5, 2024
7ca9818
Submission
ruixhuang Apr 6, 2024
9667849
WIP
ruixhuang Apr 8, 2024
6cf047a
Bump Abacus and toggle size section
ruixhuang Apr 9, 2024
ebc965b
MarketInfo buttons
ruixhuang Apr 10, 2024
cc79dd7
Validation
ruixhuang Apr 10, 2024
cdb78c1
Show validation error at sections
ruixhuang Apr 11, 2024
5874d35
Highlighting error/warning field
ruixhuang Apr 11, 2024
5560e62
Merge branch 'develop' into feature/trigger_3
ruixhuang Apr 11, 2024
e69f21e
Merge branch 'feature/trigger_3' into feature/trigger_3_1
ruixhuang Apr 11, 2024
09473cb
Merge branch 'feature/trigger_3_1' into feature/trigger_3_2
ruixhuang Apr 11, 2024
4f4986a
Slide size formatting
ruixhuang Apr 11, 2024
42ec9c7
Merge branch 'develop' into feature/trigger_3_1
ruixhuang Apr 12, 2024
3622f79
Clean up
ruixhuang Apr 12, 2024
19d5efb
Clean up TriggerOrderStream
ruixhuang Apr 12, 2024
de3b9d4
Merge branch 'feature/trigger_3_1' into feature/trigger_3_2
ruixhuang Apr 12, 2024
8baf62d
Multiple Order in the edit view
ruixhuang Apr 12, 2024
1c0669e
Multiple order on market info and route to order list
ruixhuang Apr 12, 2024
8424c18
Merge branch 'develop' into feature/trigger_3_3
ruixhuang Apr 12, 2024
3c16f80
Merge branch 'develop' into feature/trigger_3_2
ruixhuang Apr 22, 2024
6ad7541
Clean up
ruixhuang Apr 22, 2024
aa6ce99
Merge branch 'feature/trigger_3_2' into feature/trigger_3_3
ruixhuang Apr 22, 2024
0173eac
Size fix
ruixhuang Apr 22, 2024
6c2960a
Merge branch 'develop' into feature/trigger_3_3
ruixhuang Apr 23, 2024
cd5ceb9
Fix issue with switching market
ruixhuang Apr 23, 2024
2172c21
Merge branch 'develop' into feature/trigger_3_3
ruixhuang Apr 24, 2024
68929ee
Merge branch 'develop' into feature/trigger_3_3
ruixhuang Apr 24, 2024
4a8f19a
Clean up
ruixhuang Apr 25, 2024
4dbc1f4
Merge branch 'develop' into feature/trigger_3_3
ruixhuang Apr 26, 2024
c930061
Code review
ruixhuang Apr 26, 2024
ebdef7b
Merge branch 'develop' into feature/trigger_3_3
ruixhuang May 1, 2024
d074e73
Merge branch 'develop' into feature/trigger_3_3
ruixhuang May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object OnboardingRoutes {
object PortfolioRoutes {
const val main = "portfolio"
const val order_details = "orders"
const val orders = "portfolio/orders"
prashanDYDX marked this conversation as resolved.
Show resolved Hide resolved
}

object ProfileRoutes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -58,13 +59,15 @@ object DydxMarketPositionButtonsView : DydxComponent {
val triggerPrice: String? = null,
val limitPrice: String? = null,
val sizePercent: String? = null,
val hasMultipleOrders: Boolean = false,
) {
companion object {
val preview = TriggerViewState(
label = "TP",
triggerPrice = "$120.0",
limitPrice = "$110.0",
sizePercent = "10%",
hasMultipleOrders = false,
)
}
}
Expand Down Expand Up @@ -201,11 +204,13 @@ object DydxMarketPositionButtonsView : DydxComponent {
Column(
modifier = Modifier
.clickable { action() }
.padding(8.dp),
.padding(vertical = ThemeShapes.VerticalPadding),
verticalArrangement = Arrangement.spacedBy(ThemeShapes.VerticalPadding),
) {
Row(
modifier = Modifier,
modifier = Modifier
.defaultMinSize(minHeight = 36.dp)
.padding(horizontal = ThemeShapes.HorizontalPadding),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Expand All @@ -218,20 +223,30 @@ object DydxMarketPositionButtonsView : DydxComponent {

Spacer(modifier = Modifier.weight(1f))

Text(
modifier = Modifier,
text = state.triggerPrice ?: "",
style = TextStyle.dydxDefault
.themeFont(fontSize = ThemeFont.FontSize.medium)
.themeColor(ThemeColor.SemanticColor.text_primary),
)
if (state.hasMultipleOrders) {
Text(
text = localizer.localize("APP.GENERAL.MULTIPLE"),
style = TextStyle.dydxDefault
.themeFont(fontSize = ThemeFont.FontSize.medium)
.themeColor(ThemeColor.SemanticColor.text_secondary),
)
} else {
Text(
modifier = Modifier,
text = state.triggerPrice ?: "",
style = TextStyle.dydxDefault
.themeFont(fontSize = ThemeFont.FontSize.medium)
.themeColor(ThemeColor.SemanticColor.text_primary),
)
}
}

if (state.limitPrice != null || state.sizePercent != null) {
if (!state.hasMultipleOrders && (state.limitPrice != null || state.sizePercent != null)) {
PlatformDivider()

Row(
modifier = Modifier,
modifier = Modifier
.padding(horizontal = ThemeShapes.HorizontalPadding),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,30 @@ class DydxMarketPositionButtonsViewModel @Inject constructor(
presentation = DydxRouter.Presentation.Modal,
)
},
takeProfitTrigger = takeProfitOrders?.firstOrNull()?.let {
createTriggerViewState(
label = "TP",
position = position,
order = it,
configsAndAsset = configsAndAsset,
)
},
stopLossTrigger = stopLossOrders?.firstOrNull()?.let {
createTriggerViewState(
label = "SL",
position = position,
order = it,
configsAndAsset = configsAndAsset,
)
},
takeProfitTrigger = createTriggerViewState(
label = "TP",
position = position,
orders = takeProfitOrders,
configsAndAsset = configsAndAsset,
),
stopLossTrigger = createTriggerViewState(
label = "SL",
position = position,
orders = stopLossOrders,
configsAndAsset = configsAndAsset,
),
)
}

private fun createTriggerViewState(
label: String,
position: SubaccountPosition?,
order: SubaccountOrder,
orders: List<SubaccountOrder>?,
configsAndAsset: MarketConfigsAndAsset?,
): DydxMarketPositionButtonsView.TriggerViewState {
): DydxMarketPositionButtonsView.TriggerViewState? {
val order = orders?.firstOrNull()
?: return null

val tickSize = configsAndAsset?.configs?.displayTickSizeDecimals ?: 0
val size = order.size
val positionSize = position?.size?.current ?: 0.0
Expand All @@ -107,6 +106,7 @@ class DydxMarketPositionButtonsViewModel @Inject constructor(
triggerPrice = order.triggerPrice?.let { formatter.dollar(it, tickSize) },
limitPrice = order.price.let { formatter.dollar(it, tickSize) },
sizePercent = formatter.percent(percentage, 2),
hasMultipleOrders = orders.size > 1,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.navigation.navArgument
import exchange.dydx.trading.common.navigation.DydxRouter
import exchange.dydx.trading.common.navigation.PortfolioRoutes
import exchange.dydx.trading.common.navigation.dydxComposable
import exchange.dydx.trading.feature.portfolio.components.orders.DydxPortfolioOrdersView
import exchange.dydx.trading.feature.portfolio.orderdetails.DydxOrderDetailsView
import timber.log.Timber

Expand Down Expand Up @@ -35,4 +36,12 @@ fun NavGraphBuilder.portfolioGraph(
}
DydxOrderDetailsView.Content(Modifier)
}

dydxComposable(
router = appRouter,
route = PortfolioRoutes.orders,
deepLinks = appRouter.deeplinks(PortfolioRoutes.orders),
) { navBackStackEntry ->
DydxPortfolioOrdersView.Content(Modifier, isFullScreen = true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package exchange.dydx.trading.feature.portfolio.components.orders

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down Expand Up @@ -31,6 +32,7 @@ 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.portfolio.components.placeholder.DydxPortfolioPlaceholderView
import exchange.dydx.trading.feature.shared.views.HeaderView
import exchange.dydx.trading.feature.shared.viewstate.SharedOrderViewState

@Preview
Expand All @@ -52,6 +54,7 @@ object DydxPortfolioOrdersView : DydxComponent {
val localizer: LocalizerProtocol,
val orders: List<SharedOrderViewState> = listOf(),
val onOrderTappedAction: (String) -> Unit = {},
val onBackTappedAction: () -> Unit = {},
) {
companion object {
val preview = ViewState(
Expand All @@ -66,11 +69,42 @@ object DydxPortfolioOrdersView : DydxComponent {

@Composable
override fun Content(modifier: Modifier) {
Content(modifier, isFullScreen = false)
}

@Composable
fun Content(modifier: Modifier, isFullScreen: Boolean) {
val viewModel: DydxPortfolioOrdersViewModel = hiltViewModel()

val state = viewModel.state.collectAsStateWithLifecycle(initialValue = null).value
LazyColumn {
ListContent(this, modifier, state)
if (isFullScreen) {
Column(
modifier = modifier.fillMaxWidth(),
) {
HeaderView(
modifier = Modifier.fillMaxWidth(),
title = state?.localizer?.localize("APP.GENERAL.ORDERS") ?: "",
backAction = state?.onBackTappedAction,
)

PlatformDivider()

Spacer(modifier = Modifier.height(16.dp))

LazyColumn(
modifier = Modifier
.fillMaxWidth()
.weight(1f),
) {
ListContent(this, Modifier, state)
}
}
} else {
LazyColumn(
modifier = modifier,
) {
ListContent(this, Modifier, state)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class DydxPortfolioOrdersViewModel @Inject constructor(
presentation = DydxRouter.Presentation.Modal,
)
},
onBackTappedAction = {
router.navigateBack()
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface TriggerOrderStreaming {
}

interface MutableTriggerOrderStreaming : TriggerOrderStreaming {
fun updatesubmissionStatus(status: AbacusStateManagerProtocol.SubmissionStatus?)
fun updateSubmissionStatus(status: AbacusStateManagerProtocol.SubmissionStatus?)
fun clearSubmissionStatus()
fun setTakeProfitGainLossDisplayType(displayType: GainLossDisplayType)
fun setStopLossGainLossDisplayType(displayType: GainLossDisplayType)
Expand Down Expand Up @@ -71,7 +71,7 @@ class TriggerOrderStream @Inject constructor(
}
.distinctUntilChanged()

override fun updatesubmissionStatus(status: AbacusStateManagerProtocol.SubmissionStatus?) {
override fun updateSubmissionStatus(status: AbacusStateManagerProtocol.SubmissionStatus?) {
_submissionStatus.update { status }
}

Expand Down
Loading
Loading