Skip to content
28 changes: 28 additions & 0 deletions app/src/main/java/to/bitkit/ext/DateTime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,34 @@ fun Long.toRelativeTimeString(
}
}

fun formatInvoiceExpiryRelative(
expirySeconds: ULong,
locale: Locale = Locale.getDefault(),
): String {
val seconds = expirySeconds.toLong()
if (seconds <= 0) return ""

val uLocale = ULocale.forLocale(locale)
val numberFormat = NumberFormat.getNumberInstance(uLocale)?.apply { maximumFractionDigits = 0 }
val formatter = RelativeDateTimeFormatter.getInstance(
uLocale,
numberFormat,
RelativeDateTimeFormatter.Style.LONG,
DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,
) ?: return ""

val minutes = seconds / Factor.SECONDS_TO_MINUTES.toLong()
val hours = minutes / Factor.MINUTES_TO_HOURS.toLong()
val days = hours / Factor.HOURS_TO_DAYS.toLong()

return when {
minutes < 1 -> formatter.format(seconds.toDouble(), Direction.NEXT, RelativeUnit.SECONDS)
hours < 1 -> formatter.format(minutes.toDouble(), Direction.NEXT, RelativeUnit.MINUTES)
days < 1 -> formatter.format(hours.toDouble(), Direction.NEXT, RelativeUnit.HOURS)
else -> formatter.format(days.toDouble(), Direction.NEXT, RelativeUnit.DAYS)
}
}

fun getDaysInMonth(month: LocalDate): List<LocalDate?> {
val firstDayOfMonth = LocalDate(month.year, month.month, Constants.FIRST_DAY_OF_MONTH)
val daysInMonth = month.month.toJavaMonth().length(isLeapYear(month.year))
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/to/bitkit/models/FeeRate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ enum class FeeRate(
@DrawableRes val icon: Int,
val color: Color,
) {
INSTANT(
title = R.string.fee__instant__title,
description = R.string.fee__instant__description,
shortDescription = R.string.fee__instant__shortDescription,
color = Colors.Purple,
icon = R.drawable.ic_lightning,
),
FAST(
title = R.string.fee__fast__title,
description = R.string.fee__fast__description,
Expand Down Expand Up @@ -53,7 +60,7 @@ enum class FeeRate(

fun toSpeed(): TransactionSpeed {
return when (this) {
FAST -> TransactionSpeed.Fast
INSTANT, FAST -> TransactionSpeed.Fast
NORMAL -> TransactionSpeed.Medium
MINIMUM, SLOW -> TransactionSpeed.Slow
CUSTOM -> TransactionSpeed.Custom(0u)
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/to/bitkit/ui/components/SendSectionView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package to.bitkit.ui.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.HorizontalDivider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import to.bitkit.ui.theme.Colors

@Composable
fun SendSectionView(
caption: String,
modifier: Modifier = Modifier,
content: @Composable () -> Unit,
) {
Column(modifier = modifier.fillMaxWidth()) {
Caption13Up(text = caption, color = Colors.White64)
VerticalSpacer(8.dp)
content()
HorizontalDivider(modifier = Modifier.fillMaxWidth())
}
}
10 changes: 9 additions & 1 deletion app/src/main/java/to/bitkit/ui/components/SwipeToConfirm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
Expand Down Expand Up @@ -61,15 +62,16 @@ private val Padding = 8.dp

@Composable
fun SwipeToConfirm(
modifier: Modifier = Modifier,
text: String = stringResource(R.string.other__swipe),
color: Color = Colors.Brand,
icon: ImageVector = Icons.AutoMirrored.Default.ArrowForward,
@DrawableRes endIcon: Int = R.drawable.ic_check,
endIconTint: Color = Colors.Black,
loading: Boolean = false,
confirmed: Boolean = false,
onProgressChange: ((Float) -> Unit)? = null,
onConfirm: () -> Unit,
modifier: Modifier = Modifier,
) {
val scope = rememberCoroutineScope()
val trailColor = remember(color) { color.copy(alpha = 0.24f) }
Expand All @@ -94,6 +96,12 @@ fun SwipeToConfirm(
)
}

LaunchedEffect(onProgressChange) {
if (onProgressChange == null) return@LaunchedEffect
snapshotFlow { panX.value / maxPanX }
.collect { onProgressChange(it.coerceIn(0f, 1f)) }
}

Box(
modifier = modifier
.requiredHeight(CircleSize + Padding * 2)
Expand Down
Loading
Loading