-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support new on-the-fly funding (#632)
Now using lightning-kmp 1.8.0. - Updated the liquidity policy (see NodeParamsManager). We are using a policy that does not target additional liquidity and that does not use fee credit yet. - Updated the received-with database object with new types - Updated the liquidity-purchase database objects with new purchase & payment-details types. The lease data are now legacy and are removed wherever possible. - Updated the iOS and Android payment screens for liquidity purchases. Liquidity events are now stored as separate payments. These payments may be linked to incoming payments, if so a button is added in the liquidity screen to navigate to these payments. - (android) Completed the Portuguese (BR) translation. --------- Co-authored-by: Robbie Hanson <304604+robbiehanson@users.noreply.github.com>
1 parent
46397f8
commit 5fbe04e
Showing
124 changed files
with
4,417 additions
and
2,165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/components/BottomSheetDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright 2024 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.ColumnScope | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.ModalBottomSheet | ||
import androidx.compose.material3.rememberModalBottomSheetState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun BottomSheetDialog( | ||
onDismiss: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
skipPartiallyExpanded: Boolean = true, | ||
horizontalAlignment: Alignment.Horizontal = Alignment.Start, | ||
scrimAlpha: Float = 0.2f, | ||
internalPadding: PaddingValues = PaddingValues(top = 0.dp, start = 20.dp, end = 20.dp, bottom = 64.dp), | ||
content: @Composable ColumnScope.() -> Unit, | ||
) { | ||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded) | ||
ModalBottomSheet( | ||
sheetState = sheetState, | ||
onDismissRequest = { | ||
// executed when user click outside the sheet, and after sheet has been hidden thru state. | ||
onDismiss() | ||
}, | ||
modifier = modifier, | ||
containerColor = MaterialTheme.colors.surface, | ||
contentColor = MaterialTheme.colors.onSurface, | ||
scrimColor = MaterialTheme.colors.onBackground.copy(alpha = scrimAlpha), | ||
) { | ||
Column( | ||
horizontalAlignment = horizontalAlignment, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.fillMaxHeight() | ||
.verticalScroll(rememberScrollState()) | ||
.padding(internalPadding) | ||
) { | ||
content() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
880 changes: 0 additions & 880 deletions
880
...oid/src/main/kotlin/fr/acinq/phoenix/android/payments/details/PaymentDetailsSplashView.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
417 changes: 417 additions & 0 deletions
417
...d/src/main/kotlin/fr/acinq/phoenix/android/payments/details/splash/PaymentSplashStatus.kt
Large diffs are not rendered by default.
Oops, something went wrong.
234 changes: 234 additions & 0 deletions
234
...oid/src/main/kotlin/fr/acinq/phoenix/android/payments/details/splash/PaymentSplashView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
/* | ||
* Copyright 2024 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.payments.details.splash | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.ModalBottomSheet | ||
import androidx.compose.material3.rememberModalBottomSheetState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.font.FontStyle | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import fr.acinq.lightning.db.ChannelCloseOutgoingPayment | ||
import fr.acinq.lightning.db.InboundLiquidityOutgoingPayment | ||
import fr.acinq.lightning.db.IncomingPayment | ||
import fr.acinq.lightning.db.LightningOutgoingPayment | ||
import fr.acinq.lightning.db.OutgoingPayment | ||
import fr.acinq.lightning.db.SpliceCpfpOutgoingPayment | ||
import fr.acinq.lightning.db.SpliceOutgoingPayment | ||
import fr.acinq.lightning.wire.LiquidityAds | ||
import fr.acinq.phoenix.android.R | ||
import fr.acinq.phoenix.android.components.AmountView | ||
import fr.acinq.phoenix.android.components.BorderButton | ||
import fr.acinq.phoenix.android.components.Button | ||
import fr.acinq.phoenix.android.components.DefaultScreenHeader | ||
import fr.acinq.phoenix.android.components.PrimarySeparator | ||
import fr.acinq.phoenix.android.components.SplashClickableContent | ||
import fr.acinq.phoenix.android.components.SplashLabelRow | ||
import fr.acinq.phoenix.android.components.SplashLayout | ||
import fr.acinq.phoenix.android.components.TextInput | ||
import fr.acinq.phoenix.android.components.TextWithIcon | ||
import fr.acinq.phoenix.android.utils.borderColor | ||
import fr.acinq.phoenix.android.utils.mutedBgColor | ||
import fr.acinq.phoenix.android.utils.negativeColor | ||
import fr.acinq.phoenix.android.utils.positiveColor | ||
import fr.acinq.phoenix.data.WalletPaymentId | ||
import fr.acinq.phoenix.data.WalletPaymentInfo | ||
import fr.acinq.phoenix.utils.extensions.WalletPaymentState | ||
import fr.acinq.phoenix.utils.extensions.state | ||
|
||
@Composable | ||
fun PaymentDetailsSplashView( | ||
onBackClick: () -> Unit, | ||
data: WalletPaymentInfo, | ||
onDetailsClick: (WalletPaymentId) -> Unit, | ||
onMetadataDescriptionUpdate: (WalletPaymentId, String?) -> Unit, | ||
fromEvent: Boolean, | ||
) { | ||
val payment = data.payment | ||
SplashLayout( | ||
header = { DefaultScreenHeader(onBackClick = onBackClick) }, | ||
topContent = { PaymentStatus(data.payment, fromEvent, onCpfpSuccess = onBackClick) } | ||
) { | ||
if (payment is InboundLiquidityOutgoingPayment && payment.purchase.paymentDetails is LiquidityAds.PaymentDetails.FromFutureHtlc) { | ||
Unit | ||
} else { | ||
AmountView( | ||
amount = when (payment) { | ||
is InboundLiquidityOutgoingPayment -> payment.amount | ||
is OutgoingPayment -> payment.amount - payment.fees | ||
is IncomingPayment -> payment.amount | ||
}, | ||
amountTextStyle = MaterialTheme.typography.body1.copy(fontSize = 30.sp), | ||
separatorSpace = 4.dp, | ||
prefix = stringResource(id = if (payment is OutgoingPayment) R.string.paymentline_prefix_sent else R.string.paymentline_prefix_received) | ||
) | ||
Spacer(modifier = Modifier.height(36.dp)) | ||
PrimarySeparator( | ||
height = 6.dp, | ||
color = when (payment.state()) { | ||
WalletPaymentState.Failure -> negativeColor | ||
WalletPaymentState.SuccessOffChain, WalletPaymentState.SuccessOnChain -> positiveColor | ||
else -> mutedBgColor | ||
} | ||
) | ||
} | ||
Spacer(modifier = Modifier.height(36.dp)) | ||
|
||
when (payment) { | ||
is IncomingPayment -> SplashIncoming(payment = payment, metadata = data.metadata, onMetadataDescriptionUpdate = onMetadataDescriptionUpdate) | ||
is LightningOutgoingPayment -> SplashLightningOutgoing(payment = payment, metadata = data.metadata, onMetadataDescriptionUpdate = onMetadataDescriptionUpdate) | ||
is ChannelCloseOutgoingPayment -> SplashChannelClose(payment = payment, metadata = data.metadata, onMetadataDescriptionUpdate = onMetadataDescriptionUpdate) | ||
is SpliceCpfpOutgoingPayment -> SplashSpliceOutCpfp(payment = payment, metadata = data.metadata, onMetadataDescriptionUpdate = onMetadataDescriptionUpdate) | ||
is SpliceOutgoingPayment -> SplashSpliceOut(payment = payment, metadata = data.metadata, onMetadataDescriptionUpdate = onMetadataDescriptionUpdate) | ||
is InboundLiquidityOutgoingPayment -> SplashLiquidityPurchase(payment = payment) | ||
} | ||
|
||
Spacer(modifier = Modifier.height(48.dp)) | ||
BorderButton( | ||
text = stringResource(id = R.string.paymentdetails_details_button), | ||
borderColor = borderColor, | ||
textStyle = MaterialTheme.typography.caption, | ||
icon = R.drawable.ic_tool, | ||
iconTint = MaterialTheme.typography.caption.color, | ||
onClick = { onDetailsClick(data.id()) }, | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
fun SplashDescription( | ||
description: String?, | ||
userDescription: String?, | ||
paymentId: WalletPaymentId, | ||
onMetadataDescriptionUpdate: (WalletPaymentId, String?) -> Unit, | ||
) { | ||
var showEditDescriptionDialog by remember { mutableStateOf(false) } | ||
|
||
Spacer(modifier = Modifier.height(8.dp)) | ||
if (!(description.isNullOrBlank() && !userDescription.isNullOrBlank())) { | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_desc_label)) { | ||
if (description.isNullOrBlank()) { | ||
Text( | ||
text = stringResource(id = R.string.paymentdetails_no_description), | ||
style = MaterialTheme.typography.caption.copy(fontStyle = FontStyle.Italic) | ||
) | ||
} else { | ||
Text(text = description) | ||
} | ||
} | ||
} | ||
SplashLabelRow(label = if (userDescription.isNullOrBlank()) "" else stringResource(id = R.string.paymentdetails_note_label)) { | ||
SplashClickableContent(onClick = { showEditDescriptionDialog = true }) { | ||
if (!userDescription.isNullOrBlank()) { | ||
Text(text = userDescription) | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
} | ||
TextWithIcon( | ||
text = stringResource( | ||
id = when (userDescription) { | ||
null -> R.string.paymentdetails_attach_desc_button | ||
else -> R.string.paymentdetails_edit_desc_button | ||
} | ||
), | ||
textStyle = MaterialTheme.typography.subtitle2, | ||
icon = R.drawable.ic_edit, | ||
iconTint = MaterialTheme.typography.subtitle2.color, | ||
space = 6.dp, | ||
) | ||
} | ||
} | ||
|
||
if (showEditDescriptionDialog) { | ||
CustomNoteDialog( | ||
initialDescription = userDescription, | ||
onConfirm = { | ||
onMetadataDescriptionUpdate(paymentId, it?.trim()?.takeIf { it.isNotBlank() }) | ||
showEditDescriptionDialog = false | ||
}, | ||
onDismiss = { showEditDescriptionDialog = false } | ||
) | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
private fun CustomNoteDialog( | ||
initialDescription: String?, | ||
onConfirm: (String?) -> Unit, | ||
onDismiss: () -> Unit | ||
) { | ||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = false) | ||
var description by rememberSaveable { mutableStateOf(initialDescription) } | ||
|
||
ModalBottomSheet( | ||
sheetState = sheetState, | ||
onDismissRequest = onDismiss, | ||
containerColor = MaterialTheme.colors.surface, | ||
contentColor = MaterialTheme.colors.onSurface, | ||
scrimColor = MaterialTheme.colors.onBackground.copy(alpha = 0.1f), | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.verticalScroll(rememberScrollState()) | ||
.padding(top = 0.dp, start = 24.dp, end = 24.dp, bottom = 70.dp), | ||
) { | ||
Text(text = stringResource(id = R.string.paymentdetails_edit_dialog_title), style = MaterialTheme.typography.body2) | ||
Spacer(modifier = Modifier.height(16.dp)) | ||
TextInput( | ||
modifier = Modifier.fillMaxWidth(), | ||
text = description ?: "", | ||
onTextChange = { description = it.takeIf { it.isNotBlank() } }, | ||
minLines = 2, | ||
maxLines = 6, | ||
maxChars = 280, | ||
staticLabel = stringResource(id = R.string.paymentdetails_edit_dialog_input_label) | ||
) | ||
Spacer(modifier = Modifier.height(24.dp)) | ||
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) { | ||
Button(onClick = onDismiss, text = stringResource(id = R.string.btn_cancel), shape = CircleShape) | ||
Button( | ||
onClick = { onConfirm(description) }, | ||
text = stringResource(id = R.string.btn_save), | ||
icon = R.drawable.ic_check, | ||
enabled = description != initialDescription, | ||
space = 8.dp, | ||
shape = CircleShape | ||
) | ||
} | ||
} | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...id/src/main/kotlin/fr/acinq/phoenix/android/payments/details/splash/SplashChannelClose.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2024 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.payments.details.splash | ||
|
||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.text.selection.SelectionContainer | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import fr.acinq.lightning.db.ChannelCloseOutgoingPayment | ||
import fr.acinq.lightning.utils.msat | ||
import fr.acinq.phoenix.android.LocalBitcoinUnit | ||
import fr.acinq.phoenix.android.R | ||
import fr.acinq.phoenix.android.business | ||
import fr.acinq.phoenix.android.components.SplashLabelRow | ||
import fr.acinq.phoenix.android.utils.Converter.toPrettyString | ||
import fr.acinq.phoenix.android.utils.MSatDisplayPolicy | ||
import fr.acinq.phoenix.android.utils.isLegacyMigration | ||
import fr.acinq.phoenix.android.utils.smartDescription | ||
import fr.acinq.phoenix.data.WalletPaymentId | ||
import fr.acinq.phoenix.data.WalletPaymentMetadata | ||
import fr.acinq.phoenix.data.walletPaymentId | ||
|
||
@Composable | ||
fun SplashChannelClose( | ||
payment: ChannelCloseOutgoingPayment, | ||
metadata: WalletPaymentMetadata, | ||
onMetadataDescriptionUpdate: (WalletPaymentId, String?) -> Unit, | ||
) { | ||
val peer by business.peerManager.peerState.collectAsState() | ||
|
||
val isLegacyMigration = payment.isLegacyMigration(metadata, peer) | ||
val description = when (isLegacyMigration) { | ||
null -> stringResource(id = R.string.paymentdetails_desc_closing_channel) // not sure yet, but we still know it's a closing | ||
true -> stringResource(id = R.string.paymentdetails_desc_legacy_migration) | ||
false -> payment.smartDescription() | ||
} | ||
|
||
SplashDescription( | ||
description = description, | ||
userDescription = metadata.userDescription, | ||
paymentId = payment.walletPaymentId(), | ||
onMetadataDescriptionUpdate = onMetadataDescriptionUpdate | ||
) | ||
SplashDestination(payment, metadata) | ||
SplashFee(payment = payment) | ||
} | ||
|
||
@Composable | ||
private fun SplashDestination(payment: ChannelCloseOutgoingPayment, metadata: WalletPaymentMetadata) { | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_destination_label), icon = R.drawable.ic_chain) { | ||
SelectionContainer { | ||
Text(text = payment.address) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun SplashFee(payment: ChannelCloseOutgoingPayment) { | ||
val btcUnit = LocalBitcoinUnit.current | ||
if (payment.fees > 0.msat) { | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_fees_label)) { | ||
Text(text = payment.fees.toPrettyString(btcUnit, withUnit = true, mSatDisplayPolicy = MSatDisplayPolicy.SHOW_IF_ZERO_SATS)) | ||
} | ||
} | ||
} |
156 changes: 156 additions & 0 deletions
156
...ndroid/src/main/kotlin/fr/acinq/phoenix/android/payments/details/splash/SplashIncoming.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
* Copyright 2024 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.payments.details.splash | ||
|
||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.produceState | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import fr.acinq.bitcoin.PublicKey | ||
import fr.acinq.lightning.db.IncomingPayment | ||
import fr.acinq.lightning.utils.msat | ||
import fr.acinq.lightning.utils.sat | ||
import fr.acinq.lightning.utils.sum | ||
import fr.acinq.lightning.utils.toMilliSatoshi | ||
import fr.acinq.phoenix.android.LocalBitcoinUnit | ||
import fr.acinq.phoenix.android.R | ||
import fr.acinq.phoenix.android.business | ||
import fr.acinq.phoenix.android.components.SplashLabelRow | ||
import fr.acinq.phoenix.android.components.contact.ContactCompactView | ||
import fr.acinq.phoenix.android.components.contact.OfferContactState | ||
import fr.acinq.phoenix.android.utils.Converter.toPrettyString | ||
import fr.acinq.phoenix.android.utils.MSatDisplayPolicy | ||
import fr.acinq.phoenix.android.utils.smartDescription | ||
import fr.acinq.phoenix.data.WalletPaymentId | ||
import fr.acinq.phoenix.data.WalletPaymentMetadata | ||
import fr.acinq.phoenix.data.walletPaymentId | ||
import fr.acinq.phoenix.utils.extensions.incomingOfferMetadata | ||
|
||
@Composable | ||
fun SplashIncoming( | ||
payment: IncomingPayment, | ||
metadata: WalletPaymentMetadata, | ||
onMetadataDescriptionUpdate: (WalletPaymentId, String?) -> Unit, | ||
) { | ||
payment.incomingOfferMetadata()?.let { meta -> | ||
meta.payerNote?.takeIf { it.isNotBlank() }?.let { | ||
OfferPayerNote(payerNote = it) | ||
} | ||
OfferSentBy(payerPubkey = meta.payerKey, !meta.payerNote.isNullOrBlank()) | ||
} | ||
|
||
SplashDescription( | ||
description = payment.smartDescription(), | ||
userDescription = metadata.userDescription, | ||
paymentId = payment.walletPaymentId(), | ||
onMetadataDescriptionUpdate = onMetadataDescriptionUpdate, | ||
) | ||
SplashFee(payment) | ||
} | ||
|
||
@Composable | ||
fun OfferPayerNote(payerNote: String) { | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_offer_note_label)) { | ||
Text(text = payerNote) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun OfferSentBy(payerPubkey: PublicKey?, hasPayerNote: Boolean) { | ||
val contactsManager = business.contactsManager | ||
val contactState = remember { mutableStateOf<OfferContactState>(OfferContactState.Init) } | ||
LaunchedEffect(Unit) { | ||
contactState.value = payerPubkey?.let { | ||
contactsManager.getContactForPayerPubkey(it) | ||
}?.let { OfferContactState.Found(it) } ?: OfferContactState.NotFound | ||
} | ||
|
||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_offer_sender_label)) { | ||
when (val res = contactState.value) { | ||
is OfferContactState.Init -> Text(text = stringResource(id = R.string.utils_loading_data)) | ||
is OfferContactState.NotFound -> { | ||
Text(text = stringResource(id = R.string.paymentdetails_offer_sender_unknown)) | ||
if (hasPayerNote) { | ||
Spacer(modifier = Modifier.height(4.dp)) | ||
Text(text = stringResource(id = R.string.paymentdetails_offer_sender_unknown_details), style = MaterialTheme.typography.subtitle2) | ||
} | ||
} | ||
is OfferContactState.Found -> { | ||
ContactCompactView( | ||
contact = res.contact, | ||
currentOffer = null, | ||
onContactChange = { contactState.value = if (it == null) OfferContactState.NotFound else OfferContactState.Found(it) }, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun SplashFee( | ||
payment: IncomingPayment | ||
) { | ||
val btcUnit = LocalBitcoinUnit.current | ||
val receivedWithOnChain = remember(payment) { payment.received?.receivedWith?.filterIsInstance<IncomingPayment.ReceivedWith.OnChainIncomingPayment>() ?: emptyList() } | ||
val receivedWithLightning = remember(payment) { payment.received?.receivedWith?.filterIsInstance<IncomingPayment.ReceivedWith.LightningPayment>() ?: emptyList() } | ||
|
||
if (receivedWithOnChain.isNotEmpty() || receivedWithLightning.isNotEmpty()) { | ||
|
||
val paymentsManager = business.paymentsManager | ||
val txIds = remember(receivedWithLightning) { receivedWithLightning.mapNotNull { it.fundingFee?.fundingTxId } } | ||
val relatedLiquidityPayments by produceState(initialValue = emptyList()) { | ||
value = txIds.mapNotNull { paymentsManager.getLiquidityPurchaseForTxId(it) } | ||
} | ||
|
||
val serviceFee = remember(receivedWithOnChain, relatedLiquidityPayments) { | ||
receivedWithOnChain.map { it.serviceFee }.sum() + relatedLiquidityPayments.map { it.feePaidFromFutureHtlc.serviceFee.toMilliSatoshi() }.sum() | ||
} | ||
val miningFee = remember(receivedWithOnChain, relatedLiquidityPayments) { | ||
receivedWithOnChain.map { it.miningFee }.sum() + relatedLiquidityPayments.map { it.feePaidFromFutureHtlc.miningFee }.sum() | ||
} | ||
|
||
Spacer(modifier = Modifier.height(8.dp)) | ||
if (serviceFee > 0.msat) { | ||
SplashLabelRow( | ||
label = stringResource(id = R.string.paymentdetails_service_fees_label), | ||
helpMessage = stringResource(R.string.paymentdetails_service_fees_desc) | ||
) { | ||
Text(text = serviceFee.toPrettyString(btcUnit, withUnit = true, mSatDisplayPolicy = MSatDisplayPolicy.SHOW)) | ||
} | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
} | ||
|
||
if (miningFee > 0.sat) { | ||
SplashLabelRow( | ||
label = stringResource(id = R.string.paymentdetails_funding_fees_label), | ||
helpMessage = stringResource(R.string.paymentdetails_funding_fees_desc) | ||
) { | ||
Text(text = miningFee.toPrettyString(btcUnit, withUnit = true, mSatDisplayPolicy = MSatDisplayPolicy.HIDE)) | ||
} | ||
} | ||
} | ||
} |
235 changes: 235 additions & 0 deletions
235
...id/src/main/kotlin/fr/acinq/phoenix/android/payments/details/splash/SplashLightningOut.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,235 @@ | ||
/* | ||
* Copyright 2024 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.payments.details.splash | ||
|
||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.text.selection.SelectionContainer | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.produceState | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import fr.acinq.bitcoin.utils.Either | ||
import fr.acinq.lightning.db.LightningOutgoingPayment | ||
import fr.acinq.lightning.payment.FinalFailure | ||
import fr.acinq.lightning.payment.OutgoingPaymentFailure | ||
import fr.acinq.phoenix.android.LocalBitcoinUnit | ||
import fr.acinq.phoenix.android.R | ||
import fr.acinq.phoenix.android.components.ProgressView | ||
import fr.acinq.phoenix.android.components.SplashLabelRow | ||
import fr.acinq.phoenix.android.components.WebLink | ||
import fr.acinq.phoenix.android.components.contact.ContactOrOfferView | ||
import fr.acinq.phoenix.android.utils.Converter.toPrettyString | ||
import fr.acinq.phoenix.android.utils.MSatDisplayPolicy | ||
import fr.acinq.phoenix.android.utils.smartDescription | ||
import fr.acinq.phoenix.data.LnurlPayMetadata | ||
import fr.acinq.phoenix.data.WalletPaymentId | ||
import fr.acinq.phoenix.data.WalletPaymentMetadata | ||
import fr.acinq.phoenix.data.lnurl.LnurlPay | ||
import fr.acinq.phoenix.data.walletPaymentId | ||
import fr.acinq.phoenix.utils.extensions.WalletPaymentState | ||
import fr.acinq.phoenix.utils.extensions.outgoingInvoiceRequest | ||
import fr.acinq.phoenix.utils.extensions.state | ||
import io.ktor.http.Url | ||
import javax.crypto.Cipher | ||
import javax.crypto.spec.IvParameterSpec | ||
import javax.crypto.spec.SecretKeySpec | ||
|
||
@Composable | ||
fun SplashLightningOutgoing( | ||
payment: LightningOutgoingPayment, | ||
metadata: WalletPaymentMetadata, | ||
onMetadataDescriptionUpdate: (WalletPaymentId, String?) -> Unit, | ||
) { | ||
metadata.lnurl?.let { lnurlMeta -> | ||
LnurlPayInfoView(payment, lnurlMeta) | ||
} | ||
|
||
payment.outgoingInvoiceRequest()?.payerNote?.takeIf { it.isNotBlank() }?.let { | ||
OfferPayerNote(payerNote = it) | ||
} | ||
|
||
SplashDescription( | ||
description = payment.smartDescription(), | ||
userDescription = metadata.userDescription, | ||
paymentId = payment.walletPaymentId(), | ||
onMetadataDescriptionUpdate = onMetadataDescriptionUpdate | ||
) | ||
SplashDestination(payment, metadata) | ||
SplashFee(payment = payment) | ||
|
||
(payment.status as? LightningOutgoingPayment.Status.Completed.Failed)?.let { status -> | ||
PaymentErrorView(status = status, failedParts = payment.parts.map { it.status }.filterIsInstance<LightningOutgoingPayment.Part.Status.Failed>()) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun SplashDestination(payment: LightningOutgoingPayment, metadata: WalletPaymentMetadata) { | ||
val lnId = metadata.lnurl?.pay?.metadata?.lnid?.takeIf { it.isNotBlank() } | ||
if (lnId != null) { | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_destination_label), icon = R.drawable.ic_zap) { | ||
SelectionContainer { | ||
Text(text = lnId) | ||
} | ||
} | ||
} | ||
val details = payment.details | ||
if (details is LightningOutgoingPayment.Details.Blinded) { | ||
val offer = details.paymentRequest.invoiceRequest.offer | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_destination_label)) { | ||
ContactOrOfferView(offer = offer) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun SplashFee(payment: LightningOutgoingPayment) { | ||
val btcUnit = LocalBitcoinUnit.current | ||
if (payment.state() == WalletPaymentState.SuccessOffChain) { | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_fees_label)) { | ||
Text(text = payment.fees.toPrettyString(btcUnit, withUnit = true, mSatDisplayPolicy = MSatDisplayPolicy.SHOW_IF_ZERO_SATS)) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun LnurlPayInfoView(payment: LightningOutgoingPayment, metadata: LnurlPayMetadata) { | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_lnurlpay_service)) { | ||
SelectionContainer { | ||
Text(text = metadata.pay.callback.host) | ||
} | ||
} | ||
metadata.successAction?.let { | ||
LnurlSuccessAction(payment = payment, action = it) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun LnurlSuccessAction(payment: LightningOutgoingPayment, action: LnurlPay.Invoice.SuccessAction) { | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
when (action) { | ||
is LnurlPay.Invoice.SuccessAction.Message -> { | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_lnurlpay_action_message_label)) { | ||
SelectionContainer { | ||
Text(text = action.message) | ||
} | ||
} | ||
} | ||
is LnurlPay.Invoice.SuccessAction.Url -> { | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_lnurlpay_action_url_label)) { | ||
Text(text = action.description) | ||
WebLink(text = stringResource(id = R.string.paymentdetails_lnurlpay_action_url_button), url = action.url.toString()) | ||
} | ||
} | ||
is LnurlPay.Invoice.SuccessAction.Aes -> { | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_lnurlpay_action_aes_label)) { | ||
val status = payment.status | ||
if (status is LightningOutgoingPayment.Status.Completed.Succeeded.OffChain) { | ||
val deciphered by produceState<String?>(initialValue = null) { | ||
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding") | ||
cipher.init(Cipher.DECRYPT_MODE, SecretKeySpec(status.preimage.toByteArray(), "AES"), IvParameterSpec(action.iv.toByteArray())) | ||
value = String(cipher.doFinal(action.ciphertext.toByteArray()), Charsets.UTF_8) | ||
} | ||
Text(text = action.description) | ||
when (deciphered) { | ||
null -> ProgressView(text = stringResource(id = R.string.paymentdetails_lnurlpay_action_aes_decrypting), padding = PaddingValues(0.dp)) | ||
else -> { | ||
val url = try { | ||
Url(deciphered!!) | ||
} catch (e: Exception) { | ||
null | ||
} | ||
if (url != null) { | ||
WebLink(text = stringResource(id = R.string.paymentdetails_lnurlpay_action_url_button), url = url.toString()) | ||
} else { | ||
SelectionContainer { | ||
Text(text = deciphered!!) | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
Text(text = stringResource(id = R.string.paymentdetails_lnurlpay_action_aes_decrypting)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun PaymentErrorView(status: LightningOutgoingPayment.Status.Completed.Failed, failedParts: List<LightningOutgoingPayment.Part.Status.Failed>) { | ||
val failure = remember(status, failedParts) { OutgoingPaymentFailure(status.reason, failedParts) } | ||
translatePaymentError(failure).let { | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_error_label)) { | ||
Text(text = it) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun translatePaymentError(paymentFailure: OutgoingPaymentFailure): String { | ||
val context = LocalContext.current | ||
val errorMessage = remember(key1 = paymentFailure) { | ||
when (val result = paymentFailure.explain()) { | ||
is Either.Left -> { | ||
when (val partFailure = result.value) { | ||
is LightningOutgoingPayment.Part.Status.Failure.Uninterpretable -> partFailure.message | ||
LightningOutgoingPayment.Part.Status.Failure.ChannelIsClosing -> context.getString(R.string.outgoing_failuremessage_channel_closing) | ||
LightningOutgoingPayment.Part.Status.Failure.ChannelIsSplicing -> context.getString(R.string.outgoing_failuremessage_channel_splicing) | ||
LightningOutgoingPayment.Part.Status.Failure.NotEnoughFees -> context.getString(R.string.outgoing_failuremessage_not_enough_fee) | ||
LightningOutgoingPayment.Part.Status.Failure.NotEnoughFunds -> context.getString(R.string.outgoing_failuremessage_not_enough_balance) | ||
LightningOutgoingPayment.Part.Status.Failure.PaymentAmountTooBig -> context.getString(R.string.outgoing_failuremessage_too_big) | ||
LightningOutgoingPayment.Part.Status.Failure.PaymentAmountTooSmall -> context.getString(R.string.outgoing_failuremessage_too_small) | ||
LightningOutgoingPayment.Part.Status.Failure.PaymentExpiryTooBig -> context.getString(R.string.outgoing_failuremessage_expiry_too_big) | ||
LightningOutgoingPayment.Part.Status.Failure.RecipientRejectedPayment -> context.getString(R.string.outgoing_failuremessage_rejected_by_recipient) | ||
LightningOutgoingPayment.Part.Status.Failure.RecipientIsOffline -> context.getString(R.string.outgoing_failuremessage_recipient_offline) | ||
LightningOutgoingPayment.Part.Status.Failure.RecipientLiquidityIssue -> context.getString(R.string.outgoing_failuremessage_not_enough_liquidity) | ||
LightningOutgoingPayment.Part.Status.Failure.TemporaryRemoteFailure -> context.getString(R.string.outgoing_failuremessage_temporary_failure) | ||
LightningOutgoingPayment.Part.Status.Failure.TooManyPendingPayments -> context.getString(R.string.outgoing_failuremessage_too_many_pending) | ||
} | ||
} | ||
is Either.Right -> { | ||
when (result.value) { | ||
FinalFailure.InvalidPaymentId -> context.getString(R.string.outgoing_failuremessage_invalid_id) | ||
FinalFailure.AlreadyPaid -> context.getString(R.string.outgoing_failuremessage_alreadypaid) | ||
FinalFailure.ChannelClosing -> context.getString(R.string.outgoing_failuremessage_channel_closing) | ||
FinalFailure.ChannelNotConnected -> context.getString(R.string.outgoing_failuremessage_not_connected) | ||
FinalFailure.ChannelOpening -> context.getString(R.string.outgoing_failuremessage_channel_opening) | ||
FinalFailure.FeaturesNotSupported -> context.getString(R.string.outgoing_failuremessage_unsupported_features) | ||
FinalFailure.InsufficientBalance -> context.getString(R.string.outgoing_failuremessage_not_enough_balance) | ||
FinalFailure.InvalidPaymentAmount -> context.getString(R.string.outgoing_failuremessage_invalid_amount) | ||
FinalFailure.NoAvailableChannels -> context.getString(R.string.outgoing_failuremessage_no_available_channels) | ||
FinalFailure.RecipientUnreachable -> context.getString(R.string.outgoing_failuremessage_noroutefound) | ||
FinalFailure.RetryExhausted -> context.getString(R.string.outgoing_failuremessage_noroutefound) | ||
FinalFailure.UnknownError -> context.getString(R.string.outgoing_failuremessage_unknown) | ||
FinalFailure.WalletRestarted -> context.getString(R.string.outgoing_failuremessage_restarted) | ||
} | ||
} | ||
} | ||
} | ||
return errorMessage | ||
} |
144 changes: 144 additions & 0 deletions
144
...c/main/kotlin/fr/acinq/phoenix/android/payments/details/splash/SplashLiquidityPurchase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* Copyright 2024 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.payments.details.splash | ||
|
||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.widthIn | ||
import androidx.compose.foundation.layout.wrapContentHeight | ||
import androidx.compose.foundation.pager.HorizontalPager | ||
import androidx.compose.foundation.pager.rememberPagerState | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.produceState | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.unit.dp | ||
import fr.acinq.lightning.db.InboundLiquidityOutgoingPayment | ||
import fr.acinq.lightning.wire.LiquidityAds | ||
import fr.acinq.phoenix.android.LocalBitcoinUnit | ||
import fr.acinq.phoenix.android.R | ||
import fr.acinq.phoenix.android.Screen | ||
import fr.acinq.phoenix.android.business | ||
import fr.acinq.phoenix.android.components.BorderButton | ||
import fr.acinq.phoenix.android.components.BottomSheetDialog | ||
import fr.acinq.phoenix.android.components.Button | ||
import fr.acinq.phoenix.android.components.Clickable | ||
import fr.acinq.phoenix.android.components.SplashClickableContent | ||
import fr.acinq.phoenix.android.components.SplashLabelRow | ||
import fr.acinq.phoenix.android.components.TextWithIcon | ||
import fr.acinq.phoenix.android.navController | ||
import fr.acinq.phoenix.android.navigateToPaymentDetails | ||
import fr.acinq.phoenix.android.payments.details.PaymentLine | ||
import fr.acinq.phoenix.android.payments.details.PaymentLineLoading | ||
import fr.acinq.phoenix.android.utils.Converter.toPrettyString | ||
import fr.acinq.phoenix.android.utils.MSatDisplayPolicy | ||
import fr.acinq.phoenix.android.utils.mutedBgColor | ||
import fr.acinq.phoenix.data.WalletPaymentFetchOptions | ||
import fr.acinq.phoenix.data.WalletPaymentId | ||
import fr.acinq.phoenix.data.WalletPaymentInfo | ||
import fr.acinq.phoenix.utils.extensions.isManualPurchase | ||
import fr.acinq.phoenix.utils.extensions.isPaidInTheFuture | ||
import fr.acinq.phoenix.utils.extensions.relatedPaymentIds | ||
import kotlinx.coroutines.launch | ||
|
||
@Composable | ||
fun SplashLiquidityPurchase( | ||
payment: InboundLiquidityOutgoingPayment, | ||
) { | ||
SplashPurchase(payment = payment) | ||
SplashFee(payment = payment) | ||
SplashRelatedPayments(payment) | ||
} | ||
|
||
@Composable | ||
private fun SplashPurchase( | ||
payment: InboundLiquidityOutgoingPayment, | ||
) { | ||
val btcUnit = LocalBitcoinUnit.current | ||
SplashLabelRow(label = "Liquidity") { | ||
Text(text = payment.purchase.amount.toPrettyString(btcUnit, withUnit = true, mSatDisplayPolicy = MSatDisplayPolicy.SHOW_IF_ZERO_SATS)) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun SplashFee( | ||
payment: InboundLiquidityOutgoingPayment | ||
) { | ||
val btcUnit = LocalBitcoinUnit.current | ||
if (!payment.isPaidInTheFuture()) { | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
val miningFee = payment.feePaidFromChannelBalance.miningFee | ||
val serviceFee = payment.feePaidFromChannelBalance.serviceFee | ||
SplashLabelRow( | ||
label = stringResource(id = R.string.paymentdetails_liquidity_miner_fee_label), | ||
helpMessage = stringResource(id = R.string.paymentdetails_liquidity_miner_fee_help) | ||
) { | ||
Text(text = miningFee.toPrettyString(btcUnit, withUnit = true, mSatDisplayPolicy = MSatDisplayPolicy.SHOW_IF_ZERO_SATS)) | ||
} | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
SplashLabelRow( | ||
label = stringResource(id = R.string.paymentdetails_liquidity_service_fee_label), | ||
helpMessage = stringResource(id = R.string.paymentdetails_liquidity_service_fee_help) | ||
) { | ||
Text(text = serviceFee.toPrettyString(btcUnit, withUnit = true, mSatDisplayPolicy = MSatDisplayPolicy.SHOW_IF_ZERO_SATS)) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun SplashRelatedPayments(payment: InboundLiquidityOutgoingPayment) { | ||
val relatedPaymentIds = payment.relatedPaymentIds() | ||
if (relatedPaymentIds.isNotEmpty()) { | ||
val navController = navController | ||
val paymentId = relatedPaymentIds.first() | ||
Spacer(modifier = Modifier.height(4.dp)) | ||
SplashLabelRow( | ||
label = stringResource(id = R.string.paymentdetails_liquidity_caused_by_label), | ||
helpMessage = if (payment.isManualPurchase()) null else stringResource(id = R.string.paymentdetails_liquidity_caused_by_help), | ||
helpLink = stringResource(id = R.string.paymentdetails_liquidity_caused_by_help_link) to "https://acinq.co/faq", | ||
) { | ||
Button( | ||
text = paymentId.dbId, | ||
icon = R.drawable.ic_zap, | ||
onClick = { navigateToPaymentDetails(navController, paymentId, isFromEvent = false) }, | ||
maxLines = 1, | ||
padding = PaddingValues(horizontal = 7.dp, vertical = 5.dp), | ||
space = 4.dp, | ||
shape = RoundedCornerShape(12.dp), | ||
backgroundColor = mutedBgColor, | ||
modifier = Modifier.widthIn(max = 130.dp) | ||
) | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...droid/src/main/kotlin/fr/acinq/phoenix/android/payments/details/splash/SplashSpliceOut.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2024 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.payments.details.splash | ||
|
||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.text.selection.SelectionContainer | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import fr.acinq.lightning.db.SpliceOutgoingPayment | ||
import fr.acinq.phoenix.android.LocalBitcoinUnit | ||
import fr.acinq.phoenix.android.R | ||
import fr.acinq.phoenix.android.components.SplashLabelRow | ||
import fr.acinq.phoenix.android.utils.Converter.toPrettyString | ||
import fr.acinq.phoenix.android.utils.MSatDisplayPolicy | ||
import fr.acinq.phoenix.android.utils.smartDescription | ||
import fr.acinq.phoenix.data.WalletPaymentId | ||
import fr.acinq.phoenix.data.WalletPaymentMetadata | ||
import fr.acinq.phoenix.data.walletPaymentId | ||
|
||
@Composable | ||
fun SplashSpliceOut( | ||
payment: SpliceOutgoingPayment, | ||
metadata: WalletPaymentMetadata, | ||
onMetadataDescriptionUpdate: (WalletPaymentId, String?) -> Unit, | ||
) { | ||
SplashDescription( | ||
description = payment.smartDescription(), | ||
userDescription = metadata.userDescription, | ||
paymentId = payment.walletPaymentId(), | ||
onMetadataDescriptionUpdate = onMetadataDescriptionUpdate | ||
) | ||
SplashDestination(payment) | ||
SplashFee(payment = payment) | ||
} | ||
|
||
@Composable | ||
private fun SplashDestination(payment: SpliceOutgoingPayment) { | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_destination_label), icon = R.drawable.ic_chain) { | ||
SelectionContainer { | ||
Text(text = payment.address) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun SplashFee(payment: SpliceOutgoingPayment) { | ||
val btcUnit = LocalBitcoinUnit.current | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_fees_label)) { | ||
Text(text = payment.fees.toPrettyString(btcUnit, withUnit = true, mSatDisplayPolicy = MSatDisplayPolicy.SHOW_IF_ZERO_SATS)) | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...d/src/main/kotlin/fr/acinq/phoenix/android/payments/details/splash/SplashSpliceOutCpfp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2024 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.payments.details.splash | ||
|
||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.text.selection.SelectionContainer | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import fr.acinq.lightning.db.SpliceCpfpOutgoingPayment | ||
import fr.acinq.phoenix.android.LocalBitcoinUnit | ||
import fr.acinq.phoenix.android.R | ||
import fr.acinq.phoenix.android.components.SplashLabelRow | ||
import fr.acinq.phoenix.android.utils.Converter.toPrettyString | ||
import fr.acinq.phoenix.android.utils.MSatDisplayPolicy | ||
import fr.acinq.phoenix.android.utils.smartDescription | ||
import fr.acinq.phoenix.data.WalletPaymentId | ||
import fr.acinq.phoenix.data.WalletPaymentMetadata | ||
import fr.acinq.phoenix.data.walletPaymentId | ||
|
||
@Composable | ||
fun SplashSpliceOutCpfp( | ||
payment: SpliceCpfpOutgoingPayment, | ||
metadata: WalletPaymentMetadata, | ||
onMetadataDescriptionUpdate: (WalletPaymentId, String?) -> Unit, | ||
) { | ||
SplashDescription( | ||
description = payment.smartDescription(), | ||
userDescription = metadata.userDescription, | ||
paymentId = payment.walletPaymentId(), | ||
onMetadataDescriptionUpdate = onMetadataDescriptionUpdate | ||
) | ||
SplashDestination() | ||
SplashFee(payment = payment) | ||
} | ||
|
||
@Composable | ||
private fun SplashDestination() { | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_destination_label), icon = R.drawable.ic_chain) { | ||
SelectionContainer { | ||
Text(text = stringResource(id = R.string.paymentdetails_destination_cpfp_value)) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun SplashFee(payment: SpliceCpfpOutgoingPayment) { | ||
val btcUnit = LocalBitcoinUnit.current | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
SplashLabelRow(label = stringResource(id = R.string.paymentdetails_fees_label)) { | ||
Text(text = payment.fees.toPrettyString(btcUnit, withUnit = true, mSatDisplayPolicy = MSatDisplayPolicy.SHOW_IF_ZERO_SATS)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.