Wallet/src/js/controllers/modals/txDetails.js

97 lines
2.9 KiB
JavaScript
Raw Normal View History

2016-05-20 11:37:13 -03:00
'use strict';
2016-06-04 17:52:34 -03:00
angular.module('copayApp.controllers').controller('txDetailsController', function($rootScope, $log, $scope, $filter, $ionicPopup, gettextCatalog, profileService, configService, lodash) {
var self = $scope.self;
var fc = profileService.focusedClient;
var config = configService.getSync();
var configWallet = config.wallet;
var walletSettings = configWallet.settings;
$scope.alternativeIsoCode = walletSettings.alternativeIsoCode;
$scope.color = fc.backgroundColor;
$scope.copayerId = fc.credentials.copayerId;
$scope.isShared = fc.credentials.n > 1;
2016-06-23 18:46:48 -03:00
$scope.btx.amountStr = profileService.formatAmount($scope.btx.amount, true) + ' ' + walletSettings.unitName;
$scope.btx.feeStr = profileService.formatAmount($scope.btx.fees, true) + ' ' + walletSettings.unitName;
$scope.showCommentPopup = function() {
$scope.data = {
2016-06-04 17:52:34 -03:00
comment: $scope.btx.note ? $scope.btx.note.body : '',
2016-05-27 15:06:41 -03:00
};
var commentPopup = $ionicPopup.show({
templateUrl: "views/includes/note.html",
scope: $scope,
});
$scope.commentPopupClose = function() {
commentPopup.close();
2016-05-27 15:06:41 -03:00
};
$scope.commentPopupSave = function() {
2016-06-04 16:30:36 -03:00
$log.debug('Saving note');
2016-06-04 17:52:34 -03:00
var args = {
txid: $scope.btx.txid,
2016-06-04 17:52:34 -03:00
};
if (!lodash.isEmpty($scope.data.comment)) {
args.body = $scope.data.comment;
};
fc.editTxNote(args, function(err) {
if (err) {
$log.debug('Could not save tx comment');
return;
}
2016-06-04 16:30:36 -03:00
// This is only to refresh the current screen data
2016-06-23 18:46:48 -03:00
$scope.btx.note = null;
2016-06-04 17:52:34 -03:00
if (args.body) {
$scope.btx.note = {};
$scope.btx.note.body = $scope.data.comment;
$scope.btx.note.editedByName = fc.credentials.copayerName;
$scope.btx.note.editedOn = Math.floor(Date.now() / 1000);
}
2016-06-04 17:47:58 -03:00
$scope.btx.searcheableString = null;
commentPopup.close();
});
2016-05-27 15:06:41 -03:00
};
};
$scope.getAlternativeAmount = function() {
var satToBtc = 1 / 100000000;
fc.getFiatRate({
code: $scope.alternativeIsoCode,
ts: $scope.btx.time * 1000
}, function(err, res) {
if (err) {
$log.debug('Could not get historic rate');
return;
}
if (res && res.rate) {
var alternativeAmountBtc = ($scope.btx.amount * satToBtc).toFixed(8);
$scope.rateDate = res.fetchedOn;
$scope.rateStr = res.rate + ' ' + $scope.alternativeIsoCode;
2016-07-14 11:04:12 -03:00
$scope.alternativeAmountStr = $filter('formatFiatAmount')(alternativeAmountBtc * res.rate) + ' ' + $scope.alternativeIsoCode;
$scope.$apply();
}
});
};
$scope.getShortNetworkName = function() {
var n = fc.credentials.network;
return n.substring(0, 4);
};
2016-08-05 16:55:08 -03:00
$scope.copyToClipboard = function(addr, $event) {
if (!addr) return;
2016-08-05 16:55:08 -03:00
self.copyToClipboard(addr, $event);
};
$scope.cancel = function() {
$scope.txDetailsModal.hide();
};
2016-05-27 15:06:41 -03:00
});