From fe07348a5a48781b803cfca064f7825502931386 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Aug 2015 08:57:44 -0300 Subject: [PATCH] adds errorCb, handles blocks --- src/js/controllers/create.js | 3 +++ src/js/controllers/index.js | 17 +++++++++++++++++ src/js/services/profileService.js | 19 +++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/js/controllers/create.js b/src/js/controllers/create.js index c696d487b..8ac67f68a 100644 --- a/src/js/controllers/create.js +++ b/src/js/controllers/create.js @@ -63,6 +63,9 @@ angular.module('copayApp.controllers').controller('createController', if (err) { $log.debug(err); self.error = err; + $timeout(function() { + $rootScope.$apply(); + }); } else { go.walletHome(); diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 0963c7a7d..50935294a 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -960,6 +960,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r trailing: true }); + self.debouncedUpdateHistory = lodash.throttle(function() { + self.updateTxHistory(); + }, 60000); $rootScope.$on('Local/Resume', function(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() { self.updateAll({ walletStatus: null, diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index e16408c45..bbb75921c 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -12,6 +12,21 @@ angular.module('copayApp.services') 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) { var config = configService.getSync().wallet.settings; if (config.unitCode == 'sat') return amount; @@ -176,7 +191,7 @@ angular.module('copayApp.services') walletClient.createWallet('Personal Wallet', 'me', 1, 1, { network: 'livenet' }, 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({ credentials: [JSON.parse(walletClient.export())], }); @@ -198,7 +213,7 @@ angular.module('copayApp.services') walletClient.createWallet(opts.name, opts.myName || 'me', opts.m, opts.n, { network: opts.networkName }, 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.setWalletClients();