Skip to content

Commit 621ef4f

Browse files
authored
Merge pull request #289 from synonymdev/feat/update-core-lnurl
Update bitkit-core and use its new lnurl apis
2 parents aa01514 + f5a3c54 commit 621ef4f

File tree

7 files changed

+43
-309
lines changed

7 files changed

+43
-309
lines changed

app/detekt-baseline.xml

Lines changed: 18 additions & 286 deletions
Large diffs are not rendered by default.

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.google.firebase.messaging.FirebaseMessaging
44
import com.synonym.bitkitcore.FeeRates
55
import com.synonym.bitkitcore.LightningInvoice
66
import com.synonym.bitkitcore.Scanner
7+
import com.synonym.bitkitcore.createChannelRequestUrl
78
import com.synonym.bitkitcore.createWithdrawCallbackUrl
89
import com.synonym.bitkitcore.decode
910
import com.synonym.bitkitcore.lnurlAuth
@@ -447,8 +448,14 @@ class LightningRepo @Inject constructor(
447448
callback: String,
448449
nodeId: String,
449450
): Result<LnurlChannelResponse> = executeWhenNodeRunning("requestLnurlChannel") {
450-
// TODO use bitkit-core createChannelRequestUrl after it is fixed to prevent k1 duplicating
451-
lnurlService.requestLnurlChannel(k1 = k1, callback = callback, nodeId = nodeId)
451+
val url = createChannelRequestUrl(
452+
k1 = k1,
453+
callback = callback,
454+
localNodeId = nodeId,
455+
isPrivate = true,
456+
cancel = false,
457+
)
458+
lnurlService.requestLnurlChannel(url)
452459
}
453460

454461
suspend fun requestLnurlAuth(

app/src/main/java/to/bitkit/services/LnurlService.kt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,11 @@ class LnurlService @Inject constructor(
7777
}
7878

7979
suspend fun requestLnurlChannel(
80-
k1: String,
81-
callback: String,
82-
nodeId: String,
80+
url: String,
8381
): Result<LnurlChannelResponse> = runCatching {
84-
Logger.debug("Requesting LNURL channel request via: '$callback'")
82+
Logger.debug("Requesting LNURL channel request via: '$url'")
8583

86-
val response = client.get(callback) {
87-
url {
88-
parameters["k1"] = k1
89-
parameters["remoteid"] = nodeId
90-
parameters["private"] = "1" // Private channel
91-
}
92-
}
84+
val response: HttpResponse = client.get(url)
9385
Logger.debug("Http call: $response")
9486

9587
if (!response.status.isSuccess()) throw Exception("HTTP error: ${response.status}")

app/src/main/java/to/bitkit/ui/ContentView.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ import to.bitkit.ui.sheets.BackupSheet
137137
import to.bitkit.ui.sheets.LnurlAuthSheet
138138
import to.bitkit.ui.sheets.PinSheet
139139
import to.bitkit.ui.sheets.SendSheet
140+
import to.bitkit.ui.theme.TRANSITION_SHEET_MS
140141
import to.bitkit.ui.utils.AutoReadClipboardHandler
141142
import to.bitkit.ui.utils.composableWithDefaultTransitions
142143
import to.bitkit.ui.utils.screenSlideIn
@@ -961,7 +962,7 @@ private fun NavGraphBuilder.qrScanner(
961962
QrScanningScreen(navController = navController) { qrCode ->
962963
appViewModel.onScanResult(
963964
data = qrCode,
964-
delayMs = 650 // slight delay for nav transition before showing send sheet
965+
delayMs = TRANSITION_SHEET_MS,
965966
)
966967
}
967968
}

app/src/main/java/to/bitkit/ui/theme/Defaults.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ object AppSwitchDefaults {
127127
}
128128

129129
val ScreenTransitionMs = AnimationConstants.DefaultDurationMillis.milliseconds // 300ms
130+
const val TRANSITION_SHEET_MS = 650L
130131

131132
object Insets {
132133
val Top: Dp

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import androidx.annotation.StringRes
55
import androidx.compose.runtime.getValue
66
import androidx.compose.runtime.mutableStateOf
77
import androidx.compose.runtime.setValue
8-
import androidx.core.net.toUri
98
import androidx.lifecycle.ViewModel
109
import androidx.lifecycle.viewModelScope
1110
import com.synonym.bitkitcore.ActivityFilter
@@ -83,6 +82,7 @@ import to.bitkit.ui.Routes
8382
import to.bitkit.ui.components.Sheet
8483
import to.bitkit.ui.shared.toast.ToastEventBus
8584
import to.bitkit.ui.sheets.SendRoute
85+
import to.bitkit.ui.theme.ScreenTransitionMs
8686
import to.bitkit.utils.Logger
8787
import java.math.BigDecimal
8888
import javax.inject.Inject
@@ -378,6 +378,7 @@ class AppViewModel @Inject constructor(
378378
val newSatsPerVByte = state.feeRates?.getSatsPerVByteFor(speed)
379379
currentSatsPerVByte != newSatsPerVByte
380380
}
381+
381382
else -> false
382383
}
383384
val fee = when (speed is TransactionSpeed.Custom) {
@@ -695,17 +696,17 @@ class AppViewModel @Inject constructor(
695696
}
696697
}
697698

698-
private fun onScanLnurlAuth(data: LnurlAuthData, lnurl: String) {
699+
private suspend fun onScanLnurlAuth(data: LnurlAuthData, lnurl: String) {
699700
Logger.debug("LNURL: $data", context = TAG)
700-
701-
val domain = runCatching { data.uri.toUri().host }.getOrDefault(data.uri).orEmpty().trim()
702-
703-
showSheet(Sheet.LnurlAuth(domain = domain, lnurl = lnurl, k1 = data.k1))
701+
if (!isMainScanner) {
702+
hideSheet()
703+
delay(ScreenTransitionMs)
704+
}
705+
showSheet(Sheet.LnurlAuth(domain = data.domain, lnurl = lnurl, k1 = data.k1))
704706
}
705707

706708
fun requestLnurlAuth(callback: String, k1: String, domain: String) {
707709
viewModelScope.launch {
708-
// TODO pass callback and domain from bitkit-core when updated to accept decoded callback and return domain
709710
lightningRepo.requestLnurlAuth(
710711
callback = callback,
711712
k1 = k1,

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ activity-compose = { module = "androidx.activity:activity-compose", version.ref
4646
appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
4747
barcode-scanning = { module = "com.google.mlkit:barcode-scanning", version.ref = "barcodeScanning" }
4848
biometric = { module = "androidx.biometric:biometric", version.ref = "biometric" }
49-
#bitkitcore = { module = "com.synonym:bitkit-core-android", version = "0.1.3" } # mavenLocal
50-
bitkitcore = { module = "com.github.synonymdev:bitkit-core", version = "v0.1.8" } # jitpack
49+
#bitkitcore = { module = "com.synonym:bitkit-core-android", version = "0.1.9" } # mavenLocal
50+
bitkitcore = { module = "com.github.synonymdev:bitkit-core", version = "v0.1.9" } # jitpack
5151
bouncycastle-provider-jdk = { module = "org.bouncycastle:bcprov-jdk18on", version.ref = "bouncyCastle" }
5252
camera-camera2 = { module = "androidx.camera:camera-camera2", version.ref = "camera" }
5353
camera-lifecycle = { module = "androidx.camera:camera-lifecycle", version.ref = "camera" }

0 commit comments

Comments
 (0)