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
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object Versions {
const val lightningKmp = "1.5.12"
const val lightningKmp = "1.5.13"
const val secp256k1 = "0.11.0"
const val torMobile = "0.2.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import fr.acinq.phoenix.android.settings.channels.ImportChannelsData
import fr.acinq.phoenix.android.settings.displayseed.DisplaySeedView
import fr.acinq.phoenix.android.settings.fees.AdvancedIncomingFeePolicy
import fr.acinq.phoenix.android.settings.fees.LiquidityPolicyView
import fr.acinq.phoenix.android.payments.liquidity.RequestLiquidityView
import fr.acinq.phoenix.android.settings.walletinfo.FinalWalletInfo
import fr.acinq.phoenix.android.settings.walletinfo.SwapInWalletInfo
import fr.acinq.phoenix.android.settings.walletinfo.WalletInfoView
Expand Down Expand Up @@ -219,7 +220,8 @@ fun AppView(
onTorClick = { navController.navigate(Screen.TorConfig) },
onElectrumClick = { navController.navigate(Screen.ElectrumServer) },
onShowSwapInWallet = { navController.navigate(Screen.WalletInfo.SwapInWallet) },
onShowNotifications = { navController.navigate(Screen.Notifications) }
onShowNotifications = { navController.navigate(Screen.Notifications) },
onRequestLiquidityClick = { navController.navigate(Screen.LiquidityRequest.route) },
)
}
}
Expand Down Expand Up @@ -322,7 +324,7 @@ fun AppView(
}
},
onChannelClick = { navController.navigate("${Screen.ChannelDetails.route}?id=$it") },
onImportChannelsDataClick = { navController.navigate(Screen.ImportChannelsData)}
onImportChannelsDataClick = { navController.navigate(Screen.ImportChannelsData)},
)
}
composable(
Expand Down Expand Up @@ -394,9 +396,13 @@ fun AppView(
composable(Screen.LiquidityPolicy.route, deepLinks = listOf(navDeepLink { uriPattern ="phoenix:liquiditypolicy" })) {
LiquidityPolicyView(
onBackClick = { navController.popBackStack() },
onAdvancedClick = { navController.navigate(Screen.AdvancedLiquidityPolicy.route) }
onAdvancedClick = { navController.navigate(Screen.AdvancedLiquidityPolicy.route) },
onRequestLiquidityClick = { navController.navigate(Screen.LiquidityRequest.route) },
)
}
composable(Screen.LiquidityRequest.route, deepLinks = listOf(navDeepLink { uriPattern ="phoenix:requestliquidity" })) {
RequestLiquidityView(onBackClick = { navController.popBackStack() },)
}
composable(Screen.AdvancedLiquidityPolicy.route) {
AdvancedIncomingFeePolicy(onBackClick = { navController.popBackStack() })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ sealed class Screen(val route: String) {
object FinalWallet: Screen("settings/walletinfo/final")
}
object LiquidityPolicy: Screen("settings/liquiditypolicy")
object LiquidityRequest: Screen("settings/requestliquidity")
object AdvancedLiquidityPolicy: Screen("settings/advancedliquiditypolicy")
object Notifications: Screen("notifications")
object ResetWallet: Screen("settings/resetwallet")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import fr.acinq.lightning.MilliSatoshi
import fr.acinq.phoenix.android.*
import fr.acinq.phoenix.android.R
Expand Down Expand Up @@ -148,7 +149,7 @@ fun AmountWithAltView(
fun ColumnScope.AmountWithFiatBelow(
amount: MilliSatoshi,
amountTextStyle: TextStyle = MaterialTheme.typography.body1,
fiatTextStyle: TextStyle = MaterialTheme.typography.caption,
fiatTextStyle: TextStyle = MaterialTheme.typography.caption.copy(fontSize = 14.sp),
) {
val prefBtcUnit = LocalBitcoinUnit.current
val prefFiatCurrency = LocalFiatCurrency.current
Expand All @@ -162,6 +163,30 @@ fun ColumnScope.AmountWithFiatBelow(
)
}

/** Outputs a column with the amount in bitcoin on top, and the fiat amount below. */
@Composable
fun AmountWithFiatBeside(
amount: MilliSatoshi,
amountTextStyle: TextStyle = MaterialTheme.typography.body1,
fiatTextStyle: TextStyle = MaterialTheme.typography.caption.copy(fontSize = 14.sp),
) {
val prefBtcUnit = LocalBitcoinUnit.current
val prefFiatCurrency = LocalFiatCurrency.current
Row {
Text(
text = amount.toPrettyString(prefBtcUnit, withUnit = true),
style = amountTextStyle,
modifier = Modifier.alignByBaseline(),
)
Spacer(modifier = Modifier.width(6.dp))
Text(
text = stringResource(id = R.string.utils_converted_amount, amount.toPrettyString(prefFiatCurrency, fiatRate, withUnit = true)),
style = fiatTextStyle,
modifier = Modifier.alignByBaseline(),
)
}
}

/** Outputs a row with the amount in bitcoin on the left, and the fiat amount on the right. */
@Composable
fun AmountWithFiatRowView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fun BorderButton(
text: String? = null,
icon: Int? = null,
iconTint: Color = MaterialTheme.colors.primary,
shape: Shape = CircleShape,
backgroundColor: Color = MaterialTheme.colors.surface,
borderColor: Color = MaterialTheme.colors.primary,
enabled: Boolean = true,
Expand All @@ -78,7 +79,7 @@ fun BorderButton(
enabledEffect = enabledEffect,
space = space,
onClick = onClick,
shape = CircleShape,
shape = shape,
backgroundColor = backgroundColor,
border = BorderStroke(ButtonDefaults.OutlinedBorderSize, if (enabled) borderColor else borderColor.copy(alpha = 0.4f)),
textStyle = textStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fun FeerateSlider(
}
}

SatoshiSlider(
SatoshiLogSlider(
modifier = Modifier
.widthIn(max = 130.dp)
.offset(x = (-4).dp, y = (-8).dp),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2023 ACINQ SAS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package fr.acinq.phoenix.android.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Slider
import androidx.compose.material.SliderDefaults
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import fr.acinq.bitcoin.Satoshi
import fr.acinq.lightning.utils.sat
import fr.acinq.phoenix.android.R
import fr.acinq.phoenix.android.components.feedback.ErrorMessage
import kotlin.math.log10
import kotlin.math.pow

/** A logarithmic slider to get a Satoshi value. Can be used to get a feerate for example. */
@Composable
fun SatoshiLogSlider(
modifier: Modifier = Modifier,
amount: Satoshi,
onAmountChange: (Satoshi) -> Unit,
minAmount: Satoshi = 1.sat,
maxAmount: Satoshi = 500.sat,
enabled: Boolean = true,
steps: Int = 30,
) {
val context = LocalContext.current
val minAmountLog = remember { log10(minAmount.sat.toFloat()) }
val maxAmountLog = remember { log10(maxAmount.sat.toFloat()) }
var amountLog by remember { mutableStateOf(log10(amount.sat.toFloat())) }

var errorMessage by remember { mutableStateOf("") }

Column(modifier = modifier.enableOrFade(enabled)) {
Slider(
value = amountLog,
onValueChange = {
errorMessage = ""
try {
amountLog = it
val valueSat = 10f.pow(it).toLong().sat
onAmountChange(valueSat)
} catch (e: Exception) {
errorMessage = context.getString(R.string.validation_invalid_number)
}
},
valueRange = minAmountLog..maxAmountLog,
steps = steps,
enabled = enabled,
colors = SliderDefaults.colors(
activeTrackColor = MaterialTheme.colors.primary,
inactiveTrackColor = MaterialTheme.colors.primary.copy(alpha = 0.4f),
activeTickColor = MaterialTheme.colors.primary,
inactiveTickColor = Color.Transparent,
)
)

errorMessage.takeUnless { it.isBlank() }?.let {
Spacer(Modifier.height(4.dp))
ErrorMessage(header = it, padding = PaddingValues(0.dp))
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,49 @@ import androidx.compose.foundation.layout.height
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Slider
import androidx.compose.material.SliderDefaults
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import fr.acinq.bitcoin.Satoshi
import fr.acinq.lightning.utils.sat
import fr.acinq.phoenix.android.R
import fr.acinq.phoenix.android.components.feedback.ErrorMessage
import kotlin.math.log10
import kotlin.math.pow

/** A logarithmic slider to get a Satoshi value. Can be used to get a feerate for example. */
/** A slider to pick a Satoshi value from an array of accepted values. */
@Composable
fun SatoshiSlider(
modifier: Modifier = Modifier,
amount: Satoshi,
onAmountChange: (Satoshi) -> Unit,
minAmount: Satoshi = 1.sat,
maxAmount: Satoshi = 500.sat,
onErrorStateChange: (Boolean) -> Unit,
possibleValues: Array<Satoshi>,
enabled: Boolean = true,
steps: Int = 30,
) {
val context = LocalContext.current
val minFeerateLog = remember { log10(minAmount.sat.toFloat()) }
val maxFeerateLog = remember { log10(maxAmount.sat.toFloat()) }
var feerateLog by remember { mutableStateOf(log10(amount.sat.toFloat())) }

var index by remember { mutableStateOf(1.0f) }
var errorMessage by remember { mutableStateOf("") }

Column(modifier = modifier.enableOrFade(enabled)) {
Slider(
value = feerateLog,
value = index,
onValueChange = {
errorMessage = ""
try {
feerateLog = it
val valueSat = 10f.pow(it).toLong().sat
onAmountChange(valueSat)
index = it
val amountPicked = possibleValues[index.toInt() - 1]
onAmountChange(amountPicked)
onErrorStateChange(false)
} catch (e: Exception) {
errorMessage = context.getString(R.string.validation_invalid_number)
errorMessage = context.getString(R.string.validation_invalid_amount)
onErrorStateChange(true)
}
},
valueRange = minFeerateLog..maxFeerateLog,
steps = steps,
valueRange = 1.0f..possibleValues.size.toFloat(),
steps = possibleValues.size,
enabled = enabled,
colors = SliderDefaults.colors(
activeTrackColor = MaterialTheme.colors.primary,
Expand All @@ -82,4 +80,5 @@ fun SatoshiSlider(
ErrorMessage(header = it, padding = PaddingValues(0.dp))
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ fun Setting(modifier: Modifier = Modifier, title: String, description: String?)
}
}

@Composable
fun Setting(modifier: Modifier = Modifier, title: String, content: @Composable ColumnScope.() -> Unit) {
Column(
modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 12.dp)
) {
Text(title, style = MaterialTheme.typography.body2)
Spacer(modifier = Modifier.height(2.dp))
content()
}
}

@Composable
fun SettingWithCopy(
title: String,
Expand All @@ -56,7 +69,9 @@ fun SettingWithCopy(
) {
val context = LocalContext.current
Row {
Column(modifier = Modifier.padding(start = 16.dp, top = 12.dp, bottom = 12.dp).weight(1f)) {
Column(modifier = Modifier
.padding(start = 16.dp, top = 12.dp, bottom = 12.dp)
.weight(1f)) {
Row {
Text(
text = title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,16 @@ fun SplashLabelRow(
.alignByBaseline(),
) {
Spacer(modifier = Modifier.weight(1f))
if (helpMessage != null) {
IconPopup(modifier = Modifier.offset(y = (-3).dp), popupMessage = helpMessage, spaceLeft = 0.dp, spaceRight = 4.dp)
}

Text(
text = label.uppercase(),
style = MaterialTheme.typography.subtitle1.copy(fontSize = 12.sp, textAlign = TextAlign.End),
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
if (helpMessage != null) {
IconPopup(modifier = Modifier.offset(y = (-3).dp), popupMessage = helpMessage, spaceLeft = 4.dp, spaceRight = 0.dp)
}
if (icon != null) {
Spacer(modifier = Modifier.width(4.dp))
Image(
Expand Down
Loading