Wallet/src/js/controllers/tab-home.js

69 lines
2 KiB
JavaScript
Raw Normal View History

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
var self = this;
2016-08-22 17:43:31 -03:00
self.setWallets = function() {
$scope.wallets = profileService.getWallets();
};
2016-08-12 10:54:31 -03:00
2016-08-22 22:10:46 -03:00
self.updateAllWallets = function() {
$scope.wallets = profileService.getWallets();
2016-08-18 10:37:08 -03:00
var i = $scope.wallets.length;
lodash.each($scope.wallets, function(wallet) {
2016-08-17 18:48:30 -03:00
walletService.getStatus(wallet, {}, function(err, status) {
2016-08-18 10:08:23 -03:00
if (err) {
2016-08-17 18:48:30 -03:00
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
return;
2016-08-23 16:53:26 -03:00
}
2016-08-18 10:37:08 -03:00
wallet.status = status;
2016-08-12 10:54:31 -03:00
});
});
}
2016-08-22 22:10:46 -03:00
self.updateWallet = function(wallet) {
2016-08-23 10:18:43 -03:00
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) {
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
return;
2016-08-23 12:41:41 -03:00
}
2016-08-22 22:10:46 -03:00
wallet.status = status;
2016-08-23 10:26:47 -03:00
$scope.$apply();
2016-08-22 22:10:46 -03:00
});
};
self.updateAllWallets();
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);
self.updateWallet(wallet);
}),
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);
self.updateWallet(wallet);
}),
];
2016-08-17 13:16:06 -03:00
2016-08-23 09:35:32 -03:00
$scope.$on('$destroy', function() {
2016-08-23 12:41:41 -03:00
lodash.each(listeners, function(x){
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();
var glideraEnabled = config.glidera.enabled;
var coinbaseEnabled = config.coinbase.enabled;
2016-08-22 17:43:31 -03:00
var isWindowsPhoneApp = platformInfo.isWP && isCordova;
2016-08-19 10:14:36 -03:00
$scope.buyAndSellEnabled = !isWindowsPhoneApp && (glideraEnabled || coinbaseEnabled);
2016-08-22 17:43:31 -03:00
});
2016-08-19 10:14:36 -03:00
2016-08-12 10:54:31 -03:00
});