Skip to content

Commit 6a0b645

Browse files
committed
fix: leverage option on open position page
1 parent 2b36e1b commit 6a0b645

File tree

6 files changed

+38
-24
lines changed

6 files changed

+38
-24
lines changed

app/src/main/java/one/mixin/android/ui/home/web3/trade/InputTextField.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import androidx.compose.ui.text.input.KeyboardType
4242
import androidx.compose.ui.text.input.TextFieldValue
4343
import androidx.compose.ui.text.style.TextAlign
4444
import androidx.compose.ui.unit.Dp
45+
import androidx.compose.ui.unit.TextUnit
4546
import androidx.compose.ui.unit.dp
4647
import androidx.compose.ui.unit.sp
4748
import coil3.request.ImageRequest
@@ -64,6 +65,8 @@ fun InputContent(
6465
readOnly: Boolean = false,
6566
inlineEndCompose: (@Composable () -> Unit)? = null,
6667
tokenIconSize: Dp = 32.dp,
68+
inputFontSize: TextUnit = 24.sp,
69+
inputFontWeight: FontWeight = FontWeight.Black,
6770
) {
6871
if (readOnly) {
6972
Column(modifier = Modifier.fillMaxWidth()) {
@@ -79,8 +82,8 @@ fun InputContent(
7982
AutoSizeText(
8083
text = text,
8184
color = if (text == "0") MixinAppTheme.colors.textRemarks else MixinAppTheme.colors.textPrimary,
82-
fontSize = 24.sp,
83-
fontWeight = FontWeight.Black,
85+
fontSize = inputFontSize,
86+
fontWeight = inputFontWeight,
8487
textAlign = TextAlign.Start,
8588
)
8689
}
@@ -146,15 +149,15 @@ fun InputContent(
146149
.alpha(if (inlineEndCompose != null) 0f else 1f),
147150
textStyle = TextStyle(
148151
fontSize = when {
149-
textFieldValue.text.length <= 15 -> 24.sp
152+
textFieldValue.text.length <= 15 -> inputFontSize
150153
else -> {
151154
val excess = textFieldValue.text.length - 15
152155
val reduction = excess * 2
153-
(24 - reduction).coerceAtLeast(16).sp
156+
(inputFontSize.value - reduction).coerceAtLeast(16f).sp
154157
}
155158
},
156159
color = MixinAppTheme.colors.textPrimary,
157-
fontWeight = FontWeight.Black,
160+
fontWeight = inputFontWeight,
158161
textAlign = TextAlign.Start,
159162
),
160163
cursorBrush = SolidColor(MixinAppTheme.colors.textPrimary),
@@ -166,8 +169,8 @@ fun InputContent(
166169
AutoSizeText(
167170
text = "0",
168171
color = MixinAppTheme.colors.textRemarks,
169-
fontSize = 24.sp,
170-
fontWeight = FontWeight.Black,
172+
fontSize = inputFontSize,
173+
fontWeight = inputFontWeight,
171174
modifier = Modifier.align(Alignment.CenterStart)
172175
)
173176
}

app/src/main/java/one/mixin/android/ui/home/web3/trade/perps/LeverageBottomSheetDialogFragment.kt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ private fun LeverageContent(
144144
onCancel: () -> Unit,
145145
onApply: (Float) -> Unit
146146
) {
147-
var tempLeverage by remember { mutableFloatStateOf(currentLeverage) }
147+
val boundedMaxLeverage = maxLeverage.coerceAtLeast(1)
148+
var tempLeverage by remember(currentLeverage, boundedMaxLeverage) {
149+
mutableFloatStateOf(currentLeverage.coerceIn(1f, boundedMaxLeverage.toFloat()))
150+
}
148151

149152
Column(
150153
modifier = Modifier
@@ -181,8 +184,8 @@ private fun LeverageContent(
181184
Slider(
182185
value = tempLeverage,
183186
onValueChange = { tempLeverage = it },
184-
valueRange = 1f..maxLeverage.toFloat(),
185-
steps = maxLeverage - 2,
187+
valueRange = 1f..boundedMaxLeverage.toFloat(),
188+
steps = (boundedMaxLeverage - 2).coerceAtLeast(0),
186189
colors = SliderDefaults.colors(
187190
thumbColor = MixinAppTheme.colors.accent,
188191
activeTrackColor = MixinAppTheme.colors.accent,
@@ -199,10 +202,18 @@ private fun LeverageContent(
199202
modifier = Modifier.fillMaxWidth(),
200203
horizontalArrangement = Arrangement.SpaceBetween
201204
) {
202-
val steps = 5
203-
val stepValue = maxLeverage / (steps - 1)
204-
for (i in 0 until steps) {
205-
val value = if (i == steps - 1) maxLeverage else (i * stepValue)
205+
val labels = if (boundedMaxLeverage == 1) {
206+
listOf(1)
207+
} else {
208+
List(5) { index ->
209+
when (index) {
210+
0 -> 1
211+
4 -> boundedMaxLeverage
212+
else -> 1 + ((boundedMaxLeverage - 1) * index / 4)
213+
}
214+
}.distinct()
215+
}
216+
labels.forEach { value ->
206217
Text(
207218
text = "${value}x",
208219
fontSize = 12.sp,
@@ -346,4 +357,4 @@ private fun ProfitLossInfo(
346357
color = MixinAppTheme.colors.textAssist
347358
)
348359
}
349-
}
360+
}

app/src/main/java/one/mixin/android/ui/home/web3/trade/perps/OpenPositionPage.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fun OpenPositionPage(
109109

110110
val savedLeverage = remember(marketId) {
111111
context.defaultSharedPreferences
112-
.getInt(getLeveragePrefKey(marketId), 10)
112+
.getInt(getLeveragePrefKey(marketId), 1)
113113
.coerceAtLeast(1)
114114
}
115115
var leverage by remember(marketId) { mutableFloatStateOf(savedLeverage.toFloat()) }
@@ -279,7 +279,9 @@ fun OpenPositionPage(
279279
onTokenSelect()
280280
},
281281
onInputChanged = { usdtAmount = it },
282-
tokenIconSize = 25.dp
282+
tokenIconSize = 25.dp,
283+
inputFontSize = 28.sp,
284+
inputFontWeight = FontWeight.W500,
283285
)
284286

285287
Row(
@@ -385,8 +387,8 @@ fun OpenPositionPage(
385387
}.show(activity.supportFragmentManager, LeverageBottomSheetDialogFragment.TAG)
386388
},
387389
text = "${leverage.toInt()}x",
388-
fontSize = 16.sp,
389-
fontWeight = FontWeight.Bold,
390+
fontSize = 28.sp,
391+
fontWeight = FontWeight.W500,
390392
color = MixinAppTheme.colors.textPrimary
391393
)
392394

@@ -409,7 +411,7 @@ fun OpenPositionPage(
409411

410412
val displayText = when (lev) {
411413
-1 -> stringResource(R.string.slippage_custom)
412-
maxLeverage -> stringResource(R.string.Max)
414+
maxLeverage.takeIf { it > 1 } -> stringResource(R.string.Max)
413415
else -> "${lev}x"
414416
}
415417

@@ -668,7 +670,7 @@ fun OpenPositionPage(
668670

669671
private fun generateLeverageOptions(maxLeverage: Int): List<Int> {
670672
val safeMaxLeverage = maxLeverage.coerceAtLeast(1)
671-
val baseOptions = listOf(1, 2, 5, 10, 20)
673+
val baseOptions = listOf(2, 5, 10, 20)
672674
val options = baseOptions
673675
.filter { it in 1 until safeMaxLeverage }
674676
.toMutableList()

app/src/main/java/one/mixin/android/ui/home/web3/trade/perps/PerpsConfirmBottomSheetDialogFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class PerpsConfirmBottomSheetDialogFragment : MixinComposeBottomSheetDialogFragm
361361
Box(modifier = Modifier.height(20.dp))
362362

363363
PerpsInfoItem(
364-
title = stringResource(R.string.Margin).uppercase() + " (${stringResource(R.string.Isolated)})",
364+
title = stringResource(R.string.Margin).uppercase(),
365365
value = "$amount $tokenSymbol"
366366
)
367367
Box(modifier = Modifier.height(20.dp))

app/src/main/res/values-zh-rCN/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2308,7 +2308,6 @@
23082308
<string name="Time_Info">时间信息</string>
23092309
<string name="Open_Time">开仓时间</string>
23102310
<string name="Close_Time">平仓时间</string>
2311-
<string name="Isolated">逐仓</string>
23122311
<string name="Mixin_Futures">Mixin Futures</string>
23132312
<string name="Confirm_Open_Position">确认开仓</string>
23142313
<string name="Open_Position_Success">开仓成功</string>

app/src/main/res/values/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2368,7 +2368,6 @@
23682368
<string name="Time_Info">Time Info</string>
23692369
<string name="Open_Time">Open Time</string>
23702370
<string name="Close_Time">Close Time</string>
2371-
<string name="Isolated">Isolated</string>
23722371
<string name="Mixin_Futures">Mixin Futures</string>
23732372
<string name="Wallet_Not_Found">Wallet not found</string>
23742373
<string name="How_Perps_Works">How perps works?</string>

0 commit comments

Comments
 (0)