incluiding address book and transaction history cache in export file
This commit is contained in:
parent
14504ab9b3
commit
b1851c658e
2 changed files with 130 additions and 55 deletions
|
|
@ -1,44 +1,106 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('backupController',
|
||||
function($rootScope, $scope, $timeout, backupService, profileService, isMobile, notification, go, gettext, gettextCatalog) {
|
||||
this.error = null;
|
||||
this.success = null;
|
||||
function($rootScope, $scope, $timeout, $log, backupService, storageService, profileService, isMobile, notification, go, gettext, gettextCatalog) {
|
||||
var self = this;
|
||||
|
||||
self.error = null;
|
||||
self.success = null;
|
||||
|
||||
var fc = profileService.focusedClient;
|
||||
this.isEncrypted = fc.isPrivKeyEncrypted();
|
||||
self.isEncrypted = fc.isPrivKeyEncrypted();
|
||||
|
||||
this.downloadWalletBackup = function() {
|
||||
var self = this;
|
||||
var opts = {
|
||||
noSign: $scope.noSign,
|
||||
};
|
||||
backupService.walletDownload(this.password, opts, function(err) {
|
||||
self.downloadWalletBackup = function() {
|
||||
self.getMetaData(function(err, txsFromLocal, localAddressBook) {
|
||||
if (err) {
|
||||
self.error = true;
|
||||
return;
|
||||
}
|
||||
var opts = {
|
||||
noSign: $scope.noSign,
|
||||
historyCache: txsFromLocal,
|
||||
addressBook: localAddressBook
|
||||
};
|
||||
|
||||
backupService.walletDownload(self.password, opts, function(err) {
|
||||
if (err) {
|
||||
self.error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
$rootScope.$emit('Local/BackupDone');
|
||||
notification.success(gettext('Success'), gettext('Encrypted export file saved'));
|
||||
go.walletHome();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
this.getBackup = function() {
|
||||
self.getMetaData = function() {
|
||||
self.getHistoryCache(function(err, txsFromLocal) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
self.getAddressbook(function(err, localAddressBook) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
return cb(null, txsFromLocal, localAddressBook)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
self.getHistoryCache = function(cb) {
|
||||
storageService.getTxHistory(fc.credentials.walletId, function(err, txs) {
|
||||
if (err) return cb(err);
|
||||
|
||||
var localTxs = [];
|
||||
|
||||
try {
|
||||
localTxs = JSON.parse(txs);
|
||||
} catch (ex) {
|
||||
$log.warn(ex);
|
||||
}
|
||||
return cb(null, localTxs);
|
||||
});
|
||||
}
|
||||
|
||||
self.getAddressbook = function(cb) {
|
||||
storageService.getAddressbook(fc.credentials.network, function(err, addressBook) {
|
||||
if (err) return cb(err);
|
||||
|
||||
var localAddressBook = [];
|
||||
try {
|
||||
localAddressBook = JSON.parse(addressBook);
|
||||
} catch (ex) {
|
||||
$log.warn(ex);
|
||||
}
|
||||
return cb(null, localAddressBook);
|
||||
});
|
||||
}
|
||||
|
||||
self.getBackup = function() {
|
||||
self.getMetaData(function(err, txsFromLocal, localAddressBook) {
|
||||
if (err) {
|
||||
self.error = true;
|
||||
return;
|
||||
}
|
||||
var opts = {
|
||||
noSign: $scope.noSign,
|
||||
historyCache: txsFromLocal,
|
||||
addressBook: localAddressBook
|
||||
};
|
||||
|
||||
var ew = backupService.walletExport(this.password, opts);
|
||||
var ew = backupService.walletExport(self.password, opts);
|
||||
if (!ew) {
|
||||
this.error = true;
|
||||
self.error = true;
|
||||
} else {
|
||||
this.error = false;
|
||||
self.error = false;
|
||||
}
|
||||
return ew;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
this.viewWalletBackup = function() {
|
||||
self.viewWalletBackup = function() {
|
||||
var self = this;
|
||||
$timeout(function() {
|
||||
var ew = self.getBackup();
|
||||
|
|
@ -48,15 +110,15 @@ angular.module('copayApp.controllers').controller('backupController',
|
|||
}, 100);
|
||||
};
|
||||
|
||||
this.copyWalletBackup = function() {
|
||||
var ew = this.getBackup();
|
||||
self.copyWalletBackup = function() {
|
||||
var ew = self.getBackup();
|
||||
if (!ew) return;
|
||||
window.cordova.plugins.clipboard.copy(ew);
|
||||
window.plugins.toast.showShortCenter(gettextCatalog.getString('Copied to clipboard'));
|
||||
$rootScope.$emit('Local/BackupDone');
|
||||
};
|
||||
|
||||
this.sendWalletBackup = function() {
|
||||
self.sendWalletBackup = function() {
|
||||
var fc = profileService.focusedClient;
|
||||
if (isMobile.Android() || isMobile.Windows()) {
|
||||
window.ignoreMobilePause = true;
|
||||
|
|
@ -66,7 +128,7 @@ angular.module('copayApp.controllers').controller('backupController',
|
|||
if (fc.alias) {
|
||||
name = fc.alias + ' [' + name + ']';
|
||||
}
|
||||
var ew = this.getBackup();
|
||||
var ew = self.getBackup();
|
||||
if (!ew) return;
|
||||
|
||||
if ($scope.noSign)
|
||||
|
|
|
|||
|
|
@ -337,8 +337,20 @@ angular.module('copayApp.services')
|
|||
});
|
||||
};
|
||||
|
||||
root.setMetaData = function(walletClient, cb) {
|
||||
storageService.setAddressbook(walletClient.credentials.network, walletClient.credentials.historyCache, function(err) {
|
||||
if (err) return cb(err);
|
||||
storageService.setTxHistory(walletClient.credentials.historyCache, walletClient.credentials.walletId, function(err) {
|
||||
if (err) return cb(err);
|
||||
return cb(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
root._addWalletClient = function(walletClient, opts, cb) {
|
||||
var walletId = walletClient.credentials.walletId;
|
||||
root.setMetaData(walletClient, function(err) {
|
||||
if (err) console.log(err);
|
||||
|
||||
// check if exist
|
||||
var w = lodash.find(root.profile.credentials, {
|
||||
|
|
@ -366,6 +378,7 @@ angular.module('copayApp.services')
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
root.importWallet = function(str, opts, cb) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue