Skip to content

Commit 20c4f90

Browse files
committed
(android) Streamline fee warning rules in receive screen
The dialog is displayed more often. A few issues have been fixed as well. An helper method has been added to evaluate when the liquidity request button can be displayed.
1 parent f6c5425 commit 20c4f90

File tree

11 files changed

+77
-69
lines changed

11 files changed

+77
-69
lines changed

phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/home/HomeTopAndBottom.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import fr.acinq.phoenix.android.utils.negativeColor
5151
import fr.acinq.phoenix.android.utils.orange
5252
import fr.acinq.phoenix.android.utils.positiveColor
5353
import fr.acinq.phoenix.android.utils.warningColor
54+
import fr.acinq.phoenix.data.canRequestLiquidity
5455
import fr.acinq.phoenix.managers.Connections
5556

5657
@Composable
@@ -124,7 +125,7 @@ fun TopBar(
124125
}
125126
}
126127
Spacer(modifier = Modifier.weight(1f))
127-
if (!channelsState.isNullOrEmpty()) {
128+
if (channelsState.canRequestLiquidity()) {
128129
BorderButton(
129130
text = stringResource(id = R.string.home_request_liquidity),
130131
icon = R.drawable.ic_bucket,

phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/payments/receive/ReceiveLightningView.kt

+35-44
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ import fr.acinq.lightning.payment.PaymentRequest
6767
import fr.acinq.lightning.utils.msat
6868
import fr.acinq.lightning.utils.toMilliSatoshi
6969
import fr.acinq.phoenix.android.LocalBitcoinUnit
70-
import fr.acinq.phoenix.android.LocalFiatCurrency
7170
import fr.acinq.phoenix.android.R
7271
import fr.acinq.phoenix.android.business
7372
import fr.acinq.phoenix.android.components.AmountInput
@@ -90,6 +89,7 @@ import fr.acinq.phoenix.android.utils.datastore.UserPrefs
9089
import fr.acinq.phoenix.android.utils.logger
9190
import fr.acinq.phoenix.android.utils.share
9291
import fr.acinq.phoenix.data.availableForReceive
92+
import fr.acinq.phoenix.data.canRequestLiquidity
9393
import kotlinx.coroutines.launch
9494
import java.text.DecimalFormat
9595

@@ -322,31 +322,21 @@ private fun EvaluateLiquidityIssuesForPayment(
322322
val context = LocalContext.current
323323

324324
val channelsMap by business.peerManager.channelsFlow.collectAsState()
325-
val availableForReceive = remember(channelsMap) { channelsMap?.availableForReceive() }
325+
val canRequestLiquidity = remember(channelsMap) { channelsMap.canRequestLiquidity() }
326+
val availableForReceive = remember(channelsMap) { channelsMap.availableForReceive() }
326327

327328
val mempoolFeerate by business.appConfigurationManager.mempoolFeerate.collectAsState()
328329
val swapFee = remember(mempoolFeerate) { mempoolFeerate?.swapEstimationFee(hasNoChannels = channelsMap?.values?.filterNot { it.isTerminated }.isNullOrEmpty()) }
329330

330331
val liquidityPolicyPrefs = UserPrefs.getLiquidityPolicy(context).collectAsState(null)
331332

332-
when(val liquidityPolicy = liquidityPolicyPrefs.value) {
333+
when (val liquidityPolicy = liquidityPolicyPrefs.value) {
333334
null -> {}
334335
// when fee policy is disabled, we are more aggressive with the warning (dialog is shown immediately)
335336
is LiquidityPolicy.Disable -> {
336337
when {
337-
// liquidity probably insufficient => the payment MAY fail
338-
availableForReceive != null && amount != null && amount >= availableForReceive -> {
339-
IncomingLiquidityWarning(
340-
header = stringResource(id = R.string.receive_lightning_warning_title_mayfail),
341-
message = stringResource(id = R.string.receive_lightning_warning_fee_policy_disabled_insufficient_liquidity),
342-
onFeeManagementClick = onFeeManagementClick,
343-
showDialogImmediately = !isEditing,
344-
isSevere = true,
345-
useEnablePolicyWording = true,
346-
)
347-
}
348338
// no channels or no liquidity => the payment WILL fail
349-
availableForReceive != null && availableForReceive == 0.msat -> {
339+
availableForReceive == 0.msat || (availableForReceive != null && amount != null && amount >= availableForReceive) -> {
350340
IncomingLiquidityWarning(
351341
header = stringResource(id = R.string.receive_lightning_warning_title_surefail),
352342
message = stringResource(id = R.string.receive_lightning_warning_fee_policy_disabled_insufficient_liquidity),
@@ -372,24 +362,17 @@ private fun EvaluateLiquidityIssuesForPayment(
372362

373363
// fee > limit and there's no liquidity
374364
// => warning that limit should be raised, but not shown immediately
375-
swapFee != null && !liquidityPolicy.skipAbsoluteFeeCheck && swapFee > liquidityPolicy.maxAbsoluteFee && availableForReceive == 0.msat -> {
365+
swapFee != null && !liquidityPolicy.skipAbsoluteFeeCheck && swapFee > liquidityPolicy.maxAbsoluteFee
366+
&& (availableForReceive == 0.msat || (amount != null && availableForReceive != null && amount > availableForReceive)) -> {
376367
IncomingLiquidityWarning(
377368
header = stringResource(id = R.string.receive_lightning_warning_title_surefail),
378-
message = stringResource(id = R.string.receive_lightning_warning_message_above_limit, swapFee.toPrettyString(btcUnit, withUnit = true), liquidityPolicy.maxAbsoluteFee.toPrettyString(btcUnit, withUnit = true)),
379-
onFeeManagementClick = onFeeManagementClick,
380-
showDialogImmediately = !isEditing && swapFee > liquidityPolicy.maxAbsoluteFee * 1.5, // extra aggressive if we know for sure it's going to fail
381-
isSevere = true,
382-
useEnablePolicyWording = false,
383-
)
384-
}
385-
// fee > limit and the amount is above available liquidity
386-
// => strong warning that limit should be raised
387-
swapFee != null && !liquidityPolicy.skipAbsoluteFeeCheck && swapFee > liquidityPolicy.maxAbsoluteFee && amount != null && availableForReceive != null && amount > availableForReceive -> {
388-
IncomingLiquidityWarning(
389-
header = stringResource(id = R.string.receive_lightning_warning_title_mayfail),
390-
message = stringResource(id = R.string.receive_lightning_warning_message_above_limit, swapFee.toPrettyString(btcUnit, withUnit = true), liquidityPolicy.maxAbsoluteFee.toPrettyString(btcUnit, withUnit = true)),
369+
message = if (canRequestLiquidity) {
370+
stringResource(id = R.string.receive_lightning_warning_message_above_limit_or_liquidity, swapFee.toPrettyString(btcUnit, withUnit = true), liquidityPolicy.maxAbsoluteFee.toPrettyString(btcUnit, withUnit = true))
371+
} else {
372+
stringResource(id = R.string.receive_lightning_warning_message_above_limit, swapFee.toPrettyString(btcUnit, withUnit = true), liquidityPolicy.maxAbsoluteFee.toPrettyString(btcUnit, withUnit = true))
373+
},
391374
onFeeManagementClick = onFeeManagementClick,
392-
showDialogImmediately = !isEditing && swapFee > liquidityPolicy.maxAbsoluteFee * 1.5, // extra aggressive if we know for sure it's going to fail,
375+
showDialogImmediately = !isEditing,
393376
isSevere = true,
394377
useEnablePolicyWording = false,
395378
)
@@ -403,12 +386,16 @@ private fun EvaluateLiquidityIssuesForPayment(
403386
// => strong warning that limit should be raised
404387
swapFee != null && amount != null && availableForReceive != null
405388
&& amount > 0.msat && amount > availableForReceive && swapFee.toMilliSatoshi() > amount * liquidityPolicy.maxRelativeFeeBasisPoints / 10_000 -> {
389+
val prettyPercent = DecimalFormat("0.##").format(liquidityPolicy.maxRelativeFeeBasisPoints.toDouble() / 100)
406390
IncomingLiquidityWarning(
407-
header = stringResource(id = R.string.receive_lightning_warning_title_mayfail),
408-
message = stringResource(id = R.string.receive_lightning_warning_message_above_limit_percent, swapFee.toPrettyString(btcUnit, withUnit = true),
409-
DecimalFormat("0.##").format(liquidityPolicy.maxRelativeFeeBasisPoints.toDouble() / 100)),
391+
header = stringResource(id = R.string.receive_lightning_warning_title_surefail),
392+
message = if (canRequestLiquidity) {
393+
stringResource(id = R.string.receive_lightning_warning_message_above_limit_percent_or_liquidity, swapFee.toPrettyString(btcUnit, withUnit = true), prettyPercent)
394+
} else {
395+
stringResource(id = R.string.receive_lightning_warning_message_above_limit_percent, swapFee.toPrettyString(btcUnit, withUnit = true), prettyPercent)
396+
},
410397
onFeeManagementClick = onFeeManagementClick,
411-
showDialogImmediately = !isEditing && swapFee > liquidityPolicy.maxAbsoluteFee * 1.5, // extra aggressive if we know for sure it's going to fail,
398+
showDialogImmediately = !isEditing,
412399
isSevere = true,
413400
useEnablePolicyWording = false,
414401
)
@@ -430,7 +417,7 @@ private fun EvaluateLiquidityIssuesForPayment(
430417
stringResource(id = R.string.receive_lightning_warning_message_fee_expected, swapFee.toPrettyString(btcUnit, withUnit = true))
431418
},
432419
onFeeManagementClick = onFeeManagementClick,
433-
showDialogImmediately = false,
420+
showDialogImmediately = !isEditing,
434421
isSevere = false,
435422
useEnablePolicyWording = false,
436423
)
@@ -446,7 +433,7 @@ private fun EvaluateLiquidityIssuesForPayment(
446433
stringResource(id = R.string.receive_lightning_warning_message_fee_expected, swapFee.toPrettyString(btcUnit, withUnit = true))
447434
},
448435
onFeeManagementClick = onFeeManagementClick,
449-
showDialogImmediately = false,
436+
showDialogImmediately = !isEditing,
450437
isSevere = false,
451438
useEnablePolicyWording = false,
452439
)
@@ -483,9 +470,11 @@ private fun IncomingLiquidityWarning(
483470
contentColor = MaterialTheme.colors.onSurface,
484471
scrimColor = MaterialTheme.colors.onBackground.copy(alpha = 0.1f),
485472
) {
486-
Column(modifier = Modifier
487-
.verticalScroll(rememberScrollState())
488-
.padding(top = 0.dp, start = 24.dp, end = 24.dp, bottom = 50.dp)) {
473+
Column(
474+
modifier = Modifier
475+
.verticalScroll(rememberScrollState())
476+
.padding(top = 0.dp, start = 24.dp, end = 24.dp, bottom = 50.dp)
477+
) {
489478
Text(
490479
text = header,
491480
style = MaterialTheme.typography.h4
@@ -498,11 +487,13 @@ private fun IncomingLiquidityWarning(
498487
horizontalAlignment = Alignment.End
499488
) {
500489
BorderButton(
501-
text = stringResource(id = if (useEnablePolicyWording) {
502-
R.string.receive_lightning_sheet_button_enable
503-
} else {
504-
R.string.receive_lightning_sheet_button_configure
505-
}),
490+
text = stringResource(
491+
id = if (useEnablePolicyWording) {
492+
R.string.receive_lightning_sheet_button_enable
493+
} else {
494+
R.string.receive_lightning_sheet_button_configure
495+
}
496+
),
506497
icon = if (useEnablePolicyWording) R.drawable.ic_tool else R.drawable.ic_plus,
507498
onClick = onFeeManagementClick,
508499
)

phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/settings/fees/LiquidityPolicyView.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import fr.acinq.phoenix.android.utils.logger
5050
import fr.acinq.phoenix.android.utils.negativeColor
5151
import fr.acinq.phoenix.data.BitcoinUnit
5252
import fr.acinq.phoenix.data.MempoolFeerate
53+
import fr.acinq.phoenix.data.canRequestLiquidity
5354
import kotlinx.coroutines.launch
5455

5556
@OptIn(ExperimentalComposeUiApi::class)
@@ -158,7 +159,7 @@ fun LiquidityPolicyView(
158159
}
159160

160161
val channelsState by business.peerManager.channelsFlow.collectAsState()
161-
if (!channelsState.isNullOrEmpty()) {
162+
if (channelsState.canRequestLiquidity()) {
162163
Card(modifier = Modifier.fillMaxWidth()) {
163164
Button(
164165
text = stringResource(id = R.string.liquiditypolicy_request_button),

phoenix-android/src/main/res/values-b+es+419/important_strings.xml

+4-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107
<!-- receive view: warning about fee/liquidity -->
108108

109109
<string name="receive_lightning_warning_title_surefail">El pago no se realizará</string>
110-
<string name="receive_lightning_warning_title_mayfail">Es posible que no se realice el pago</string>
111110
<string name="receive_lightning_warning_title_fee_expected">Comisión prevista</string>
112111

113112
<string name="receive_lightning_warning_hint_show_details">Más información</string>
@@ -119,8 +118,10 @@
119118
<string name="receive_lightning_warning_message_fee_expected">Probablemente será necesaria una transacción en la cadena para recibir esta cantidad.\n\nLas comisiones serán de aproximadamente %1$s.</string>
120119
<string name="receive_lightning_warning_message_fee_expected_unknown">Probablemente será necesaria una transacción en la cadena para recibir esta cantidad.</string>
121120

122-
<string name="receive_lightning_warning_message_above_limit">Se estima una comisión de %1$s por recibir este importe, y esta comisión excede su límite autorizado de %2$s.\n\nAumente este límite o solicite liquidez adicional.</string>
123-
<string name="receive_lightning_warning_message_above_limit_percent">Se estiman unas comisiones de %1$s para recibir este importe, y estas comisiones superan el %2$s%% del importe.\n\nAumente este límite o solicite liquidez adicional..</string>
121+
<string name="receive_lightning_warning_message_above_limit">Se estima una comisión de %1$s por recibir este importe, y esta comisión excede su límite autorizado de %2$s.\n\nAumenta este límite en los ajustes de gestión de canales.</string>
122+
<string name="receive_lightning_warning_message_above_limit_or_liquidity">Se estima una comisión de %1$s por recibir este importe, y esta comisión excede su límite autorizado de %2$s.\n\nAumente este límite o solicite liquidez adicional.</string>
123+
<string name="receive_lightning_warning_message_above_limit_percent">Se estiman unas comisiones de %1$s para recibir este importe, y estas comisiones superan el %2$s%% del importe.\n\nAumenta este límite en los ajustes de gestión de canales.</string>
124+
<string name="receive_lightning_warning_message_above_limit_percent_or_liquidity">Se estiman unas comisiones de %1$s para recibir este importe, y estas comisiones superan el %2$s%% del importe.\n\nAumente este límite o solicite liquidez adicional.</string>
124125

125126
<string name="receive_lightning_warning_fee_policy_disabled_insufficient_liquidity">La liquidez entrante es insuficiente y tienes desactivada la gestión automatizada de canales.</string>
126127

phoenix-android/src/main/res/values-cs/important_strings.xml

+5-3
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@
110110
<!-- receive view: warning about fee/liquidity -->
111111

112112
<string name="receive_lightning_warning_title_surefail">Platba se nezdaří</string>
113-
<string name="receive_lightning_warning_title_mayfail">Platba může selhat</string>
114113
<string name="receive_lightning_warning_title_fee_expected">Očekávaný poplatek</string>
114+
<string name="receive_lightning_warning_hint_show_details">Více informací</string>
115115

116116
<string name="receive_lightning_sheet_dismiss">Zavření</string>
117117
<string name="receive_lightning_sheet_button_enable">Povolit automatické kanály</string>
@@ -120,8 +120,10 @@
120120
<string name="receive_lightning_warning_message_fee_expected">Pro příjem této částky bude pravděpodobně nutná operace v řetězci.\n\nPoplatek se odhaduje na přibližně %1$s.</string>
121121
<string name="receive_lightning_warning_message_fee_expected_unknown">Pro obdržení této částky bude pravděpodobně nutná operace na řetězci.</string>
122122

123-
<string name="receive_lightning_warning_message_above_limit">Pro obdržení této částky se očekává poplatek ve výši %1$s a tento poplatek je vyšší než váš limit %2$s.\n\nZvýšte tento limit v nastavení správy kanálů nebo požádejte o dodatečnou likviditu.</string>
124-
<string name="receive_lightning_warning_message_above_limit_percent">Očekává se, že tuto částku obdrží poplatek ve výši %1$s, a tento poplatek je vyšší než %2$s% částky.\n\nZvýšte tento limit v nastavení správy kanálů, nebo požádejte o dodatečnou likviditu.</string>
123+
<string name="receive_lightning_warning_message_above_limit">Pro obdržení této částky se očekává poplatek ve výši %1$s a tento poplatek je vyšší než váš limit %2$s.\n\nZvyšte tento limit v nastavení správy kanálů.</string>
124+
<string name="receive_lightning_warning_message_above_limit_or_liquidity">Pro obdržení této částky se očekává poplatek ve výši %1$s a tento poplatek je vyšší než váš limit %2$s.\n\nZvýšte tento limit v nastavení správy kanálů nebo požádejte o dodatečnou likviditu.</string>
125+
<string name="receive_lightning_warning_message_above_limit_percent">Očekává se, že tuto částku obdrží poplatek ve výši %1$s, a tento poplatek je vyšší než %2$s% částky.\n\nZvyšte tento limit v nastavení správy kanálů.</string>
126+
<string name="receive_lightning_warning_message_above_limit_percent_or_liquidity">Očekává se, že tuto částku obdrží poplatek ve výši %1$s, a tento poplatek je vyšší než %2$s% částky.\n\nZvýšte tento limit v nastavení správy kanálů, nebo požádejte o dodatečnou likviditu.</string>
125127

126128
<string name="receive_lightning_warning_fee_policy_disabled_insufficient_liquidity">Příchozí likvidita není dostatečná a máte zakázanou automatickou správu kanálů.</string>
127129

0 commit comments

Comments
 (0)