delete Wallet WIP
This commit is contained in:
parent
bde2ae8576
commit
46feadf57c
6 changed files with 134 additions and 83 deletions
|
|
@ -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() {
|
||||||
|
|
@ -14,7 +14,9 @@ angular.module('copayApp.controllers').controller('BackupController',
|
||||||
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) {
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -148,12 +150,7 @@ 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.'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -180,9 +177,11 @@ WalletFactory.prototype.getWallets = function() {
|
||||||
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(),
|
||||||
|
|
|
||||||
|
|
@ -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…
Add table
Add a link
Reference in a new issue