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

139 lines
3.8 KiB
JavaScript
Raw Normal View History

2016-08-12 10:54:31 -03:00
'use strict';
angular.module('copayApp.controllers').controller('tabHomeController',
2016-08-18 10:08:23 -03:00
function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService, txFormatService, $ionicModal, $log) {
2016-08-12 10:54:31 -03:00
var self = this;
// wallet list change
$rootScope.$on('Local/WalletListUpdated', function(event) {
self.walletSelection = false;
self.setWallets();
});
$rootScope.$on('Local/ColorUpdated', function(event) {
self.setWallets();
});
$rootScope.$on('Local/AliasUpdated', function(event) {
self.setWallets();
});
2016-08-17 15:23:17 -03:00
self.setWallets = function() {
2016-08-15 10:25:43 -03:00
$scope.wallets = profileService.getWallets();
2016-08-12 10:54:31 -03:00
};
2016-08-18 10:08:23 -03:00
var setPendingTxps = function(txps) {
$scope.pendingTxProposalsCountForUs = 0;
var now = Math.floor(Date.now() / 1000);
/* To test multiple outputs...
var txp = {
message: 'test multi-output',
fee: 1000,
createdOn: new Date() / 1000,
outputs: []
};
function addOutput(n) {
txp.outputs.push({
amount: 600,
toAddress: '2N8bhEwbKtMvR2jqMRcTCQqzHP6zXGToXcK',
message: 'output #' + (Number(n) + 1)
});
};
lodash.times(150, addOutput);
txps.push(txp);
*/
lodash.each(txps, function(tx) {
tx = txFormatService.processTx(tx);
// no future transactions...
if (tx.createdOn > now)
tx.createdOn = now;
tx.wallet = profileService.getWallet(tx.walletId);
if (!tx.wallet) {
$log.error("no wallet at txp?");
return;
}
var action = lodash.find(tx.actions, {
copayerId: tx.wallet.copayerId
});
if (!action && tx.status == 'pending') {
tx.pendingForUs = true;
}
if (action && action.type == 'accept') {
tx.statusForUs = 'accepted';
} else if (action && action.type == 'reject') {
tx.statusForUs = 'rejected';
} else {
tx.statusForUs = 'pending';
}
if (!tx.deleteLockTime)
tx.canBeRemoved = true;
if (tx.creatorId != tx.wallet.copayerId) {
$scope.pendingTxProposalsCountForUs = $scope.pendingTxProposalsCountForUs + 1;
}
});
$scope.txps = txps;
};
2016-08-15 10:25:43 -03:00
self.updateAllClients = function() {
2016-08-18 10:08:23 -03:00
var txps = [];
2016-08-18 10:37:08 -03:00
var i = $scope.wallets.length;
2016-08-18 10:08:23 -03:00
2016-08-18 10:37:08 -03:00
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-18 10:08:23 -03:00
} // TODO
if (status.pendingTxps && status.pendingTxps[0]) {
txps = txps.concat(status.pendingTxps);
}
2016-08-18 10:37:08 -03:00
if (--i == 0) {
2016-08-18 10:08:23 -03:00
setPendingTxps(txps);
}
2016-08-18 10:37:08 -03:00
wallet.status = status;
2016-08-12 10:54:31 -03:00
});
});
}
self.setWallets();
self.updateAllClients();
$scope.bitpayCardEnabled = true; // TODO
2016-08-17 13:16:06 -03:00
2016-08-18 10:08:23 -03:00
var config = configService.getSync().wallet;
var GLIDERA_LOCK_TIME = 6 * 60 * 60;
var glideraActive = true; // TODO TODO TODO
// isGlidera flag is a security measure so glidera status is not
// only determined by the tx.message
$scope.openTxpModal = function(tx) {
var scope = $rootScope.$new(true);
scope.tx = tx;
scope.wallet = tx.wallet;
scope.copayers = tx.wallet.copayers;
scope.isGlidera = glideraActive;
scope.currentSpendUnconfirmed = config.spendUnconfirmed;
$ionicModal.fromTemplateUrl('views/modals/txp-details.html', {
scope: scope
}).then(function(modal) {
scope.txpDetailsModal = modal;
scope.txpDetailsModal.show();
});
};
// $state.transitionTo('confirm', {toAmount:555500, toAddress: 'mvfAwUJohJWibGzBZgAUGsDarsr4Z4NovU', toName: 'bla bla'});
2016-08-12 10:54:31 -03:00
});