Updated on 2026-08-14
This commit is contained in:
parent
68920e11b5
commit
2754318b8e
9 changed files with 45 additions and 13 deletions
|
|
@ -64,6 +64,7 @@ fun AmountTextField(
|
|||
keyboardType = KeyboardType.Number,
|
||||
),
|
||||
keyboardActions: KeyboardActions = KeyboardActions.Default,
|
||||
isEnabled: Boolean = true,
|
||||
isAutoResize: Boolean = false,
|
||||
@FloatRange(from = 0.0, to = 1.0, fromInclusive = false, toInclusive = false)
|
||||
reduceFactor: Double = 0.9,
|
||||
|
|
@ -106,21 +107,20 @@ fun AmountTextField(
|
|||
textStyle = textStyle.copy(
|
||||
fontSize = fontSize,
|
||||
textDirection = TextDirection.ContentOrLtr,
|
||||
textAlign = TextAlign.Center,
|
||||
),
|
||||
color = color,
|
||||
keyboardOptions = keyboardOptions,
|
||||
keyboardActions = keyboardActions,
|
||||
singleLine = true,
|
||||
readOnly = !isEnabled,
|
||||
visualTransformation = AmountVisualTransformation(decimals, symbol, decimalFormat),
|
||||
modifier = Modifier.background(TangemTheme.colors.background.action),
|
||||
decorationBox = { innerTextField ->
|
||||
Box {
|
||||
if (value.isBlank() && showPlaceholder) {
|
||||
val placeholder = if (symbol != null) {
|
||||
decimalFormat.defaultFormat().plus(" $symbol")
|
||||
} else {
|
||||
decimalFormat.defaultFormat()
|
||||
var placeholder = decimalFormat.defaultFormat()
|
||||
if (symbol != null) {
|
||||
placeholder = placeholder.plus(" $symbol")
|
||||
}
|
||||
Text(
|
||||
text = placeholder,
|
||||
|
|
|
|||
|
|
@ -11,10 +11,11 @@ class JobHolder {
|
|||
|
||||
private var job: Job? = null
|
||||
|
||||
/** Update current [job] */
|
||||
fun update(job: Job?) {
|
||||
/** Update current [JobHolder.job] and return new [job] */
|
||||
fun update(job: Job): Job {
|
||||
this.job?.cancel()
|
||||
this.job = job
|
||||
return job
|
||||
}
|
||||
|
||||
/** Cancel current [job] */
|
||||
|
|
@ -23,4 +24,4 @@ class JobHolder {
|
|||
}
|
||||
}
|
||||
|
||||
fun Job.saveIn(jobHolder: JobHolder) = jobHolder.update(job = this)
|
||||
fun Job.saveIn(jobHolder: JobHolder): Job = jobHolder.update(job = this)
|
||||
|
|
@ -50,4 +50,11 @@ internal class AmountStateFactory(
|
|||
amountState = state.amountState?.copy(notifications = notifications),
|
||||
)
|
||||
}
|
||||
|
||||
fun getOnAmountFeeLoadingCancel(): SendUiState {
|
||||
val state = currentStateProvider()
|
||||
return state.copy(
|
||||
amountState = state.amountState?.copy(isFeeLoading = false),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -104,7 +104,7 @@ private fun SendNavigationButton(
|
|||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(TangemTheme.dimens.radius16))
|
||||
.background(TangemTheme.colors.button.secondary)
|
||||
.clickable(enabled = !showProgress) { uiState.clickIntents.onPrevClick() }
|
||||
.clickable { uiState.clickIntents.onPrevClick() }
|
||||
.padding(TangemTheme.dimens.spacing12),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ private const val AMOUNT_BUTTONS_KEY = "amountButtonsKey"
|
|||
internal fun LazyListScope.buttons(
|
||||
segmentedButtonConfig: PersistentList<SendAmountSegmentedButtonsConfig>,
|
||||
clickIntents: SendClickIntents,
|
||||
isMaxButtonEnabled: Boolean,
|
||||
) {
|
||||
item(
|
||||
key = AMOUNT_BUTTONS_KEY,
|
||||
|
|
@ -55,6 +56,7 @@ internal fun LazyListScope.buttons(
|
|||
}
|
||||
SecondaryButton(
|
||||
text = stringResource(R.string.send_max_amount),
|
||||
enabled = isMaxButtonEnabled,
|
||||
onClick = {
|
||||
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
clickIntents.onMaxValueClick()
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import com.tangem.core.ui.utils.rememberDecimalFormat
|
|||
import com.tangem.features.send.impl.presentation.state.fields.SendTextField
|
||||
|
||||
@Composable
|
||||
internal fun AmountField(sendField: SendTextField.AmountField, isFiat: Boolean) {
|
||||
internal fun AmountField(sendField: SendTextField.AmountField, isFiat: Boolean, isEnabled: Boolean) {
|
||||
val decimalFormat = rememberDecimalFormat()
|
||||
val (primaryValue, secondaryValue) = if (isFiat) {
|
||||
sendField.fiatValue to sendField.value
|
||||
|
|
@ -47,6 +47,7 @@ internal fun AmountField(sendField: SendTextField.AmountField, isFiat: Boolean)
|
|||
color = TangemTheme.colors.text.primary1,
|
||||
textAlign = TextAlign.Center,
|
||||
),
|
||||
isEnabled = isEnabled,
|
||||
placeholderAlignment = TopCenter,
|
||||
modifier = Modifier
|
||||
.padding(
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ internal fun LazyListScope.amountField(
|
|||
AmountField(
|
||||
sendField = amountState.amountTextField,
|
||||
isFiat = amountState.amountTextField.isFiatValue,
|
||||
isEnabled = !amountState.isFeeLoading,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,11 @@ internal fun SendAmountContent(
|
|||
.background(TangemTheme.colors.background.tertiary),
|
||||
) {
|
||||
amountField(amountState = amountState, isBalanceHiding = isBalanceHiding)
|
||||
buttons(amountState.segmentedButtonConfig, clickIntents)
|
||||
buttons(
|
||||
segmentedButtonConfig = amountState.segmentedButtonConfig,
|
||||
clickIntents = clickIntents,
|
||||
isMaxButtonEnabled = !amountState.isFeeLoading,
|
||||
)
|
||||
notifications(amountState.notifications)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -482,7 +482,11 @@ internal class SendViewModel @Inject constructor(
|
|||
|
||||
// region screen state navigation
|
||||
override fun popBackStack() = stateRouter.popBackStack()
|
||||
override fun onBackClick() = stateRouter.onBackClick(isSuccess = uiState.sendState?.isSuccess == true)
|
||||
override fun onBackClick() {
|
||||
cancelFeeRequest()
|
||||
stateRouter.onBackClick(isSuccess = uiState.sendState?.isSuccess == true)
|
||||
}
|
||||
|
||||
override fun onNextClick() {
|
||||
val currentState = stateRouter.currentState.value
|
||||
sendOnNextScreenAnalyticSender.send(currentState.type, uiState)
|
||||
|
|
@ -504,7 +508,10 @@ internal class SendViewModel @Inject constructor(
|
|||
stateRouter.onNextClick()
|
||||
}
|
||||
|
||||
override fun onPrevClick() = stateRouter.onPrevClick()
|
||||
override fun onPrevClick() {
|
||||
cancelFeeRequest()
|
||||
stateRouter.onPrevClick()
|
||||
}
|
||||
|
||||
override fun onQrCodeScanClick() {
|
||||
analyticsEventHandler.send(SendAnalyticEvents.QrCodeButtonClicked)
|
||||
|
|
@ -541,6 +548,12 @@ internal class SendViewModel @Inject constructor(
|
|||
false
|
||||
}
|
||||
}
|
||||
|
||||
private fun cancelFeeRequest() {
|
||||
viewModelScope.launch(dispatchers.main) {
|
||||
feeJobHolder.cancel()
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region amount state clicks
|
||||
|
|
@ -691,6 +704,9 @@ internal class SendViewModel @Inject constructor(
|
|||
updateFeeNotifications()
|
||||
updateAmountNotifications()
|
||||
}.saveIn(feeJobHolder)
|
||||
.invokeOnCompletion {
|
||||
uiState = amountStateFactory.getOnAmountFeeLoadingCancel()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun checkIfSubtractAvailable() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue