Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions app/src/main/java/to/bitkit/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,4 @@ class CurrentActivity : ActivityLifecycleCallbacks {
override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) = Unit
override fun onActivityDestroyed(activity: Activity) = Unit
}

/**
* Returns the current activity of the application.
*
* **NEVER** store the result to a variable, further calls to such reference can lead to memory leaks.
*
* **ALWAYS** retrieve the current activity functionally, processing on the result of this function.
* */
internal inline fun <reified T> currentActivity(): T? {
return when (val activity = App.currentActivity?.value) {
is T -> activity
else -> null
}
}
// endregion
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class LightningNodeService : Service() {
ACTION_STOP_SERVICE_AND_APP -> {
Logger.debug("ACTION_STOP_SERVICE_AND_APP detected", context = TAG)
// Close all activities
App.currentActivity?.value?.finishAffinity()
App.currentActivity?.value?.finishAndRemoveTask()
// Stop the service
stopSelf()
return START_NOT_STICKY
Expand Down
38 changes: 23 additions & 15 deletions app/src/main/java/to/bitkit/data/backup/VssStoreIdProvider.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package to.bitkit.data.backup

import org.lightningdevkit.ldknode.Network
import com.synonym.vssclient.vssDeriveStoreId
import to.bitkit.data.keychain.Keychain
import to.bitkit.env.Env
import to.bitkit.ext.toHex
import to.bitkit.ext.toSha256
import to.bitkit.utils.Logger
import to.bitkit.utils.ServiceError
import javax.inject.Inject
Expand All @@ -14,21 +12,31 @@ import javax.inject.Singleton
class VssStoreIdProvider @Inject constructor(
private val keychain: Keychain,
) {
@Volatile
private var cachedStoreId: String? = null

fun getVssStoreId(): String {
// TODO Temp fix as we don't have VSS auth yet
if (Env.network == Network.BITCOIN) {
error(
"Do not run this on mainnet until VSS auth is implemented. Below hack is a temporary fix and not safe for mainnet."
)
}
cachedStoreId?.let { return it }

return synchronized(this) {
cachedStoreId?.let { return it }

val mnemonic = keychain.loadString(Keychain.Key.BIP39_MNEMONIC.name) ?: throw ServiceError.MnemonicNotFound
val mnemonicData = mnemonic.encodeToByteArray()
val hashedMnemonic = mnemonicData.toSha256()
val mnemonic = keychain.loadString(Keychain.Key.BIP39_MNEMONIC.name) ?: throw ServiceError.MnemonicNotFound
val passphrase = keychain.loadString(Keychain.Key.BIP39_PASSPHRASE.name)

val storeIdHack = Env.vssStoreId + hashedMnemonic.toHex()
Logger.info("storeIdHack: $storeIdHack")
val storeId = vssDeriveStoreId(
prefix = Env.vssStoreIdPrefix,
mnemonic = mnemonic,
passphrase = passphrase,
)

Logger.info("VSS store id: '$storeId'", context = TAG)
cachedStoreId = storeId
storeId
}
}

return storeIdHack
companion object {
private const val TAG = "VssStoreIdProvider"
}
}
9 changes: 2 additions & 7 deletions app/src/main/java/to/bitkit/env/Env.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,11 @@ internal object Env {
}

val lnurlAuthSeverUrl = when (network) {
// Network.REGTEST -> "http://localhost:3000/auth"
// Network.REGTEST -> "http://localhost:5005/auth"
else -> "" // TODO implement LNURL-auth Server for other networks
}

val vssStoreId
get() = when (network) {
Network.REGTEST -> "bitkit_regtest"
Network.TESTNET -> "bitkit_testnet"
else -> TODO("${network.name} network not implemented")
}
val vssStoreIdPrefix get() = "bitkit_v1_${network.name.lowercase()}"

val esploraServerUrl
get() = when (network) {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/to/bitkit/ui/components/IsOnlineTracker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package to.bitkit.ui.components
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import to.bitkit.R
Expand All @@ -17,7 +19,15 @@ fun IsOnlineTracker(
val context = LocalContext.current
val connectivityState by app.isOnline.collectAsStateWithLifecycle(initialValue = ConnectivityState.CONNECTED)

val (isFirstEmission, setIsFirstEmission) = remember { mutableStateOf(true) }

LaunchedEffect(connectivityState) {
// Skip the first emission to prevent toast on startup
if (isFirstEmission) {
setIsFirstEmission(true)
return@LaunchedEffect
}

when (connectivityState) {
ConnectivityState.CONNECTED -> {
app.toast(
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ test-junit-ext = { module = "androidx.test.ext:junit", version.ref = "junitExt"
test-mockito-kotlin = { module = "org.mockito.kotlin:mockito-kotlin", version.ref = "mockitoKotlin" }
test-robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
test-turbine = { group = "app.cash.turbine", name = "turbine", version.ref = "turbine" }
vss = { module = "com.synonym:vss-client-android", version = "0.2.0" }
vss = { module = "com.synonym:vss-client-android", version = "0.3.0" }
work-runtime-ktx = { module = "androidx.work:work-runtime-ktx", version.ref = "workRuntimeKtx" }
zxing = { module = "com.google.zxing:core", version.ref = "zxing" }
lottie = { module = "com.airbnb.android:lottie-compose", version.ref = "lottieVersion" }
Expand Down