delete Wallet WIP

This commit is contained in:
Matias Alejo Garcia 2014-06-16 15:51:19 -03:00
parent bde2ae8576
commit 46feadf57c
6 changed files with 134 additions and 83 deletions

View File

@ -219,7 +219,6 @@ small.has-error {
font-weight: bold; font-weight: bold;
} }
.totalAmount { .totalAmount {
line-height: 120%; line-height: 120%;
margin-top:2px; margin-top:2px;

View File

@ -727,6 +727,9 @@
</a> </a>
</div> </div>
</div> </div>
<div class="row text-center small" style="margin-top:20px">
<div class="button radius warning" ng-really-message="Are you sure to delete this wallet from this computer?" ng-really-click="deleteWallet()">Delete this wallet from this computer</div>
</div>
</div> </div>
</script> </script>

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('BackupController', angular.module('copayApp.controllers').controller('BackupController',
function($scope, $rootScope, $location, $window, $timeout, $modal) { function($scope, $rootScope, $location, $window, $timeout, $modal, controllerUtils, walletFactory) {
$scope.title = 'Backup'; $scope.title = 'Backup';
var _getEncryptedWallet = function() { var _getEncryptedWallet = function() {
@ -11,10 +11,12 @@ angular.module('copayApp.controllers').controller('BackupController',
$scope.download = function() { $scope.download = function() {
var timestamp = +(new Date); var timestamp = +(new Date);
var walletName = ($rootScope.wallet.name ? $rootScope.wallet.name : '') + '-' + $rootScope.wallet.id ; var walletName = ($rootScope.wallet.name ? $rootScope.wallet.name : '') + '-' + $rootScope.wallet.id;
var filename = walletName + '-' + timestamp + '.json.aes'; var filename = walletName + '-' + timestamp + '.json.aes';
var wallet = _getEncryptedWallet(); var wallet = _getEncryptedWallet();
var blob = new Blob([wallet], {type: 'text/plain;charset=utf-8'}); var blob = new Blob([wallet], {
type: 'text/plain;charset=utf-8'
});
// show a native save dialog if we are in the shell // show a native save dialog if we are in the shell
// and pass the wallet to the shell to convert to node Buffer // and pass the wallet to the shell to convert to node Buffer
if (window.cshell) { if (window.cshell) {
@ -27,7 +29,7 @@ angular.module('copayApp.controllers').controller('BackupController',
saveAs(blob, filename); saveAs(blob, filename);
}; };
$scope.openModal = function () { $scope.openModal = function() {
var modalInstance = $modal.open({ var modalInstance = $modal.open({
templateUrl: 'backupModal.html', templateUrl: 'backupModal.html',
controller: ModalInstanceCtrl, controller: ModalInstanceCtrl,
@ -36,12 +38,18 @@ angular.module('copayApp.controllers').controller('BackupController',
modalInstance.result.then(sendEmail); modalInstance.result.then(sendEmail);
}; };
$scope.deleteWallet = function() {
var w=$rootScope.wallet;
w.disconnect();
walletFactory.remove(w.id, function() {
controllerUtils.logout();
});
};
var sendEmail = function(email) { var sendEmail = function(email) {
var body = _getEncryptedWallet(); var body = _getEncryptedWallet();
var subject = ($rootScope.wallet.name ? $rootScope.wallet.name + ' - ' : '') + $rootScope.wallet.id; var subject = ($rootScope.wallet.name ? $rootScope.wallet.name + ' - ' : '') + $rootScope.wallet.id;
var href = 'mailto:' + email + '?' var href = 'mailto:' + email + '?' + 'subject=[Copay Backup] ' + subject + '&' + 'body=' + body;
+ 'subject=[Copay Backup] ' + subject + '&'
+ 'body=' + body;
if (window.cshell) { if (window.cshell) {
return window.cshell.send('backup:email', href); return window.cshell.send('backup:email', href);
@ -55,15 +63,15 @@ angular.module('copayApp.controllers').controller('BackupController',
}, 1000); }, 1000);
} }
}; };
}); });
var ModalInstanceCtrl = function ($scope, $modalInstance) { var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.submit = function (form) { $scope.submit = function(form) {
$modalInstance.close($scope.email); $modalInstance.close($scope.email);
}; };
$scope.cancel = function () { $scope.cancel = function() {
$modalInstance.dismiss('cancel'); $modalInstance.dismiss('cancel');
}; };
}; };

View File

@ -202,4 +202,23 @@ angular.module('copayApp.directives')
}); });
} }
}; };
})
// From https://gist.github.com/asafge/7430497
.directive('ngReallyClick', [
function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', function() {
var message = attrs.ngReallyMessage;
if (message && confirm(message)) {
scope.$apply(attrs.ngReallyClick);
}
}); });
}
}
}
])
;

View File

@ -29,7 +29,7 @@ function WalletFactory(config, version) {
this.version = version; this.version = version;
} }
WalletFactory.prototype.log = function(){ WalletFactory.prototype.log = function() {
if (!this.verbose) return; if (!this.verbose) return;
if (console) { if (console) {
console.log.apply(console, arguments); console.log.apply(console, arguments);
@ -69,7 +69,7 @@ WalletFactory.prototype.fromEncryptedObj = function(base64, password) {
}; };
WalletFactory.prototype.read = function(walletId) { WalletFactory.prototype.read = function(walletId) {
if (! this._checkRead(walletId)) if (!this._checkRead(walletId))
return false; return false;
var obj = {}; var obj = {};
@ -92,7 +92,9 @@ WalletFactory.prototype.create = function(opts) {
(opts.privateKey ? ' USING PrivateKey: ' + opts.privateKey.getId() : ' NEW PrivateKey') (opts.privateKey ? ' USING PrivateKey: ' + opts.privateKey.getId() : ' NEW PrivateKey')
); );
opts.privateKey = opts.privateKey || new PrivateKey({ networkName: this.networkName }); opts.privateKey = opts.privateKey || new PrivateKey({
networkName: this.networkName
});
var requiredCopayers = opts.requiredCopayers || this.walletDefaults.requiredCopayers; var requiredCopayers = opts.requiredCopayers || this.walletDefaults.requiredCopayers;
var totalCopayers = opts.totalCopayers || this.walletDefaults.totalCopayers; var totalCopayers = opts.totalCopayers || this.walletDefaults.totalCopayers;
@ -137,7 +139,7 @@ WalletFactory.prototype._checkVersion = function(inVersion) {
var inV0 = parseInt(inV[0]); var inV0 = parseInt(inV[0]);
//We only check for major version differences //We only check for major version differences
if( thisV0 < inV0 ) { if (thisV0 < inV0) {
throw new Error('Major difference in software versions' + throw new Error('Major difference in software versions' +
'. Received:' + inVersion + '. Received:' + inVersion +
'. Current version:' + this.version + '. Current version:' + this.version +
@ -147,13 +149,8 @@ WalletFactory.prototype._checkVersion = function(inVersion) {
WalletFactory.prototype._checkNetwork = function(inNetworkName) { WalletFactory.prototype._checkNetwork = function(inNetworkName) {
if( this.networkName !== inNetworkName ) { if (this.networkName !== inNetworkName) {
throw new Error('This Wallet is configured for ' throw new Error('This Wallet is configured for ' + inNetworkName + ' while currently Copay is configured for: ' + this.networkName + '. Check your settings.');
+ inNetworkName
+ ' while currently Copay is configured for: '
+ this.networkName
+ '. Check your settings.'
);
} }
}; };
@ -175,14 +172,16 @@ WalletFactory.prototype.open = function(walletId, opts) {
WalletFactory.prototype.getWallets = function() { WalletFactory.prototype.getWallets = function() {
var ret = this.storage.getWallets(); var ret = this.storage.getWallets();
ret.forEach(function(i) { ret.forEach(function(i) {
i.show = i.name ? ( (i.name + ' <'+i.id+'>') ) : i.id; i.show = i.name ? ((i.name + ' <' + i.id + '>')) : i.id;
}); });
return ret; return ret;
}; };
WalletFactory.prototype.remove = function(walletId) { WalletFactory.prototype.remove = function(walletId, cb) {
// TODO remove wallet contents var s = this.storage;
this.log('TODO: remove wallet contents'); this.log('## DELETING WALLET ID:'+ walletId); //TODO
s.get(walletId, 'opts');
return cb();
}; };
WalletFactory.prototype.decodeSecret = function(secret) { WalletFactory.prototype.decodeSecret = function(secret) {
@ -200,7 +199,9 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras
if (!s) return cb('badSecret'); if (!s) return cb('badSecret');
//Create our PrivateK //Create our PrivateK
var privateKey = new PrivateKey({ networkName: this.networkName }); var privateKey = new PrivateKey({
networkName: this.networkName
});
this.log('\t### PrivateKey Initialized'); this.log('\t### PrivateKey Initialized');
var opts = { var opts = {
copayerId: privateKey.getId(), copayerId: privateKey.getId(),
@ -219,8 +220,8 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras
return cb(connectedOnce ? 'walletFull' : 'joinError'); return cb(connectedOnce ? 'walletFull' : 'joinError');
}); });
self.network.on('data', function(sender, data) { self.network.on('data', function(sender, data) {
if (data.type ==='walletId') { if (data.type === 'walletId') {
if (data.networkName !== self.networkName ){ if (data.networkName !== self.networkName) {
return cb('badNetwork'); return cb('badNetwork');
} }

View File

@ -147,6 +147,27 @@ Storage.prototype.getWallets = function() {
return wallets; return wallets;
}; };
Storage.prototype.deleteWallet = function(walletId) {
var walletIds = [];
var uniq = {};
for (var i = 0; i < localStorage.length; i++) {
var key = localStorage.key(i);
var split = key.split('::');
if (split.length == 2) {
var walletId = split[0];
if (walletId === 'nameFor') continue;
if (typeof uniq[walletId] === 'undefined') {
walletIds.push(walletId);
uniq[walletId] = 1;
}
}
}
};
//obj contains keys to be set //obj contains keys to be set
Storage.prototype.setFromObj = function(walletId, obj) { Storage.prototype.setFromObj = function(walletId, obj) {
for (var k in obj) { for (var k in obj) {