Skip to content

Commit 37eb079

Browse files
committed
fix: show contact activity titles
1 parent c1b8120 commit 37eb079

4 files changed

Lines changed: 32 additions & 6 deletions

File tree

app/src/main/java/to/bitkit/ext/Activities.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ fun Activity.isSent() = when (this) {
5252
is Activity.Onchain -> v1.txType == PaymentType.SENT
5353
}
5454

55+
fun Activity.contact(): String? = when (this) {
56+
is Activity.Lightning -> v1.contact
57+
is Activity.Onchain -> v1.contact
58+
}
59+
5560
fun Activity.matchesPaymentId(paymentHashOrTxId: String): Boolean = when (this) {
5661
is Activity.Lightning -> paymentHashOrTxId == v1.id
5762
is Activity.Onchain -> paymentHashOrTxId == v1.txId

app/src/main/java/to/bitkit/repositories/ActivityRepo.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import to.bitkit.data.dto.PendingBoostActivity
3535
import to.bitkit.di.BgDispatcher
3636
import to.bitkit.di.IoDispatcher
3737
import to.bitkit.ext.amountOnClose
38+
import to.bitkit.ext.contact
3839
import to.bitkit.ext.matchesPaymentId
3940
import to.bitkit.ext.nowMillis
4041
import to.bitkit.ext.nowTimestamp
@@ -404,11 +405,6 @@ class ActivityRepo @Inject constructor(
404405
coreService.activity.getActivity(forPaymentId)
405406
?: getOnchainActivityByTxId(forPaymentId)?.let { Activity.Onchain(it) }
406407

407-
private fun Activity.contact(): String? = when (this) {
408-
is Activity.Lightning -> v1.contact
409-
is Activity.Onchain -> v1.contact
410-
}
411-
412408
private fun Activity.withContact(normalizedKey: String, updatedAt: ULong): Activity = when (this) {
413409
is Activity.Lightning -> Activity.Lightning(v1.copy(contact = normalizedKey, updatedAt = updatedAt))
414410
is Activity.Onchain -> Activity.Onchain(v1.copy(contact = normalizedKey, updatedAt = updatedAt))

app/src/main/java/to/bitkit/ui/screens/wallets/activity/components/ActivityRow.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import com.synonym.bitkitcore.PaymentState
3131
import com.synonym.bitkitcore.PaymentType
3232
import to.bitkit.R
3333
import to.bitkit.ext.DatePattern
34+
import to.bitkit.ext.contact
3435
import to.bitkit.ext.formatted
3536
import to.bitkit.ext.isSent
3637
import to.bitkit.ext.isTransfer
@@ -40,6 +41,8 @@ import to.bitkit.ext.totalValue
4041
import to.bitkit.ext.txType
4142
import to.bitkit.models.FeeRate.Companion.getFeeShortDescription
4243
import to.bitkit.models.PrimaryDisplay
44+
import to.bitkit.models.PubkyProfile
45+
import to.bitkit.models.PubkyPublicKeyFormat
4346
import to.bitkit.models.formatToModernDisplay
4447
import to.bitkit.repositories.CurrencyState
4548
import to.bitkit.ui.LocalCurrencies
@@ -90,6 +93,19 @@ fun ActivityRow(
9093
val isTransfer = item.isTransfer()
9194

9295
val activityListViewModel = activityListViewModel
96+
val contacts by activityListViewModel?.contacts?.collectAsStateWithLifecycle() ?: remember {
97+
mutableStateOf(emptyList())
98+
}
99+
val contactName = remember(item, contacts) { contactName(item, contacts) }
100+
val contactTitle = contactName?.let {
101+
val titleRes = if (item.isSent()) {
102+
R.string.contacts__activity_sent_to
103+
} else {
104+
R.string.contacts__activity_received_from
105+
}
106+
stringResource(titleRes, it)
107+
}
108+
val resolvedTitle = title ?: contactTitle
93109
var isCpfpChild by remember { mutableStateOf(false) }
94110

95111
LaunchedEffect(item) {
@@ -121,7 +137,7 @@ fun ActivityRow(
121137
status = status,
122138
isTransfer = isTransfer,
123139
isCpfpChild = isCpfpChild,
124-
title = title,
140+
title = resolvedTitle,
125141
)
126142
val context = LocalContext.current
127143
val subtitleText = when (item) {
@@ -172,6 +188,11 @@ fun ActivityRow(
172188
}
173189
}
174190

191+
private fun contactName(activity: Activity, contacts: List<PubkyProfile>): String? {
192+
val contact = activity.contact() ?: return null
193+
return contacts.firstOrNull { PubkyPublicKeyFormat.matches(it.publicKey, contact) }?.name
194+
}
195+
175196
@Suppress("CyclomaticComplexMethod")
176197
@Composable
177198
private fun TransactionStatusText(

app/src/main/java/to/bitkit/viewmodels/ActivityListViewModel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import kotlinx.coroutines.launch
2828
import to.bitkit.di.BgDispatcher
2929
import to.bitkit.ext.isTransfer
3030
import to.bitkit.repositories.ActivityRepo
31+
import to.bitkit.repositories.PubkyRepo
3132
import to.bitkit.ui.screens.wallets.activity.components.ActivityTab
3233
import to.bitkit.utils.Logger
3334
import javax.inject.Inject
@@ -37,6 +38,7 @@ import javax.inject.Inject
3738
class ActivityListViewModel @Inject constructor(
3839
@BgDispatcher private val bgDispatcher: CoroutineDispatcher,
3940
private val activityRepo: ActivityRepo,
41+
pubkyRepo: PubkyRepo,
4042
) : ViewModel() {
4143
private val _filteredActivities = MutableStateFlow<ImmutableList<Activity>?>(null)
4244
val filteredActivities = _filteredActivities.asStateFlow()
@@ -50,6 +52,8 @@ class ActivityListViewModel @Inject constructor(
5052
private val _latestActivities = MutableStateFlow<ImmutableList<Activity>?>(null)
5153
val latestActivities = _latestActivities.asStateFlow()
5254

55+
val contacts = pubkyRepo.contacts
56+
5357
val availableTags: StateFlow<ImmutableList<String>> =
5458
activityRepo.state.map { it.tags }.stateInScope(persistentListOf())
5559

0 commit comments

Comments
 (0)