2016-05-20 11:37:13 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-09-19 12:02:39 -03:00
|
|
|
angular.module('copayApp.controllers').controller('txDetailsController', function($log, $timeout, $scope, $filter, $stateParams, gettextCatalog, profileService, configService, txFormatService, externalLinkService, popupService) {
|
2016-05-31 14:51:17 -03:00
|
|
|
var self = $scope.self;
|
2016-08-19 13:09:27 -03:00
|
|
|
var wallet = profileService.getWallet($stateParams.walletId);
|
2016-05-31 14:51:17 -03:00
|
|
|
var config = configService.getSync();
|
|
|
|
|
var configWallet = config.wallet;
|
|
|
|
|
var walletSettings = configWallet.settings;
|
|
|
|
|
|
|
|
|
|
$scope.alternativeIsoCode = walletSettings.alternativeIsoCode;
|
2016-08-19 13:09:27 -03:00
|
|
|
$scope.color = wallet.color;
|
|
|
|
|
$scope.copayerId = wallet.credentials.copayerId;
|
|
|
|
|
$scope.isShared = wallet.credentials.n > 1;
|
2016-06-23 18:46:48 -03:00
|
|
|
|
2016-08-18 11:45:30 -03:00
|
|
|
$scope.btx.amountStr = txFormatService.formatAmount($scope.btx.amount, true) + ' ' + walletSettings.unitName;
|
|
|
|
|
$scope.btx.feeStr = txFormatService.formatAmount($scope.btx.fees, true) + ' ' + walletSettings.unitName;
|
2016-09-18 19:38:55 -03:00
|
|
|
$scope.btx.feeLevel = walletSettings.feeLevel;
|
2016-09-19 10:37:32 -03:00
|
|
|
|
|
|
|
|
if ($scope.btx.action != 'invalid') {
|
|
|
|
|
if ($scope.btx.action == 'sent') $scope.title = gettextCatalog.getString('Sent Funds');
|
|
|
|
|
if ($scope.btx.action == 'received') $scope.title = gettextCatalog.getString('Received Funds');
|
|
|
|
|
if ($scope.btx.action == 'moved') $scope.title = gettextCatalog.getString('Moved Funds');
|
|
|
|
|
}
|
2016-06-23 18:46:48 -03:00
|
|
|
|
2016-05-31 14:51:17 -03:00
|
|
|
$scope.showCommentPopup = function() {
|
2016-09-19 12:00:44 -03:00
|
|
|
popupService.showPrompt(gettextCatalog.getString('Memo'), null, null, function(res) {
|
|
|
|
|
$log.debug('Saving memo');
|
2016-05-27 15:06:41 -03:00
|
|
|
|
2016-06-04 17:52:34 -03:00
|
|
|
var args = {
|
2016-05-31 14:51:17 -03:00
|
|
|
txid: $scope.btx.txid,
|
2016-09-19 12:00:44 -03:00
|
|
|
body: res
|
2016-06-04 17:52:34 -03:00
|
|
|
};
|
|
|
|
|
|
2016-08-19 13:09:27 -03:00
|
|
|
wallet.editTxNote(args, function(err) {
|
2016-06-03 14:44:03 -03:00
|
|
|
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 = {};
|
2016-09-19 12:00:44 -03:00
|
|
|
$scope.btx.note.body = res;
|
2016-08-19 13:09:27 -03:00
|
|
|
$scope.btx.note.editedByName = wallet.credentials.copayerName;
|
2016-06-04 17:52:34 -03:00
|
|
|
$scope.btx.note.editedOn = Math.floor(Date.now() / 1000);
|
|
|
|
|
}
|
2016-06-04 17:47:58 -03:00
|
|
|
$scope.btx.searcheableString = null;
|
2016-09-19 12:00:44 -03:00
|
|
|
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.$apply();
|
|
|
|
|
}, 200);
|
2016-06-03 14:44:03 -03:00
|
|
|
});
|
2016-09-19 12:00:44 -03:00
|
|
|
});
|
2016-05-31 14:51:17 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.getAlternativeAmount = function() {
|
|
|
|
|
var satToBtc = 1 / 100000000;
|
|
|
|
|
|
2016-08-19 13:09:27 -03:00
|
|
|
wallet.getFiatRate({
|
2016-05-31 14:51:17 -03:00
|
|
|
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;
|
2016-05-31 14:51:17 -03:00
|
|
|
$scope.$apply();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-02 14:50:50 -03:00
|
|
|
$scope.openExternalLink = function(url, target) {
|
2016-09-05 14:59:11 -03:00
|
|
|
externalLinkService.open(url, target);
|
2016-09-02 14:50:50 -03:00
|
|
|
};
|
|
|
|
|
|
2016-05-31 14:51:17 -03:00
|
|
|
$scope.getShortNetworkName = function() {
|
2016-08-19 13:09:27 -03:00
|
|
|
var n = wallet.credentials.network;
|
2016-05-31 14:51:17 -03:00
|
|
|
return n.substring(0, 4);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.cancel = function() {
|
|
|
|
|
$scope.txDetailsModal.hide();
|
|
|
|
|
};
|
2016-05-27 15:06:41 -03:00
|
|
|
|
2016-05-31 14:51:17 -03:00
|
|
|
});
|