mirror of
https://codeberg.org/r4v3r23/mysu.git
synced 2024-11-10 05:03:44 +01:00
prevents seed from being copied in dialog, and makes wallet restore/creation async
This commit is contained in:
parent
8c112f60f1
commit
b1f8552628
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user