From 44836a24bb4b7f919f4ad49d58f539a04c7fb3fc Mon Sep 17 00:00:00 2001
From: m2049r <30435443+m2049r@users.noreply.github.com>
Date: Thu, 17 Aug 2017 20:57:26 +0200
Subject: [PATCH 1/3] tweaks
---
.../com/m2049r/xmrwallet/GenerateReviewFragment.java | 11 ++++++++++-
.../com/m2049r/xmrwallet/service/WalletService.java | 6 +++---
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/app/src/main/java/com/m2049r/xmrwallet/GenerateReviewFragment.java b/app/src/main/java/com/m2049r/xmrwallet/GenerateReviewFragment.java
index 8089323d..efe8ec55 100644
--- a/app/src/main/java/com/m2049r/xmrwallet/GenerateReviewFragment.java
+++ b/app/src/main/java/com/m2049r/xmrwallet/GenerateReviewFragment.java
@@ -29,6 +29,8 @@ import com.m2049r.xmrwallet.model.WalletManager;
public class GenerateReviewFragment extends Fragment {
static final String TAG = "GenerateReviewFragment";
+ static final public String VIEW_DETAILS = "details";
+ static final public String VIEW_ACCEPT = "accept";
TextView tvWalletName;
TextView tvWalletPassword;
@@ -93,7 +95,14 @@ public class GenerateReviewFragment extends Fragment {
} else {
tvWalletSpendKey.setText(getString(R.string.generate_wallet_watchonly));
}
- bAccept.setEnabled(true);
+
+ String type = b.getString("view");
+ if (type.equals(GenerateReviewFragment.VIEW_ACCEPT)) {
+ bAccept.setVisibility(View.VISIBLE);
+ bAccept.setEnabled(true);
+ } else {
+ bAccept.setVisibility(View.GONE);
+ }
}
GenerateReviewFragment.Listener activityCallback;
diff --git a/app/src/main/java/com/m2049r/xmrwallet/service/WalletService.java b/app/src/main/java/com/m2049r/xmrwallet/service/WalletService.java
index ce4bc3c9..84e6dbb8 100644
--- a/app/src/main/java/com/m2049r/xmrwallet/service/WalletService.java
+++ b/app/src/main/java/com/m2049r/xmrwallet/service/WalletService.java
@@ -131,7 +131,7 @@ public class WalletService extends Service {
updateDaemonState(wallet, 0);
TransactionHistory history = wallet.getHistory();
history.refresh();
- observer.onRefreshed(wallet, true);
+ if (observer != null) observer.onRefreshed(wallet, true);
updated = false;
}
}
@@ -258,7 +258,7 @@ public class WalletService extends Service {
} else if (cmd.equals(REQUEST_CMD_STORE)) {
Wallet myWallet = getWallet();
Log.d(TAG, "storing wallet: " + myWallet.getName());
- getWallet().store();
+ myWallet.store();
Log.d(TAG, "wallet stored: " + myWallet.getName());
if (observer != null) observer.onWalletStored();
}
@@ -387,7 +387,7 @@ public class WalletService extends Service {
}
private Wallet loadWallet(String walletName, String walletPassword) {
- String path = Helper.getWalletPath(getApplicationContext(), walletName);
+ //String path = Helper.getWalletPath(getApplicationContext(), walletName);
//Log.d(TAG, "open wallet " + path);
Wallet wallet = openWallet(walletName, walletPassword);
//Log.d(TAG, "wallet opened: " + wallet);
From c9ae39508f50136265296e5669737f0515ac08d7 Mon Sep 17 00:00:00 2001
From: m2049r <30435443+m2049r@users.noreply.github.com>
Date: Thu, 17 Aug 2017 22:35:25 +0200
Subject: [PATCH 2/3] details view works mostly (seed) need to prevent opening
wallet while preparing details new wallets sont store the cache ?! (except
watch only)
---
.../com/m2049r/xmrwallet/LoginActivity.java | 67 +++++++++++++++++--
.../com/m2049r/xmrwallet/LoginFragment.java | 40 +++++++++++
app/src/main/res/values/strings.xml | 1 +
3 files changed, 102 insertions(+), 6 deletions(-)
diff --git a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java
index 1ddc8df8..57a06f82 100644
--- a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java
+++ b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java
@@ -79,16 +79,37 @@ public class LoginActivity extends AppCompatActivity
// now it's getting real, check if wallet exists
String walletPath = Helper.getWalletPath(this, walletName);
if (WalletManager.getInstance().walletExists(walletPath)) {
- promptPassword(walletName);
+ promptPassword(walletName, new PasswordAction() {
+ @Override
+ public void action(String walletName, String password) {
+ startWallet(walletName, password);
+ }
+ });
} else { // this cannot really happen as we prefilter choices
Toast.makeText(this, getString(R.string.bad_wallet), Toast.LENGTH_SHORT).show();
}
}
}
+ @Override
+ public void onWalletDetails(final String walletName) {
+ Log.d(TAG, "details for wallet ." + walletName + ".");
+ String walletPath = Helper.getWalletPath(this, walletName);
+ if (WalletManager.getInstance().walletExists(walletPath)) {
+ promptPassword(walletName, new PasswordAction() {
+ @Override
+ public void action(String walletName, String password) {
+ startDetails(walletName, password);
+ }
+ });
+ } else { // this cannot really happen as we prefilter choices
+ Toast.makeText(this, getString(R.string.bad_wallet), Toast.LENGTH_SHORT).show();
+ }
+ }
+
AlertDialog passwordDialog = null; // for preventing multiple clicks in wallet list
- void promptPassword(final String wallet) {
+ void promptPassword(final String wallet, final PasswordAction action) {
if (passwordDialog != null) return; // we are already asking for password
Context context = LoginActivity.this;
LayoutInflater li = LayoutInflater.from(context);
@@ -110,7 +131,7 @@ public class LoginActivity extends AppCompatActivity
public void onClick(DialogInterface dialog, int id) {
Helper.hideKeyboardAlways(LoginActivity.this);
String pass = etPassword.getText().toString();
- processPasswordEntry(wallet, pass);
+ processPasswordEntry(wallet, pass, action);
passwordDialog = null;
}
})
@@ -133,7 +154,7 @@ public class LoginActivity extends AppCompatActivity
Helper.hideKeyboardAlways(LoginActivity.this);
String pass = etPassword.getText().toString();
passwordDialog.cancel();
- processPasswordEntry(wallet, pass);
+ processPasswordEntry(wallet, pass, action);
passwordDialog = null;
return false;
}
@@ -151,9 +172,13 @@ public class LoginActivity extends AppCompatActivity
return WalletManager.getInstance().verifyWalletPassword(walletPath, password, true);
}
- private void processPasswordEntry(String walletName, String pass) {
+ interface PasswordAction {
+ void action(String walletName, String password);
+ }
+
+ private void processPasswordEntry(String walletName, String pass, PasswordAction action) {
if (checkWalletPassword(walletName, pass)) {
- startWallet(walletName, pass);
+ action.action(walletName, pass);
} else {
Toast.makeText(this, getString(R.string.bad_password), Toast.LENGTH_SHORT).show();
}
@@ -201,6 +226,34 @@ public class LoginActivity extends AppCompatActivity
startActivity(intent);
}
+ void startDetails(final String walletName, final String password) {
+ Log.d(TAG, "startDetails()");
+ new Thread(null,
+ new Runnable() {
+ @Override
+ public void run() {
+ String path = Helper.getWalletPath(getApplicationContext(), walletName);
+ Wallet wallet = WalletManager.getInstance().openWallet(path, password);
+ final String seed = wallet.getSeed();
+ final String address = wallet.getAddress();
+ final String view = wallet.getSecretViewKey();
+ final String spend = wallet.isWatchOnly() ? "" : "not available - use seed for recovery";
+ wallet.close();
+ Bundle b = new Bundle();
+ b.putString("name", walletName);
+ b.putString("password", password);
+ b.putString("seed", seed);
+ b.putString("address", address);
+ b.putString("viewkey", view);
+ b.putString("spendkey", spend);
+ b.putString("view", GenerateReviewFragment.VIEW_DETAILS);
+ startReviewFragment(b);
+ }
+ }
+ , "DetailsWallet", MoneroHandlerThread.THREAD_STACK_SIZE).start();
+ }
+
+
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
Log.d(TAG, "onRequestPermissionsResult()");
@@ -296,6 +349,7 @@ public class LoginActivity extends AppCompatActivity
final String spend = newWallet.isWatchOnly() ? "" : "not available - use seed for recovery";
newWallet.close();
Log.d(TAG, "Created " + address);
+ //TODO: is runOnUiThread needed?
runOnUiThread(new Runnable() {
public void run() {
Bundle b = new Bundle();
@@ -305,6 +359,7 @@ public class LoginActivity extends AppCompatActivity
b.putString("address", address);
b.putString("viewkey", view);
b.putString("spendkey", spend);
+ b.putString("view", GenerateReviewFragment.VIEW_ACCEPT);
startReviewFragment(b);
}
});
diff --git a/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java b/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java
index 50e06272..20d5de2d 100644
--- a/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java
+++ b/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java
@@ -79,6 +79,8 @@ public class LoginFragment extends Fragment {
void onWalletSelected(final String wallet);
+ void onWalletDetails(final String wallet);
+
void setTitle(String title);
}
@@ -190,6 +192,44 @@ public class LoginFragment extends Fragment {
}
});
+ listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
+ @Override
+ public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
+ EditText tvDaemonAddress = (EditText) getView().findViewById(R.id.etDaemonAddress);
+ if (tvDaemonAddress.getText().toString().length() == 0) {
+ Toast.makeText(getActivity(), getString(R.string.prompt_daemon_missing), Toast.LENGTH_SHORT).show();
+ tvDaemonAddress.requestFocus();
+ Helper.showKeyboard(getActivity());
+ return true;
+ }
+
+ String itemValue = (String) listView.getItemAtPosition(position);
+
+ if (itemValue.length() <= (WALLETNAME_PREAMBLE_LENGTH)) {
+ Toast.makeText(getActivity(), getString(R.string.panic), Toast.LENGTH_LONG).show();
+ return true;
+ }
+
+ String x = isMainNet() ? "4-" : "9A-";
+ if (x.indexOf(itemValue.charAt(1)) < 0) {
+ Toast.makeText(getActivity(), getString(R.string.prompt_wrong_net), Toast.LENGTH_LONG).show();
+ return true;
+ }
+
+ if (!checkAndSetWalletDaemon(getDaemon(), !isMainNet())) {
+ Toast.makeText(getActivity(), getString(R.string.warn_daemon_unavailable), Toast.LENGTH_SHORT).show();
+ return true;
+ }
+
+ // looking good
+ savePrefs(false);
+
+ String wallet = itemValue.substring(WALLETNAME_PREAMBLE_LENGTH);
+ if (itemValue.charAt(1) == '-') wallet = ':' + wallet;
+ activityCallback.onWalletDetails(wallet);
+ return true;
+ }
+ });
activityCallback.setTitle(getString(R.string.app_name) + " " +
getString(isMainNet() ? R.string.connect_mainnet : R.string.connect_testnet));
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9ec235a0..8344105c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -18,6 +18,7 @@
Password for
Bad password!
Wallet does not exists!
+ This is not a wallet!
Daemon address must be set!
Wallet does not match selected net
Cannot connect to daemon! Try again.
From 62433f6e1092304f2943a4fd74881ad556cd91b0 Mon Sep 17 00:00:00 2001
From: m2049r <30435443+m2049r@users.noreply.github.com>
Date: Fri, 18 Aug 2017 02:01:39 +0200
Subject: [PATCH 3/3] tweaks & fixed store() error, refactoring
---
app/src/main/cpp/monerujo.cpp | 3 +
.../xmrwallet/GenerateReviewFragment.java | 67 ++++----
.../com/m2049r/xmrwallet/LoginActivity.java | 143 +++++++-----------
.../com/m2049r/xmrwallet/WalletActivity.java | 8 +-
.../com/m2049r/xmrwallet/model/Wallet.java | 5 +-
.../xmrwallet/service/WalletService.java | 11 +-
.../main/res/layout/gen_review_fragment.xml | 12 +-
app/src/main/res/values/strings.xml | 2 +
8 files changed, 117 insertions(+), 134 deletions(-)
diff --git a/app/src/main/cpp/monerujo.cpp b/app/src/main/cpp/monerujo.cpp
index 1d14de8a..25069939 100644
--- a/app/src/main/cpp/monerujo.cpp
+++ b/app/src/main/cpp/monerujo.cpp
@@ -579,6 +579,9 @@ Java_com_m2049r_xmrwallet_model_Wallet_store(JNIEnv *env, jobject instance,
const char *_path = env->GetStringUTFChars(path, JNI_FALSE);
Bitmonero::Wallet *wallet = getHandle(env, instance);
bool success = wallet->store(std::string(_path));
+ if (!success) {
+ LOGE("store() %s", wallet->errorString().c_str());
+ }
env->ReleaseStringUTFChars(path, _path);
return success;
}
diff --git a/app/src/main/java/com/m2049r/xmrwallet/GenerateReviewFragment.java b/app/src/main/java/com/m2049r/xmrwallet/GenerateReviewFragment.java
index efe8ec55..8e2dcdd6 100644
--- a/app/src/main/java/com/m2049r/xmrwallet/GenerateReviewFragment.java
+++ b/app/src/main/java/com/m2049r/xmrwallet/GenerateReviewFragment.java
@@ -25,7 +25,9 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
+import com.m2049r.xmrwallet.model.Wallet;
import com.m2049r.xmrwallet.model.WalletManager;
+import com.m2049r.xmrwallet.service.MoneroHandlerThread;
public class GenerateReviewFragment extends Fragment {
static final String TAG = "GenerateReviewFragment";
@@ -65,7 +67,12 @@ public class GenerateReviewFragment extends Fragment {
}
});
- showDetails();
+ Bundle b = getArguments();
+ String name = b.getString("name");
+ String password = b.getString("password");
+ String type = b.getString("type");
+ show(name, password, type);
+
return view;
}
@@ -76,33 +83,41 @@ public class GenerateReviewFragment extends Fragment {
activityCallback.onAccept(name, password);
}
- public void showDetails() {
- Bundle b = getArguments();
- String name = b.getString("name");
- String password = b.getString("password");
- String address = b.getString("address");
- String seed = b.getString("seed");
- String view = b.getString("viewkey");
- String spend = b.getString("spendkey");
+ private void show(final String walletPath, final String password, final String type) {
+ new Thread(null,
+ new Runnable() {
+ @Override
+ public void run() {
+ Wallet wallet = WalletManager.getInstance().openWallet(walletPath, password);
+ final String name = wallet.getName();
+ final String seed = wallet.getSeed();
+ final String address = wallet.getAddress();
+ final String view = wallet.getSecretViewKey();
+ final String spend = wallet.isWatchOnly() ? "" : "not available - use seed for recovery";
+ wallet.close();
- tvWalletName.setText(name);
- tvWalletPassword.setText(password);
- tvWalletAddress.setText(address);
- tvWalletMnemonic.setText(seed);
- tvWalletViewKey.setText(view);
- if (spend.length() > 0) { // should be == 64, but spendkey is not in the API yet
- tvWalletSpendKey.setText(spend);
- } else {
- tvWalletSpendKey.setText(getString(R.string.generate_wallet_watchonly));
- }
+ getActivity().runOnUiThread(new Runnable() {
+ public void run() {
+ if (type.equals(GenerateReviewFragment.VIEW_ACCEPT)) {
+ tvWalletPassword.setText(password);
+ bAccept.setVisibility(View.VISIBLE);
+ bAccept.setEnabled(true);
+ }
+ tvWalletName.setText(name);
+ tvWalletAddress.setText(address);
+ tvWalletMnemonic.setText(seed);
+ tvWalletViewKey.setText(view);
+ if (spend.length() > 0) { //TODO should be == 64, but spendkey is not in the API yet
+ tvWalletSpendKey.setText(spend);
+ } else {
+ tvWalletSpendKey.setText(getString(R.string.generate_wallet_watchonly));
+ }
+ }
+ });
+ }
+ }
+ , "DetailsReview", MoneroHandlerThread.THREAD_STACK_SIZE).start();
- String type = b.getString("view");
- if (type.equals(GenerateReviewFragment.VIEW_ACCEPT)) {
- bAccept.setVisibility(View.VISIBLE);
- bAccept.setEnabled(true);
- } else {
- bAccept.setVisibility(View.GONE);
- }
}
GenerateReviewFragment.Listener activityCallback;
diff --git a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java
index 57a06f82..d74b1037 100644
--- a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java
+++ b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java
@@ -94,12 +94,12 @@ public class LoginActivity extends AppCompatActivity
@Override
public void onWalletDetails(final String walletName) {
Log.d(TAG, "details for wallet ." + walletName + ".");
- String walletPath = Helper.getWalletPath(this, walletName);
+ final String walletPath = Helper.getWalletPath(this, walletName);
if (WalletManager.getInstance().walletExists(walletPath)) {
promptPassword(walletName, new PasswordAction() {
@Override
public void action(String walletName, String password) {
- startDetails(walletName, password);
+ startDetails(walletPath, password, GenerateReviewFragment.VIEW_DETAILS);
}
});
} else { // this cannot really happen as we prefilter choices
@@ -226,31 +226,13 @@ public class LoginActivity extends AppCompatActivity
startActivity(intent);
}
- void startDetails(final String walletName, final String password) {
+ void startDetails(final String walletPath, final String password, String type) {
Log.d(TAG, "startDetails()");
- new Thread(null,
- new Runnable() {
- @Override
- public void run() {
- String path = Helper.getWalletPath(getApplicationContext(), walletName);
- Wallet wallet = WalletManager.getInstance().openWallet(path, password);
- final String seed = wallet.getSeed();
- final String address = wallet.getAddress();
- final String view = wallet.getSecretViewKey();
- final String spend = wallet.isWatchOnly() ? "" : "not available - use seed for recovery";
- wallet.close();
- Bundle b = new Bundle();
- b.putString("name", walletName);
- b.putString("password", password);
- b.putString("seed", seed);
- b.putString("address", address);
- b.putString("viewkey", view);
- b.putString("spendkey", spend);
- b.putString("view", GenerateReviewFragment.VIEW_DETAILS);
- startReviewFragment(b);
- }
- }
- , "DetailsWallet", MoneroHandlerThread.THREAD_STACK_SIZE).start();
+ Bundle b = new Bundle();
+ b.putString("name", walletPath);
+ b.putString("password", password);
+ b.putString("type", type);
+ startReviewFragment(b);
}
@@ -332,53 +314,36 @@ public class LoginActivity extends AppCompatActivity
if (cacheFile.exists() || keysFile.exists() || addressFile.exists()) {
Log.e(TAG, "Cannot remove all old wallet files: " + cacheFile.getAbsolutePath());
genFragment.walletGenerateError();
- ;
return;
}
- final String newWalletPath = new File(newWalletFolder, name).getAbsolutePath();
- new Thread(null,
- new Runnable() {
- @Override
- public void run() {
- Log.d(TAG, "creating wallet " + newWalletPath);
- Wallet newWallet = walletCreator.createWallet(newWalletPath, password);
- final String seed = newWallet.getSeed();
- final String address = newWallet.getAddress();
- final String view = newWallet.getSecretViewKey();
- final String spend = newWallet.isWatchOnly() ? "" : "not available - use seed for recovery";
- newWallet.close();
- Log.d(TAG, "Created " + address);
- //TODO: is runOnUiThread needed?
- runOnUiThread(new Runnable() {
- public void run() {
- Bundle b = new Bundle();
- b.putString("name", name);
- b.putString("password", password);
- b.putString("seed", seed);
- b.putString("address", address);
- b.putString("viewkey", view);
- b.putString("spendkey", spend);
- b.putString("view", GenerateReviewFragment.VIEW_ACCEPT);
- startReviewFragment(b);
- }
- });
- }
- }
- , "CreateWallet", MoneroHandlerThread.THREAD_STACK_SIZE).start();
+ String newWalletPath = new File(newWalletFolder, name).getAbsolutePath();
+ boolean success = walletCreator.createWallet(newWalletPath, password);
+ if (success) {
+ startDetails(newWalletPath, password, GenerateReviewFragment.VIEW_ACCEPT);
+ } else {
+ Toast.makeText(LoginActivity.this,
+ getString(R.string.generate_wallet_create_failed), Toast.LENGTH_LONG).show();
+ Log.e(TAG, "Could not create new wallet in " + newWalletPath);
+
+ }
}
interface WalletCreator {
- Wallet createWallet(String path, String password);
+ boolean createWallet(String path, String password);
}
@Override
public void onGenerate(String name, String password) {
createWallet(name, password,
new WalletCreator() {
- public Wallet createWallet(String path, String password) {
- return WalletManager.getInstance()
+ public boolean createWallet(String path, String password) {
+ Wallet newWallet = WalletManager.getInstance()
.createWallet(path, password, MNEMONIC_LANGUAGE);
+ boolean success = (newWallet.getStatus() == Wallet.Status.Status_Ok);
+ if (!success) Log.e(TAG, newWallet.getErrorString());
+ newWallet.close();
+ return success;
}
});
}
@@ -387,11 +352,14 @@ public class LoginActivity extends AppCompatActivity
public void onGenerate(String name, String password, final String seed, final long restoreHeight) {
createWallet(name, password,
new WalletCreator() {
- public Wallet createWallet(String path, String password) {
+ public boolean createWallet(String path, String password) {
Wallet newWallet = WalletManager.getInstance().recoveryWallet(path, seed, restoreHeight);
+ boolean success = (newWallet.getStatus() == Wallet.Status.Status_Ok);
+ if (!success) Log.e(TAG, newWallet.getErrorString());
newWallet.setPassword(password);
- newWallet.store();
- return newWallet;
+ success = success && newWallet.store();
+ newWallet.close();
+ return success;
}
});
}
@@ -401,13 +369,16 @@ public class LoginActivity extends AppCompatActivity
final String address, final String viewKey, final String spendKey, final long restoreHeight) {
createWallet(name, password,
new WalletCreator() {
- public Wallet createWallet(String path, String password) {
+ public boolean createWallet(String path, String password) {
Wallet newWallet = WalletManager.getInstance()
.createWalletFromKeys(path, MNEMONIC_LANGUAGE, restoreHeight,
address, viewKey, spendKey);
+ boolean success = (newWallet.getStatus() == Wallet.Status.Status_Ok);
+ if (!success) Log.e(TAG, newWallet.getErrorString());
newWallet.setPassword(password);
- newWallet.store();
- return newWallet;
+ success = success && newWallet.store();
+ newWallet.close();
+ return success;
}
});
}
@@ -417,31 +388,20 @@ public class LoginActivity extends AppCompatActivity
public void onAccept(final String name, final String password) {
final File newWalletFolder = new File(getStorageRoot(), ".new");
final File walletFolder = getStorageRoot();
- new Thread(null,
- new Runnable() {
- @Override
- public void run() {
- final String walletPath = new File(walletFolder, name).getAbsolutePath();
- final boolean rc = copyWallet(walletFolder, newWalletFolder, name)
- &&
- (testWallet(walletPath, password) == Wallet.Status.Status_Ok);
- runOnUiThread(new Runnable() {
- public void run() {
- if (rc) {
- getFragmentManager().popBackStack("gen",
- FragmentManager.POP_BACK_STACK_INCLUSIVE);
- Toast.makeText(LoginActivity.this,
- getString(R.string.generate_wallet_created), Toast.LENGTH_SHORT).show();
- } else {
- Log.e(TAG, "Wallet store failed to " + walletPath);
- Toast.makeText(LoginActivity.this,
- getString(R.string.generate_wallet_create_failed_2), Toast.LENGTH_LONG).show();
- }
- }
- });
- }
- }
- , "AcceptWallet", MoneroHandlerThread.THREAD_STACK_SIZE).start();
+ final String walletPath = new File(walletFolder, name).getAbsolutePath();
+ final boolean rc = copyWallet(walletFolder, newWalletFolder, name)
+ &&
+ (testWallet(walletPath, password) == Wallet.Status.Status_Ok);
+ if (rc) {
+ getFragmentManager().popBackStack("gen",
+ FragmentManager.POP_BACK_STACK_INCLUSIVE);
+ Toast.makeText(LoginActivity.this,
+ getString(R.string.generate_wallet_created), Toast.LENGTH_SHORT).show();
+ } else {
+ Log.e(TAG, "Wallet store failed to " + walletPath);
+ Toast.makeText(LoginActivity.this,
+ getString(R.string.generate_wallet_create_failed_2), Toast.LENGTH_LONG).show();
+ }
}
Wallet.Status testWallet(String path, String password) {
@@ -458,6 +418,7 @@ public class LoginActivity extends AppCompatActivity
boolean success = false;
try {
// TODO: the cache is corrupt if we recover (!!)
+ // TODO: the cache is ok if we immediately to a full refresh()
// TODO recoveryheight is ignored but not on watchonly wallet ?! - find out why
//copyFile(dstDir, srcDir, name);
copyFile(dstDir, srcDir, name + ".keys");
diff --git a/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java b/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java
index a0c5620b..0bb2231b 100644
--- a/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java
+++ b/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java
@@ -256,10 +256,14 @@ public class WalletActivity extends AppCompatActivity implements WalletFragment.
}
@Override
- public void onWalletStored() {
+ public void onWalletStored(final boolean success) {
runOnUiThread(new Runnable() {
public void run() {
- Toast.makeText(WalletActivity.this, getString(R.string.status_wallet_unloaded), Toast.LENGTH_SHORT).show();
+ if (success) {
+ Toast.makeText(WalletActivity.this, getString(R.string.status_wallet_unloaded), Toast.LENGTH_SHORT).show();
+ } else {
+ Toast.makeText(WalletActivity.this, getString(R.string.status_wallet_unload_failed), Toast.LENGTH_LONG).show();
+ }
}
});
}
diff --git a/app/src/main/java/com/m2049r/xmrwallet/model/Wallet.java b/app/src/main/java/com/m2049r/xmrwallet/model/Wallet.java
index 2eaaf8f6..9c79df61 100644
--- a/app/src/main/java/com/m2049r/xmrwallet/model/Wallet.java
+++ b/app/src/main/java/com/m2049r/xmrwallet/model/Wallet.java
@@ -28,8 +28,7 @@ public class Wallet {
static final String TAG = "Wallet";
public String getName() {
- String p = getPath();
- return new File(p).getName();
+ return new File(getPath()).getName();
}
private long handle = 0;
@@ -83,7 +82,7 @@ public class Wallet {
public native String getSecretViewKey();
public boolean store() {
- return store(this.getPath());
+ return store("");
}
public native boolean store(String path);
diff --git a/app/src/main/java/com/m2049r/xmrwallet/service/WalletService.java b/app/src/main/java/com/m2049r/xmrwallet/service/WalletService.java
index 84e6dbb8..83271401 100644
--- a/app/src/main/java/com/m2049r/xmrwallet/service/WalletService.java
+++ b/app/src/main/java/com/m2049r/xmrwallet/service/WalletService.java
@@ -193,7 +193,7 @@ public class WalletService extends Service {
void onProgress(int n);
- void onWalletStored();
+ void onWalletStored(boolean success);
}
String progressText = null;
@@ -258,9 +258,12 @@ public class WalletService extends Service {
} else if (cmd.equals(REQUEST_CMD_STORE)) {
Wallet myWallet = getWallet();
Log.d(TAG, "storing wallet: " + myWallet.getName());
- myWallet.store();
- Log.d(TAG, "wallet stored: " + myWallet.getName());
- if (observer != null) observer.onWalletStored();
+ boolean rc = myWallet.store();
+ Log.d(TAG, "wallet stored: " + myWallet.getName() + " with rc=" + rc);
+ if (!rc) {
+ Log.d(TAG, "Wallet store failed: " + myWallet.getErrorString());
+ }
+ if (observer != null) observer.onWalletStored(rc);
}
}
break;
diff --git a/app/src/main/res/layout/gen_review_fragment.xml b/app/src/main/res/layout/gen_review_fragment.xml
index 9332dc37..851a0f07 100644
--- a/app/src/main/res/layout/gen_review_fragment.xml
+++ b/app/src/main/res/layout/gen_review_fragment.xml
@@ -34,8 +34,8 @@
@@ -53,7 +52,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
- android:text="@string/generate_password_hint"
+ android:text="***"
android:textAlignment="center"
android:textColor="@color/colorPrimaryDark"
android:textSize="16sp" />
@@ -72,7 +71,6 @@
android:id="@+id/tvWalletMnemonic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:text="@string/generate_mnemonic_placeholder"
android:textAlignment="center"
android:textColor="@color/colorPrimaryDark"
android:textSize="16sp" />
@@ -92,7 +90,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:selectAllOnFocus="true"
- android:text="@string/generate_address_placeholder"
android:textAlignment="center"
android:textColor="@color/colorPrimaryDark"
android:textIsSelectable="true"
@@ -113,7 +110,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:selectAllOnFocus="true"
- android:text="@string/generate_viewkey_placeholder"
android:textAlignment="center"
android:textColor="@color/colorPrimaryDark"
android:textIsSelectable="true"
@@ -134,7 +130,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:selectAllOnFocus="true"
- android:text="@string/generate_spendkey_placeholder"
android:textAlignment="center"
android:textColor="@color/colorPrimaryDark"
android:textIsSelectable="true"
@@ -146,6 +141,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@color/colorPrimary"
- android:text="@string/generate_button_accept" />
+ android:text="@string/generate_button_accept"
+ android:visibility="gone" />
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 8344105c..9779d5ca 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -12,6 +12,7 @@
Loading Wallet …
Saving Wallet
Wallet saved
+ Wallet save failed!
Connecting …
Working on it …
@@ -58,6 +59,7 @@
Wallet exists! Choose another name
Wallet created
+ Wallet create failed
Wallet create failed (1/2)
Wallet create failed (2/2)
9tDC52GsMjTNt4dpnRCwAF7ekVBkbkgkXGaMKTcSTpBhGpqkPX56jCNRydLq9oGjbbAQBsZhLfgmTKsntmxRd3TaJFYM2f8