adds errorCb, handles blocks

This commit is contained in:
Matias Alejo Garcia 2015-08-12 08:57:44 -03:00
commit fe07348a5a
3 changed files with 37 additions and 2 deletions

View file

@ -63,6 +63,9 @@ angular.module('copayApp.controllers').controller('createController',
if (err) { if (err) {
$log.debug(err); $log.debug(err);
self.error = err; self.error = err;
$timeout(function() {
$rootScope.$apply();
});
} }
else { else {
go.walletHome(); go.walletHome();

View file

@ -960,6 +960,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
trailing: true trailing: true
}); });
self.debouncedUpdateHistory = lodash.throttle(function() {
self.updateTxHistory();
}, 60000);
$rootScope.$on('Local/Resume', function(event) { $rootScope.$on('Local/Resume', function(event) {
$log.debug('### Resume event'); $log.debug('### Resume event');
@ -1023,6 +1026,20 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
}); });
$rootScope.$on('NewBlock', function() {
if (self.pendingAmount) {
self.updateAll();
}
if (self.network =='testnet') {
self.debouncedUpdateHistory();
} else {
self.updateTxHistory();
}
});
$rootScope.$on('NewOutgoingTx', function() { $rootScope.$on('NewOutgoingTx', function() {
self.updateAll({ self.updateAll({
walletStatus: null, walletStatus: null,

View file

@ -12,6 +12,21 @@ angular.module('copayApp.services')
return bwcService.getUtils(); return bwcService.getUtils();
}; };
root.errorCb = function(err, prefix, cb) {
var body = '';
prefix = gettext(prefix);
if (!err || !err.code) return cb(prefix);
switch(err.code) {
case 'CONNECTION_ERROR':
body = gettext('Network connection error');
;;
}
return cb(prefix + ( body ? ': ' + body : ''));
};
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;
@ -176,7 +191,7 @@ angular.module('copayApp.services')
walletClient.createWallet('Personal Wallet', 'me', 1, 1, { walletClient.createWallet('Personal Wallet', 'me', 1, 1, {
network: 'livenet' network: 'livenet'
}, function(err) { }, function(err) {
if (err) return cb(gettext('Error creating wallet. Check your internet connection')); if (err) return root.errorCb(err, 'Error creating wallet', cb);
var p = Profile.create({ var p = Profile.create({
credentials: [JSON.parse(walletClient.export())], credentials: [JSON.parse(walletClient.export())],
}); });
@ -198,7 +213,7 @@ angular.module('copayApp.services')
walletClient.createWallet(opts.name, opts.myName || 'me', opts.m, opts.n, { walletClient.createWallet(opts.name, opts.myName || 'me', opts.m, opts.n, {
network: opts.networkName network: opts.networkName
}, function(err, secret) { }, function(err, secret) {
if (err) return cb(gettext('Error creating wallet')); if (err) return root.errorCb(err, 'Error creating wallet', cb);
root.profile.credentials.push(JSON.parse(walletClient.export())); root.profile.credentials.push(JSON.parse(walletClient.export()));
root.setWalletClients(); root.setWalletClients();