2016-08-12 10:54:31 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('tabHomeController',
|
2016-08-19 10:14:36 -03:00
|
|
|
function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService, txFormatService, $ionicModal, $log, platformInfo) {
|
2016-08-12 10:54:31 -03:00
|
|
|
|
2016-08-24 17:54:01 -03:00
|
|
|
var setNotifications = function(notifications) {
|
|
|
|
|
var n = walletService.processNotifications(notifications, 5);
|
|
|
|
|
$scope.notifications = n;
|
2016-08-25 16:14:13 -03:00
|
|
|
$scope.notificationsMore = notifications.length > 5 ? notifications.length - 5 : null;
|
2016-08-24 17:54:01 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.$apply();
|
|
|
|
|
}, 1);
|
2016-08-22 17:43:31 -03:00
|
|
|
};
|
2016-08-12 10:54:31 -03:00
|
|
|
|
2016-08-24 19:00:50 -03:00
|
|
|
$scope.updateAllWallets = function() {
|
2016-08-25 16:14:13 -03:00
|
|
|
$scope.wallets = profileService.getWallets();
|
|
|
|
|
if (lodash.isEmpty($scope.wallets)) return;
|
2016-08-24 19:00:50 -03:00
|
|
|
|
2016-08-25 16:14:13 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
var i = $scope.wallets.length;
|
|
|
|
|
var j = 0;
|
2016-08-24 20:17:48 -03:00
|
|
|
var timeSpan = 60 * 60 * 24 * 7;
|
2016-08-24 19:00:50 -03:00
|
|
|
var notifications = [];
|
|
|
|
|
|
|
|
|
|
$scope.fetchingNotifications = true;
|
|
|
|
|
|
|
|
|
|
lodash.each($scope.wallets, function(wallet) {
|
|
|
|
|
|
|
|
|
|
walletService.getStatus(wallet, {}, function(err, status) {
|
|
|
|
|
if (err) {
|
|
|
|
|
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
wallet.status = status;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
walletService.getNotifications(wallet, {
|
|
|
|
|
timeSpan: timeSpan
|
|
|
|
|
}, function(err, n) {
|
2016-08-25 19:05:50 -03:00
|
|
|
console.log('[tab-home.js.39]', wallet.name, n); //TODO
|
2016-08-24 19:00:50 -03:00
|
|
|
if (err) {
|
|
|
|
|
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
notifications.push(n);
|
|
|
|
|
if (++j == i) {
|
|
|
|
|
$scope.fetchingNotifications = false;
|
|
|
|
|
setNotifications(lodash.compact(lodash.flatten(notifications)));
|
|
|
|
|
};
|
|
|
|
|
});
|
2016-08-24 17:54:01 -03:00
|
|
|
|
|
|
|
|
});
|
2016-08-25 16:14:13 -03:00
|
|
|
$scope.$digest();
|
2016-08-24 19:00:50 -03:00
|
|
|
}, 100);
|
|
|
|
|
};
|
2016-08-24 17:54:01 -03:00
|
|
|
|
2016-08-24 19:00:50 -03:00
|
|
|
$scope.updateWallet = function(wallet) {
|
2016-08-23 12:41:41 -03:00
|
|
|
$log.debug('Updating wallet:' + wallet.name)
|
2016-08-22 22:10:46 -03:00
|
|
|
walletService.getStatus(wallet, {}, function(err, status) {
|
|
|
|
|
if (err) {
|
2016-08-24 19:00:50 -03:00
|
|
|
$log.error(err); //TODO
|
2016-08-22 22:10:46 -03:00
|
|
|
return;
|
2016-08-23 12:41:41 -03:00
|
|
|
}
|
2016-08-22 22:10:46 -03:00
|
|
|
wallet.status = status;
|
2016-08-24 17:54:01 -03:00
|
|
|
$timeout(function() {
|
2016-08-23 17:45:23 -03:00
|
|
|
$scope.$apply();
|
|
|
|
|
}, 1);
|
2016-08-22 22:10:46 -03:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-12 10:54:31 -03:00
|
|
|
$scope.bitpayCardEnabled = true; // TODO
|
2016-08-17 13:16:06 -03:00
|
|
|
|
2016-08-23 12:41:41 -03:00
|
|
|
var listeners = [
|
|
|
|
|
$rootScope.$on('bwsEvent', function(e, walletId, type, n) {
|
|
|
|
|
var wallet = profileService.getWallet(walletId);
|
2016-08-24 19:00:50 -03:00
|
|
|
$scope.updateWallet(wallet);
|
2016-08-23 12:41:41 -03:00
|
|
|
}),
|
2016-08-23 13:20:57 -03:00
|
|
|
$rootScope.$on('Local/TxAction', function(e, walletId) {
|
2016-08-23 12:41:41 -03:00
|
|
|
var wallet = profileService.getWallet(walletId);
|
2016-08-24 19:00:50 -03:00
|
|
|
$scope.updateWallet(wallet);
|
2016-08-23 12:41:41 -03:00
|
|
|
}),
|
|
|
|
|
];
|
2016-08-17 13:16:06 -03:00
|
|
|
|
2016-08-23 09:35:32 -03:00
|
|
|
$scope.$on('$destroy', function() {
|
2016-08-24 17:54:01 -03:00
|
|
|
lodash.each(listeners, function(x) {
|
2016-08-23 12:41:41 -03:00
|
|
|
x();
|
|
|
|
|
});
|
2016-08-23 09:35:32 -03:00
|
|
|
});
|
2016-08-22 22:10:46 -03:00
|
|
|
|
2016-08-22 17:43:31 -03:00
|
|
|
configService.whenAvailable(function() {
|
2016-08-19 10:14:36 -03:00
|
|
|
var config = configService.getSync();
|
2016-08-22 17:43:31 -03:00
|
|
|
var isWindowsPhoneApp = platformInfo.isWP && isCordova;
|
2016-08-24 11:33:43 -03:00
|
|
|
$scope.glideraEnabled = config.glidera.enabled && !isWindowsPhoneApp;
|
|
|
|
|
$scope.coinbaseEnabled = config.coinbase.enabled && !isWindowsPhoneApp;
|
2016-08-22 17:43:31 -03:00
|
|
|
});
|
2016-08-19 10:14:36 -03:00
|
|
|
|
2016-08-12 10:54:31 -03:00
|
|
|
});
|