Skip to content

Commit

Permalink
Merge pull request #1092 from tari-project/release/0.25.3
Browse files Browse the repository at this point in the history
feat: align with master
  • Loading branch information
igordanilcenko authored Apr 16, 2024
2 parents ab9b817 + 16bceff commit 6ded9d3
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 52 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ apply plugin: "kotlin-android"
apply plugin: "kotlin-kapt"
apply from: "../download-libwallet.gradle"
apply plugin: "io.sentry.android.gradle"
apply plugin: "kotlin-parcelize"

android {
namespace "com.tari.android.wallet"
Expand Down Expand Up @@ -37,6 +38,7 @@ android {
buildConfigField("String", "YAT_ORGANIZATION_RETURN_URL", "\"${yatProperties.getProperty("yat.returnUrl")}\"")
def dropboxProperties = loadDropboxProps()
buildConfigField("String", "DROPBOX_ACCESS_TOKEN", "\"${dropboxProperties.getProperty("dropbox_key")}\"")
buildConfigField("String", "LIB_WALLET_MIN_VALID_VERSION", "\"$libwalletMinValidVersion\"")
}

flavorDimensions.add("privacy-mode")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tari.android.wallet.application

import androidx.lifecycle.viewModelScope
import com.tari.android.wallet.BuildConfig
import com.tari.android.wallet.ui.common.SimpleViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -11,13 +12,12 @@ import javax.inject.Singleton
@Singleton
class MigrationManager @Inject constructor(private val manager: WalletManager) {

private val minValidVersion = DefaultArtifactVersion("v0.52.0")
private val simpleViewModel = SimpleViewModel()

fun validateVersion(onValid: () -> Unit, onError: () -> Unit) {
val walletVersion = getCurrentWalletVersion()

if (walletVersion.isEmpty() || DefaultArtifactVersion(walletVersion) < minValidVersion) {
if (walletVersion.isEmpty() || DefaultArtifactVersion(walletVersion) < DefaultArtifactVersion(BuildConfig.LIB_WALLET_MIN_VALID_VERSION)) {
simpleViewModel.viewModelScope.launch(Dispatchers.Main) { onError() }
} else {
simpleViewModel.viewModelScope.launch(Dispatchers.Main) { onValid() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ import com.tari.android.wallet.service.connection.TariWalletServiceConnection
import io.reactivex.disposables.CompositeDisposable
import org.apache.commons.io.IOUtils

private const val REGEX_ONION = "(.+::[A-Za-z0-9 ]{64}::/onion3/[A-Za-z0-9]+:[\\d]+)"
private const val REGEX_IPV4 = "(.+::[A-Za-z0-9 ]{64}::/ip4/[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}/tcp/[0-9]{2,6})"

class BaseNodes(
private val context: Context,
private val baseNodeSharedRepository: BaseNodeSharedRepository,
private val networkRepository: NetworkRepository,
) {
private val logger = Logger.t(this::class.simpleName)

private val compositeDisposable = CompositeDisposable()

private val serviceConnection = TariWalletServiceConnection()
Expand All @@ -45,9 +50,6 @@ class BaseNodes(
}.addTo(compositeDisposable)
}

val onionRegex = "(.+::[A-Za-z0-9 ]{64}::/onion3/[A-Za-z0-9]+:[\\d]+)"
val ipV4Regex = "(.+::[A-Za-z0-9 ]{64}::/ip4/[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}/tcp/[0-9]{2,6})"

/**
* Returns the list of base nodes in the resource file base_nodes.txt as pairs of
* ({name}, {public_key_hex}, {public_address}).
Expand All @@ -57,20 +59,20 @@ class BaseNodes(
context.resources.openRawResource(getBaseNodeResource(networkRepository.currentNetwork!!.network)),
"UTF-8"
)
Logger.t(this::class.simpleName).e("baseNodeList: $fileContent")
logger.i("baseNodeList: $fileContent")
val list = mutableListOf<BaseNodeDto>()
val onionBaseNodes = findAndAddBaseNode(fileContent, onionRegex).toList()
val ipV4BaseNodes = findAndAddBaseNode(fileContent, ipV4Regex).toList()
val onionBaseNodes = findAndAddBaseNode(fileContent, REGEX_ONION).toList()
val ipV4BaseNodes = findAndAddBaseNode(fileContent, REGEX_IPV4).toList()
list.addAll(onionBaseNodes)
list.addAll(ipV4BaseNodes)
list.sortedBy { it.name }
}

private fun findAndAddBaseNode(fileContent: String, regex: String): Sequence<BaseNodeDto> {
return Regex(regex).findAll(fileContent).map { matchResult ->
val tripleString = matchResult.value.split("::")
Logger.t(this::class.simpleName).i("baseNodeList0: $tripleString, baseNodeList1: ${tripleString[1]}, baseNodeList2: ${tripleString[2]}")
BaseNodeDto(tripleString[0], tripleString[1], tripleString[2])
val (name, publicKeyHex, address) = matchResult.value.split("::")
logger.i("baseNodeList0: $name, baseNodeList1: $publicKeyHex, baseNodeList2: $address")
BaseNodeDto(name, publicKeyHex, address)
}
}

Expand All @@ -95,21 +97,21 @@ class BaseNodes(

fun startSync() {
try {
Logger.t(this::class.simpleName).i("startSync")
logger.i("startSync")
//essential for wallet creation flow
val baseNode = baseNodeSharedRepository.currentBaseNode ?: return
serviceConnection.currentState.service ?: return
if (EventBus.walletState.publishSubject.value != WalletState.Running) return

Logger.t(this::class.simpleName).i("startSync:publicKeyHex: ${baseNode.publicKeyHex}")
Logger.t(this::class.simpleName).i("startSync:address: ${baseNode.address}")
Logger.t(this::class.simpleName).i("startSync:address: ${Gson().toJson(baseNodeSharedRepository.userBaseNodes)}")
logger.i("startSync:publicKeyHex: ${baseNode.publicKeyHex}")
logger.i("startSync:address: ${baseNode.address}")
logger.i("startSync:userBaseNodes: ${Gson().toJson(baseNodeSharedRepository.userBaseNodes)}")
val baseNodeKeyFFI = FFIPublicKey(HexString(baseNode.publicKeyHex))
FFIWallet.instance?.addBaseNodePeer(baseNodeKeyFFI, baseNode.address)
baseNodeKeyFFI.destroy()
walletService.getWithError { error, wallet -> wallet.startBaseNodeSync(error) }
} catch (e: Throwable) {
Logger.t(this::class.simpleName).i("startSync")
logger.i("startSync:error connecting to base node: ${e.message}")
setNextBaseNode()
startSync()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ abstract class CommonFragment<Binding : ViewBinding, VM : CommonViewModel> : Fra

override fun onResume() {
super.onResume()
if (!isAdded) return

if (blockScreenRecording) {
requireActivity().window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class CommonAdapter<T : CommonViewHolderItem> : ListAdapter<T, CommonVi

abstract var viewHolderBuilders: List<ViewHolderBuilder>

fun update(newItems: MutableList<T>) {
fun update(newItems: List<T>) {
submitList(newItems.toList())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import com.daasuu.ei.Ease
import com.daasuu.ei.EasingInterpolator
Expand All @@ -49,7 +50,7 @@ import com.tari.android.wallet.application.WalletState
import com.tari.android.wallet.databinding.FragmentLocalAuthBinding
import com.tari.android.wallet.event.EventBus
import com.tari.android.wallet.extension.addTo
import com.tari.android.wallet.extension.observe
import com.tari.android.wallet.extension.launchAndRepeatOnLifecycle
import com.tari.android.wallet.infrastructure.security.biometric.BiometricAuthenticationException
import com.tari.android.wallet.ui.common.CommonFragment
import com.tari.android.wallet.ui.extension.doOnGlobalLayout
Expand Down Expand Up @@ -78,11 +79,15 @@ class LocalAuthFragment : CommonFragment<FragmentLocalAuthBinding, LocalAuthView
}

private fun observeUi() = with(viewModel) {
observe(secureState) {
ui.continueBtn.setVisible(it.pinCodeSecured)
ui.authTypeBiometrics.setVisible(it.biometricsAvailable)
ui.secureWithPasscode.setVisible(!it.pinCodeSecured)
ui.secureWithBiometrics.setVisible(it.biometricsAvailable && !it.biometricsSecured)
viewLifecycleOwner.launchAndRepeatOnLifecycle(Lifecycle.State.STARTED) {
launch {
secureState.collect { state ->
ui.continueBtn.setVisible(state.pinCodeSecured)
ui.authTypeBiometrics.setVisible(state.biometricsAvailable)
ui.secureWithPasscode.setVisible(!state.pinCodeSecured)
ui.secureWithBiometrics.setVisible(state.biometricsAvailable && !state.biometricsSecured)
}
}
}
}

Expand Down Expand Up @@ -122,10 +127,11 @@ class LocalAuthFragment : CommonFragment<FragmentLocalAuthBinding, LocalAuthView
lifecycleScope.launch {
try {
val subtitle = string(onboarding_auth_biometric_prompt)
if (viewModel.authService.authenticate(this@LocalAuthFragment, string(onboarding_auth_title), subtitle))
if (viewModel.authService.authenticate(this@LocalAuthFragment, string(onboarding_auth_title), subtitle)) {
viewModel.securedWithBiometrics()
}
} catch (exception: BiometricAuthenticationException) {
viewModel.logger.i( exception.message + "Biometric authentication failed")
viewModel.logger.i(exception.message + "Biometric authentication failed")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.tari.android.wallet.ui.fragment.onboarding.localAuth

import androidx.lifecycle.MutableLiveData
import com.tari.android.wallet.extension.addTo
import com.tari.android.wallet.infrastructure.backup.BackupManager
import com.tari.android.wallet.infrastructure.security.biometric.BiometricAuthenticationService
import com.tari.android.wallet.ui.common.CommonViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import javax.inject.Inject

class LocalAuthViewModel : CommonViewModel() {
Expand All @@ -15,8 +17,8 @@ class LocalAuthViewModel : CommonViewModel() {
@Inject
lateinit var backupManager: BackupManager

val secureState = MutableLiveData(SecureState(true, false, false))

private val _secureState = MutableStateFlow(SecureState())
val secureState = _secureState.asStateFlow()

init {
component.inject(this)
Expand All @@ -28,16 +30,18 @@ class LocalAuthViewModel : CommonViewModel() {
}.addTo(compositeDisposable)
}

fun updateState() {
secureState.value = SecureState(
authService.isBiometricAuthAvailable,
securityPrefRepository.pinCode != null,
securityPrefRepository.biometricsAuth == true
)
private fun updateState() {
_secureState.update {
SecureState(
biometricsAvailable = authService.isBiometricAuthAvailable,
pinCodeSecured = securityPrefRepository.pinCode != null,
biometricsSecured = securityPrefRepository.biometricsAuth == true,
)
}
}

fun securedWithBiometrics() {
securityPrefRepository.biometricsAuth = true
secureState.value = secureState.value!!.copy(biometricsSecured = true)
_secureState.update { it.copy(biometricsSecured = true) }
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
package com.tari.android.wallet.ui.fragment.onboarding.localAuth

data class SecureState(val biometricsAvailable: Boolean, val pinCodeSecured: Boolean, val biometricsSecured: Boolean)
data class SecureState(
val biometricsAvailable: Boolean = true,
val pinCodeSecured: Boolean = false,
val biometricsSecured: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.tari.android.wallet.R.drawable.vector_all_settings_screen_recording_i
import com.tari.android.wallet.R.drawable.vector_all_settings_select_base_node_icon
import com.tari.android.wallet.R.drawable.vector_all_settings_select_network_icon
import com.tari.android.wallet.R.drawable.vector_all_settings_select_theme_icon
import com.tari.android.wallet.R.drawable.vector_all_settings_block_explorer_icon
import com.tari.android.wallet.R.drawable.vector_all_settings_user_agreement_icon
import com.tari.android.wallet.R.drawable.vector_all_settings_visit_tari_icon
import com.tari.android.wallet.R.drawable.vector_all_settings_yat_icon
Expand All @@ -30,6 +31,7 @@ import com.tari.android.wallet.R.string.all_settings_biometrics
import com.tari.android.wallet.R.string.all_settings_bluetooth_settings
import com.tari.android.wallet.R.string.all_settings_bridge_configuration
import com.tari.android.wallet.R.string.all_settings_connect_yats
import com.tari.android.wallet.R.string.explorer_url
import com.tari.android.wallet.R.string.all_settings_contribute
import com.tari.android.wallet.R.string.all_settings_create_pin_code
import com.tari.android.wallet.R.string.all_settings_data_collection
Expand All @@ -41,6 +43,7 @@ import com.tari.android.wallet.R.string.all_settings_report_a_bug
import com.tari.android.wallet.R.string.all_settings_secondary_settings_label
import com.tari.android.wallet.R.string.all_settings_security_label
import com.tari.android.wallet.R.string.all_settings_select_base_node
import com.tari.android.wallet.R.string.all_settings_explorer
import com.tari.android.wallet.R.string.all_settings_select_network
import com.tari.android.wallet.R.string.all_settings_select_theme
import com.tari.android.wallet.R.string.all_settings_store
Expand Down Expand Up @@ -86,6 +89,7 @@ import com.tari.android.wallet.ui.fragment.settings.allSettings.title.SettingsTi
import com.tari.android.wallet.ui.fragment.settings.allSettings.version.SettingsVersionViewHolderItem
import com.tari.android.wallet.ui.fragment.settings.backup.data.BackupSettingsRepository
import com.tari.android.wallet.ui.fragment.settings.userAutorization.BiometricAuthenticationViewModel
import com.tari.android.wallet.util.DebugConfig
import com.tari.android.wallet.yat.YatAdapter
import com.tari.android.wallet.yat.YatSharedRepository
import javax.inject.Inject
Expand Down Expand Up @@ -116,8 +120,8 @@ class AllSettingsViewModel : CommonViewModel() {
private val _openYatOnboarding = SingleLiveEvent<Unit>()
val openYatOnboarding: LiveData<Unit> = _openYatOnboarding

private val _allSettingsOptions = MutableLiveData<MutableList<CommonViewHolderItem>>()
val allSettingsOptions: LiveData<MutableList<CommonViewHolderItem>> = _allSettingsOptions
private val _allSettingsOptions = MutableLiveData<List<CommonViewHolderItem>>()
val allSettingsOptions: LiveData<List<CommonViewHolderItem>> = _allSettingsOptions

init {
component.inject(this)
Expand All @@ -141,7 +145,7 @@ class AllSettingsViewModel : CommonViewModel() {
val alias = settingsRepository.name.orEmpty() + " " + settingsRepository.surname.orEmpty()
val pinCode = securityPrefRepository.pinCode

val allOptions = mutableListOf(
_allSettingsOptions.postValue(listOfNotNull(
MyProfileViewHolderItem(settingsRepository.emojiId.orEmpty(), yatSharedPrefsRepository.connectedYat.orEmpty(), alias) {
navigation.postValue(AllSettingsNavigation.ToMyProfile)
},
Expand Down Expand Up @@ -208,9 +212,9 @@ class AllSettingsViewModel : CommonViewModel() {
_openLink.postValue(resourceManager.getString(disclaimer_url))
},
DividerViewHolderItem(),
// ButtonViewDto(resourceManager.getString(all_settings_explorer), vector_all_settings_block_explorer_icon) {
// _openLink.postValue(resourceManager.getString(explorer_url))
// },
SettingsRowViewDto(resourceManager.getString(all_settings_explorer), vector_all_settings_block_explorer_icon) {
_openLink.postValue(resourceManager.getString(explorer_url))
}.takeIf { DebugConfig.isBlockExplorerEnabled },
SettingsTitleViewHolderItem(resourceManager.getString(all_settings_advanced_settings_label)),
SettingsRowViewDto(resourceManager.getString(all_settings_select_theme), vector_all_settings_select_theme_icon) {
navigation.postValue(AllSettingsNavigation.ToThemeSelection)
Expand Down Expand Up @@ -251,9 +255,8 @@ class AllSettingsViewModel : CommonViewModel() {
style = SettingsRowStyle.Warning,
) { navigation.postValue(AllSettingsNavigation.ToDeleteWallet) },
DividerViewHolderItem(),
SettingsVersionViewHolderItem(versionText) { _copyToClipboard.postValue(versionArgs) }
SettingsVersionViewHolderItem(versionText) { _copyToClipboard.postValue(versionArgs) })
)
_allSettingsOptions.postValue(allOptions)
}

private fun onBackupStateChanged(backupState: BackupsState?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import com.tari.android.wallet.ui.fragment.contact_book.data.contacts.ContactDto
import com.tari.android.wallet.ui.fragment.tx.details.gif.GIFView
import com.tari.android.wallet.ui.fragment.tx.details.gif.GIFViewModel
import com.tari.android.wallet.ui.fragment.tx.details.gif.TxState
import com.tari.android.wallet.util.DebugConfig
import com.tari.android.wallet.util.WalletUtil
import java.util.Date

Expand Down Expand Up @@ -161,7 +162,11 @@ class TxDetailsFragment : CommonFragment<FragmentTxDetailsBinding, TxDetailsView

observe(cancellationReason) { setCancellationReason(it) }

observe(explorerLink) { showExplorerLink(it) }
observe(explorerLink) { link ->
if (DebugConfig.isBlockExplorerEnabled) {
showExplorerLink(link)
}
}
}

private fun updateContactInfo(contact: ContactDto) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/tari/android/wallet/util/DebugConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ object DebugConfig {
private const val _useYatSandbox = false
val yatEnvironment = if (_useYatSandbox && isDebug()) YatEnvironment.SANDBOX else YatEnvironment.PRODUCTION

val isBlockExplorerEnabled = false

private fun isDebug() = BuildConfig.BUILD_TYPE == "debug"
}

Expand Down
9 changes: 6 additions & 3 deletions app/src/main/res/raw/nextnet_base_nodes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
NextNet 01::0cff11dff44458bfea3e39444d440e54260746ff2a5ce6a6c3f7355decff2167::/ip4/54.195.217.107/tcp/18189
NextNet 02::0cff11dff44458bfea3e39444d440e54260746ff2a5ce6a6c3f7355decff2167::/onion3/h6oj2cusgtaxo63zbfw2wjir4mltkqzz4jquoak2i5mvgyszaieowwad:18141
NextNet 03::4c236de788e803ef9615f72a4d973cf3f8a9b83c9d2fb176cbaf65c1b0442572::/onion3/3jtk3e2ud3zqtbrq36sw6ata6u5epkjmqgr5tfuemcfpyhisrzkgbtyd:18141
NextNet 1::0cff11dff44458bfea3e39444d440e54260746ff2a5ce6a6c3f7355decff2167::/ip4/54.195.217.107/tcp/18189
NextNet 2::0cff11dff44458bfea3e39444d440e54260746ff2a5ce6a6c3f7355decff2167::/onion3/cmdlunlzessyz7snnat6ktxwmcl7bubvfzneb7ljva4w4izcmlqyc2id:18141
NextNet 3::2caf4be53523ecf2b71ca23db33f7df590fd41792b2d14c2bb0bbebe1b2c4b52::/ip4/34.254.114.227/tcp/18189
NextNet 4::2caf4be53523ecf2b71ca23db33f7df590fd41792b2d14c2bb0bbebe1b2c4b52::/onion3/wi2teiwyyq33jwblcuy7anmja6d7iyuciyrzbwumvldeiw73d6ce5ryd:18141
NextNet 5::4c236de788e803ef9615f72a4d973cf3f8a9b83c9d2fb176cbaf65c1b0442572::/ip4/52.210.35.123/tcp/18189
NextNet 6::4c236de788e803ef9615f72a4d973cf3f8a9b83c9d2fb176cbaf65c1b0442572::/onion3/7gwfakr7ko5uo3fl3yz3fsjc7elccbzter5botggodrmmwi2exm3vbid:18141
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<string name="user_agreement_url">https://www.tari.com/user_agreement/</string>
<string name="privacy_policy_url">https://www.tari.com/privacy_policy/</string>
<string name="disclaimer_url">https://www.tari.com/disclaimer/</string>
<string name="explorer_url">https://explore-esme.tari.com/</string>
<string name="explorer_kernel_url">https://explore-esme.tari.com/kernel/</string>
<string name="explorer_url">https://explore.tari.com/</string>
<string name="explorer_kernel_url">https://explore.tari.com/kernel/</string>
<string name="tor_bridges_url">https://bridges.torproject.org/bridges</string>
<string name="tari_lab_university_url" translatable="false">https://tlu.tarilabs.com/</string>

Expand Down
Loading

0 comments on commit 6ded9d3

Please sign in to comment.