Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 0 additions & 5 deletions app/src/main/java/to/bitkit/ui/ContentView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,6 @@ private fun RootNavHost(
walletId = walletId,
viewModel = hiltViewModel<SparkFundingViewModel>(parentEntry),
onBackClick = { navController.popBackStack() },
onLearnMoreClick = { navController.navigateTo(Routes.TransferLearnMore) },
onSent = {
navController.navigateTo(Routes.SpendingHwSigned) {
popUpTo<Routes.SpendingHwSign> { inclusive = true }
Expand Down Expand Up @@ -1243,11 +1242,7 @@ private fun RootNavHost(
)
}
composableWithDefaultTransitions<Routes.TransferLearnMore> {
val parentEntry = remember(it) { navController.getBackStackEntry(Routes.SparkFundingNav) }
val sparkState by walletViewModel.sparkState.collectAsStateWithLifecycle()
TransferLearnMoreScreen(
viewModel = hiltViewModel<SparkFundingViewModel>(parentEntry),
spendingBalanceSats = sparkState.spendingSats.toLong(),
onBackClick = { navController.popBackStack() },
onContinueClick = { navController.popBackStack() },
)
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/to/bitkit/ui/components/FeeInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.material3.HorizontalDivider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import to.bitkit.ui.theme.Colors

Expand All @@ -21,12 +22,13 @@ fun RowScope.FeeInfo(
modifier: Modifier = Modifier,
prefix: String? = null,
isLoading: Boolean = false,
topPadding: Dp = 16.dp,
) {
Column(
modifier = modifier
.fillMaxHeight()
.weight(1f)
.padding(top = 16.dp)
.padding(top = topPadding)
) {
Caption13Up(
text = label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ import to.bitkit.ui.theme.Colors
/** Illustration width as a fraction of the sheet width — the 256-wide Visual in the 375-wide Figma frame. */
internal const val HW_ILLUSTRATION_SIZE_RATIO = 256f / 375f

/** Figma top ratio for the signed check visual within the content area below navigation. */
internal const val SIGNED_VISUAL_TOP_RATIO = (481f - 92f) / (812f - 92f - 34f)

/** Figma top ratio for the Trezor visual within the content area below navigation. */
internal const val SIGN_VISUAL_TOP_RATIO = (488f - 92f) / (812f - 92f - 34f)

/** Trezor illustration left bleed past the frame, as a fraction of the sheet width; keeps its screen text in view. */
private const val HW_DEVICE_TREZOR_BLEED_RATIO = 71f / 375f

Expand Down
76 changes: 41 additions & 35 deletions app/src/main/java/to/bitkit/ui/screens/transfer/FundingScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ fun FundingScreen(
modifier = Modifier.padding(horizontal = 16.dp),
)
VerticalSpacer(24.dp)
// Spark keeps Spending fundable from savings or another wallet without a channel.
if (canFundWithSpark) {
FundingOption(
R.string.lightning__funding__button1,
Expand All @@ -88,51 +87,58 @@ fun FundingScreen(
"FundTransfer",
{ if (hasSavings) onTransfer() else showNoFundsAlert = true }.takeIf { canFundOnChain },
)
FundingOption(
R.string.lightning__funding__button_hw,
R.drawable.ic_device_tablet_speaker,
16.25.dp,
"FundHardware",
onHardware.takeIf { canFundOnChain },
)
FundingOption(
R.string.lightning__funding__button2,
R.drawable.ic_qr_purple,
13.75.dp,
"FundReceive",
onFund
onFund,
)
FundingOption(
R.string.lightning__funding_advanced__button2,
R.drawable.ic_pencil_full,
13.37.dp,
"FundManual",
onManual,
)
} else {
FundingOption(
R.string.lightning__funding_advanced__button2,
R.drawable.ic_pencil_full,
13.37.dp,
"FundManual",
onManual,
)
}
VerticalSpacer(8.dp)
RectangleButton(
label = stringResource(R.string.lightning__funding_advanced__button2),
icon = R.drawable.ic_pencil_full,
iconTint = Colors.Purple,
iconSize = 13.37.dp,
onClick = onManual,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
.testTag("FundManual")
)
if (!canFundWithSpark) {
FundingOption(R.string.lightning__funding__button1, R.drawable.ic_transfer, 20.dp, "FundTransfer")
}
FundingOption(
R.string.lightning__funding__button_hw,
R.drawable.ic_device_tablet_speaker,
16.25.dp,
"FundHardware",
onHardware.takeIf { canFundWithSpark && canFundOnChain },
)
if (!canFundWithSpark) {
FundingOption(
R.string.lightning__funding__button_hw,
R.drawable.ic_device_tablet_speaker,
16.25.dp,
"FundHardware",
)
FundingOption(R.string.lightning__funding__button2, R.drawable.ic_qr_purple, 13.75.dp, "FundReceive")
}
VerticalSpacer(32.dp)
}
SecondaryButton(
text = stringResource(R.string.common__learn_more),
onClick = {
runCatching { context.startActivity(Intent(Intent.ACTION_VIEW, Env.BLOCKTANK_SUNSET_URL.toUri())) }
},
modifier = Modifier
.padding(horizontal = 16.dp)
.testTag("FundLearnMore")
)
VerticalSpacer(16.dp)
if (!canFundWithSpark) {
SecondaryButton(
text = stringResource(R.string.common__learn_more),
onClick = {
runCatching { context.startActivity(Intent(Intent.ACTION_VIEW, Env.BLOCKTANK_SUNSET_URL.toUri())) }
},
modifier = Modifier
.padding(horizontal = 16.dp)
.testTag("FundLearnMore")
)
VerticalSpacer(16.dp)
}
if (showNoFundsAlert) {
AppAlertDialog(
title = stringResource(R.string.lightning__no_funds__title),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ internal fun Content(
.fillMaxWidth()
.testTag("SettingUpText")
)
VerticalSpacer(28.dp)
if (isSuccess) {
VerticalSpacer(44.dp)
Box(
contentAlignment = Alignment.Center,
contentAlignment = Alignment.TopCenter,
modifier = Modifier
.weight(1f)
.fillMaxWidth()
Expand All @@ -147,19 +147,20 @@ internal fun Content(
)
}
} else {
VerticalSpacer(32.dp)
Illustration(
hasCoins = frame.hasCoins,
modifier = Modifier
.weight(1f)
.fillMaxWidth()
)
VerticalSpacer(16.dp)
VerticalSpacer(14.dp)
ProgressSteps(
steps = steps(frame),
activeStepIndex = frame.stepIndex,
modifier = Modifier.align(alignment = Alignment.CenterHorizontally)
)
VerticalSpacer(16.dp)
VerticalSpacer(32.dp)
}
Buttons(
frame = frame,
Expand Down
154 changes: 100 additions & 54 deletions app/src/main/java/to/bitkit/ui/screens/transfer/SpendingAmountScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ import androidx.compose.material3.HorizontalDivider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Devices.NEXUS_5
Expand Down Expand Up @@ -60,6 +64,12 @@ private val PAD_ROW_HEIGHT = 78.dp
/** Shortest number pad row, reached only when four 50 dp rows don't fit, as on a 640 dp tall phone. */
private val PAD_ROW_MIN_HEIGHT = 40.dp

/** Gap between the amount and the Available row; it gives way only once the pad rows are at their shortest. */
private val AVAILABLE_ROW_GAP = 32.dp

/** Number pad rows; the layout reserves room for at least this many rows of [PAD_ROW_MIN_HEIGHT]. */
private const val PAD_ROWS = 4

@Suppress("ViewModelForwarding")
@Composable
fun SpendingAmountScreen(
Expand Down Expand Up @@ -177,6 +187,16 @@ private fun SpendingAmountNodeRunning(
if (!uiState.isMaxLoading) amountInputViewModel.setMaxAmount(uiState.maxSats)
}

// Review's fee grid switches the unit while this screen waits in the back stack, so redraw the amount in it,
// only when the unit changed: redrawing on every return would rewrite what the user typed.
var drawnDisplay by rememberSaveable { mutableStateOf(currencies.primaryDisplay) }
LaunchedEffect(currencies.primaryDisplay) {
if (currencies.primaryDisplay == drawnDisplay) return@LaunchedEffect
drawnDisplay = currencies.primaryDisplay
val sats = amountInputViewModel.uiState.value.sats
if (sats > 0) amountInputViewModel.setSats(sats, currencies)
Comment thread
ovitrif marked this conversation as resolved.
Resolved
}

Column(
modifier = Modifier
.padding(horizontal = 16.dp)
Expand Down Expand Up @@ -208,74 +228,100 @@ private fun SpendingAmountNodeRunning(
.testTag("${tag}NumberField")
)

Column(
verticalArrangement = Arrangement.Bottom,
modifier = Modifier.weight(1f)
) {
Row(
verticalAlignment = Alignment.Bottom,
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.testTag(
if (isHardware) "HardwareTransferAmountNumberPad" else "SendAmountNumberPad"
)
) {
Column {
Text13Up(
text = stringResource(R.string.wallet__send_available),
color = Colors.White64,
modifier = Modifier.testTag("${tag}Available")
AvailableRowLayout(modifier = Modifier.weight(1f)) {
Column(modifier = Modifier.fillMaxWidth()) {
Row(
verticalAlignment = Alignment.Bottom,
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.testTag(
if (isHardware) "HardwareTransferAmountNumberPad" else "SendAmountNumberPad"
)
VerticalSpacer(8.dp)
MoneySSB(
sats = uiState.maxSats,
showSymbol = true,
modifier = Modifier.testTag("${tag}Unit")
) {
Column {
Text13Up(
text = stringResource(R.string.wallet__send_available),
color = Colors.White64,
modifier = Modifier.testTag("${tag}Available")
)
VerticalSpacer(4.dp)
MoneySSB(
sats = uiState.maxSats,
showSymbol = true,
modifier = Modifier.testTag("${tag}Unit")
)
}
FillWidth()
UnitButton(
color = Colors.Purple,
onClick = { amountInputViewModel.switchUnit(currencies) },
modifier = Modifier.testTag(
if (isHardware) "HardwareTransferAmountUnitButton" else "SpendingNumberPadUnit"
)
)
}
FillWidth()
UnitButton(
color = Colors.Purple,
onClick = { amountInputViewModel.switchUnit(currencies) },
modifier = Modifier.testTag(
if (isHardware) "HardwareTransferAmountUnitButton" else "SpendingNumberPadUnit"
NumberPadActionButton(
text = stringResource(R.string.lightning__spending_amount__quarter),
color = Colors.Purple,
enabled = isReady && hasFunds,
onClick = onClickQuarter,
modifier = Modifier.testTag("${tag}Quarter")
)
)
NumberPadActionButton(
text = stringResource(R.string.lightning__spending_amount__quarter),
color = Colors.Purple,
enabled = isReady && hasFunds,
onClick = onClickQuarter,
modifier = Modifier.testTag("${tag}Quarter")
)
NumberPadActionButton(
text = stringResource(R.string.common__max),
color = Colors.Purple,
enabled = isReady && hasFunds,
onClick = onClickMaxAmount,
modifier = Modifier.testTag("${tag}Max")
)
}
NumberPadActionButton(
text = stringResource(R.string.common__max),
color = Colors.Purple,
enabled = isReady && hasFunds,
onClick = onClickMaxAmount,
modifier = Modifier.testTag("${tag}Max")
)
}

HorizontalDivider(modifier = Modifier.padding(top = 12.dp))
HorizontalDivider(modifier = Modifier.padding(top = 16.dp))
}

NumberPad(
viewModel = amountInputViewModel,
currencies = currencies,
enabled = isReady && hasFunds,
idealRowHeight = PAD_ROW_HEIGHT,
minRowHeight = PAD_ROW_MIN_HEIGHT,
modifier = Modifier.weight(1f, fill = false)
modifier = Modifier.fillMaxWidth()
)

PrimaryButton(
text = stringResource(R.string.common__continue),
onClick = onConfirmAmount,
enabled = isReady && amountUiState.sats > 0 && amountUiState.sats <= uiState.maxSats,
isLoading = uiState.isLoading,
modifier = Modifier.testTag("${tag}Continue")
)
Column(modifier = Modifier.fillMaxWidth()) {
PrimaryButton(
text = stringResource(R.string.common__continue),
onClick = onConfirmAmount,
enabled = isReady && amountUiState.sats > 0 && amountUiState.sats <= uiState.maxSats,
isLoading = uiState.isLoading,
modifier = Modifier.testTag("${tag}Continue")
)
VerticalSpacer(16.dp)
}
}
}
}

VerticalSpacer(16.dp)
/**
* Lays out the Available row, the number pad and Continue: the row [AVAILABLE_ROW_GAP] under the amount, the pad and
* Continue pinned to the bottom. The pad rows shrink first; the gap gives way only once they are at their shortest.
*/
@Composable
private fun AvailableRowLayout(
modifier: Modifier = Modifier,
content: @Composable () -> Unit,
) {
Layout(content = content, modifier = modifier) { measurables, constraints ->
val (rowMeasurable, padMeasurable, footerMeasurable) = measurables
val loose = constraints.copy(minHeight = 0)
val row = rowMeasurable.measure(loose)
val footer = footerMeasurable.measure(loose)
val gap = AVAILABLE_ROW_GAP.roundToPx()
val room = (constraints.maxHeight - row.height - footer.height).coerceAtLeast(0)
val minPad = (PAD_ROW_MIN_HEIGHT * PAD_ROWS).roundToPx().coerceAtMost(room)
val pad = padMeasurable.measure(loose.copy(maxHeight = (room - gap).coerceAtLeast(minPad)))
layout(constraints.maxWidth, constraints.maxHeight) {
row.place(0, gap.coerceAtMost(room - pad.height))
footer.place(0, constraints.maxHeight - footer.height)
pad.place(0, constraints.maxHeight - footer.height - pad.height)
}
}
}
Expand Down
Loading
Loading