Puts the ZapValue calculator inside a caching function.

This commit is contained in:
Vitor Pamplona
2023-03-10 10:15:32 -05:00
parent 57ee0ff1ff
commit 78261ccd94

View File

@@ -33,12 +33,17 @@ class LnZapEvent(
} }
override fun amount(): BigDecimal? { override fun amount(): BigDecimal? {
return lnInvoice()?.let { LnInvoiceUtil.getAmountInSats(it) } return amount
} }
// Keeps this as a field because it's a heavier function used everywhere. // Keeps this as a field because it's a heavier function used everywhere.
val amount by lazy { val amount by lazy {
lnInvoice()?.let { LnInvoiceUtil.getAmountInSats(it) } try {
lnInvoice()?.let { LnInvoiceUtil.getAmountInSats(it) }
} catch (e: Exception) {
Log.e("LnZapEvent", "Failed to Parse LnInvoice ${description()}", e)
null
}
} }
override fun containedPost(): Event? = try { override fun containedPost(): Event? = try {