diff --git a/public/views/preferences.html b/public/views/preferences.html
index 075194522..6e761c24a 100644
--- a/public/views/preferences.html
+++ b/public/views/preferences.html
@@ -22,7 +22,7 @@
Wallet Type
- wallet.m-of-wallet.n
+ {{wallet.m}}-of-{{wallet.n}}
@@ -55,7 +55,7 @@
-
+
Request Spending Password
diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js
index 4ec35031e..e9af90994 100644
--- a/src/js/controllers/confirm.js
+++ b/src/js/controllers/confirm.js
@@ -189,7 +189,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
};
var setSendError = function(msg) {
- showAlert(gettext('Error creating transaction'), msg);
+ showAlert(gettext('Error at confirm:'), msg);
};
function apply(txp) {
diff --git a/src/js/controllers/preferences.js b/src/js/controllers/preferences.js
index 5118d70ef..92fb04344 100644
--- a/src/js/controllers/preferences.js
+++ b/src/js/controllers/preferences.js
@@ -31,71 +31,39 @@ angular.module('copayApp.controllers').controller('preferencesController',
}
};
- var handleEncryptedWallet = function(cb) {
- $rootScope.$emit('Local/NeedsPassword', false, function(err, password) {
- if (err) return cb(err);
- return cb(walletService.unlock(wallet, password));
- });
- };
-
$scope.encryptChange = function() {
if (!wallet) return;
var val = $scope.encryptEnabled;
- var setPrivateKeyEncryption = function(password, cb) {
- $log.debug('Encrypting private key for', wallet.credentials.walletName);
-
- wallet.setPrivateKeyEncryption(password);
- wallet.lock();
- profileService.updateCredentials(JSON.parse(wallet.export()), function() {
- $log.debug('Wallet encrypted');
- return cb();
- });
- };
-
- var disablePrivateKeyEncryption = function(cb) {
- $log.debug('Disabling private key encryption for', wallet.credentials.walletName);
-
- try {
- wallet.disablePrivateKeyEncryption();
- } catch (e) {
- return cb(e);
- }
- profileService.updateCredentials(JSON.parse(wallet.export()), function() {
- $log.debug('Wallet encryption disabled');
- return cb();
- });
- };
-
if (val && !walletService.isEncrypted(wallet)) {
- $rootScope.$emit('Local/NeedsPassword', true, function(err, password) {
- if (err || !password) {
+ $log.debug('Encrypting private key for', wallet.name);
+ walletService.encrypt(wallet, function(err) {
+ if (err) {
+ $log.warn(err);
+
+ // ToDo show error?
$scope.encryptEnabled = false;
return;
}
- setPrivateKeyEncryption(password, function() {
- $rootScope.$emit('Local/NewEncryptionSetting');
+ profileService.updateCredentials(JSON.parse(wallet.export()), function() {
+ $log.debug('Wallet encrypted');
+ return;
+ });
+ })
+ } else if (!val && walletService.isEncrypted(wallet)) {
+ walletService.decrypt(wallet, function(err) {
+ if (err) {
+ $log.warn(err);
+
+ // ToDo show error?
$scope.encryptEnabled = true;
+ return;
+ }
+ profileService.updateCredentials(JSON.parse(wallet.export()), function() {
+ $log.debug('Wallet decrypted');
+ return;
});
- });
- } else {
- if (!val && walletService.isEncrypted(wallet)) {
- handleEncryptedWallet(function(err) {
- if (err) {
- $scope.encryptEnabled = true;
- return;
- }
- disablePrivateKeyEncryption(function(err) {
- $rootScope.$emit('Local/NewEncryptionSetting');
- if (err) {
- $scope.encryptEnabled = true;
- $log.error(err);
- return;
- }
- $scope.encryptEnabled = false;
- });
- });
- }
+ })
}
};
diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js
index da9538144..b6886b5c2 100644
--- a/src/js/controllers/tab-home.js
+++ b/src/js/controllers/tab-home.js
@@ -37,7 +37,6 @@ angular.module('copayApp.controllers').controller('tabHomeController',
walletService.getNotifications(wallet, {
timeSpan: timeSpan
}, function(err, n) {
-console.log('[tab-home.js.39]', wallet.name, n); //TODO
if (err) {
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
return;
diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js
index 12d55b3e5..d54881695 100644
--- a/src/js/services/profileService.js
+++ b/src/js/services/profileService.js
@@ -87,11 +87,6 @@ angular.module('copayApp.services')
});
});
- if (wallet.hasPrivKeyEncrypted() && !wallet.isPrivKeyEncrypted()) {
- $log.warn('Auto locking unlocked wallet:' + walletId);
- wallet.lock();
- }
-
wallet.initialize({}, function(err) {
if (err) {
$log.error('Could not init notifications err:', err);
@@ -548,14 +543,6 @@ angular.module('copayApp.services')
return cb(gettext('Could not import. Check input file and spending password'));
}
- if (walletClient.hasPrivKeyEncrypted()) {
- try {
- walletClient.disablePrivateKeyEncryption();
- } catch (e) {
- $log.warn(e);
- }
- }
-
str = JSON.parse(str);
var addressBook = str.addressBook || {};
diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js
index 5d3cbaf4c..26407ee1e 100644
--- a/src/js/services/walletService.js
+++ b/src/js/services/walletService.js
@@ -557,28 +557,12 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
else return cb(null, createdTxp);
});
} else {
- wallet.getFeeLevels(wallet.credentials.network, function(err, levels) {
+ wallet.createTxProposal(txp, function(err, createdTxp) {
if (err) return cb(err);
-
- var feeLevelValue = lodash.find(levels, {
- level: txp.feeLevel
- });
-
- if (!feeLevelValue || !feeLevelValue.feePerKB)
- return cb({
- message: 'Could not get dynamic fee for level: ' + feeLevel
- });
-
- $log.debug('Dynamic fee: ' + txp.feeLevel + ' ' + feeLevelValue.feePerKB + ' SAT');
-
- txp.feePerKb = feeLevelValue.feePerKB;
- wallet.createTxProposal(txp, function(err, createdTxp) {
- if (err) return cb(err);
- else {
- $log.debug('Transaction created');
- return cb(null, createdTxp);
- }
- });
+ else {
+ $log.debug('Transaction created');
+ return cb(null, createdTxp);
+ }
});
}
};
@@ -599,7 +583,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
};
root.signTx = function(wallet, txp, password, cb) {
- if (lodash.isEmpty(txp) || lodash.isEmpty(wallet) || lodash.isEmpty(cb))
+ if (!wallet || !txp || !cb)
return cb('MISSING_PARAMETER');
if (wallet.isPrivKeyExternal()) {
@@ -840,12 +824,12 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
// An alert dialog
- var askPassword = function(name, cb) {
+ var askPassword = function(name, title, cb) {
var scope = $rootScope.$new(true);
scope.data = [];
var pass = $ionicPopup.show({
template: '',
- title: 'Enter Spending Password',
+ title: title,
subTitle: name,
scope: scope,
buttons: [{
@@ -870,10 +854,39 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
});
};
+
+ root.encrypt = function(wallet, cb) {
+ askPassword(wallet.name, gettext('Enter new spending password'), function(password) {
+ if (!password) return cb('no password');
+ askPassword(wallet.name, gettext('Confirm you new spending password'), function(password2) {
+ if (!password2 || password != password2)
+ return cb('password mismatch');
+
+ wallet.encryptPrivateKey(password);
+ return cb();
+ });
+ });
+ };
+
+
+ root.decrypt = function(wallet, cb) {
+ $log.debug('Disabling private key encryption for' + wallet.name);
+ askPassword(wallet.name, gettext('Enter Spending Password'), function(password) {
+ if (!password) return cb('no password');
+
+ try {
+ wallet.decryptPrivateKey(password);
+ } catch (e) {
+ return cb(e);
+ }
+ return cb();
+ });
+ };
+
root.handleEncryptedWallet = function(wallet, cb) {
if (!root.isEncrypted(wallet)) return cb();
- askPassword(wallet.name, function(password) {
+ askPassword(wallet.name, gettext('Enter Spending Password'), function(password) {
if (!password) return cb('no password');
return cb(null, password);
@@ -937,12 +950,12 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
}
root.prepare(wallet, function(err, password) {
- if (err) return cb(err);
+ if (err) return cb('Prepare error: ' + err);
ongoingProcess.set('sendingTx', true);
publishFn(wallet, txp, function(err, publishedTxp) {
ongoingProcess.set('sendingTx', false);
- if (err) return cb(err);
+ if (err) return cb('Send Error: ' + err);
ongoingProcess.set('signingTx', true);
root.signTx(wallet, publishedTxp, password, function(err, signedTxp) {
@@ -951,19 +964,20 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
if (err) {
+ $log.warn('sign error:' + err);
// TODO?
var msg = err.message ?
err.message :
gettext('The payment was created but could not be completed. Please try again from home screen');
$rootScope.$emit('Local/TxAction', wallet.id);
- return cb(err);
+ return cb(msg);
}
if (signedTxp.status == 'accepted') {
ongoingProcess.set('broadcastingTx', true);
root.broadcastTx(wallet, signedTxp, function(err, broadcastedTxp) {
ongoingProcess.set('broadcastingTx', false);
- if (err) return cb(err);
+ if (err) return cb('sign error' + err);
var type = txStatus.notify(broadcastedTxp);
root.openStatusModal(type, broadcastedTxp, function() {