copay/js/controllers/transactions.js

94 lines
2.4 KiB
JavaScript
Raw Normal View History

2014-03-26 05:18:42 -07:00
'use strict';
2014-06-12 13:42:26 -07:00
var bitcore = require('bitcore');
2014-03-26 05:18:42 -07:00
2014-06-03 13:42:36 -07:00
angular.module('copayApp.controllers').controller('TransactionsController',
function($scope, $rootScope, $timeout, controllerUtils, notification, rateService) {
2014-10-10 13:58:19 -07:00
controllerUtils.redirIfNotComplete();
2014-04-23 08:59:21 -07:00
var w = $rootScope.wallet;
2014-03-26 05:18:42 -07:00
$scope.title = 'Transactions';
2014-04-24 18:43:19 -07:00
$scope.loading = false;
$scope.lastShowed = false;
$scope.txpCurrentPage = 1;
$scope.txpItemsPerPage = 4;
$scope.blockchain_txs = [];
$scope.alternativeCurrency = [];
var satToUnit = 1 / w.settings.unitToSatoshi;
$scope.update = function() {
$scope.loading = true;
var from = ($scope.txpCurrentPage - 1) * $scope.txpItemsPerPage;
var opts = {
pending: false,
skip: [from, from + $scope.txpItemsPerPage]
};
controllerUtils.updateTxs(opts);
setTimeout(function() {
$rootScope.$digest();
}, 0);
};
$scope.show = function() {
$scope.loading = true;
setTimeout(function() {
$scope.update();
}, 10);
};
$scope.toogleLast = function() {
$scope.lastShowed = !$scope.lastShowed;
if ($scope.lastShowed) {
$scope.getTransactions();
}
};
$scope.getTransactions = function() {
2014-10-22 09:10:41 -07:00
var self = this;
var w = $rootScope.wallet;
2014-10-22 09:10:41 -07:00
if (!w) return;
2014-10-22 12:57:29 -07:00
$scope.blockchain_txs = w.cached_txs || [];
$scope.loading = true;
2014-10-22 09:10:41 -07:00
w.getTransactionHistory(function(err, res) {
if (err) throw err;
if (!res) {
$scope.loading = false;
$scope.lastShowed = false;
return;
2014-04-24 19:13:55 -07:00
}
2014-10-22 09:10:41 -07:00
2014-10-22 12:57:29 -07:00
$scope.blockchain_txs = w.cached_txs = res;
2014-10-22 09:10:41 -07:00
$scope.loading = false;
});
};
2014-10-22 09:10:41 -07:00
$scope.hasAction = function(actions, action) {
return actions.hasOwnProperty('create');
}
$scope.getShortNetworkName = function() {
2014-09-11 11:25:32 -07:00
return w.getNetworkName().substring(0, 4);
};
2014-06-24 11:46:07 -07:00
// Autoload transactions on 1-of-1
if ($rootScope.wallet && $rootScope.wallet.totalCopayers == 1) {
$scope.lastShowed = true;
$scope.getTransactions();
}
2014-10-22 09:10:41 -07:00
$scope.amountAlternative = function(amount, txIndex, cb) {
var w = $rootScope.wallet;
rateService.whenAvailable(function() {
var valueSat = amount * w.settings.unitToSatoshi;
$scope.alternativeCurrency[txIndex] = rateService.toFiat(valueSat, w.settings.alternativeIsoCode);
2014-09-25 12:50:15 -07:00
return cb ? cb() : null;
});
};
2014-03-26 05:18:42 -07:00
});