mirror of https://github.com/BTCPrivate/copay.git
wallet and profile backup working on the UX
This commit is contained in:
parent
e1b9f4f859
commit
7a463c9a9d
|
@ -1,3 +1,7 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.controllers').controller('ManageController', function($scope, $rootScope, $location, controllerUtils) {
|
||||
angular.module('copayApp.controllers').controller('ManageController', function($scope, $rootScope, $location, controllerUtils, backupService) {
|
||||
|
||||
$scope.downloadBackup = function() {
|
||||
backupService.profileDownload($rootScope.iden);
|
||||
};
|
||||
});
|
||||
|
|
|
@ -74,7 +74,7 @@ angular.module('copayApp.controllers').controller('MoreController',
|
|||
}
|
||||
|
||||
$scope.downloadBackup = function() {
|
||||
backupService.download(w);
|
||||
backupService.walletDownload(w);
|
||||
}
|
||||
|
||||
$scope.viewBackup = function() {
|
||||
|
|
|
@ -39,7 +39,6 @@ function Identity(email, password, opts) {
|
|||
|
||||
this.walletDefaults = opts.walletDefaults || {};
|
||||
this.version = opts.version || version;
|
||||
this.email = email;
|
||||
|
||||
// open wallets
|
||||
this.openWallets = [];
|
||||
|
@ -401,7 +400,7 @@ Identity.prototype.createWallet = function(opts, cb) {
|
|||
});
|
||||
opts.publicKeyRing.addCopayer(
|
||||
opts.privateKey.deriveBIP45Branch().extendedPublicKeyString(),
|
||||
opts.nickname || this.email
|
||||
opts.nickname || this.profile.getName()
|
||||
);
|
||||
log.debug('\t### PublicKeyRing Initialized');
|
||||
|
||||
|
@ -632,7 +631,7 @@ Identity.prototype.joinWallet = function(opts, cb) {
|
|||
walletOpts.network = joinNetwork;
|
||||
|
||||
walletOpts.privateKey = privateKey;
|
||||
walletOpts.nickname = opts.nickname || this.email;
|
||||
walletOpts.nickname = opts.nickname || this.profile.getName();
|
||||
|
||||
if (opts.password)
|
||||
walletOpts.password = opts.password;
|
||||
|
|
|
@ -1171,7 +1171,7 @@ Wallet.fromObj = function(o, readOpts) {
|
|||
*/
|
||||
Wallet.prototype.toEncryptedObj = function() {
|
||||
var walletObj = this.toObj();
|
||||
return this.storage.export(walletObj);
|
||||
return this.storage.encrypt(walletObj);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,32 +5,16 @@ var BackupService = function(notification) {
|
|||
this.notifications = notification;
|
||||
};
|
||||
|
||||
BackupService.prototype.getName = function(wallet) {
|
||||
return (wallet.name ? (wallet.name + '-') : '') + wallet.id;
|
||||
};
|
||||
|
||||
BackupService.prototype.getCopayer = function(wallet) {
|
||||
return wallet.totalCopayers > 1 ? wallet.getMyCopayerNickname() : '';
|
||||
};
|
||||
|
||||
BackupService.prototype.getBackup = function(wallet) {
|
||||
return wallet.toEncryptedObj();
|
||||
};
|
||||
|
||||
BackupService.prototype.getFilename = function(wallet) {
|
||||
var walletName = this.getName(wallet);
|
||||
var copayerName = this.getCopayer(wallet);
|
||||
return (copayerName ? copayerName + '-' : '') + walletName + '-keybackup.json.aes';
|
||||
};
|
||||
|
||||
BackupService.prototype.download = function(wallet) {
|
||||
var ew = this.getBackup(wallet);
|
||||
var filename = this.getFilename(wallet);
|
||||
|
||||
this.notifications.success('Backup created', 'Encrypted backup file saved');
|
||||
BackupService.prototype._download = function(ew, walletName, filename) {
|
||||
var blob = new Blob([ew], {
|
||||
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) {
|
||||
|
@ -49,9 +33,29 @@ BackupService.prototype.download = function(wallet) {
|
|||
attachments: ['base64:' + filename + '//' + btoa(ew)]
|
||||
});
|
||||
}
|
||||
this.notifications.success('Backup created', 'Encrypted backup file saved');
|
||||
|
||||
// otherwise lean on the browser implementation
|
||||
saveAs(blob, filename);
|
||||
};
|
||||
|
||||
|
||||
BackupService.prototype.walletDownload = function(wallet) {
|
||||
var ew = wallet.toEncryptedObj();
|
||||
var walletName = wallet.getName();
|
||||
var copayerName = this.getCopayer(wallet);
|
||||
var filename = (copayerName ? copayerName + '-' : '') + walletName + '-keybackup.json.aes';
|
||||
this._download(ew, walletName, filename)
|
||||
};
|
||||
|
||||
BackupService.prototype.profileDownload = function(iden) {
|
||||
var ew = iden.toEncryptedObj();
|
||||
var name = iden.profile.getName();
|
||||
var filename = name + '-profile.json';
|
||||
this._download(ew, name, filename)
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
angular.module('copayApp.services').service('backupService', BackupService);
|
||||
|
|
Loading…
Reference in New Issue