2016-08-15 10:25:43 -03:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
2016-09-27 16:01:15 -03:00
|
|
|
|
angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $state, $stateParams, profileService, lodash, configService, gettextCatalog, platformInfo, walletService, txpModalService, externalLinkService, popupService) {
|
2016-09-08 12:13:37 -03:00
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
var HISTORY_SHOW_LIMIT = 10;
|
2016-09-29 19:04:52 -03:00
|
|
|
|
var currentTxHistoryPage = 0;
|
|
|
|
|
|
var listeners = [];
|
2016-08-23 17:31:50 -03:00
|
|
|
|
$scope.txps = [];
|
2016-09-29 19:04:52 -03:00
|
|
|
|
$scope.completeTxHistory = [];
|
|
|
|
|
|
$scope.openTxpModal = txpModalService.open;
|
2016-10-10 15:19:33 -03:00
|
|
|
|
$scope.isCordova = platformInfo.isCordova;
|
2016-08-23 17:31:50 -03:00
|
|
|
|
|
2016-09-05 14:59:11 -03:00
|
|
|
|
$scope.openExternalLink = function(url, target) {
|
|
|
|
|
|
externalLinkService.open(url, target);
|
|
|
|
|
|
};
|
2016-08-23 17:31:50 -03:00
|
|
|
|
|
|
|
|
|
|
var setPendingTxps = function(txps) {
|
2016-09-20 10:02:28 -03:00
|
|
|
|
|
|
|
|
|
|
/* Uncomment to test multiple outputs */
|
|
|
|
|
|
|
|
|
|
|
|
// var txp = {
|
|
|
|
|
|
// message: 'test multi-output',
|
|
|
|
|
|
// fee: 1000,
|
|
|
|
|
|
// createdOn: new Date() / 1000,
|
|
|
|
|
|
// outputs: [],
|
2016-09-29 19:04:52 -03:00
|
|
|
|
// wallet: $scope.wallet
|
2016-09-20 10:02:28 -03:00
|
|
|
|
// };
|
|
|
|
|
|
//
|
|
|
|
|
|
// function addOutput(n) {
|
|
|
|
|
|
// txp.outputs.push({
|
|
|
|
|
|
// amount: 600,
|
|
|
|
|
|
// toAddress: '2N8bhEwbKtMvR2jqMRcTCQqzHP6zXGToXcK',
|
|
|
|
|
|
// message: 'output #' + (Number(n) + 1)
|
|
|
|
|
|
// });
|
|
|
|
|
|
// };
|
|
|
|
|
|
// lodash.times(15, addOutput);
|
|
|
|
|
|
// txps.push(txp);
|
|
|
|
|
|
|
2016-08-23 17:31:50 -03:00
|
|
|
|
if (!txps) {
|
|
|
|
|
|
$scope.txps = [];
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
$scope.txps = lodash.sortBy(txps, 'createdOn').reverse();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-09-29 19:04:52 -03:00
|
|
|
|
var updateStatus = function(force) {
|
2016-08-23 17:31:50 -03:00
|
|
|
|
$scope.updatingStatus = true;
|
|
|
|
|
|
$scope.updateStatusError = false;
|
2016-09-08 12:13:37 -03:00
|
|
|
|
$scope.walletNotRegistered = false;
|
2016-08-23 17:31:50 -03:00
|
|
|
|
|
2016-09-29 19:04:52 -03:00
|
|
|
|
walletService.getStatus($scope.wallet, {
|
2016-08-23 17:31:50 -03:00
|
|
|
|
force: !!force,
|
|
|
|
|
|
}, function(err, status) {
|
|
|
|
|
|
$scope.updatingStatus = false;
|
|
|
|
|
|
if (err) {
|
2016-09-08 12:13:37 -03:00
|
|
|
|
if (err === 'WALLET_NOT_REGISTERED') {
|
|
|
|
|
|
$scope.walletNotRegistered = true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$scope.updateStatusError = true;
|
|
|
|
|
|
}
|
2016-08-23 17:31:50 -03:00
|
|
|
|
$scope.status = null;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setPendingTxps(status.pendingTxps);
|
|
|
|
|
|
|
|
|
|
|
|
$scope.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-24 17:54:01 -03:00
|
|
|
|
|
2016-08-23 17:31:50 -03:00
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-08-15 10:25:43 -03:00
|
|
|
|
$scope.openSearchModal = function() {
|
2016-09-29 19:04:52 -03:00
|
|
|
|
$scope.color = $scope.wallet.color;
|
2016-08-15 10:25:43 -03:00
|
|
|
|
|
|
|
|
|
|
$ionicModal.fromTemplateUrl('views/modals/search.html', {
|
|
|
|
|
|
scope: $scope,
|
|
|
|
|
|
focusFirstInput: true
|
|
|
|
|
|
}).then(function(modal) {
|
|
|
|
|
|
$scope.searchModal = modal;
|
|
|
|
|
|
$scope.searchModal.show();
|
|
|
|
|
|
});
|
2016-09-02 14:29:34 -03:00
|
|
|
|
|
|
|
|
|
|
$scope.close = function() {
|
|
|
|
|
|
$scope.searchModal.hide();
|
|
|
|
|
|
}
|
2016-08-15 10:25:43 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-08-18 17:56:04 -03:00
|
|
|
|
$scope.openTxModal = function(btx) {
|
2016-08-15 10:25:43 -03:00
|
|
|
|
$scope.btx = lodash.cloneDeep(btx);
|
2016-09-29 19:04:52 -03:00
|
|
|
|
$scope.walletId = $scope.wallet.id;
|
2016-08-15 10:25:43 -03:00
|
|
|
|
$ionicModal.fromTemplateUrl('views/modals/tx-details.html', {
|
2016-09-20 16:21:05 -03:00
|
|
|
|
scope: $scope
|
2016-08-15 10:25:43 -03:00
|
|
|
|
}).then(function(modal) {
|
|
|
|
|
|
$scope.txDetailsModal = modal;
|
|
|
|
|
|
$scope.txDetailsModal.show();
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-08-18 10:37:08 -03:00
|
|
|
|
$scope.recreate = function() {
|
2016-09-29 19:04:52 -03:00
|
|
|
|
walletService.recreate($scope.wallet, function(err) {
|
2016-09-08 12:13:37 -03:00
|
|
|
|
if (err) return;
|
|
|
|
|
|
$timeout(function() {
|
2016-09-29 19:04:52 -03:00
|
|
|
|
walletService.startScan($scope.wallet, function() {
|
2016-09-08 12:13:37 -03:00
|
|
|
|
$scope.$apply();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2016-08-18 10:37:08 -03:00
|
|
|
|
};
|
2016-08-17 18:48:30 -03:00
|
|
|
|
|
2016-09-29 19:04:52 -03:00
|
|
|
|
var updateTxHistory = function(cb) {
|
2016-09-07 15:35:14 -03:00
|
|
|
|
if (!cb) cb = function() {};
|
2016-08-18 10:37:08 -03:00
|
|
|
|
if ($scope.updatingTxHistory) return;
|
|
|
|
|
|
|
|
|
|
|
|
$scope.updatingTxHistory = true;
|
|
|
|
|
|
$scope.updateTxHistoryError = false;
|
2016-09-29 19:04:52 -03:00
|
|
|
|
$scope.updatingTxHistoryProgress = 0;
|
2016-08-18 10:37:08 -03:00
|
|
|
|
|
2016-09-30 15:58:56 -03:00
|
|
|
|
var progressFn = function(txs, newTxs) {
|
|
|
|
|
|
$scope.updatingTxHistoryProgress = newTxs;
|
2016-08-22 18:20:01 -03:00
|
|
|
|
$scope.completeTxHistory = txs;
|
2016-08-18 10:37:08 -03:00
|
|
|
|
$scope.showHistory();
|
2016-09-30 15:58:56 -03:00
|
|
|
|
$timeout(function() {
|
|
|
|
|
|
$scope.$apply();
|
|
|
|
|
|
});
|
2016-08-18 10:37:08 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$timeout(function() {
|
2016-09-29 19:04:52 -03:00
|
|
|
|
walletService.getTxHistory($scope.wallet, {
|
2016-08-18 10:37:08 -03:00
|
|
|
|
progressFn: progressFn,
|
|
|
|
|
|
}, function(err, txHistory) {
|
|
|
|
|
|
$scope.updatingTxHistory = false;
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
$scope.txHistory = null;
|
|
|
|
|
|
$scope.updateTxHistoryError = true;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2016-08-22 18:20:01 -03:00
|
|
|
|
$scope.completeTxHistory = txHistory;
|
2016-08-18 10:37:08 -03:00
|
|
|
|
$scope.showHistory();
|
2016-09-30 12:27:31 -03:00
|
|
|
|
$scope.$apply();
|
2016-08-24 17:54:01 -03:00
|
|
|
|
return cb();
|
2016-08-18 10:37:08 -03:00
|
|
|
|
});
|
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() {
|
2016-08-22 18:20:01 -03:00
|
|
|
|
if ($scope.completeTxHistory) {
|
|
|
|
|
|
$scope.txHistory = $scope.completeTxHistory.slice(0, (currentTxHistoryPage + 1) * HISTORY_SHOW_LIMIT);
|
|
|
|
|
|
$scope.txHistoryShowMore = $scope.completeTxHistory.length > $scope.txHistory.length;
|
2016-08-18 10:37:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$scope.showMore = function() {
|
2016-10-03 11:52:48 -03:00
|
|
|
|
$timeout(function() {
|
|
|
|
|
|
currentTxHistoryPage++;
|
|
|
|
|
|
$scope.showHistory();
|
|
|
|
|
|
$scope.$broadcast('scroll.infiniteScrollComplete');
|
|
|
|
|
|
}, 100);
|
2016-08-18 10:37:08 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-10-10 15:19:33 -03:00
|
|
|
|
$scope.onRefresh = function() {
|
|
|
|
|
|
$scope.$broadcast('scroll.refreshComplete');
|
|
|
|
|
|
$scope.updateAll(true);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-09-29 19:04:52 -03:00
|
|
|
|
$scope.updateAll = function(force, cb) {
|
|
|
|
|
|
updateStatus(force);
|
|
|
|
|
|
updateTxHistory(cb);
|
2016-09-22 10:34:00 -03:00
|
|
|
|
};
|
2016-08-18 10:37:08 -03:00
|
|
|
|
|
2016-08-15 10:25:43 -03:00
|
|
|
|
$scope.hideToggle = function() {
|
2016-09-29 19:04:52 -03:00
|
|
|
|
profileService.toggleHideBalanceFlag($scope.wallet.credentials.walletId, function(err) {
|
2016-08-31 12:03:44 -03:00
|
|
|
|
if (err) $log.error(err);
|
|
|
|
|
|
});
|
2016-09-22 10:34:00 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-09-30 11:16:33 -03:00
|
|
|
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
2016-09-22 10:34:00 -03:00
|
|
|
|
|
2016-09-29 19:04:52 -03:00
|
|
|
|
$scope.wallet = profileService.getWallet(data.stateParams.walletId);
|
|
|
|
|
|
$scope.requiresMultipleSignatures = $scope.wallet.credentials.m > 1;
|
|
|
|
|
|
|
|
|
|
|
|
$scope.updateAll();
|
|
|
|
|
|
|
|
|
|
|
|
listeners = [
|
|
|
|
|
|
$rootScope.$on('bwsEvent', function(e, walletId) {
|
|
|
|
|
|
if (walletId == $scope.wallet.id)
|
|
|
|
|
|
updateStatus();
|
|
|
|
|
|
}),
|
|
|
|
|
|
$rootScope.$on('Local/TxAction', function(e, walletId) {
|
|
|
|
|
|
if (walletId == $scope.wallet.id)
|
|
|
|
|
|
updateStatus();
|
|
|
|
|
|
}),
|
|
|
|
|
|
];
|
|
|
|
|
|
});
|
2016-09-22 10:34:00 -03:00
|
|
|
|
|
2016-09-29 19:04:52 -03:00
|
|
|
|
$scope.$on("$ionicView.leave", function(event, data) {
|
|
|
|
|
|
lodash.each(listeners, function(x) {
|
|
|
|
|
|
x();
|
2016-09-22 10:34:00 -03:00
|
|
|
|
});
|
|
|
|
|
|
});
|
2016-08-15 10:25:43 -03:00
|
|
|
|
});
|