diff --git a/app/src/main/java/com/bitcointxoko/gudariwallet/data/model/PaymentFeedItemMapper.kt b/app/src/main/java/com/bitcointxoko/gudariwallet/data/model/PaymentFeedItemMapper.kt new file mode 100644 index 0000000..9ef33b2 --- /dev/null +++ b/app/src/main/java/com/bitcointxoko/gudariwallet/data/model/PaymentFeedItemMapper.kt @@ -0,0 +1,72 @@ +package com.bitcointxoko.gudariwallet.data.model + +import com.bitcointxoko.gudariwallet.api.PaymentRecord +import com.bitcointxoko.gudariwallet.data.db.ContactEntity + +// Placeholder preimage that LNbits returns when the real one isn't available yet +private const val PREIMAGE_PLACEHOLDER = "0000000000000000000000000000000000000000000000000000000000000000" + +// ── ContactEntity → ContactSummary ─────────────────────────────────────────── + +fun ContactEntity.toContactSummary(): ContactSummary = ContactSummary( + id = id, + displayName = localAlias + ?: displayName + ?: name + ?: id // last resort — never shown as empty +) + +// ── PaymentRecord → PaymentFeedItem ────────────────────────────────────────── + +fun PaymentRecord.toPaymentFeedItem( + linkedContacts: List, + resolvedAlias: String?, // from NodeAliasCache; fallback to payment.alias handled here + fiatCurrency: String?, + fiatSatsPerUnit: Double? +): PaymentFeedItem { + + val isOutgoing = amountMsat < 0 + + return PaymentFeedItem( + + // ── Identity ───────────────────────────────────────────────────────── + id = paymentHash, + + // ── Row ────────────────────────────────────────────────────────────── + isOutgoing = isOutgoing, + amountSat = Math.abs(amountMsat) / 1000L, + memo = memo, + contactName = linkedContacts.firstOrNull()?.displayName, + createdAt = createdAt, + time = time.toLongOrNull(), + isPending = pending, + isFailed = status == "failed", + fiatCurrency = fiatCurrency, + fiatSatsPerUnit = fiatSatsPerUnit, + + // ── Filter / search keys ───────────────────────────────────────────── + paymentHash = paymentHash, + tag = extra?.tag, + contactIds = linkedContacts.map { it.id }.toSet(), + + // ── Detail — amounts ───────────────────────────────────────────────── + feeSat = if (feeMsat != 0L) Math.abs(feeMsat) / 1000L else null, + + // ── Detail — contacts ──────────────────────────────────────────────── + linkedContacts = linkedContacts, + + // ── Detail — basic info ────────────────────────────────────────────── + comment = extra?.comment, + + // ── Detail — LNURL success action ──────────────────────────────────── + successActionMessage = extra?.successAction?.message, + successActionUrl = extra?.successAction?.url, + successActionDescription = extra?.successAction?.description, + + // ── Detail — technical ─────────────────────────────────────────────── + preimage = preimage?.takeIf { it != PREIMAGE_PLACEHOLDER }, + pubkey = pubkey, + alias = resolvedAlias ?: alias, // live cache first, snapshot fallback + bolt11 = bolt11, + ) +}