Skip to content

Commit a46450c

Browse files
authored
Merge pull request #385 from synonymdev/fix/channel-misleading-sheet
CJIT receive Sheets
2 parents 37bea88 + f5231d4 commit a46450c

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

app/src/main/java/to/bitkit/fcm/WakeNodeWorker.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import kotlinx.serialization.json.contentOrNull
1515
import kotlinx.serialization.json.jsonObject
1616
import org.lightningdevkit.ldknode.Event
1717
import to.bitkit.di.json
18+
import to.bitkit.ext.amountOnClose
1819
import to.bitkit.models.BlocktankNotificationType
1920
import to.bitkit.models.BlocktankNotificationType.cjitPaymentArrived
2021
import to.bitkit.models.BlocktankNotificationType.incomingHtlc
@@ -140,15 +141,15 @@ class WakeNodeWorker @AssistedInject constructor(
140141
self.bestAttemptContent?.body = "Via new channel"
141142

142143
lightningRepo.getChannels()?.find { it.channelId == event.channelId }?.let { channel ->
143-
val sats = channel.outboundCapacityMsat / 1000u
144+
val sats = channel.amountOnClose
144145
self.bestAttemptContent?.title = "Received ⚡ $sats sats"
145146
// Save for UI to pick up
146147
NewTransactionSheetDetails.save(
147148
appContext,
148149
NewTransactionSheetDetails(
149150
type = NewTransactionSheetType.LIGHTNING,
150151
direction = NewTransactionSheetDirection.RECEIVED,
151-
sats = sats.toLong(),
152+
sats = channel.amountOnClose.toLong(),
152153
)
153154
)
154155
}

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

Lines changed: 10 additions & 0 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,6 +97,15 @@ class BlocktankRepo @Inject constructor(
9697
}
9798
}
9899

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)
107+
}
108+
99109
suspend fun refreshInfo() = withContext(bgDispatcher) {
100110
try {
101111
// Load from cache first

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,11 @@ class WalletRepo @Inject constructor(
471471
return@withContext 0uL
472472
}
473473
val fallbackMaxFee = (spendableOnchainSats.toDouble() * FALLBACK_FEE_PERCENT).toULong()
474+
val speed = settingsStore.data.first().defaultTransactionSpeed
474475

475476
val fee = lightningRepo.calculateTotalFee(
476477
amountSats = spendableOnchainSats,
477-
speed = TransactionSpeed.default(),
478+
speed = speed,
478479
utxosToSpend = lightningRepo.listSpendableOutputs().getOrNull()
479480
).onFailure {
480481
Logger.debug("Could not calculate max send fee, using as fallback 10% of total", context = TAG)

app/src/main/java/to/bitkit/ui/screens/wallets/send/SendAmountScreen.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ fun SendAmountScreen(
101101
onBack()
102102
}.takeIf { canGoBack },
103103
onClickMax = { maxSats ->
104-
// TODO port the RN sendMax logic if still needed
105104
if (uiState.lnurl == null) {
106105
app?.toast(
107106
type = Toast.ToastType.WARNING,

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import to.bitkit.data.resetPin
4848
import to.bitkit.di.BgDispatcher
4949
import to.bitkit.env.Env
5050
import to.bitkit.ext.WatchResult
51+
import to.bitkit.ext.amountOnClose
5152
import to.bitkit.ext.getClipboardText
5253
import to.bitkit.ext.getSatsPerVByteFor
5354
import to.bitkit.ext.maxSendableSat
@@ -211,33 +212,26 @@ class AppViewModel @Inject constructor(
211212
is Event.ChannelPending -> Unit // Only relevant for channels to external nodes
212213

213214
is Event.ChannelReady -> {
214-
// TODO: handle ONLY cjit as payment received. This makes it look like any channel confirmed is a received payment.
215215
val channel = lightningRepo.getChannels()?.find { it.channelId == event.channelId }
216-
if (channel != null) {
216+
if (channel != null && blocktankRepo.isCjitOrder(channel)) {
217217
showNewTransactionSheet(
218218
NewTransactionSheetDetails(
219219
type = NewTransactionSheetType.LIGHTNING,
220220
direction = NewTransactionSheetDirection.RECEIVED,
221-
sats = (channel.inboundCapacityMsat / 1000u).toLong(),
221+
sats = channel.amountOnClose.toLong(),
222222
),
223223
event = event
224224
)
225225
} else {
226226
toast(
227-
type = Toast.ToastType.ERROR,
228-
title = "Channel opened",
229-
description = "Ready to send"
227+
type = Toast.ToastType.LIGHTNING,
228+
title = context.getString(R.string.lightning__channel_opened_title),
229+
description = context.getString(R.string.lightning__channel_opened_msg),
230230
)
231231
}
232232
}
233233

234-
is Event.ChannelClosed -> {
235-
toast(
236-
type = Toast.ToastType.LIGHTNING,
237-
title = "Channel closed",
238-
description = "Balance moved from spending to savings"
239-
)
240-
}
234+
is Event.ChannelClosed -> Unit
241235

242236
is Event.PaymentSuccessful -> {
243237
val paymentHash = event.paymentHash

0 commit comments

Comments
 (0)