mirror of https://github.com/BTCPrivate/copay.git
encrypted wallet feat migrated to BWC 4.0.0
This commit is contained in:
parent
5864afd8c0
commit
392d8f7292
|
@ -22,7 +22,7 @@
|
|||
<div class="item">
|
||||
<span translate>Wallet Type</span>
|
||||
<span class="item-note">
|
||||
wallet.m-of-wallet.n
|
||||
{{wallet.m}}-of-{{wallet.n}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="item" ng-show="wallet.isPrivKeyExternal()">
|
||||
|
@ -55,7 +55,7 @@
|
|||
<i class="icon ion-ios-arrow-right"></i>
|
||||
</div>
|
||||
<div ng-show="wallet.canSign()">
|
||||
<ion-toggleng-model="encryptEnabled" toggle-class="toggle-balanced" ng-change="encryptChange()">
|
||||
<ion-toggle ng-model="encryptEnabled" toggle-class="toggle-balanced" ng-change="encryptChange()">
|
||||
<span class="toggle-label" translate>Request Spending Password</span>
|
||||
</ion-toggle>
|
||||
</div>
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 || {};
|
||||
|
|
|
@ -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: '<input type="password" ng-model="data.pass">',
|
||||
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() {
|
||||
|
|
Loading…
Reference in New Issue