fix zap splits when using amber with intents

pull/705/head
greenart7c3 2023-12-01 10:52:15 -03:00
rodzic 9bc5549d76
commit ecb8344287
2 zmienionych plików z 54 dodań i 11 usunięć

Wyświetl plik

@ -14,7 +14,6 @@ import com.vitorpamplona.quartz.events.ZapSplitSetup
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlin.math.round import kotlin.math.round
@ -142,8 +141,17 @@ class ZapPaymentHandler(val account: Account) {
} else { } else {
launch(Dispatchers.IO) { launch(Dispatchers.IO) {
// Awaits for the event to come back to LocalCache. // Awaits for the event to come back to LocalCache.
delay(5000) var count = 0
onProgress(1f) while (invoicesToPayOnIntent.size < zapsToSend.size || count < 4) {
count++
Thread.sleep(5000)
}
if (invoicesToPayOnIntent.isNotEmpty()) {
onPayViaIntent(invoicesToPayOnIntent.toImmutableList())
onProgress(1f)
} else {
onProgress(1f)
}
} }
} }
} }

Wyświetl plik

@ -6,10 +6,17 @@ import android.net.Uri
import android.util.Log import android.util.Log
import android.util.LruCache import android.util.LruCache
import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.vitorpamplona.quartz.encoders.HexKey import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.events.EventInterface import com.vitorpamplona.quartz.events.EventInterface
import com.vitorpamplona.quartz.events.LnZapRequestEvent import com.vitorpamplona.quartz.events.LnZapRequestEvent
import org.json.JSONArray
enum class SignerType { enum class SignerType {
@ -38,7 +45,40 @@ class Result(
val signature: String?, val signature: String?,
@JsonProperty("id") @JsonProperty("id")
val id: String? val id: String?
) ) {
companion object {
val mapper = jacksonObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModule(
SimpleModule()
.addDeserializer(Result::class.java, ResultDeserializer())
)
private class ResultDeserializer : StdDeserializer<Result>(Result::class.java) {
override fun deserialize(jp: JsonParser, ctxt: DeserializationContext): Result {
val jsonObject: JsonNode = jp.codec.readTree(jp)
return Result(
jsonObject.get("package").asText().intern(),
jsonObject.get("signature").asText().intern(),
jsonObject.get("id").asText().intern()
)
}
}
fun fromJson(json: String): Result = mapper.readValue(json, Result::class.java)
fun fromJsonArray(json: String): Array<Result> {
val result: MutableList<Result> = mutableListOf()
val array = JSONArray(json)
(0 until array.length()).forEach {
val resultJson = array.getJSONObject(it)
val localResult = fromJson(resultJson.toString())
result.add(localResult)
}
return result.toTypedArray()
}
}
}
class ExternalSignerLauncher( class ExternalSignerLauncher(
private val npub: String, private val npub: String,
@ -71,12 +111,7 @@ class ExternalSignerLauncher(
fun newResult(data: Intent) { fun newResult(data: Intent) {
val results = data.getStringExtra("results") val results = data.getStringExtra("results")
if (results != null) { if (results != null) {
val objectMapper = ObjectMapper() val localResults: Array<Result> = Result.fromJsonArray(results)
val localResults: Array<Result> = objectMapper.readValue(
results,
Array<Result>::class.java
)
localResults.forEach { localResults.forEach {
val signature = it.signature ?: "" val signature = it.signature ?: ""
val packageName = it.`package` ?: "" val packageName = it.`package` ?: ""