interface Templates {
	transactions: Template;
}

Template.transactions.onRendered(function() {


	this.autorun(() => {
		this.subscribe('Banking.Method');
		var method = Banking.Methods.BitcoinMethodClient.db.findOne();
		var wallet = Banking.WalletClient.db.findOne({currency: 'BTC'});

		if (!method || !wallet) {
			return;
		}

		this.subscribe('Banking/userTransactions', {
			wallet: wallet._id,
			'reference.id': method._id,
			$or: [
				{referenceType: Banking.TransactionType.DEPOSIT},
				{referenceType: Banking.TransactionType.WITHDRAW}
			]

		}, {sort: {createTime: -1}}, function () {
			Session.set('depositsReady', true);
		});
	});
});

Template.transactions.helpers({

	transactions: function() {
		return Banking.Transaction.db.find({}, {sort: {createTime: -1}});
	}

});

Template.transactions.events({
	'click tr td': function(){
		var self: Banking.Transaction = this;
		self.showDetails();
	}
});