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';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('backupController',
|
angular.module('copayApp.controllers').controller('backupController',
|
||||||
function($rootScope, $scope, $timeout, backupService, profileService, isMobile, notification, go, gettext, gettextCatalog) {
|
function($rootScope, $scope, $timeout, $log, backupService, storageService, profileService, isMobile, notification, go, gettext, gettextCatalog) {
|
||||||
this.error = null;
|
var self = this;
|
||||||
this.success = null;
|
|
||||||
|
self.error = null;
|
||||||
|
self.success = null;
|
||||||
|
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
this.isEncrypted = fc.isPrivKeyEncrypted();
|
self.isEncrypted = fc.isPrivKeyEncrypted();
|
||||||
|
|
||||||
this.downloadWalletBackup = function() {
|
self.downloadWalletBackup = function() {
|
||||||
var self = this;
|
self.getMetaData(function(err, txsFromLocal, localAddressBook) {
|
||||||
var opts = {
|
|
||||||
noSign: $scope.noSign,
|
|
||||||
};
|
|
||||||
backupService.walletDownload(this.password, opts, function(err) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
self.error = true;
|
self.error = true;
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
$rootScope.$emit('Local/BackupDone');
|
var opts = {
|
||||||
notification.success(gettext('Success'), gettext('Encrypted export file saved'));
|
noSign: $scope.noSign,
|
||||||
go.walletHome();
|
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() {
|
||||||
var opts = {
|
self.getHistoryCache(function(err, txsFromLocal) {
|
||||||
noSign: $scope.noSign,
|
if (err) {
|
||||||
};
|
return cb(err);
|
||||||
|
}
|
||||||
|
self.getAddressbook(function(err, localAddressBook) {
|
||||||
|
if (err) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
return cb(null, txsFromLocal, localAddressBook)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var ew = backupService.walletExport(this.password, opts);
|
self.getHistoryCache = function(cb) {
|
||||||
if (!ew) {
|
storageService.getTxHistory(fc.credentials.walletId, function(err, txs) {
|
||||||
this.error = true;
|
if (err) return cb(err);
|
||||||
} else {
|
|
||||||
this.error = false;
|
|
||||||
}
|
|
||||||
return ew;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.viewWalletBackup = function() {
|
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(self.password, opts);
|
||||||
|
if (!ew) {
|
||||||
|
self.error = true;
|
||||||
|
} else {
|
||||||
|
self.error = false;
|
||||||
|
}
|
||||||
|
return ew;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
self.viewWalletBackup = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
var ew = self.getBackup();
|
var ew = self.getBackup();
|
||||||
|
|
@ -48,15 +110,15 @@ angular.module('copayApp.controllers').controller('backupController',
|
||||||
}, 100);
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.copyWalletBackup = function() {
|
self.copyWalletBackup = function() {
|
||||||
var ew = this.getBackup();
|
var ew = self.getBackup();
|
||||||
if (!ew) return;
|
if (!ew) return;
|
||||||
window.cordova.plugins.clipboard.copy(ew);
|
window.cordova.plugins.clipboard.copy(ew);
|
||||||
window.plugins.toast.showShortCenter(gettextCatalog.getString('Copied to clipboard'));
|
window.plugins.toast.showShortCenter(gettextCatalog.getString('Copied to clipboard'));
|
||||||
$rootScope.$emit('Local/BackupDone');
|
$rootScope.$emit('Local/BackupDone');
|
||||||
};
|
};
|
||||||
|
|
||||||
this.sendWalletBackup = function() {
|
self.sendWalletBackup = function() {
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
if (isMobile.Android() || isMobile.Windows()) {
|
if (isMobile.Android() || isMobile.Windows()) {
|
||||||
window.ignoreMobilePause = true;
|
window.ignoreMobilePause = true;
|
||||||
|
|
@ -66,10 +128,10 @@ angular.module('copayApp.controllers').controller('backupController',
|
||||||
if (fc.alias) {
|
if (fc.alias) {
|
||||||
name = fc.alias + ' [' + name + ']';
|
name = fc.alias + ' [' + name + ']';
|
||||||
}
|
}
|
||||||
var ew = this.getBackup();
|
var ew = self.getBackup();
|
||||||
if (!ew) return;
|
if (!ew) return;
|
||||||
|
|
||||||
if( $scope.noSign)
|
if ($scope.noSign)
|
||||||
name = name + '(No Private Key)';
|
name = name + '(No Private Key)';
|
||||||
|
|
||||||
var properties = {
|
var properties = {
|
||||||
|
|
@ -81,4 +143,4 @@ angular.module('copayApp.controllers').controller('backupController',
|
||||||
window.plugin.email.open(properties);
|
window.plugin.email.open(properties);
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -11,7 +11,7 @@ angular.module('copayApp.services')
|
||||||
root.focusedClient = null;
|
root.focusedClient = null;
|
||||||
root.walletClients = {};
|
root.walletClients = {};
|
||||||
|
|
||||||
root.Utils = bwcService.getUtils();
|
root.Utils = bwcService.getUtils();
|
||||||
root.formatAmount = function(amount) {
|
root.formatAmount = function(amount) {
|
||||||
var config = configService.getSync().wallet.settings;
|
var config = configService.getSync().wallet.settings;
|
||||||
if (config.unitCode == 'sat') return amount;
|
if (config.unitCode == 'sat') return amount;
|
||||||
|
|
@ -276,8 +276,8 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
// check if exist
|
// check if exist
|
||||||
if (lodash.find(root.profile.credentials, {
|
if (lodash.find(root.profile.credentials, {
|
||||||
'walletId': walletData.walletId
|
'walletId': walletData.walletId
|
||||||
})) {
|
})) {
|
||||||
return cb(gettext('Cannot join the same wallet more that once'));
|
return cb(gettext('Cannot join the same wallet more that once'));
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
|
|
@ -337,32 +337,45 @@ 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) {
|
root._addWalletClient = function(walletClient, opts, cb) {
|
||||||
var walletId = walletClient.credentials.walletId;
|
var walletId = walletClient.credentials.walletId;
|
||||||
|
root.setMetaData(walletClient, function(err) {
|
||||||
// check if exist
|
|
||||||
var w = lodash.find(root.profile.credentials, {
|
|
||||||
'walletId': walletId
|
|
||||||
});
|
|
||||||
if (w) {
|
|
||||||
return cb(gettext('Wallet already in Copay' + ": ") + w.walletName);
|
|
||||||
}
|
|
||||||
|
|
||||||
var defaults = configService.getDefaults();
|
|
||||||
var bwsFor = {};
|
|
||||||
bwsFor[walletId] = opts.bwsurl || defaults.bws.url;
|
|
||||||
|
|
||||||
configService.set({
|
|
||||||
bwsFor: bwsFor,
|
|
||||||
}, function(err) {
|
|
||||||
if (err) console.log(err);
|
if (err) console.log(err);
|
||||||
|
|
||||||
root.profile.credentials.push(JSON.parse(walletClient.export()));
|
// check if exist
|
||||||
root.setWalletClients();
|
var w = lodash.find(root.profile.credentials, {
|
||||||
|
'walletId': walletId
|
||||||
|
});
|
||||||
|
if (w) {
|
||||||
|
return cb(gettext('Wallet already in Copay' + ": ") + w.walletName);
|
||||||
|
}
|
||||||
|
|
||||||
root.setAndStoreFocus(walletId, function() {
|
var defaults = configService.getDefaults();
|
||||||
storageService.storeProfile(root.profile, function(err) {
|
var bwsFor = {};
|
||||||
return cb(err, walletId);
|
bwsFor[walletId] = opts.bwsurl || defaults.bws.url;
|
||||||
|
|
||||||
|
configService.set({
|
||||||
|
bwsFor: bwsFor,
|
||||||
|
}, function(err) {
|
||||||
|
if (err) console.log(err);
|
||||||
|
|
||||||
|
root.profile.credentials.push(JSON.parse(walletClient.export()));
|
||||||
|
root.setWalletClients();
|
||||||
|
|
||||||
|
root.setAndStoreFocus(walletId, function() {
|
||||||
|
storageService.storeProfile(root.profile, function(err) {
|
||||||
|
return cb(err, walletId);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue