prevents seed from being copied in dialog, and makes wallet restore/creation async

This commit is contained in:
pokkst 2022-10-01 22:07:12 -05:00
parent 8c112f60f1
commit b1f8552628
No known key found for this signature in database
GPG Key ID: 90C2ED85E67A50FF
2 changed files with 40 additions and 29 deletions

View File

@ -1,5 +1,6 @@
package net.mynero.wallet.fragment.onboarding; package net.mynero.wallet.fragment.onboarding;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
@ -54,34 +55,13 @@ public class OnboardingFragment extends Fragment {
moreOptionsChevronImageView.setOnClickListener(view12 -> mViewModel.onMoreOptionsClicked()); moreOptionsChevronImageView.setOnClickListener(view12 -> mViewModel.onMoreOptionsClicked());
createWalletButton.setOnClickListener(view1 -> { createWalletButton.setOnClickListener(view1 -> {
String walletPassword = walletPasswordEditText.getText().toString(); AsyncTask.execute(() -> {
if (!walletPassword.isEmpty()) { createOrImportWallet(
PrefService.getInstance().edit().putBoolean(Constants.PREF_USES_PASSWORD, true).apply(); walletPasswordEditText.getText().toString(),
} walletSeedEditText.getText().toString().trim(),
String walletSeed = walletSeedEditText.getText().toString().trim(); walletRestoreHeightEditText.getText().toString().trim()
String restoreHeightText = walletRestoreHeightEditText.getText().toString().trim(); );
long restoreHeight = -1; });
File walletFile = new File(getActivity().getApplicationInfo().dataDir, Constants.WALLET_NAME);
Wallet wallet = null;
if (walletSeed.isEmpty()) {
wallet = WalletManager.getInstance().createWallet(walletFile, walletPassword, Constants.MNEMONIC_LANGUAGE, restoreHeight);
} else {
if (!checkMnemonic(walletSeed)) {
Toast.makeText(getContext(), getString(R.string.invalid_mnemonic_code), Toast.LENGTH_SHORT).show();
return;
}
if (!restoreHeightText.isEmpty()) {
restoreHeight = Long.parseLong(restoreHeightText);
}
wallet = WalletManager.getInstance().recoveryWallet(walletFile, walletPassword, walletSeed, "", restoreHeight);
}
boolean ok = wallet.getStatus().isOk();
walletFile.delete(); // cache is broken for some reason when recovering wallets. delete the file here. this happens in monerujo too.
if (ok) {
((MainActivity) getActivity()).init(walletFile, walletPassword);
getActivity().onBackPressed();
}
}); });
walletSeedEditText.addTextChangedListener(new TextWatcher() { walletSeedEditText.addTextChangedListener(new TextWatcher() {
@Override @Override
@ -116,6 +96,37 @@ public class OnboardingFragment extends Fragment {
}); });
} }
private void createOrImportWallet(String walletPassword, String walletSeed, String restoreHeightText) {
MainActivity mainActivity = (MainActivity) getActivity();
if(mainActivity != null) {
if (!walletPassword.isEmpty()) {
PrefService.getInstance().edit().putBoolean(Constants.PREF_USES_PASSWORD, true).apply();
}
long restoreHeight = -1;
File walletFile = new File(mainActivity.getApplicationInfo().dataDir, Constants.WALLET_NAME);
Wallet wallet = null;
if (walletSeed.isEmpty()) {
wallet = WalletManager.getInstance().createWallet(walletFile, walletPassword, Constants.MNEMONIC_LANGUAGE, restoreHeight);
} else {
if (!checkMnemonic(walletSeed)) {
Toast.makeText(getContext(), getString(R.string.invalid_mnemonic_code), Toast.LENGTH_SHORT).show();
return;
}
if (!restoreHeightText.isEmpty()) {
restoreHeight = Long.parseLong(restoreHeightText);
}
wallet = WalletManager.getInstance().recoveryWallet(walletFile, walletPassword, walletSeed, "", restoreHeight);
}
boolean ok = wallet.getStatus().isOk();
walletFile.delete(); // cache is broken for some reason when recovering wallets. delete the file here. this happens in monerujo too.
if (ok) {
mainActivity.init(walletFile, walletPassword);
mainActivity.runOnUiThread(mainActivity::onBackPressed);
}
}
}
private boolean checkMnemonic(String seed) { private boolean checkMnemonic(String seed) {
return (seed.split("\\s").length == 25); return (seed.split("\\s").length == 25);
} }

View File

@ -169,7 +169,7 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
private void displaySeedDialog() { private void displaySeedDialog() {
InformationBottomSheetDialog informationDialog = new InformationBottomSheetDialog(); InformationBottomSheetDialog informationDialog = new InformationBottomSheetDialog();
informationDialog.showCopyButton = true; informationDialog.showCopyButton = false;
informationDialog.information = WalletManager.getInstance().getWallet().getSeed(""); informationDialog.information = WalletManager.getInstance().getWallet().getSeed("");
informationDialog.show(getActivity().getSupportFragmentManager(), "information_seed_dialog"); informationDialog.show(getActivity().getSupportFragmentManager(), "information_seed_dialog");
} }