Skip to content

Commit 4e2b61f

Browse files
committed
feat: get cjit order invoice
1 parent 2418531 commit 4e2b61f

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,11 @@ class BlocktankRepo @Inject constructor(
9797
}
9898
}
9999

100-
suspend fun isCjitOrder(channel: ChannelDetails): Boolean = withContext(bgDispatcher) {
101-
return@withContext runCatching {
102-
_blocktankState.value.cjitEntries.any { order ->
103-
order.channelSizeSat == channel.channelValueSats &&
104-
order.lspNode.pubkey == channel.counterpartyNodeId
105-
}
106-
}.getOrDefault(false)
100+
suspend fun getCjitOrder(channel: ChannelDetails): IcJitEntry? = withContext(bgDispatcher) {
101+
return@withContext _blocktankState.value.cjitEntries.firstOrNull { order ->
102+
order.channelSizeSat == channel.channelValueSats &&
103+
order.lspNode.pubkey == channel.counterpartyNodeId
104+
}
107105
}
108106

109107
suspend fun refreshInfo() = withContext(bgDispatcher) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import to.bitkit.di.BgDispatcher
5757
import to.bitkit.env.Env
5858
import to.bitkit.ext.WatchResult
5959
import to.bitkit.ext.amountOnClose
60-
import to.bitkit.ext.amountSats
6160
import to.bitkit.ext.getClipboardText
6261
import to.bitkit.ext.getSatsPerVByteFor
6362
import to.bitkit.ext.maxSendableSat
@@ -226,7 +225,8 @@ class AppViewModel @Inject constructor(
226225

227226
is Event.ChannelReady -> {
228227
val channel = lightningRepo.getChannels()?.find { it.channelId == event.channelId }
229-
if (channel != null && blocktankRepo.isCjitOrder(channel)) {
228+
val cjitOrder = channel?.let { blocktankRepo.getCjitOrder(it) }
229+
if (cjitOrder != null) {
230230
val amount = channel.amountOnClose.toLong()
231231
showNewTransactionSheet(
232232
NewTransactionSheetDetails(
@@ -245,7 +245,7 @@ class AppViewModel @Inject constructor(
245245
status = PaymentState.SUCCEEDED,
246246
value = amount.toULong(),
247247
fee = 0U,
248-
invoice = "Loading...", // todo
248+
invoice = cjitOrder.invoice.request,
249249
message = "",
250250
timestamp = now,
251251
preimage = null,

0 commit comments

Comments
 (0)