added support for the wallet backups
This commit is contained in:
parent
1d511141b9
commit
2838b3ecd2
4 changed files with 97 additions and 16 deletions
|
|
@ -1,13 +1,65 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copay.backup').controller('BackupController',
|
||||
function($scope, $rootScope, $location) {
|
||||
|
||||
function($scope, $rootScope, $location, $window, $timeout) {
|
||||
|
||||
if (!$rootScope.wallet.id) {
|
||||
$location.path('signin');
|
||||
}
|
||||
|
||||
|
||||
$scope.title = 'Backup';
|
||||
|
||||
var filename = $rootScope.wallet.id + '.json.aes';
|
||||
|
||||
// TODO: get the real encrypted wallet.
|
||||
var _getEncryptedWallet = function() {
|
||||
var wallet = JSON.stringify($rootScope.wallet.toObj());
|
||||
return wallet;
|
||||
};
|
||||
|
||||
var _getWalletBlob = function() {
|
||||
var wallet = _getEncryptedWallet();
|
||||
var blob = new Blob([wallet], {type: 'text/plain;charset=utf-8'});
|
||||
|
||||
return blob;
|
||||
};
|
||||
|
||||
$scope.download = function() {
|
||||
var blob = _getWalletBlob();
|
||||
saveAs(blob, filename);
|
||||
};
|
||||
|
||||
$scope.dropbox = function() {
|
||||
var blob = _getWalletBlob();
|
||||
var url = $window.URL.createObjectURL(blob);
|
||||
|
||||
// TODO: send the blob to Dropbox, (if we can...)
|
||||
};
|
||||
|
||||
$scope.email = function() {
|
||||
var email = prompt('Please enter your email addres.');
|
||||
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
|
||||
|
||||
if (!email.match(mailformat)) {
|
||||
alert('Enter a valid email address');
|
||||
} else {
|
||||
if (email && email !== '') {
|
||||
var body = _getEncryptedWallet();
|
||||
console.log(body);
|
||||
var subject = 'Copay Backup';
|
||||
var href = 'mailto:' + email + '?'
|
||||
+ 'subject=' + subject + '&'
|
||||
+ 'body=' + 'body'; // TODO: Uncomment this when get the real encrypted wallet.
|
||||
|
||||
var newWin = $window.open(href, '_blank', 'scrollbars=yes,resizable=yes,width=10,height=10');
|
||||
|
||||
if (newWin) {
|
||||
$timeout(function() {
|
||||
newWin.close();
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue