2016-08-15 10:25:43 -03:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $state, $stateParams, bwcError, profileService, lodash, configService, gettext, gettextCatalog, platformInfo, go, walletService) {
|
2016-08-15 10:25:43 -03:00
|
|
|
|
|
|
|
|
|
|
var isCordova = platformInfo.isCordova;
|
|
|
|
|
|
var isWP = platformInfo.isWP;
|
|
|
|
|
|
var isAndroid = platformInfo.isAndroid;
|
|
|
|
|
|
var isChromeApp = platformInfo.isChromeApp;
|
|
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
var errorPopup;
|
|
|
|
|
|
|
|
|
|
|
|
var HISTORY_SHOW_LIMIT = 10;
|
|
|
|
|
|
|
2016-08-15 16:07:30 -03:00
|
|
|
|
|
2016-08-15 10:25:43 -03:00
|
|
|
|
$scope.openSearchModal = function() {
|
|
|
|
|
|
var fc = profileService.focusedClient;
|
|
|
|
|
|
$scope.color = fc.backgroundColor;
|
|
|
|
|
|
$scope.self = self;
|
|
|
|
|
|
|
|
|
|
|
|
$ionicModal.fromTemplateUrl('views/modals/search.html', {
|
|
|
|
|
|
scope: $scope,
|
|
|
|
|
|
focusFirstInput: true
|
|
|
|
|
|
}).then(function(modal) {
|
|
|
|
|
|
$scope.searchModal = modal;
|
|
|
|
|
|
$scope.searchModal.show();
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-08-18 17:56:04 -03:00
|
|
|
|
$scope.openTxModal = function(btx) {
|
2016-08-15 10:25:43 -03:00
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
|
|
$scope.btx = lodash.cloneDeep(btx);
|
|
|
|
|
|
$scope.self = self;
|
|
|
|
|
|
|
|
|
|
|
|
$ionicModal.fromTemplateUrl('views/modals/tx-details.html', {
|
|
|
|
|
|
scope: $scope,
|
|
|
|
|
|
hideDelay: 500
|
|
|
|
|
|
}).then(function(modal) {
|
|
|
|
|
|
$scope.txDetailsModal = modal;
|
|
|
|
|
|
$scope.txDetailsModal.show();
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
$scope.recreate = function() {
|
|
|
|
|
|
walletService.recreate();
|
|
|
|
|
|
};
|
2016-08-17 18:48:30 -03:00
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
$scope.updateStatus = function(force) {
|
|
|
|
|
|
$scope.updatingStatus = true;
|
|
|
|
|
|
$scope.updateStatusError = false;
|
2016-08-17 18:48:30 -03:00
|
|
|
|
$timeout(function() {
|
|
|
|
|
|
walletService.getStatus(wallet, {
|
2016-08-18 10:37:08 -03:00
|
|
|
|
force: !!force,
|
2016-08-17 18:48:30 -03:00
|
|
|
|
}, function(err, status) {
|
2016-08-18 10:37:08 -03:00
|
|
|
|
$scope.updatingStatus = false;
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
$scope.status = null;
|
|
|
|
|
|
$scope.updateStatusError = true;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2016-08-17 18:48:30 -03:00
|
|
|
|
$scope.status = status;
|
|
|
|
|
|
});
|
|
|
|
|
|
})
|
2016-08-15 10:25:43 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
$scope.updateTxHistory = function() {
|
|
|
|
|
|
|
|
|
|
|
|
if ($scope.updatingTxHistory) return;
|
|
|
|
|
|
|
|
|
|
|
|
$scope.updatingTxHistory = true;
|
|
|
|
|
|
$scope.updateTxHistoryError = false;
|
|
|
|
|
|
$scope.updatingTxHistoryProgress = null;
|
|
|
|
|
|
|
|
|
|
|
|
var progressFn = function(txs) {
|
|
|
|
|
|
$scope.updatingTxHistoryProgress = txs ? txs.length : 0;
|
|
|
|
|
|
completeTxHistory = txs;
|
|
|
|
|
|
$scope.showHistory();
|
|
|
|
|
|
$scope.$digest();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
|
walletService.getTxHistory(wallet, {
|
|
|
|
|
|
progressFn: progressFn,
|
|
|
|
|
|
}, function(err, txHistory) {
|
|
|
|
|
|
$scope.updatingTxHistory = false;
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
$scope.txHistory = null;
|
|
|
|
|
|
$scope.updateTxHistoryError = true;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
completeTxHistory = txHistory;
|
|
|
|
|
|
|
|
|
|
|
|
$scope.showHistory();
|
|
|
|
|
|
$scope.$apply();
|
|
|
|
|
|
});
|
2016-08-15 16:07:30 -03:00
|
|
|
|
});
|
2016-08-15 10:25:43 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
$scope.showHistory = function() {
|
|
|
|
|
|
if ($scope.isSearching) {
|
|
|
|
|
|
$scope.txHistorySearchResults = filteredTxHistory ? filteredTxHistory.slice(0, (currentTxHistoryPage + 1) * HISTORY_SHOW_LIMIT) : [];
|
|
|
|
|
|
$scope.txHistoryShowMore = filteredTxHistory.length > $scope.txHistorySearchResults.length;
|
2016-08-18 18:15:58 -03:00
|
|
|
|
} else if (completeTxHistory) {
|
|
|
|
|
|
$scope.txHistory = completeTxHistory.slice(0, (currentTxHistoryPage + 1) * HISTORY_SHOW_LIMIT);
|
2016-08-18 10:37:08 -03:00
|
|
|
|
$scope.txHistoryShowMore = completeTxHistory.length > $scope.txHistory.length;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$scope.showMore = function() {
|
|
|
|
|
|
currentTxHistoryPage++;
|
|
|
|
|
|
$scope.showHistory();
|
|
|
|
|
|
$scope.$broadcast('scroll.infiniteScrollComplete');
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$scope.updateAll = function() {
|
|
|
|
|
|
$scope.updateStatus(false);
|
|
|
|
|
|
$scope.updateTxHistory();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-15 10:25:43 -03:00
|
|
|
|
$scope.hideToggle = function() {
|
2016-08-15 16:07:30 -03:00
|
|
|
|
console.log('[walletDetails.js.70:hideToogle:] TODO'); //TODO
|
2016-08-15 10:25:43 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
var currentTxHistoryPage;
|
|
|
|
|
|
var completeTxHistory;
|
|
|
|
|
|
var wallet;
|
2016-08-15 16:07:30 -03:00
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
$scope.init = function() {
|
|
|
|
|
|
currentTxHistoryPage = 0;
|
|
|
|
|
|
completeTxHistory = [];
|
2016-08-15 16:07:30 -03:00
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
wallet = profileService.getWallet($stateParams.walletId);
|
|
|
|
|
|
$scope.wallet = wallet;
|
|
|
|
|
|
$scope.requiresMultipleSignatures = wallet.credentials.m > 1;
|
|
|
|
|
|
$scope.newTx = false;
|
|
|
|
|
|
|
|
|
|
|
|
$scope.updateAll();
|
|
|
|
|
|
};
|
2016-08-15 16:07:30 -03:00
|
|
|
|
|
2016-08-15 10:25:43 -03:00
|
|
|
|
});
|