fix: adminKey ignored

This commit is contained in:
2026-06-09 00:46:14 +02:00
parent 767d7d19cf
commit 2490ea2f75
2 changed files with 37 additions and 28 deletions
@@ -31,14 +31,14 @@ object LNbitsClient {
fun create(secrets: SecretStore): LNbitsApi { fun create(secrets: SecretStore): LNbitsApi {
// Auth header interceptor — reads invoice key per-request (unchanged) // Auth header interceptor — reads invoice key per-request (unchanged)
val authInterceptor = Interceptor { chain -> // val authInterceptor = Interceptor { chain ->
val key = runBlocking { secrets.invoiceKey() } // val key = runBlocking { secrets.invoiceKey() }
chain.proceed( // chain.proceed(
chain.request().newBuilder() // chain.request().newBuilder()
.header("X-Api-Key", key) // .header("X-Api-Key", key)
.build() // .build()
) // )
} // }
// Dynamic base URL interceptor — rewrites the placeholder host to the // Dynamic base URL interceptor — rewrites the placeholder host to the
// real base URL at request time, not at Retrofit construction time. // real base URL at request time, not at Retrofit construction time.
@@ -65,7 +65,7 @@ object LNbitsClient {
} }
val client = httpClient.newBuilder() val client = httpClient.newBuilder()
.addInterceptor(authInterceptor) // .addInterceptor(authInterceptor)
.addInterceptor(dynamicBaseUrlInterceptor) .addInterceptor(dynamicBaseUrlInterceptor)
.apply { .apply {
// Logging goes LAST — after URL rewrite — so logs show the real URL // Logging goes LAST — after URL rewrite — so logs show the real URL
@@ -19,6 +19,7 @@ import com.bitcointxoko.gudariwallet.data.HistoricalSyncStore
import com.bitcointxoko.gudariwallet.security.SecretStore import com.bitcointxoko.gudariwallet.security.SecretStore
import com.bitcointxoko.gudariwallet.sync.HistoricalSyncWorker import com.bitcointxoko.gudariwallet.sync.HistoricalSyncWorker
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import timber.log.Timber
private const val PAGE_WELCOME = 0 private const val PAGE_WELCOME = 0
private const val PAGE_SERVER_URL = 1 private const val PAGE_SERVER_URL = 1
@@ -64,20 +65,20 @@ fun OnboardingScreen(
LaunchedEffect(pagerState.currentPage) { error = null } LaunchedEffect(pagerState.currentPage) { error = null }
var previousPage by remember { mutableIntStateOf(0) } // var previousPage by remember { mutableIntStateOf(0) }
LaunchedEffect(pagerState.currentPage) { // LaunchedEffect(pagerState.currentPage) {
val current = pagerState.currentPage // val current = pagerState.currentPage
if (current > previousPage) { // if (current > previousPage) {
// User moved forward — save whatever the previous page owned // // User moved forward — save whatever the previous page owned
when (previousPage) { // when (previousPage) {
PAGE_SERVER_URL -> secretStore.saveBaseUrl(baseUrl) // PAGE_SERVER_URL -> secretStore.saveBaseUrl(baseUrl)
PAGE_INVOICE -> secretStore.saveInvoiceKey(invoiceKey) // PAGE_INVOICE -> secretStore.saveInvoiceKey(invoiceKey)
PAGE_ADMIN -> secretStore.saveAdminKey(adminKey) // PAGE_ADMIN -> secretStore.saveAdminKey(adminKey)
else -> Unit // else -> Unit
} // }
} // }
previousPage = current // previousPage = current
} // }
fun validateCurrentPage(): Boolean { fun validateCurrentPage(): Boolean {
error = when (pagerState.currentPage) { error = when (pagerState.currentPage) {
@@ -172,11 +173,19 @@ fun OnboardingScreen(
Button(onClick = { Button(onClick = {
if (!validateCurrentPage()) return@Button if (!validateCurrentPage()) return@Button
scope.launch { scope.launch {
// Save each field as soon as the user advances past it
when (pagerState.currentPage) { when (pagerState.currentPage) {
PAGE_SERVER_URL -> secretStore.saveBaseUrl(baseUrl) PAGE_SERVER_URL -> {
PAGE_INVOICE -> secretStore.saveInvoiceKey(invoiceKey) Timber.d("ONBOARDING saving baseUrl (len=${baseUrl.length}): $baseUrl")
PAGE_ADMIN -> secretStore.saveAdminKey(adminKey) secretStore.saveBaseUrl(baseUrl)
}
PAGE_INVOICE -> {
Timber.d("ONBOARDING saving invoiceKey (len=${invoiceKey.length}): $invoiceKey")
secretStore.saveInvoiceKey(invoiceKey)
}
PAGE_ADMIN -> {
Timber.d("ONBOARDING saving adminKey (len=${adminKey.length}): $adminKey")
secretStore.saveAdminKey(adminKey)
}
else -> Unit else -> Unit
} }
pagerState.animateScrollToPage(pagerState.currentPage + 1) pagerState.animateScrollToPage(pagerState.currentPage + 1)