support for public and anon zaps
This commit is contained in:
@@ -337,18 +337,54 @@ class Account(
|
||||
}
|
||||
|
||||
fun createZapRequestFor(note: Note, pollOption: Int?, message: String = "", zapType: LnZapEvent.ZapType): LnZapRequestEvent? {
|
||||
if (!isWriteable()) return null
|
||||
if (!isWriteable() && !loginWithAmber) return null
|
||||
|
||||
note.event?.let { event ->
|
||||
return LnZapRequestEvent.create(
|
||||
event,
|
||||
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
||||
?: localRelays.map { it.url }.toSet(),
|
||||
keyPair.privKey!!,
|
||||
pollOption,
|
||||
message,
|
||||
zapType
|
||||
)
|
||||
if (loginWithAmber) {
|
||||
when (zapType) {
|
||||
LnZapEvent.ZapType.ANONYMOUS -> {
|
||||
return LnZapRequestEvent.createAnonymous(
|
||||
event,
|
||||
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
||||
?: localRelays.map { it.url }.toSet(),
|
||||
pollOption,
|
||||
message
|
||||
)
|
||||
}
|
||||
LnZapEvent.ZapType.PUBLIC -> {
|
||||
val unsignedEvent = LnZapRequestEvent.createPublic(
|
||||
event,
|
||||
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
||||
?: localRelays.map { it.url }.toSet(),
|
||||
keyPair.pubKey.toHexKey(),
|
||||
pollOption,
|
||||
message
|
||||
)
|
||||
AmberUtils.content = ""
|
||||
AmberUtils.openAmber(unsignedEvent)
|
||||
if (AmberUtils.content.isBlank()) return null
|
||||
return LnZapRequestEvent(
|
||||
unsignedEvent.id,
|
||||
unsignedEvent.pubKey,
|
||||
unsignedEvent.createdAt,
|
||||
unsignedEvent.tags,
|
||||
unsignedEvent.content,
|
||||
AmberUtils.content
|
||||
)
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
} else {
|
||||
return LnZapRequestEvent.create(
|
||||
event,
|
||||
userProfile().latestContactList?.relays()?.keys?.ifEmpty { null }
|
||||
?: localRelays.map { it.url }.toSet(),
|
||||
keyPair.privKey!!,
|
||||
pollOption,
|
||||
message,
|
||||
zapType
|
||||
)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -1118,14 +1118,35 @@ private fun zapClick(
|
||||
.show()
|
||||
}
|
||||
} else if (!accountViewModel.isWriteable()) {
|
||||
scope.launch {
|
||||
Toast
|
||||
.makeText(
|
||||
if (accountViewModel.loggedInWithAmber()) {
|
||||
if (accountViewModel.account.zapAmountChoices.size == 1) {
|
||||
accountViewModel.zap(
|
||||
baseNote,
|
||||
accountViewModel.account.zapAmountChoices.first() * 1000,
|
||||
null,
|
||||
"",
|
||||
context,
|
||||
context.getString(R.string.login_with_a_private_key_to_be_able_to_send_zaps),
|
||||
Toast.LENGTH_SHORT
|
||||
onError = onError,
|
||||
onProgress = {
|
||||
scope.launch(Dispatchers.Main) {
|
||||
onZappingProgress(it)
|
||||
}
|
||||
},
|
||||
zapType = accountViewModel.account.defaultZapType
|
||||
)
|
||||
.show()
|
||||
} else if (accountViewModel.account.zapAmountChoices.size > 1) {
|
||||
onMultipleChoices()
|
||||
}
|
||||
} else {
|
||||
scope.launch {
|
||||
Toast
|
||||
.makeText(
|
||||
context,
|
||||
context.getString(R.string.login_with_a_private_key_to_be_able_to_send_zaps),
|
||||
Toast.LENGTH_SHORT
|
||||
)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
} else if (accountViewModel.account.zapAmountChoices.size == 1) {
|
||||
accountViewModel.zap(
|
||||
|
||||
Reference in New Issue
Block a user