Fixes not being able to create an invoice because of an old cache of the lud16

Fixes inserting invoice in the cursor.
This commit is contained in:
Vitor Pamplona
2024-02-29 17:35:44 -05:00
parent 7497237763
commit d257f7e253
2 changed files with 39 additions and 25 deletions
@@ -475,10 +475,8 @@ fun NewPostView(
} }
} }
val user = postViewModel.account?.userProfile() if (postViewModel.wantsInvoice) {
val lud16 = user?.info?.lnAddress() postViewModel.lnAddress()?.let { lud16 ->
if (lud16 != null && postViewModel.wantsInvoice) {
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(vertical = Size5dp, horizontal = Size10dp), modifier = Modifier.padding(vertical = Size5dp, horizontal = Size10dp),
@@ -486,13 +484,12 @@ fun NewPostView(
Column(Modifier.fillMaxWidth()) { Column(Modifier.fillMaxWidth()) {
InvoiceRequest( InvoiceRequest(
lud16, lud16,
user.pubkeyHex, accountViewModel.account.userProfile().pubkeyHex,
accountViewModel.account, accountViewModel.account,
stringResource(id = R.string.lightning_invoice), stringResource(id = R.string.lightning_invoice),
stringResource(id = R.string.lightning_create_and_add_invoice), stringResource(id = R.string.lightning_create_and_add_invoice),
onSuccess = { onSuccess = {
postViewModel.message = postViewModel.insertAtCursor(it)
TextFieldValue(postViewModel.message.text + "\n\n" + it)
postViewModel.wantsInvoice = false postViewModel.wantsInvoice = false
}, },
onClose = { postViewModel.wantsInvoice = false }, onClose = { postViewModel.wantsInvoice = false },
@@ -501,8 +498,9 @@ fun NewPostView(
} }
} }
} }
}
if (lud16 != null && postViewModel.wantsZapraiser) { if (postViewModel.wantsZapraiser && postViewModel.hasLnAddress()) {
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(vertical = Size5dp, horizontal = Size10dp), modifier = Modifier.padding(vertical = Size5dp, horizontal = Size10dp),
@@ -569,7 +567,7 @@ private fun BottomRowActions(postViewModel: NewPostViewModel) {
} }
} }
if (postViewModel.canAddInvoice) { if (postViewModel.canAddInvoice && postViewModel.hasLnAddress()) {
AddLnInvoiceButton(postViewModel.wantsInvoice) { AddLnInvoiceButton(postViewModel.wantsInvoice) {
postViewModel.wantsInvoice = !postViewModel.wantsInvoice postViewModel.wantsInvoice = !postViewModel.wantsInvoice
} }
@@ -163,6 +163,18 @@ open class NewPostViewModel() : ViewModel() {
// NIP24 Wrapped DMs / Group messages // NIP24 Wrapped DMs / Group messages
var nip24 by mutableStateOf(false) var nip24 by mutableStateOf(false)
fun lnAddress(): String? {
return account?.userProfile()?.info?.lnAddress()
}
fun hasLnAddress(): Boolean {
return account?.userProfile()?.info?.lnAddress() != null
}
fun user(): User? {
return account?.userProfile()
}
open fun load( open fun load(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
replyingTo: Note?, replyingTo: Note?,
@@ -819,6 +831,10 @@ open class NewPostViewModel() : ViewModel() {
) )
} }
fun insertAtCursor(newElement: String) {
message = message.insertUrlAtCursor(newElement)
}
fun createNIP95Record( fun createNIP95Record(
bytes: ByteArray, bytes: ByteArray,
mimeType: String?, mimeType: String?,