More bug fixes

This commit is contained in:
pokkst 2023-12-09 11:58:45 -06:00
parent a128617342
commit 19544c1b3d
No known key found for this signature in database
GPG Key ID: EC4FAAA66859FAA4
6 changed files with 90 additions and 51 deletions

View File

@ -24,6 +24,7 @@ import net.mynero.wallet.MainActivity
import net.mynero.wallet.R import net.mynero.wallet.R
import net.mynero.wallet.adapter.TransactionInfoAdapter import net.mynero.wallet.adapter.TransactionInfoAdapter
import net.mynero.wallet.adapter.TransactionInfoAdapter.TxInfoAdapterListener import net.mynero.wallet.adapter.TransactionInfoAdapter.TxInfoAdapterListener
import net.mynero.wallet.model.EnumTorState
import net.mynero.wallet.model.TransactionInfo import net.mynero.wallet.model.TransactionInfo
import net.mynero.wallet.model.WalletManager import net.mynero.wallet.model.WalletManager
import net.mynero.wallet.service.BalanceService import net.mynero.wallet.service.BalanceService
@ -79,9 +80,10 @@ class HomeFragment : Fragment(), TxInfoAdapterListener {
ProxyService.instance?.proxyChangeEvents?.observe(viewLifecycleOwner) { proxy -> ProxyService.instance?.proxyChangeEvents?.observe(viewLifecycleOwner) { proxy ->
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
Log.d("HomeFragment", "Updating proxy:: $proxy") Log.d("HomeFragment", "Updating proxy, restarting wallet. proxy=$proxy")
WalletManager.instance?.setProxy(proxy) val finalProxy = if(proxy.isNotEmpty() && ProxyService.instance?.usingProxy == true) proxy else ""
WalletManager.instance?.wallet?.setProxy(proxy) WalletManager.instance?.setProxy(finalProxy)
WalletManager.instance?.wallet?.setProxy(finalProxy)
WalletManager.instance?.wallet?.init(0) WalletManager.instance?.wallet?.init(0)
WalletManager.instance?.wallet?.startRefresh() WalletManager.instance?.wallet?.startRefresh()
} }
@ -89,7 +91,7 @@ class HomeFragment : Fragment(), TxInfoAdapterListener {
DaemonService.instance?.daemonChangeEvents?.observe(viewLifecycleOwner) { daemon -> DaemonService.instance?.daemonChangeEvents?.observe(viewLifecycleOwner) { daemon ->
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
Log.d("HomeFragment", "Updating daemon:: $daemon") Log.d("HomeFragment", "Updating daemon, restarting wallet. daemon=$daemon")
WalletManager.instance?.setDaemon(daemon) WalletManager.instance?.setDaemon(daemon)
WalletManager.instance?.wallet?.init(0) WalletManager.instance?.wallet?.init(0)
WalletManager.instance?.wallet?.setTrustedDaemon(daemon.trusted) WalletManager.instance?.wallet?.setTrustedDaemon(daemon.trusted)
@ -170,6 +172,27 @@ class HomeFragment : Fragment(), TxInfoAdapterListener {
) )
} }
} }
val samouraiTorManager = ProxyService.instance?.samouraiTorManager
samouraiTorManager?.getTorStateLiveData()?.observe(viewLifecycleOwner) {
samouraiTorManager.getProxy()?.address()?.let { socketAddress ->
if(socketAddress.toString().isEmpty()) return@let
if(ProxyService.instance?.usingProxy == true && ProxyService.instance?.useBundledTor == true) {
val proxyString = socketAddress.toString().substring(1)
val address = proxyString.split(":")[0]
val port = proxyString.split(":")[1]
refreshProxy(address, port)
}
}
}
}
private fun refreshProxy(proxyAddress: String, proxyPort: String) {
val cachedProxyAddress = ProxyService.instance?.proxyAddress
val cachedProxyPort = ProxyService.instance?.proxyPort
if((proxyAddress != cachedProxyAddress) || (proxyPort != cachedProxyPort)) {
ProxyService.instance?.updateProxy(proxyAddress, proxyPort)
}
} }
override fun onClickTransaction(txInfo: TransactionInfo?) { override fun onClickTransaction(txInfo: TransactionInfo?) {

View File

@ -172,6 +172,10 @@ class OnboardingFragment : Fragment(), NodeSelectionDialogListener, AddNodeListe
if(mViewModel?.useProxy?.value == true && mViewModel?.useBundledTor?.value == true) { if(mViewModel?.useProxy?.value == true && mViewModel?.useBundledTor?.value == true) {
torIcon?.visibility = View.VISIBLE torIcon?.visibility = View.VISIBLE
indicatorCircle?.visibility = View.INVISIBLE indicatorCircle?.visibility = View.INVISIBLE
val proxyString = socketAddress.toString().substring(1)
val address = proxyString.split(":")[0]
val port = proxyString.split(":")[1]
updateProxy(address, port)
} }
} }
@ -192,6 +196,11 @@ class OnboardingFragment : Fragment(), NodeSelectionDialogListener, AddNodeListe
} }
} }
private fun updateProxy(address: String, port: String) {
walletProxyPortEditText?.setText(port)
walletProxyAddressEditText?.setText(address)
}
private fun bindListeners() { private fun bindListeners() {
// Disable onBack click // Disable onBack click
val onBackPressedCallback: OnBackPressedCallback = object : OnBackPressedCallback(true) { val onBackPressedCallback: OnBackPressedCallback = object : OnBackPressedCallback(true) {

View File

@ -58,7 +58,7 @@ class OnboardingViewModel : ViewModel() {
if(seedType == SeedType.POLYSEED && (passphrase.isEmpty() || confirmedPassphrase.isEmpty())) return@combineLiveDatas false if(seedType == SeedType.POLYSEED && (passphrase.isEmpty() || confirmedPassphrase.isEmpty())) return@combineLiveDatas false
if(useProxy && (proxyAddress.isEmpty() || proxyPort.isEmpty()) && !useBundledTor) return@combineLiveDatas false if(useProxy && (proxyAddress.isEmpty() || proxyPort.isEmpty()) && !useBundledTor) return@combineLiveDatas false
val progress = torState?.progressIndicator ?: 0 val progress = torState?.progressIndicator ?: 0
if(useBundledTor && progress < 100) return@combineLiveDatas false if(useBundledTor && progress < 100 && useProxy) return@combineLiveDatas false
return@combineLiveDatas true return@combineLiveDatas true
} }

View File

@ -15,6 +15,7 @@ import android.widget.Toast
import androidx.activity.OnBackPressedCallback import androidx.activity.OnBackPressedCallback
import androidx.appcompat.widget.SwitchCompat import androidx.appcompat.widget.SwitchCompat
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.NavHostFragment import androidx.navigation.fragment.NavHostFragment
@ -77,21 +78,23 @@ class SettingsFragment : Fragment(), PasswordListener, NodeSelectionDialogListen
walletProxyPortEditText = view.findViewById(R.id.wallet_proxy_port_edittext) walletProxyPortEditText = view.findViewById(R.id.wallet_proxy_port_edittext)
useBundledTor = view.findViewById(R.id.bundled_tor_checkbox) useBundledTor = view.findViewById(R.id.bundled_tor_checkbox)
useBundledTor?.isChecked = ProxyService.instance?.useBundledTor == true val cachedProxyAddress = ProxyService.instance?.proxyAddress ?: return
walletProxyPortEditText?.visibility = if (useBundledTor?.isChecked == true) View.GONE else View.VISIBLE val cachedProxyPort = ProxyService.instance?.proxyPort ?: return
walletProxyAddressEditText?.visibility = if (useBundledTor?.isChecked == true) View.GONE else View.VISIBLE val cachedUsingProxy = ProxyService.instance?.usingProxy == true
val cachedUsingBundledTor = ProxyService.instance?.useBundledTor == true
val useProxyVisibility = if (cachedUsingProxy) View.VISIBLE else View.GONE
walletProxyPortEditText?.visibility = if (cachedUsingBundledTor) View.GONE else useProxyVisibility
walletProxyAddressEditText?.visibility = if (cachedUsingBundledTor) View.GONE else useProxyVisibility
proxySettingsLayout?.visibility = useProxyVisibility
streetModeSwitch?.isChecked = PrefService.instance?.getBoolean(Constants.PREF_STREET_MODE, false) == true streetModeSwitch?.isChecked = PrefService.instance?.getBoolean(Constants.PREF_STREET_MODE, false) == true
monerochanSwitch?.isChecked = PrefService.instance?.getBoolean(Constants.PREF_MONEROCHAN, true) == true monerochanSwitch?.isChecked = PrefService.instance?.getBoolean(Constants.PREF_MONEROCHAN, true) == true
donationSwitch?.isChecked = PrefService.instance?.getBoolean(Constants.PREF_DONATE_PER_TX, false) == true donationSwitch?.isChecked = PrefService.instance?.getBoolean(Constants.PREF_DONATE_PER_TX, false) == true
useBundledTor?.isChecked = cachedUsingBundledTor
torSwitch?.isChecked = cachedUsingProxy
updateProxy(cachedProxyAddress, cachedProxyPort)
val usesProxy = ProxyService.instance?.usingProxy == true
val cachedProxyAddress = ProxyService.instance?.proxyAddress ?: return
val cachedProxyPort = ProxyService.instance?.proxyPort ?: return
if (ProxyService.instance?.hasProxySet() == true) {
initProxyStuff(cachedProxyAddress, cachedProxyPort)
}
torSwitch?.isChecked = usesProxy
proxySettingsLayout?.visibility = if (usesProxy) View.VISIBLE else View.GONE
val node = PrefService.instance?.node // shouldn't use default value here val node = PrefService.instance?.node // shouldn't use default value here
selectNodeButton?.text = getString(R.string.node_button_text, node?.address) selectNodeButton?.text = getString(R.string.node_button_text, node?.address)
@ -154,26 +157,32 @@ class SettingsFragment : Fragment(), PasswordListener, NodeSelectionDialogListen
torSwitch?.setOnCheckedChangeListener { _: CompoundButton?, b: Boolean -> torSwitch?.setOnCheckedChangeListener { _: CompoundButton?, b: Boolean ->
mViewModel?.setUseProxy(b) mViewModel?.setUseProxy(b)
} }
walletProxyPortEditText?.addTextChangedListener {
mViewModel?.edited = true
}
walletProxyAddressEditText?.addTextChangedListener {
mViewModel?.edited = true
}
} }
private fun bindObservers() { private fun bindObservers() {
mViewModel?.useProxy?.observe(viewLifecycleOwner) { b -> mViewModel?.useProxy?.observe(viewLifecycleOwner) { b ->
if (b) { val visibility = if(b) View.VISIBLE else View.GONE
if (ProxyService.instance?.hasProxySet() == true) { proxySettingsLayout?.visibility = visibility
val proxyAddress = ProxyService.instance?.proxyAddress ?: return@observe
val proxyPort = ProxyService.instance?.proxyPort ?: return@observe val useBundledTor = mViewModel?.useBundledTor?.value == true
initProxyStuff(proxyAddress, proxyPort) walletProxyPortEditText?.visibility = if (useBundledTor) View.GONE else visibility
} walletProxyAddressEditText?.visibility = if (useBundledTor) View.GONE else visibility
proxySettingsLayout?.visibility = View.VISIBLE
} else {
proxySettingsLayout?.visibility = View.GONE
}
refreshProxy() refreshProxy()
} }
mViewModel?.useBundledTor?.observe(viewLifecycleOwner) { isChecked -> mViewModel?.useBundledTor?.observe(viewLifecycleOwner) { isChecked ->
walletProxyPortEditText?.visibility = if (isChecked) View.GONE else View.VISIBLE val usingProxy = mViewModel?.useProxy?.value == true
walletProxyAddressEditText?.visibility = if (isChecked) View.GONE else View.VISIBLE val visibility = if(usingProxy) View.VISIBLE else View.GONE
walletProxyPortEditText?.visibility = if (isChecked) View.GONE else visibility
walletProxyAddressEditText?.visibility = if (isChecked) View.GONE else visibility
} }
val samouraiTorManager = ProxyService.instance?.samouraiTorManager val samouraiTorManager = ProxyService.instance?.samouraiTorManager
@ -186,6 +195,10 @@ class SettingsFragment : Fragment(), PasswordListener, NodeSelectionDialogListen
if(mViewModel?.useProxy?.value == true && mViewModel?.useBundledTor?.value == true) { if(mViewModel?.useProxy?.value == true && mViewModel?.useBundledTor?.value == true) {
torIcon?.visibility = View.VISIBLE torIcon?.visibility = View.VISIBLE
indicatorCircle?.visibility = View.INVISIBLE indicatorCircle?.visibility = View.INVISIBLE
val proxyString = socketAddress.toString().substring(1)
val address = proxyString.split(":")[0]
val port = proxyString.split(":")[1]
updateProxy(address, port)
} }
} }
@ -206,9 +219,17 @@ class SettingsFragment : Fragment(), PasswordListener, NodeSelectionDialogListen
} }
} }
private fun updateProxy(address: String, port: String) {
walletProxyPortEditText?.setText(port)
walletProxyAddressEditText?.setText(address)
refreshProxy()
}
private fun refreshProxy() { private fun refreshProxy() {
val proxyAddress = walletProxyAddressEditText?.text.toString() val proxyAddress = walletProxyAddressEditText?.text.toString()
val proxyPort = walletProxyPortEditText?.text.toString() val proxyPort = walletProxyPortEditText?.text.toString()
if(mViewModel?.edited == true)
ProxyService.instance?.updateProxy(proxyAddress, proxyPort) ProxyService.instance?.updateProxy(proxyAddress, proxyPort)
} }
@ -228,14 +249,6 @@ class SettingsFragment : Fragment(), PasswordListener, NodeSelectionDialogListen
Toast.makeText(context, R.string.bad_password, Toast.LENGTH_SHORT).show() Toast.makeText(context, R.string.bad_password, Toast.LENGTH_SHORT).show()
} }
private fun initProxyStuff(proxyAddress: String, proxyPort: String) {
val validIpAddress = Patterns.IP_ADDRESS.matcher(proxyAddress).matches()
if (validIpAddress) {
walletProxyAddressEditText?.setText(proxyAddress)
walletProxyPortEditText?.setText(proxyPort)
}
}
override fun onNodeSelected() { override fun onNodeSelected() {
val node = PrefService.instance?.node val node = PrefService.instance?.node
selectNodeButton?.text = getString(R.string.node_button_text, node?.address) selectNodeButton?.text = getString(R.string.node_button_text, node?.address)

View File

@ -15,6 +15,7 @@ class SettingsViewModel : ViewModel() {
val useProxy: LiveData<Boolean> = _useProxy val useProxy: LiveData<Boolean> = _useProxy
private val _useBundledTor = MutableLiveData(false) private val _useBundledTor = MutableLiveData(false)
val useBundledTor: LiveData<Boolean> = _useBundledTor val useBundledTor: LiveData<Boolean> = _useBundledTor
var edited = false
init { init {
_useProxy.value = ProxyService.instance?.usingProxy _useProxy.value = ProxyService.instance?.usingProxy
@ -31,6 +32,8 @@ class SettingsViewModel : ViewModel() {
} else { } else {
samouraiTorManager?.stop() samouraiTorManager?.stop()
} }
edited = true
} }
fun setUseBundledTor(use: Boolean) { fun setUseBundledTor(use: Boolean) {
@ -43,5 +46,7 @@ class SettingsViewModel : ViewModel() {
} else { } else {
samouraiTorManager?.stop() samouraiTorManager?.stop()
} }
edited = true
} }
} }

View File

@ -15,17 +15,6 @@ class ProxyService(application: Application) : ServiceBase(null) {
instance = this instance = this
samouraiTorManager = SamouraiTorManager(application, TorKmpManager(application)) samouraiTorManager = SamouraiTorManager(application, TorKmpManager(application))
samouraiTorManager?.getTorStateLiveData()?.observeForever {
samouraiTorManager?.getProxy()?.address()?.let { socketAddress ->
if(socketAddress.toString().isEmpty()) return@let
val proxyString = socketAddress.toString().substring(1)
val address = proxyString.split(":")[0]
val port = proxyString.split(":")[1]
if(usingProxy && useBundledTor)
updateProxy(address, port)
}
}
if(useBundledTor && usingProxy) { if(useBundledTor && usingProxy) {
samouraiTorManager?.start() samouraiTorManager?.start()
} }
@ -54,7 +43,7 @@ class ProxyService(application: Application) : ServiceBase(null) {
} }
} }
fun hasProxySet(): Boolean { private fun hasProxySet(): Boolean {
val proxyString = proxy val proxyString = proxy
return proxyString?.contains(":") == true return proxyString?.contains(":") == true
} }
@ -70,7 +59,7 @@ class ProxyService(application: Application) : ServiceBase(null) {
val proxyAddress: String val proxyAddress: String
get() { get() {
if (hasProxySet()) { if (hasProxySet() && usingProxy) {
val proxyString = proxy val proxyString = proxy
return proxyString?.split(":".toRegex())?.dropLastWhile { it.isEmpty() } return proxyString?.split(":".toRegex())?.dropLastWhile { it.isEmpty() }
?.toTypedArray() ?.toTypedArray()
@ -80,7 +69,7 @@ class ProxyService(application: Application) : ServiceBase(null) {
} }
val proxyPort: String val proxyPort: String
get() { get() {
if (hasProxySet()) { if (hasProxySet() && usingProxy) {
val proxyString = proxy val proxyString = proxy
return proxyString?.split(":".toRegex())?.dropLastWhile { it.isEmpty() } return proxyString?.split(":".toRegex())?.dropLastWhile { it.isEmpty() }
?.toTypedArray() ?.toTypedArray()