-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBackupTimedSheet.kt
More file actions
51 lines (43 loc) · 1.58 KB
/
BackupTimedSheet.kt
File metadata and controls
51 lines (43 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package to.bitkit.utils.timedsheets.sheets
import kotlinx.coroutines.flow.first
import to.bitkit.data.SettingsStore
import to.bitkit.ext.nowMillis
import to.bitkit.repositories.WalletRepo
import to.bitkit.ui.components.TimedSheetType
import to.bitkit.utils.Logger
import to.bitkit.utils.timedsheets.ONE_DAY_ASK_INTERVAL_MILLIS
import to.bitkit.utils.timedsheets.TimedSheetItem
import to.bitkit.utils.timedsheets.checkTimeout
import javax.inject.Inject
import kotlin.time.ExperimentalTime
class BackupTimedSheet @Inject constructor(
private val settingsStore: SettingsStore,
private val walletRepo: WalletRepo,
) : TimedSheetItem {
override val type = TimedSheetType.BACKUP
override val priority = 4
override suspend fun shouldShow(): Boolean {
val settings = settingsStore.data.first()
if (settings.backupVerified) return false
val hasBalance = walletRepo.balanceState.value.totalSats > 0U
if (!hasBalance) return false
return checkTimeout(
lastIgnoredMillis = settings.backupWarningIgnoredMillis,
intervalMillis = ONE_DAY_ASK_INTERVAL_MILLIS
)
}
override suspend fun onShown() {
Logger.debug("Backup sheet shown", context = TAG)
}
@OptIn(ExperimentalTime::class)
override suspend fun onDismissed() {
val currentTime = nowMillis()
settingsStore.update {
it.copy(backupWarningIgnoredMillis = currentTime)
}
Logger.debug("Backup sheet dismissed", context = TAG)
}
companion object {
private const val TAG = "BackupTimedSheet"
}
}