Reset node pref, fix crashing issue in 0.3.0

This commit is contained in:
pokkst 2022-10-14 23:37:58 -05:00
parent 119ccd67bb
commit ab51d6cf06
No known key found for this signature in database
GPG Key ID: 90C2ED85E67A50FF
7 changed files with 10 additions and 18 deletions

View File

@ -96,7 +96,7 @@ public class NodeSelectionAdapter extends RecyclerView.Adapter<NodeSelectionAdap
} }
public void bind(Node node) { public void bind(Node node) {
String currentNodeString = PrefService.getInstance().getString(Constants.PREF_NODE, ""); String currentNodeString = PrefService.getInstance().getString(Constants.PREF_NODE_2, "");
Node currentNode = Node.fromString(currentNodeString); Node currentNode = Node.fromString(currentNodeString);
boolean match = node.equals(currentNode); boolean match = node.equals(currentNode);
if (match) { if (match) {

View File

@ -83,7 +83,7 @@ public class NodeSelectionBottomSheetDialog extends BottomSheetDialogFragment im
Toast.makeText(activity, getString(R.string.node_selected), Toast.LENGTH_SHORT).show(); Toast.makeText(activity, getString(R.string.node_selected), Toast.LENGTH_SHORT).show();
}); });
} }
PrefService.getInstance().edit().putString(Constants.PREF_NODE, node.getAddress()).apply(); PrefService.getInstance().edit().putString(Constants.PREF_NODE_2, node.toNodeString()).apply();
WalletManager.getInstance().setDaemon(node); WalletManager.getInstance().setDaemon(node);
adapter.updateSelectedNode(); adapter.updateSelectedNode();
listener.onNodeSelected(); listener.onNodeSelected();

View File

@ -30,8 +30,6 @@ import net.mynero.wallet.service.PrefService;
import net.mynero.wallet.util.Constants; import net.mynero.wallet.util.Constants;
import java.io.File; import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class OnboardingFragment extends Fragment { public class OnboardingFragment extends Fragment {
@ -163,7 +161,7 @@ public class OnboardingFragment extends Fragment {
private void prepareDefaultNode() { private void prepareDefaultNode() {
boolean usesTor = PrefService.getInstance().getBoolean(Constants.PREF_USES_TOR, false); boolean usesTor = PrefService.getInstance().getBoolean(Constants.PREF_USES_TOR, false);
DefaultNodes defaultNode = usesTor ? DefaultNodes.SAMOURAI_ONION : DefaultNodes.SAMOURAI; DefaultNodes defaultNode = usesTor ? DefaultNodes.SAMOURAI_ONION : DefaultNodes.SAMOURAI;
PrefService.getInstance().edit().putString(Constants.PREF_NODE, defaultNode.getAddress()).apply(); PrefService.getInstance().edit().putString(Constants.PREF_NODE_2, defaultNode.getUri()).apply();
} }
private void createOrImportWallet(String walletPassword, String walletSeed, String restoreHeightText) { private void createOrImportWallet(String walletPassword, String walletSeed, String restoreHeightText) {

View File

@ -174,7 +174,8 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
statusTextView.setText(getResources().getText(R.string.version_mismatch)); statusTextView.setText(getResources().getText(R.string.version_mismatch));
} }
}); });
Node node = Node.fromString(PrefService.getInstance().getString(Constants.PREF_NODE, "")); // shouldn't use default value here DefaultNodes defaultNode = usesProxy ? DefaultNodes.SAMOURAI_ONION : DefaultNodes.SAMOURAI;
Node node = Node.fromString(PrefService.getInstance().getString(Constants.PREF_NODE_2, defaultNode.getUri())); // shouldn't use default value here
selectNodeButton.setText(getString(R.string.node_button_text, node.getAddress())); selectNodeButton.setText(getString(R.string.node_button_text, node.getAddress()));
selectNodeButton.setOnClickListener(view1 -> { selectNodeButton.setOnClickListener(view1 -> {
NodeSelectionBottomSheetDialog dialog = new NodeSelectionBottomSheetDialog(); NodeSelectionBottomSheetDialog dialog = new NodeSelectionBottomSheetDialog();
@ -220,7 +221,7 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
@Override @Override
public void onNodeSelected() { public void onNodeSelected() {
Node node = Node.fromString(PrefService.getInstance().getString(Constants.PREF_NODE, "")); Node node = Node.fromString(PrefService.getInstance().getString(Constants.PREF_NODE_2, ""));
selectNodeButton.setText(getString(R.string.node_button_text, node.getAddress())); selectNodeButton.setText(getString(R.string.node_button_text, node.getAddress()));
mViewModel.updateProxy(((MoneroApplication)getActivity().getApplication())); mViewModel.updateProxy(((MoneroApplication)getActivity().getApplication()));
((MoneroApplication)getActivity().getApplication()).getExecutor().execute(() -> { ((MoneroApplication)getActivity().getApplication()).getExecutor().execute(() -> {

View File

@ -5,14 +5,10 @@ import android.util.Patterns;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
import net.mynero.wallet.MoneroApplication; import net.mynero.wallet.MoneroApplication;
import net.mynero.wallet.data.DefaultNodes;
import net.mynero.wallet.model.WalletManager; import net.mynero.wallet.model.WalletManager;
import net.mynero.wallet.service.PrefService; import net.mynero.wallet.service.PrefService;
import net.mynero.wallet.util.Constants; import net.mynero.wallet.util.Constants;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class SettingsViewModel extends ViewModel { public class SettingsViewModel extends ViewModel {
private String proxyAddress = ""; private String proxyAddress = "";
@ -21,7 +17,7 @@ public class SettingsViewModel extends ViewModel {
public void updateProxy(MoneroApplication application) { public void updateProxy(MoneroApplication application) {
application.getExecutor().execute(() -> { application.getExecutor().execute(() -> {
boolean usesProxy = PrefService.getInstance().getBoolean(Constants.PREF_USES_TOR, false); boolean usesProxy = PrefService.getInstance().getBoolean(Constants.PREF_USES_TOR, false);
String currentNodeString = PrefService.getInstance().getString(Constants.PREF_NODE, ""); String currentNodeString = PrefService.getInstance().getString(Constants.PREF_NODE_2, "");
boolean isNodeLocalIp = currentNodeString.startsWith("10.") || currentNodeString.startsWith("192.168.") || currentNodeString.equals("localhost") || currentNodeString.equals("127.0.0.1"); boolean isNodeLocalIp = currentNodeString.startsWith("10.") || currentNodeString.startsWith("192.168.") || currentNodeString.equals("localhost") || currentNodeString.equals("127.0.0.1");
if (!usesProxy || isNodeLocalIp) { if (!usesProxy || isNodeLocalIp) {

View File

@ -57,11 +57,8 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
@Override @Override
public void run() { public void run() {
boolean usesTor = PrefService.getInstance().getBoolean(Constants.PREF_USES_TOR, false); boolean usesTor = PrefService.getInstance().getBoolean(Constants.PREF_USES_TOR, false);
DefaultNodes defaultNode = DefaultNodes.SAMOURAI; DefaultNodes defaultNode = usesTor ? DefaultNodes.SAMOURAI_ONION : DefaultNodes.SAMOURAI;
if(usesTor) { String currentNodeString = PrefService.getInstance().getString(Constants.PREF_NODE_2, defaultNode.getUri());
defaultNode = DefaultNodes.SAMOURAI_ONION;
}
String currentNodeString = PrefService.getInstance().getString(Constants.PREF_NODE, defaultNode.getAddress());
Node selectedNode = Node.fromString(currentNodeString); Node selectedNode = Node.fromString(currentNodeString);
boolean isLocalIp = currentNodeString.startsWith("10.") || currentNodeString.startsWith("192.168.") || currentNodeString.equals("localhost") || currentNodeString.equals("127.0.0.1"); boolean isLocalIp = currentNodeString.startsWith("10.") || currentNodeString.startsWith("192.168.") || currentNodeString.equals("localhost") || currentNodeString.equals("127.0.0.1");
if (usesTor && !isLocalIp) { if (usesTor && !isLocalIp) {

View File

@ -7,7 +7,7 @@ public class Constants {
public static final String PREF_USES_TOR = "pref_uses_tor"; public static final String PREF_USES_TOR = "pref_uses_tor";
public static final String PREF_NIGHT_MODE = "pref_night_mode"; public static final String PREF_NIGHT_MODE = "pref_night_mode";
public static final String PREF_PROXY = "pref_proxy"; public static final String PREF_PROXY = "pref_proxy";
public static final String PREF_NODE = "pref_node"; public static final String PREF_NODE_2 = "pref_node_2";
public static final String PREF_CUSTOM_NODES = "pref_custom_nodes"; public static final String PREF_CUSTOM_NODES = "pref_custom_nodes";
public static final String URI_PREFIX = "monero:"; public static final String URI_PREFIX = "monero:";