mirror of https://github.com/BTCPrivate/copay.git
delete Wallet WIP
This commit is contained in:
parent
bde2ae8576
commit
46feadf57c
|
@ -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;
|
||||||
|
|
|
@ -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>
|
||||||
|
|
||||||
|
|
|
@ -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,43 +29,49 @@ 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,
|
||||||
});
|
});
|
||||||
|
|
||||||
modalInstance.result.then(sendEmail);
|
modalInstance.result.then(sendEmail);
|
||||||
};
|
};
|
||||||
|
|
||||||
var sendEmail = function(email) {
|
$scope.deleteWallet = function() {
|
||||||
var body = _getEncryptedWallet();
|
var w=$rootScope.wallet;
|
||||||
var subject = ($rootScope.wallet.name ? $rootScope.wallet.name + ' - ' : '') + $rootScope.wallet.id;
|
w.disconnect();
|
||||||
var href = 'mailto:' + email + '?'
|
walletFactory.remove(w.id, function() {
|
||||||
+ 'subject=[Copay Backup] ' + subject + '&'
|
controllerUtils.logout();
|
||||||
+ 'body=' + body;
|
});
|
||||||
|
};
|
||||||
|
|
||||||
if (window.cshell) {
|
var sendEmail = function(email) {
|
||||||
return window.cshell.send('backup:email', href);
|
var body = _getEncryptedWallet();
|
||||||
}
|
var subject = ($rootScope.wallet.name ? $rootScope.wallet.name + ' - ' : '') + $rootScope.wallet.id;
|
||||||
|
var href = 'mailto:' + email + '?' + 'subject=[Copay Backup] ' + subject + '&' + 'body=' + body;
|
||||||
|
|
||||||
var newWin = $window.open(href, '_blank', 'scrollbars=yes,resizable=yes,width=10,height=10');
|
if (window.cshell) {
|
||||||
|
return window.cshell.send('backup:email', href);
|
||||||
|
}
|
||||||
|
|
||||||
if (newWin) {
|
var newWin = $window.open(href, '_blank', 'scrollbars=yes,resizable=yes,width=10,height=10');
|
||||||
$timeout(function() {
|
|
||||||
newWin.close();
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
var ModalInstanceCtrl = function ($scope, $modalInstance) {
|
if (newWin) {
|
||||||
|
$timeout(function() {
|
||||||
|
newWin.close();
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
$scope.submit = function (form) {
|
var ModalInstanceCtrl = function($scope, $modalInstance) {
|
||||||
|
|
||||||
|
$scope.submit = function(form) {
|
||||||
$modalInstance.close($scope.email);
|
$modalInstance.close($scope.email);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.cancel = function () {
|
$scope.cancel = function() {
|
||||||
$modalInstance.dismiss('cancel');
|
$modalInstance.dismiss('cancel');
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var imports = require('soop').imports();
|
var imports = require('soop').imports();
|
||||||
var Storage = imports.Storage;
|
var Storage = imports.Storage;
|
||||||
var Network = imports.Network;
|
var Network = imports.Network;
|
||||||
var Blockchain = imports.Blockchain;
|
var Blockchain = imports.Blockchain;
|
||||||
|
|
||||||
var TxProposals = require('./TxProposals');
|
var TxProposals = require('./TxProposals');
|
||||||
var PublicKeyRing = require('./PublicKeyRing');
|
var PublicKeyRing = require('./PublicKeyRing');
|
||||||
|
@ -23,13 +23,13 @@ function WalletFactory(config, version) {
|
||||||
this.network = new Network(config.network);
|
this.network = new Network(config.network);
|
||||||
this.blockchain = new Blockchain(config.blockchain);
|
this.blockchain = new Blockchain(config.blockchain);
|
||||||
|
|
||||||
this.networkName = config.networkName;
|
this.networkName = config.networkName;
|
||||||
this.verbose = config.verbose;
|
this.verbose = config.verbose;
|
||||||
this.walletDefaults = config.wallet;
|
this.walletDefaults = config.wallet;
|
||||||
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);
|
||||||
|
@ -40,17 +40,17 @@ WalletFactory.prototype.log = function(){
|
||||||
WalletFactory.prototype._checkRead = function(walletId) {
|
WalletFactory.prototype._checkRead = function(walletId) {
|
||||||
var s = this.storage;
|
var s = this.storage;
|
||||||
var ret =
|
var ret =
|
||||||
s.get(walletId, 'publicKeyRing') &&
|
s.get(walletId, 'publicKeyRing') &&
|
||||||
s.get(walletId, 'txProposals') &&
|
s.get(walletId, 'txProposals') &&
|
||||||
s.get(walletId, 'opts') &&
|
s.get(walletId, 'opts') &&
|
||||||
s.get(walletId, 'privateKey');
|
s.get(walletId, 'privateKey');
|
||||||
return !!ret;
|
return !!ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletFactory.prototype.fromObj = function(obj) {
|
WalletFactory.prototype.fromObj = function(obj) {
|
||||||
|
|
||||||
// not stored options
|
// not stored options
|
||||||
obj.opts.reconnectDelay = this.walletDefaults.reconnectDelay;
|
obj.opts.reconnectDelay = this.walletDefaults.reconnectDelay;
|
||||||
|
|
||||||
var w = Wallet.fromObj(obj, this.storage, this.network, this.blockchain);
|
var w = Wallet.fromObj(obj, this.storage, this.network, this.blockchain);
|
||||||
if (!w) return false;
|
if (!w) return false;
|
||||||
|
@ -69,33 +69,35 @@ 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 = {};
|
||||||
var s = this.storage;
|
var s = this.storage;
|
||||||
|
|
||||||
obj.id = walletId;
|
obj.id = walletId;
|
||||||
obj.opts = s.get(walletId, 'opts');
|
obj.opts = s.get(walletId, 'opts');
|
||||||
obj.publicKeyRing = s.get(walletId, 'publicKeyRing');
|
obj.publicKeyRing = s.get(walletId, 'publicKeyRing');
|
||||||
obj.txProposals = s.get(walletId, 'txProposals');
|
obj.txProposals = s.get(walletId, 'txProposals');
|
||||||
obj.privateKey = s.get(walletId, 'privateKey');
|
obj.privateKey = s.get(walletId, 'privateKey');
|
||||||
|
|
||||||
var w = this.fromObj(obj);
|
var w = this.fromObj(obj);
|
||||||
return w;
|
return w;
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletFactory.prototype.create = function(opts) {
|
WalletFactory.prototype.create = function(opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
this.log('### CREATING NEW WALLET.' +
|
this.log('### CREATING NEW WALLET.' +
|
||||||
(opts.id ? ' USING ID: ' + opts.id : ' NEW ID') +
|
(opts.id ? ' USING ID: ' + opts.id : ' NEW ID') +
|
||||||
(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;
|
||||||
|
|
||||||
opts.publicKeyRing = opts.publicKeyRing || new PublicKeyRing({
|
opts.publicKeyRing = opts.publicKeyRing || new PublicKeyRing({
|
||||||
networkName: this.networkName,
|
networkName: this.networkName,
|
||||||
|
@ -120,10 +122,10 @@ WalletFactory.prototype.create = function(opts) {
|
||||||
opts.verbose = this.verbose;
|
opts.verbose = this.verbose;
|
||||||
|
|
||||||
opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed;
|
opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed;
|
||||||
opts.reconnectDelay = opts.reconnectDelay || this.walletDefaults.reconnectDelay;
|
opts.reconnectDelay = opts.reconnectDelay || this.walletDefaults.reconnectDelay;
|
||||||
opts.requiredCopayers = requiredCopayers;
|
opts.requiredCopayers = requiredCopayers;
|
||||||
opts.totalCopayers = totalCopayers;
|
opts.totalCopayers = totalCopayers;
|
||||||
opts.version = opts.version || this.version;
|
opts.version = opts.version || this.version;
|
||||||
var w = new Wallet(opts);
|
var w = new Wallet(opts);
|
||||||
w.store();
|
w.store();
|
||||||
return w;
|
return w;
|
||||||
|
@ -133,27 +135,22 @@ WalletFactory.prototype.create = function(opts) {
|
||||||
WalletFactory.prototype._checkVersion = function(inVersion) {
|
WalletFactory.prototype._checkVersion = function(inVersion) {
|
||||||
var thisV = this.version.split('.');
|
var thisV = this.version.split('.');
|
||||||
var thisV0 = parseInt(thisV[0]);
|
var thisV0 = parseInt(thisV[0]);
|
||||||
var inV = inVersion.split('.');
|
var inV = inVersion.split('.');
|
||||||
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 +
|
||||||
'. Aborting.');
|
'. Aborting.');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
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,13 +220,13 @@ 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');
|
||||||
}
|
}
|
||||||
|
|
||||||
data.opts.privateKey = privateKey;
|
data.opts.privateKey = privateKey;
|
||||||
data.opts.nickname = nickname;
|
data.opts.nickname = nickname;
|
||||||
data.opts.passphrase = passphrase;
|
data.opts.passphrase = passphrase;
|
||||||
data.opts.id = data.walletId;
|
data.opts.id = data.walletId;
|
||||||
var w = self.create(data.opts);
|
var w = self.create(data.opts);
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue