diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 9ef5ce4a7..ac2a6b471 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('tabHomeController', - function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, appConfigService, bitpayCardService, startupService, addressbookService, feedbackService, bwcError) { + function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, appConfigService, bitpayCardService, startupService, addressbookService, feedbackService, bwcError, coinbaseService) { var wallet; var listeners = []; var notifications = []; @@ -83,6 +83,10 @@ angular.module('copayApp.controllers').controller('tabHomeController', var wallet = profileService.getWallet(walletId); updateWallet(wallet); if ($scope.recentTransactionsEnabled) getNotifications(); + if (type == 'NewBlock' && n && n.data && n.data.network == 'livenet') { + // Update Coinbase + coinbaseService.updatePendingTransactions(); + } }), $rootScope.$on('Local/TxAction', function(e, walletId) { $log.debug('Got action for wallet ' + walletId); diff --git a/src/js/services/coinbaseService.js b/src/js/services/coinbaseService.js index 2c83ccb98..ccb6401b1 100644 --- a/src/js/services/coinbaseService.js +++ b/src/js/services/coinbaseService.js @@ -181,7 +181,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ if (lodash.isEmpty(credentials.CLIENT_ID)) { return cb('Coinbase is Disabled'); } - $log.debug('Init Token...'); + $log.debug('Trying to initialise Coinbase...'); storageService.getCoinbaseToken(credentials.NETWORK, function(err, accessToken) { if (err || !accessToken) return cb(); @@ -478,6 +478,10 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ root.getPendingTransactions = function(coinbasePendingTransactions) { root.init(function(err, data) { + if (err || lodash.isEmpty(data)) { + if (err) $log.error(err); + return; + } var accessToken = data.accessToken; var accountId = data.accountId; storageService.getCoinbaseTxs(credentials.NETWORK, function(err, txs) { @@ -550,6 +554,13 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $ }); }; + root.updatePendingTransactions = lodash.throttle(function() { + $log.debug('Updating pending transactions...'); + root.setCredentials(); + var pendingTransactions = { data: {} }; + root.getPendingTransactions(pendingTransactions); + }, 20000); + var _updateTxs = function(coinbasePendingTransactions) { storageService.getCoinbaseTxs(credentials.NETWORK, function(err, txs) { txs = txs ? JSON.parse(txs) : {};