Skip to content

Commit aab6297

Browse files
committed
chore: cleanup dev settings vm
1 parent 094518f commit aab6297

1 file changed

Lines changed: 49 additions & 72 deletions

File tree

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

Lines changed: 49 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ import com.google.firebase.messaging.FirebaseMessaging
88
import com.synonym.bitkitcore.testNotification
99
import dagger.hilt.android.lifecycle.HiltViewModel
1010
import dagger.hilt.android.qualifiers.ApplicationContext
11-
import kotlinx.coroutines.CoroutineDispatcher
1211
import kotlinx.coroutines.launch
1312
import kotlinx.coroutines.tasks.await
1413
import to.bitkit.R
1514
import to.bitkit.data.AppDb
1615
import to.bitkit.data.CacheStore
1716
import to.bitkit.data.WidgetsStore
18-
import to.bitkit.di.BgDispatcher
1917
import to.bitkit.env.Env
2018
import to.bitkit.models.NewTransactionSheetDetails
2119
import to.bitkit.models.NewTransactionSheetDirection
@@ -34,7 +32,6 @@ import javax.inject.Inject
3432
@HiltViewModel
3533
class DevSettingsViewModel @Inject constructor(
3634
@ApplicationContext private val context: Context,
37-
@BgDispatcher private val bgDispatcher: CoroutineDispatcher,
3835
private val firebaseMessaging: FirebaseMessaging,
3936
private val lightningRepo: LightningRepo,
4037
private val walletRepo: WalletRepo,
@@ -46,71 +43,59 @@ class DevSettingsViewModel @Inject constructor(
4643
private val appDb: AppDb,
4744
) : ViewModel() {
4845

49-
fun openChannel() {
50-
viewModelScope.launch(bgDispatcher) {
51-
val peer = lightningRepo.getPeers()?.firstOrNull()
46+
fun openChannel() = viewModelScope.launch {
47+
val peer = lightningRepo.getPeers()?.firstOrNull()
5248

53-
if (peer == null) {
54-
ToastEventBus.send(type = Toast.ToastType.WARNING, title = "No peer connected")
55-
return@launch
56-
}
57-
58-
lightningRepo.openChannel(peer, 50_000u, 25_000u)
59-
.onSuccess {
60-
ToastEventBus.send(type = Toast.ToastType.INFO, title = "Channel pending")
61-
}
62-
.onFailure { ToastEventBus.send(it) }
49+
if (peer == null) {
50+
ToastEventBus.send(type = Toast.ToastType.WARNING, title = "No peer connected")
51+
return@launch
6352
}
64-
}
6553

66-
fun registerForNotifications() {
67-
viewModelScope.launch {
68-
lightningRepo.registerForNotifications()
69-
.onSuccess {
70-
ToastEventBus.send(type = Toast.ToastType.INFO, title = "Registered for notifications")
71-
}
72-
.onFailure { ToastEventBus.send(it) }
73-
}
54+
lightningRepo.openChannel(peer, 50_000u, 25_000u)
55+
.onSuccess {
56+
ToastEventBus.send(type = Toast.ToastType.INFO, title = "Channel pending")
57+
}
58+
.onFailure { ToastEventBus.send(it) }
7459
}
7560

76-
fun testLspNotification() {
77-
viewModelScope.launch(bgDispatcher) {
78-
runCatching {
79-
testNotification(
80-
deviceToken = firebaseMessaging.token.await(),
81-
secretMessage = "hello",
82-
notificationType = "incomingHtlc",
83-
customUrl = Env.blocktankNotificationApiUrl,
84-
)
85-
ToastEventBus.send(type = Toast.ToastType.INFO, title = "LSP notification sent to this device")
86-
}.onFailure {
87-
ToastEventBus.send(type = Toast.ToastType.WARNING, title = "Error testing LSP notification")
61+
fun registerForNotifications() = viewModelScope.launch {
62+
lightningRepo.registerForNotifications()
63+
.onSuccess {
64+
ToastEventBus.send(type = Toast.ToastType.INFO, title = "Registered for notifications")
8865
}
89-
}
66+
.onFailure { ToastEventBus.send(it) }
9067
}
9168

92-
fun fakeBgReceive() {
93-
viewModelScope.launch {
94-
cacheStore.setBackgroundReceive(
95-
NewTransactionSheetDetails(
96-
type = NewTransactionSheetType.LIGHTNING,
97-
direction = NewTransactionSheetDirection.RECEIVED,
98-
sats = 21_000_000,
99-
)
69+
fun testLspNotification() = viewModelScope.launch {
70+
runCatching {
71+
testNotification(
72+
deviceToken = firebaseMessaging.token.await(),
73+
secretMessage = "hello",
74+
notificationType = "incomingHtlc",
75+
customUrl = Env.blocktankNotificationApiUrl,
10076
)
77+
ToastEventBus.send(type = Toast.ToastType.INFO, title = "LSP notification sent to this device")
78+
}.onFailure {
79+
ToastEventBus.send(type = Toast.ToastType.WARNING, title = "Error testing LSP notification")
10180
}
10281
}
10382

104-
fun resetWidgetsState() {
105-
viewModelScope.launch {
106-
widgetsStore.reset()
107-
}
83+
fun fakeBgReceive() = viewModelScope.launch {
84+
cacheStore.setBackgroundReceive(
85+
NewTransactionSheetDetails(
86+
type = NewTransactionSheetType.LIGHTNING,
87+
direction = NewTransactionSheetDirection.RECEIVED,
88+
sats = 21_000_000,
89+
)
90+
)
10891
}
10992

110-
fun refreshCurrencyRates() {
111-
viewModelScope.launch {
112-
currencyRepo.triggerRefresh()
113-
}
93+
fun resetWidgetsState() = viewModelScope.launch {
94+
widgetsStore.reset()
95+
}
96+
97+
fun refreshCurrencyRates() = viewModelScope.launch {
98+
currencyRepo.triggerRefresh()
11499
}
115100

116101
fun zipLogsForSharing(onReady: (Uri) -> Unit) {
@@ -127,33 +112,25 @@ class DevSettingsViewModel @Inject constructor(
127112
}
128113
}
129114

130-
fun wipeLogs() = Logger.reset()
131-
132-
fun resetBackupState() {
133-
viewModelScope.launch {
134-
cacheStore.update { it.copy(backupStatuses = mapOf()) }
135-
}
115+
fun resetBackupState() = viewModelScope.launch {
116+
cacheStore.update { it.copy(backupStatuses = mapOf()) }
136117
}
137118

138-
fun wipeWallet() {
139-
viewModelScope.launch {
140-
walletRepo.wipeWallet()
141-
}
119+
fun wipeWallet() = viewModelScope.launch {
120+
walletRepo.wipeWallet()
142121
}
143122

144-
fun resetCacheStore() {
145-
viewModelScope.launch {
146-
cacheStore.reset()
147-
}
123+
fun resetCacheStore() = viewModelScope.launch {
124+
cacheStore.reset()
148125
}
149126

150127
fun resetDatabase() = viewModelScope.launch {
151128
appDb.clearAllTables()
152129
}
153130

154-
fun resetBlocktankState() {
155-
viewModelScope.launch {
156-
blocktankRepo.resetState()
157-
}
131+
fun resetBlocktankState() = viewModelScope.launch {
132+
blocktankRepo.resetState()
158133
}
134+
135+
fun wipeLogs() = Logger.reset()
159136
}

0 commit comments

Comments
 (0)