Skip to content

Commit

Permalink
Handle new offer types (#562)
Browse files Browse the repository at this point in the history
Also remove keysend origin/details for incoming/outgoing payments

---------

Co-authored-by: Robbie Hanson <304604+robbiehanson@users.noreply.github.com>
  • Loading branch information
dpad85 and robbiehanson authored May 22, 2024
1 parent 6662ca8 commit 7720975
Show file tree
Hide file tree
Showing 23 changed files with 115 additions and 212 deletions.
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.6.1"
const val lightningKmp = "1.6.2-SNAPSHOT"
const val secp256k1 = "0.14.0"
const val torMobile = "0.2.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import fr.acinq.bitcoin.ByteVector32
import fr.acinq.bitcoin.PrivateKey
import fr.acinq.lightning.MilliSatoshi
import fr.acinq.lightning.db.*
import fr.acinq.lightning.payment.Bolt11Invoice
import fr.acinq.lightning.payment.Bolt12Invoice
import fr.acinq.lightning.payment.OfferPaymentMetadata
import fr.acinq.lightning.utils.currentTimestampMillis
import fr.acinq.lightning.utils.msat
import fr.acinq.lightning.utils.sum
Expand Down Expand Up @@ -133,7 +135,7 @@ private fun HeaderForOutgoing(
is LightningOutgoingPayment -> when (payment.details) {
is LightningOutgoingPayment.Details.Normal -> stringResource(R.string.paymentdetails_normal_outgoing)
is LightningOutgoingPayment.Details.SwapOut -> stringResource(R.string.paymentdetails_swapout)
is LightningOutgoingPayment.Details.KeySend -> stringResource(R.string.paymentdetails_keysend)
is LightningOutgoingPayment.Details.Blinded -> stringResource(id = R.string.paymentdetails_offer_outgoing)
}
is SpliceCpfpOutgoingPayment -> stringResource(id = R.string.paymentdetails_splice_cpfp_outgoing)
is InboundLiquidityOutgoingPayment -> stringResource(id = R.string.paymentdetails_inbound_liquidity)
Expand Down Expand Up @@ -172,9 +174,9 @@ private fun HeaderForIncoming(
Text(
when (payment.origin) {
is IncomingPayment.Origin.Invoice -> stringResource(R.string.paymentdetails_normal_incoming)
is IncomingPayment.Origin.KeySend -> stringResource(R.string.paymentdetails_keysend)
is IncomingPayment.Origin.SwapIn -> stringResource(R.string.paymentdetails_swapin)
is IncomingPayment.Origin.OnChain -> stringResource(R.string.paymentdetails_swapin)
is IncomingPayment.Origin.Offer -> stringResource(id = R.string.paymentdetails_offer_incoming)
}
)
}
Expand Down Expand Up @@ -300,19 +302,14 @@ private fun DetailsForLightningOutgoingPayment(
// -- details of the payment
when (details) {
is LightningOutgoingPayment.Details.Normal -> {
when (val paymentRequest = details.paymentRequest) {
is Bolt11Invoice -> InvoiceSection(invoice = paymentRequest)
is Bolt12Invoice -> {
// TODO
}
}
Bolt11InvoiceSection(invoice = details.paymentRequest)
}
is LightningOutgoingPayment.Details.SwapOut -> {
TechnicalRowSelectable(label = stringResource(id = R.string.paymentdetails_bitcoin_address_label), value = details.address)
TechnicalRowSelectable(label = stringResource(id = R.string.paymentdetails_payment_hash_label), value = details.paymentHash.toHex())
}
is LightningOutgoingPayment.Details.KeySend -> {
TechnicalRowSelectable(label = stringResource(id = R.string.paymentdetails_payment_hash_label), value = details.paymentHash.toHex())
is LightningOutgoingPayment.Details.Blinded -> {
Bolt12InvoiceSection(invoice = details.paymentRequest, payerKey = details.payerKey)
}
}

Expand Down Expand Up @@ -408,15 +405,14 @@ private fun DetailsForIncoming(
// -- details about the origin of the payment
when (val origin = payment.origin) {
is IncomingPayment.Origin.Invoice -> {
InvoiceSection(invoice = origin.paymentRequest)
Bolt11InvoiceSection(invoice = origin.paymentRequest)
TechnicalRowSelectable(label = stringResource(id = R.string.paymentdetails_preimage_label), value = payment.preimage.toHex())
}
is IncomingPayment.Origin.SwapIn -> {
TechnicalRow(label = stringResource(id = R.string.paymentdetails_swapin_address_label)) {
Text(origin.address ?: stringResource(id = R.string.utils_unknown))
}
}
is IncomingPayment.Origin.KeySend -> {}
is IncomingPayment.Origin.OnChain -> {
TechnicalRow(label = stringResource(id = R.string.paymentdetails_dualswapin_tx_label)) {
origin.localInputs.mapIndexed { index, outpoint ->
Expand All @@ -428,6 +424,9 @@ private fun DetailsForIncoming(
}
}
}
is IncomingPayment.Origin.Offer -> {
Bolt12MetadataSection(metadata = origin.metadata)
}
}
}

Expand Down Expand Up @@ -507,7 +506,7 @@ private fun LightningPart(
}

@Composable
private fun InvoiceSection(
private fun Bolt11InvoiceSection(
invoice: Bolt11Invoice
) {
val requestedAmount = invoice.amount
Expand All @@ -530,6 +529,49 @@ private fun InvoiceSection(
TechnicalRowSelectable(label = stringResource(id = R.string.paymentdetails_payment_request_label), value = invoice.write())
}

@Composable
private fun Bolt12InvoiceSection(
invoice: Bolt12Invoice,
payerKey: PrivateKey,
) {
val requestedAmount = invoice.amount
if (requestedAmount != null) {
TechnicalRowAmount(
label = stringResource(id = R.string.paymentdetails_invoice_requested_label),
amount = requestedAmount,
rateThen = null
)
}

val description = invoice.description?.takeIf { it.isNotBlank() }
if (description != null) {
TechnicalRow(label = stringResource(id = R.string.paymentdetails_payment_request_description_label)) {
Text(text = description)
}
}

TechnicalRowSelectable(label = stringResource(id = R.string.paymentdetails_payerkey_label), value = payerKey.toHex())
TechnicalRowSelectable(label = stringResource(id = R.string.paymentdetails_payment_hash_label), value = invoice.paymentHash.toHex())
TechnicalRowSelectable(label = stringResource(id = R.string.paymentdetails_payment_request_label), value = invoice.write())
}

@Composable
private fun Bolt12MetadataSection(
metadata: OfferPaymentMetadata
) {
TechnicalRowAmount(
label = stringResource(id = R.string.paymentdetails_invoice_requested_label),
amount = metadata.amount,
rateThen = null
)
TechnicalRowSelectable(label = stringResource(id = R.string.paymentdetails_payment_hash_label), value = metadata.paymentHash.toHex())
TechnicalRowSelectable(label = stringResource(id = R.string.paymentdetails_preimage_label), value = metadata.preimage.toHex())
TechnicalRowSelectable(label = stringResource(id = R.string.paymentdetails_offerid_label), value = metadata.offerId.toHex())
if (metadata is OfferPaymentMetadata.V1) {
TechnicalRowSelectable(label = stringResource(id = R.string.paymentdetails_payerkey_label), value = metadata.payerKey.toHex())
}
}

// ============== utility components for this view

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ object LegacyMigrationHelper {
} else if (paymentRequest != null) {
LightningOutgoingPayment.Details.Normal(paymentRequest)
} else {
LightningOutgoingPayment.Details.KeySend(preimage = Lightning.randomBytes32().sha256())
throw RuntimeException("unhandled outgoing payment details")
}

val parts = listOfParts.filter { it.paymentType() == PaymentType.Standard() }.map { part ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ fun Connection.CLOSED.isBadCertificate() = this.reason?.cause is CertificateExce
fun WalletPayment.smartDescription(context: Context): String? = when (this) {
is LightningOutgoingPayment -> when (val details = this.details) {
is LightningOutgoingPayment.Details.Normal -> details.paymentRequest.desc
is LightningOutgoingPayment.Details.KeySend -> context.getString(R.string.paymentdetails_desc_keysend)
is LightningOutgoingPayment.Details.SwapOut -> context.getString(R.string.paymentdetails_desc_swapout, details.address)
is LightningOutgoingPayment.Details.Blinded -> details.paymentRequest.description
}
is IncomingPayment -> when (val origin = this.origin) {
is IncomingPayment.Origin.Invoice -> origin.paymentRequest.description
is IncomingPayment.Origin.KeySend -> context.getString(R.string.paymentdetails_desc_keysend)
is IncomingPayment.Origin.SwapIn, is IncomingPayment.Origin.OnChain -> context.getString(R.string.paymentdetails_desc_swapin)
is IncomingPayment.Origin.Offer -> context.getString(R.string.paymentdetails_desc_offer_incoming, origin.metadata.offerId.toHex())
}
is SpliceOutgoingPayment -> context.getString(R.string.paymentdetails_desc_splice_out)
is ChannelCloseOutgoingPayment -> context.getString(R.string.paymentdetails_desc_closing_channel)
Expand Down
2 changes: 0 additions & 2 deletions phoenix-android/src/main/res/values-b+es+419/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@
<string name="paymentdetails_desc_closing_channel">Canal de cierre</string>
<string name="paymentdetails_desc_legacy_migration">Migración desde aplicación heredada</string>
<string name="paymentdetails_desc_cpfp">Impulsar transacciones</string>
<string name="paymentdetails_desc_keysend">Donación</string>
<string name="paymentdetails_desc_swapout">Intercambiar a %1$s</string>
<string name="paymentdetails_desc_swapin">Depósito en la cadena</string>
<string name="paymentdetails_desc_identifier">Pago a %1$s</string>
Expand All @@ -366,7 +365,6 @@
<string name="paymentdetails_normal_incoming">Pago estándar entrante de Lightning</string>
<string name="paymentdetails_swapin">Depósito de Bitcoin para intercambio</string>
<string name="paymentdetails_swapout">Intercambio a dirección de Bitcoin</string>
<string name="paymentdetails_keysend">Keysend (pago espontáneo)</string>
<string name="paymentdetails_swapin_address_label">Dirección de depósito</string>
<string name="paymentdetails_bitcoin_address_label">Dirección de Bitcoin</string>

Expand Down
2 changes: 0 additions & 2 deletions phoenix-android/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@
<string name="paymentdetails_desc_closing_channel">Zavírání kanálu</string>
<string name="paymentdetails_desc_legacy_migration">Migrace ze staré aplikace</string>
<string name="paymentdetails_desc_cpfp">Postrčit transakci</string>
<string name="paymentdetails_desc_keysend">Darovat</string>
<string name="paymentdetails_desc_swapout">Swap-out do %1$s</string>
<string name="paymentdetails_desc_swapin">On-Chain vklad</string>
<string name="paymentdetails_desc_identifier">Platba pro %1$s</string>
Expand All @@ -327,7 +326,6 @@
<string name="paymentdetails_normal_incoming">Standardní příchozí Lightning platba</string>
<string name="paymentdetails_swapin">Swap-in vklad Bitcoinu</string>
<string name="paymentdetails_swapout">Swap-out na Bitcoinovou adresu</string>
<string name="paymentdetails_keysend">Keysend (spontánní platba)</string>
<string name="paymentdetails_swapin_address_label">Adresa vkladu</string>
<string name="paymentdetails_bitcoin_address_label">Bitcoinová adresa</string>

Expand Down
2 changes: 0 additions & 2 deletions phoenix-android/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@
<string name="paymentdetails_desc_legacy_migration">Migration von Legacy-App</string>
<string name="paymentdetails_desc_cpfp">Beschleunigte Transaktion</string>
<string name="paymentdetails_desc_inbound_liquidity">+%1$s eingehende Liquidität</string>
<string name="paymentdetails_desc_keysend">Spende</string>
<string name="paymentdetails_desc_swapout">Swap-out an %1$s</string>
<string name="paymentdetails_desc_swapin">On-Chain Einzahlung</string>
<string name="paymentdetails_desc_identifier">Zahlung an %1$s</string>
Expand All @@ -375,7 +374,6 @@
<string name="paymentdetails_normal_incoming">Standard eingehende Lightning-Zahlung</string>
<string name="paymentdetails_swapin">Swap-in Bitcoin-Einzahlung</string>
<string name="paymentdetails_swapout">Swap-out an Bitcoin-Adresse</string>
<string name="paymentdetails_keysend">Keysend (unaufgeforderte Zahlung)</string>
<string name="paymentdetails_swapin_address_label">Einzahlungs-Adresse</string>
<string name="paymentdetails_bitcoin_address_label">Bitcoin-Adresse</string>

Expand Down
2 changes: 0 additions & 2 deletions phoenix-android/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@
<string name="paymentdetails_desc_legacy_migration">Migration depuis l\'ancienne appli</string>
<string name="paymentdetails_desc_cpfp">Accélération de transactions</string>
<string name="paymentdetails_desc_inbound_liquidity">+%1$s de liquidité entrante</string>
<string name="paymentdetails_desc_keysend">Don</string>
<string name="paymentdetails_desc_swapout">Swap-out vers %1$s</string>
<string name="paymentdetails_desc_swapin">Dépôt on-chain</string>
<string name="paymentdetails_desc_identifier">Paiement vers %1$s</string>
Expand All @@ -347,7 +346,6 @@
<string name="paymentdetails_normal_incoming">Paiement Lightning entrant</string>
<string name="paymentdetails_swapin">Dépôt on-chain (swap-in)</string>
<string name="paymentdetails_swapout">Swap-out vers une adresse Bitcoin</string>
<string name="paymentdetails_keysend">Keysend (paiement spontané)</string>
<string name="paymentdetails_swapin_address_label">Adresse de dépôt on-chain</string>
<string name="paymentdetails_bitcoin_address_label">Adresse Bitcoin</string>

Expand Down
2 changes: 0 additions & 2 deletions phoenix-android/src/main/res/values-sk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@
<string name="paymentdetails_desc_legacy_migration">Migrácia zo staršej aplikácie</string>
<string name="paymentdetails_desc_cpfp">Urýchliť transakciu</string>
<string name="paymentdetails_desc_inbound_liquidity">+%1$s prichádzajúca likvidita</string>
<string name="paymentdetails_desc_keysend">Darovať</string>
<string name="paymentdetails_desc_swapout">Swap-out na %1$s</string>
<string name="paymentdetails_desc_swapin">On-chain vklad</string>
<string name="paymentdetails_desc_identifier">Platba pre %1$s</string>
Expand All @@ -373,7 +372,6 @@
<string name="paymentdetails_normal_incoming">Štandardná prichádzajúca Lightning platba</string>
<string name="paymentdetails_swapin">Swap-in vklad Bitcoinu</string>
<string name="paymentdetails_swapout">Swap-out na Bitcoinovú adresu</string>
<string name="paymentdetails_keysend">Keysend (spontánna platba)</string>
<string name="paymentdetails_swapin_address_label">Adresa vkladu</string>
<string name="paymentdetails_bitcoin_address_label">Bitcoinová adresa</string>

Expand Down
2 changes: 0 additions & 2 deletions phoenix-android/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@
<string name="paymentdetails_desc_legacy_migration">Di chuyển từ ứng dụng cũ</string>
<string name="paymentdetails_desc_cpfp">Các giao dịch tăng đột biến</string>
<string name="paymentdetails_desc_inbound_liquidity">+%1$s thanh khoản đầu vào</string>
<string name="paymentdetails_desc_keysend">Quyên góp</string>
<string name="paymentdetails_desc_swapout">Swap-out thành %1$s</string>
<string name="paymentdetails_desc_swapin">Tiền cọc on-chain</string>
<string name="paymentdetails_desc_identifier">Khoản thanh toán cho %1$s</string>
Expand All @@ -376,7 +375,6 @@
<string name="paymentdetails_normal_incoming">Thanh toán đầu vào Lightning thông thường</string>
<string name="paymentdetails_swapin">Swap-in tiền cọc Bitcoin</string>
<string name="paymentdetails_swapout">Swap-out đến địa chỉ Bitcoin</string>
<string name="paymentdetails_keysend">Keysend (thanh toán tự phát)</string>
<string name="paymentdetails_swapin_address_label">Địa chỉ tiền cọc</string>
<string name="paymentdetails_bitcoin_address_label">Điạ chỉ Bitcoin</string>

Expand Down
7 changes: 5 additions & 2 deletions phoenix-android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@
<string name="paymentdetails_desc_legacy_migration">Migration from legacy app</string>
<string name="paymentdetails_desc_cpfp">Bump transactions</string>
<string name="paymentdetails_desc_inbound_liquidity">+%1$s inbound liquidity</string>
<string name="paymentdetails_desc_keysend">Donation</string>
<string name="paymentdetails_desc_swapout">Swap-out to %1$s</string>
<string name="paymentdetails_desc_swapin">On-chain deposit</string>
<string name="paymentdetails_desc_identifier">Payment to %1$s</string>
<string name="paymentdetails_desc_offer_incoming">Payment to %1$s</string>

<string name="paymentdetails_edit_dialog_title">Add a custom description to this payment</string>
<string name="paymentdetails_edit_dialog_input_label">Description</string>
Expand All @@ -387,7 +387,8 @@
<string name="paymentdetails_normal_incoming">Standard incoming Lightning payment</string>
<string name="paymentdetails_swapin">Swap-in Bitcoin deposit</string>
<string name="paymentdetails_swapout">Swap-out to Bitcoin address</string>
<string name="paymentdetails_keysend">Keysend (spontaneous payment)</string>
<string name="paymentdetails_offer_outgoing">Offer outgoing Lightning payment</string>
<string name="paymentdetails_offer_incoming">Offer incoming Lightning payment</string>
<string name="paymentdetails_swapin_address_label">Deposit address</string>
<string name="paymentdetails_bitcoin_address_label">Bitcoin address</string>

Expand All @@ -410,6 +411,8 @@
<string name="paymentdetails_payment_hash_label">Payment Hash</string>
<string name="paymentdetails_payment_request_label">Invoice</string>
<string name="paymentdetails_preimage_label">Preimage</string>
<string name="paymentdetails_payerkey_label">Payer key</string>
<string name="paymentdetails_offerid_label">Offer ID</string>

<string name="paymentdetails_status_label">Payment status</string>
<string name="paymentdetails_status_success">Successful</string>
Expand Down
82 changes: 0 additions & 82 deletions phoenix-ios/phoenix-ios/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -14274,47 +14274,6 @@
}
}
},
"Donation" : {
"comment" : "Payment description for received KeySend",
"localizations" : {
"ar" : {
"stringUnit" : {
"state" : "translated",
"value" : "التبرع"
}
},
"cs" : {
"stringUnit" : {
"state" : "translated",
"value" : "Dary"
}
},
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Spende"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Donación"
}
},
"es-419" : {
"stringUnit" : {
"state" : "translated",
"value" : "Donación"
}
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Don"
}
}
}
},
"Done" : {
"localizations" : {
"ar" : {
Expand Down Expand Up @@ -21318,47 +21277,6 @@
}
}
},
"KeySend" : {
"comment" : "Transaction Info: Value",
"localizations" : {
"ar" : {
"stringUnit" : {
"state" : "translated",
"value" : "الدفع عبر KeySend"
}
},
"cs" : {
"stringUnit" : {
"state" : "translated",
"value" : "KeySend"
}
},
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "KeySend"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "KeySend"
}
},
"es-419" : {
"stringUnit" : {
"state" : "translated",
"value" : "KeySend"
}
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "KeySend"
}
}
}
},
"know when fees may occur" : {
"localizations" : {
"ar" : {
Expand Down
Loading

0 comments on commit 7720975

Please sign in to comment.