Skip to content

Commit 2eba211

Browse files
committed
refactor: reduce channel details call
1 parent 369037e commit 2eba211

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import kotlinx.coroutines.flow.update
2626
import kotlinx.coroutines.isActive
2727
import kotlinx.coroutines.launch
2828
import kotlinx.coroutines.withContext
29+
import org.lightningdevkit.ldknode.ChannelDetails
2930
import to.bitkit.data.CacheStore
3031
import to.bitkit.di.BgDispatcher
3132
import to.bitkit.env.Env
@@ -96,12 +97,11 @@ class BlocktankRepo @Inject constructor(
9697
}
9798
}
9899

99-
suspend fun isCjitOrder(channelId: String): Boolean = withContext(bgDispatcher) {
100+
suspend fun isCjitOrder(channel: ChannelDetails): Boolean = withContext(bgDispatcher) {
100101
return@withContext runCatching {
101-
val channel = lightningService.channels?.find { it.channelId == channelId }
102102
_blocktankState.value.cjitEntries.any { order ->
103-
order.channelSizeSat == channel?.channelValueSats &&
104-
order.lspNode.pubkey == channel.counterpartyNodeId
103+
order.channelSizeSat == channel.channelValueSats &&
104+
order.lspNode.pubkey == channel.counterpartyNodeId
105105
}
106106
}.getOrDefault(false)
107107
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class AppViewModel @Inject constructor(
213213

214214
is Event.ChannelReady -> {
215215
val channel = lightningRepo.getChannels()?.find { it.channelId == event.channelId }
216-
if (channel != null && blocktankRepo.isCjitOrder(event.channelId)) {
216+
if (channel != null && blocktankRepo.isCjitOrder(channel)) {
217217
showNewTransactionSheet(
218218
NewTransactionSheetDetails(
219219
type = NewTransactionSheetType.LIGHTNING,

0 commit comments

Comments
 (0)