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;
|
||||
}
|
||||
|
||||
|
||||
.totalAmount {
|
||||
line-height: 120%;
|
||||
margin-top:2px;
|
||||
|
|
|
@ -727,6 +727,9 @@
|
|||
</a>
|
||||
</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>
|
||||
</script>
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
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';
|
||||
|
||||
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 filename = walletName + '-' + timestamp + '.json.aes';
|
||||
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
|
||||
// and pass the wallet to the shell to convert to node Buffer
|
||||
if (window.cshell) {
|
||||
|
@ -36,12 +38,18 @@ angular.module('copayApp.controllers').controller('BackupController',
|
|||
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 body = _getEncryptedWallet();
|
||||
var subject = ($rootScope.wallet.name ? $rootScope.wallet.name + ' - ' : '') + $rootScope.wallet.id;
|
||||
var href = 'mailto:' + email + '?'
|
||||
+ 'subject=[Copay Backup] ' + subject + '&'
|
||||
+ 'body=' + body;
|
||||
var href = 'mailto:' + email + '?' + 'subject=[Copay Backup] ' + subject + '&' + 'body=' + body;
|
||||
|
||||
if (window.cshell) {
|
||||
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 = opts.privateKey || new PrivateKey({ networkName: this.networkName });
|
||||
opts.privateKey = opts.privateKey || new PrivateKey({
|
||||
networkName: this.networkName
|
||||
});
|
||||
|
||||
var requiredCopayers = opts.requiredCopayers || this.walletDefaults.requiredCopayers;
|
||||
var totalCopayers = opts.totalCopayers || this.walletDefaults.totalCopayers;
|
||||
|
@ -148,12 +150,7 @@ WalletFactory.prototype._checkVersion = function(inVersion) {
|
|||
|
||||
WalletFactory.prototype._checkNetwork = function(inNetworkName) {
|
||||
if (this.networkName !== inNetworkName) {
|
||||
throw new Error('This Wallet is configured for '
|
||||
+ inNetworkName
|
||||
+ ' while currently Copay is configured for: '
|
||||
+ this.networkName
|
||||
+ '. Check your settings.'
|
||||
);
|
||||
throw new Error('This Wallet is configured for ' + inNetworkName + ' while currently Copay is configured for: ' + this.networkName + '. Check your settings.');
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -180,9 +177,11 @@ WalletFactory.prototype.getWallets = function() {
|
|||
return ret;
|
||||
};
|
||||
|
||||
WalletFactory.prototype.remove = function(walletId) {
|
||||
// TODO remove wallet contents
|
||||
this.log('TODO: remove wallet contents');
|
||||
WalletFactory.prototype.remove = function(walletId, cb) {
|
||||
var s = this.storage;
|
||||
this.log('## DELETING WALLET ID:'+ walletId); //TODO
|
||||
s.get(walletId, 'opts');
|
||||
return cb();
|
||||
};
|
||||
|
||||
WalletFactory.prototype.decodeSecret = function(secret) {
|
||||
|
@ -200,7 +199,9 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras
|
|||
if (!s) return cb('badSecret');
|
||||
|
||||
//Create our PrivateK
|
||||
var privateKey = new PrivateKey({ networkName: this.networkName });
|
||||
var privateKey = new PrivateKey({
|
||||
networkName: this.networkName
|
||||
});
|
||||
this.log('\t### PrivateKey Initialized');
|
||||
var opts = {
|
||||
copayerId: privateKey.getId(),
|
||||
|
|
|
@ -147,6 +147,27 @@ Storage.prototype.getWallets = function() {
|
|||
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
|
||||
Storage.prototype.setFromObj = function(walletId, obj) {
|
||||
for (var k in obj) {
|
||||
|
|
Loading…
Reference in New Issue