feat: add history sync worker
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.bitcointxoko.gudariwallet.data
|
||||
|
||||
import android.content.Context
|
||||
import androidx.datastore.preferences.core.booleanPreferencesKey
|
||||
import androidx.datastore.preferences.core.edit
|
||||
import androidx.datastore.preferences.preferencesDataStore
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
private val Context.historicalSyncDataStore by preferencesDataStore("historical_sync_prefs")
|
||||
|
||||
class HistoricalSyncStore(private val context: Context) {
|
||||
|
||||
private val KEY_COMPLETE = booleanPreferencesKey("historical_sync_complete")
|
||||
|
||||
/** One-shot suspend check — used by the worker guard at startup. */
|
||||
suspend fun isComplete(): Boolean =
|
||||
context.historicalSyncDataStore.data.first()[KEY_COMPLETE] == true
|
||||
|
||||
/** Persist the completion flag. Called once by the worker on success. */
|
||||
suspend fun markComplete() =
|
||||
context.historicalSyncDataStore.edit { it[KEY_COMPLETE] = true }
|
||||
|
||||
/** Observable — used by the onboarding UI to react to completion. */
|
||||
val isCompleteFlow: Flow<Boolean> =
|
||||
context.historicalSyncDataStore.data.map { it[KEY_COMPLETE] == true }
|
||||
}
|
||||
@@ -280,6 +280,9 @@ class LNbitsWalletRepository(
|
||||
return api.getPayments(secrets.invoiceKey(), limit, offset)
|
||||
}
|
||||
|
||||
override suspend fun getPaymentsPaginated(offset: Int, limit: Int): PaginatedPaymentsResponse =
|
||||
api.getPaymentsPaginated(secrets.invoiceKey(), offset, limit)
|
||||
|
||||
override suspend fun getPaymentDetail(checkingId: String): PaymentDetailResponse {
|
||||
return api.getPaymentDetail(secrets.invoiceKey(), checkingId)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bitcointxoko.gudariwallet.data
|
||||
|
||||
import com.bitcointxoko.gudariwallet.api.LnurlScanResponse
|
||||
import com.bitcointxoko.gudariwallet.api.PaginatedPaymentsResponse
|
||||
import com.bitcointxoko.gudariwallet.api.PaymentDetailResponse
|
||||
import com.bitcointxoko.gudariwallet.api.PaymentRecord
|
||||
import com.bitcointxoko.gudariwallet.api.WithdrawCallbackResponse
|
||||
@@ -36,6 +37,7 @@ interface WalletRepository {
|
||||
): WithdrawCallbackResponse
|
||||
suspend fun getLightningAddress(): String?
|
||||
suspend fun getPayments(offset: Int, limit: Int): List<PaymentRecord>
|
||||
suspend fun getPaymentsPaginated(offset: Int, limit: Int): PaginatedPaymentsResponse
|
||||
suspend fun getPaymentDetail(checkingId: String): PaymentDetailResponse
|
||||
suspend fun getFiatRate(currency: String): Double
|
||||
suspend fun getSupportedCurrencies(): List<String>
|
||||
|
||||
Reference in New Issue
Block a user