2016-08-24 17:54:01 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('activityController',
|
2016-10-21 19:04:18 -04:00
|
|
|
function($timeout, $scope, $log, $ionicModal, lodash, txpModalService, profileService, walletService, ongoingProcess, popupService, gettextCatalog, $state) {
|
2016-09-21 11:38:38 -03:00
|
|
|
$scope.openTxpModal = txpModalService.open;
|
2016-09-22 01:47:39 -03:00
|
|
|
$scope.fetchingNotifications = true;
|
2016-09-21 11:38:38 -03:00
|
|
|
|
2016-10-17 11:15:36 -03:00
|
|
|
$scope.$on("$ionicView.enter", function(event, data) {
|
2016-08-31 17:12:36 -03:00
|
|
|
profileService.getNotifications(50, function(err, n) {
|
|
|
|
|
if (err) {
|
2016-09-22 01:47:39 -03:00
|
|
|
$log.error(err);
|
2016-08-31 17:12:36 -03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$scope.fetchingNotifications = false;
|
2016-08-31 18:12:28 -03:00
|
|
|
$scope.notifications = n;
|
2016-09-21 11:38:38 -03:00
|
|
|
|
|
|
|
|
profileService.getTxps({}, function(err, txps, n) {
|
|
|
|
|
if (err) $log.error(err);
|
|
|
|
|
$scope.txps = txps;
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.$apply();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-08-31 18:12:28 -03:00
|
|
|
});
|
2016-09-22 01:47:39 -03:00
|
|
|
});
|
2016-09-21 11:38:38 -03:00
|
|
|
|
|
|
|
|
$scope.openNotificationModal = function(n) {
|
2016-09-21 12:26:44 -03:00
|
|
|
if (n.txid) {
|
2016-09-21 11:38:38 -03:00
|
|
|
openTxModal(n);
|
|
|
|
|
} else {
|
|
|
|
|
var txp = lodash.find($scope.txps, {
|
|
|
|
|
id: n.txpId
|
|
|
|
|
});
|
|
|
|
|
if (txp) txpModalService.open(txp);
|
2016-09-21 11:43:40 -03:00
|
|
|
else {
|
2016-09-22 01:47:39 -03:00
|
|
|
ongoingProcess.set('loadingTxInfo', true);
|
|
|
|
|
walletService.getTxp(n.wallet, n.txpId, function(err, txp) {
|
|
|
|
|
var _txp = txp;
|
|
|
|
|
ongoingProcess.set('loadingTxInfo', false);
|
|
|
|
|
if (err) {
|
|
|
|
|
$log.warn('No txp found');
|
|
|
|
|
return popupService.showAlert(null, gettextCatalog.getString('Transaction not found'));
|
|
|
|
|
}
|
|
|
|
|
txpModalService.open(_txp);
|
|
|
|
|
});
|
2016-09-21 11:43:40 -03:00
|
|
|
}
|
2016-09-21 11:38:38 -03:00
|
|
|
}
|
|
|
|
|
};
|
2016-09-20 16:21:05 -03:00
|
|
|
|
2016-09-21 11:38:38 -03:00
|
|
|
var openTxModal = function(n) {
|
2016-09-20 16:21:05 -03:00
|
|
|
var wallet = profileService.getWallet(n.walletId);
|
|
|
|
|
|
|
|
|
|
ongoingProcess.set('loadingTxInfo', true);
|
|
|
|
|
walletService.getTx(wallet, n.txid, function(err, tx) {
|
|
|
|
|
ongoingProcess.set('loadingTxInfo', false);
|
|
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
$log.error(err);
|
|
|
|
|
return popupService.showAlert(gettextCatalog.getString('Error'), err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!tx) {
|
|
|
|
|
$log.warn('No tx found');
|
2016-09-21 12:38:49 -03:00
|
|
|
return popupService.showAlert(null, gettextCatalog.getString('Transaction not found'));
|
2016-09-20 16:21:05 -03:00
|
|
|
}
|
|
|
|
|
|
2016-09-22 01:47:39 -03:00
|
|
|
$scope.wallet = wallet;
|
|
|
|
|
$scope.btx = lodash.cloneDeep(tx);
|
2016-10-22 17:43:05 -03:00
|
|
|
$state.transitionTo('tabs.wallet.tx-details', {
|
|
|
|
|
txid: $scope.btx.txid,
|
|
|
|
|
walletId: $scope.walletId
|
|
|
|
|
});
|
2016-09-21 17:28:59 -03:00
|
|
|
|
2016-09-22 01:47:39 -03:00
|
|
|
walletService.getTxNote(wallet, n.txid, function(err, note) {
|
2016-10-17 11:15:36 -03:00
|
|
|
if (err) $log.warn('Could not fetch transaction note: ' + err);
|
2016-09-21 17:28:59 -03:00
|
|
|
$scope.btx.note = note;
|
2016-09-20 16:21:05 -03:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
2016-08-24 17:54:01 -03:00
|
|
|
});
|