diff --git a/app/src/main/java/com/tari/android/wallet/application/MigrationManager.kt b/app/src/main/java/com/tari/android/wallet/application/MigrationManager.kt index 1d9259730..d2123e333 100644 --- a/app/src/main/java/com/tari/android/wallet/application/MigrationManager.kt +++ b/app/src/main/java/com/tari/android/wallet/application/MigrationManager.kt @@ -2,48 +2,27 @@ package com.tari.android.wallet.application import com.tari.android.wallet.BuildConfig import com.tari.android.wallet.application.walletManager.WalletManager -import com.tari.android.wallet.data.sharedPrefs.network.NetworkPrefRepository import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.apache.maven.artifact.versioning.DefaultArtifactVersion -import java.io.File import javax.inject.Inject import javax.inject.Singleton @Singleton class MigrationManager @Inject constructor( private val walletManager: WalletManager, - private val application: TariWalletApplication, - private val networkRepository: NetworkPrefRepository, ) { - - suspend fun validateVersion(onValid: () -> Unit, onError: () -> Unit) { - val walletVersion = getCurrentWalletVersion() - - // FIXME: Temporary migration mechanism. It should be removed when minValidVersion is greater than 1.0.0-rc.8 - if (walletVersion.isNotEmpty() && DefaultArtifactVersion(walletVersion) < DefaultArtifactVersion(PEER_DB_MIGRATION_MIN_VERSION)) { - performPeerDbMigration() - } - - if (walletVersion.isEmpty() || DefaultArtifactVersion(walletVersion) < DefaultArtifactVersion(BuildConfig.LIB_WALLET_MIN_VALID_VERSION)) { + suspend fun validateVersion(onValid: () -> Unit, onError: () -> Unit) = withContext(Dispatchers.IO) { + val walletVersion = walletManager.getCommsConfig().getLastVersion() + .replace("v", "") + .takeIf { it.isNotEmpty() } + ?.let { DefaultArtifactVersion(it) } + val minValidVersion = DefaultArtifactVersion(BuildConfig.LIB_WALLET_MIN_VALID_VERSION.replace("v", "")) + + if (walletVersion == null || walletVersion < minValidVersion) { onError() } else { onValid() } } - - private suspend fun getCurrentWalletVersion(): String = withContext(Dispatchers.IO) { walletManager.getCommsConfig().getLastVersion() } - - private suspend fun performPeerDbMigration() = withContext(Dispatchers.IO) { - application.applicationInfo.dataDir?.let { appDir -> - val peerDbFile = File(appDir, "files/${networkRepository.currentNetwork.network.uriComponent}/data.mdb") - if (peerDbFile.exists()) { - peerDbFile.delete() - } - } - } - - companion object { - const val PEER_DB_MIGRATION_MIN_VERSION = "1.0.0-rc.8" - } } diff --git a/app/src/main/java/com/tari/android/wallet/ui/fragment/auth/AuthViewModel.kt b/app/src/main/java/com/tari/android/wallet/ui/fragment/auth/AuthViewModel.kt index 19b195ad3..1fd27398e 100644 --- a/app/src/main/java/com/tari/android/wallet/ui/fragment/auth/AuthViewModel.kt +++ b/app/src/main/java/com/tari/android/wallet/ui/fragment/auth/AuthViewModel.kt @@ -1,8 +1,9 @@ package com.tari.android.wallet.ui.fragment.auth -import androidx.lifecycle.viewModelScope import com.tari.android.wallet.R import com.tari.android.wallet.application.MigrationManager +import com.tari.android.wallet.extension.launchOnIo +import com.tari.android.wallet.extension.launchOnMain import com.tari.android.wallet.infrastructure.security.biometric.BiometricAuthenticationService import com.tari.android.wallet.service.service.WalletServiceLauncher import com.tari.android.wallet.ui.common.CommonViewModel @@ -12,8 +13,6 @@ import com.tari.android.wallet.ui.dialog.modular.modules.button.ButtonModule import com.tari.android.wallet.ui.dialog.modular.modules.button.ButtonStyle import com.tari.android.wallet.ui.dialog.modular.modules.head.HeadModule import com.tari.android.wallet.ui.fragment.home.navigation.Navigation -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch import javax.inject.Inject class AuthViewModel : CommonViewModel() { @@ -32,15 +31,15 @@ class AuthViewModel : CommonViewModel() { init { component.inject(this) - viewModelScope.launch(Dispatchers.IO) { + launchOnIo { migrationManager.validateVersion( onValid = { - viewModelScope.launch(Dispatchers.Main) { + launchOnMain { goAuth.postValue(Unit) } }, onError = { - viewModelScope.launch(Dispatchers.Main) { + launchOnMain { showIncompatibleVersionDialog() } } @@ -65,7 +64,7 @@ class AuthViewModel : CommonViewModel() { private fun deleteWallet() { // disable CTAs - viewModelScope.launch(Dispatchers.IO) { + launchOnIo { walletServiceLauncher.stopAndDelete() navigation.postValue(Navigation.TxListNavigation.ToSplashScreen) } diff --git a/build.gradle b/build.gradle index 33e5a5f2a..76b914395 100644 --- a/build.gradle +++ b/build.gradle @@ -6,8 +6,8 @@ buildscript { ext.coroutines_version = '1.8.0' // build & version - ext.buildNumber = 304 - ext.versionNumber = "0.27.0" + ext.buildNumber = 306 + ext.versionNumber = "0.27.1" // JNI libs ext.libwalletHostURL = "https://github.com/tari-project/tari/releases/download/"