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

154 lines
4.5 KiB
JavaScript
Raw Normal View History

2016-05-20 11:37:13 -03:00
'use strict';
2016-09-20 13:56:54 -03:00
angular.module('copayApp.controllers').controller('txDetailsController', function($log, $timeout, $scope, $filter, $stateParams, ongoingProcess, walletService, lodash, gettextCatalog, profileService, configService, txFormatService, externalLinkService, popupService) {
var config = configService.getSync();
var configWallet = config.wallet;
var walletSettings = configWallet.settings;
2016-09-20 16:21:05 -03:00
var wallet;
2016-09-20 13:56:54 -03:00
$scope.title = gettextCatalog.getString('Transaction');
2016-09-19 17:52:01 -03:00
$scope.init = function() {
2016-09-20 16:21:05 -03:00
wallet = $scope.wallet;
$scope.alternativeIsoCode = walletSettings.alternativeIsoCode;
$scope.color = wallet.color;
$scope.copayerId = wallet.credentials.copayerId;
$scope.isShared = wallet.credentials.n > 1;
$scope.btx.feeLevel = walletSettings.feeLevel;
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-09-21 10:49:56 -03:00
updateMemo();
2016-09-20 16:21:05 -03:00
initActionList();
getAlternativeAmount();
2016-09-21 10:49:56 -03:00
};
function updateMemo() {
2016-10-11 16:46:06 -03:00
walletService.getTxNote(wallet, $scope.btx.txid, function(err, note) {
2016-10-12 10:19:27 -03:00
if (err) {
2016-10-17 11:15:36 -03:00
$log.warn('Could not fetch transaction note: ' + err);
2016-09-21 10:49:56 -03:00
return;
}
2016-10-12 10:19:27 -03:00
if (!note) return;
2016-10-11 16:46:06 -03:00
$scope.btx.note = note;
walletService.getTx(wallet, $scope.btx.txid, function(err, tx) {
if (err) {
$log.error(err);
return;
}
tx.note = note;
$timeout(function() {
$scope.$apply();
});
2016-09-21 10:49:56 -03:00
});
});
2016-09-19 17:52:01 -03:00
};
function initActionList() {
$scope.actionList = [];
if ($scope.btx.action != 'sent' || !$scope.isShared) return;
var actionDescriptions = {
created: gettextCatalog.getString('Proposal Created'),
accept: gettextCatalog.getString('Accepted'),
reject: gettextCatalog.getString('Rejected'),
broadcasted: gettextCatalog.getString('Broadcasted'),
};
$scope.actionList.push({
type: 'created',
time: $scope.btx.createdOn,
description: actionDescriptions['created'],
by: $scope.btx.creatorName
});
lodash.each($scope.btx.actions, function(action) {
$scope.actionList.push({
type: action.type,
time: action.createdOn,
description: actionDescriptions[action.type],
by: action.copayerName
});
});
$scope.actionList.push({
type: 'broadcasted',
time: $scope.btx.time,
description: actionDescriptions['broadcasted'],
});
2016-09-28 10:42:25 -03:00
$scope.actionList.reverse();
2016-09-19 17:52:01 -03:00
};
2016-06-23 18:46:48 -03:00
$scope.showCommentPopup = function() {
2016-09-21 14:55:56 -03:00
var opts = {};
if ($scope.btx.note && $scope.btx.note.body) opts.defaultText = $scope.btx.note.body;
2016-10-06 16:04:36 -03:00
popupService.showPrompt(wallet.name, gettextCatalog.getString('Memo'), opts, function(text) {
2016-09-21 14:55:56 -03:00
if (typeof text == "undefined") return;
2016-09-19 12:00:44 -03:00
$log.debug('Saving memo');
2016-05-27 15:06:41 -03:00
2016-06-04 17:52:34 -03:00
var args = {
txid: $scope.btx.txid,
2016-09-21 10:49:56 -03:00
body: text
2016-06-04 17:52:34 -03:00
};
2016-10-11 16:46:06 -03:00
walletService.editTxNote(wallet, args, function(err, res) {
if (err) {
2016-10-12 10:19:27 -03:00
$log.debug('Could not save tx comment ' + err);
return;
}
2016-06-04 16:30:36 -03:00
// This is only to refresh the current screen data
2016-10-11 16:46:06 -03:00
updateMemo();
2016-06-04 17:47:58 -03:00
$scope.btx.searcheableString = null;
2016-09-19 12:00:44 -03:00
$timeout(function() {
$scope.$apply();
2016-09-21 10:49:56 -03:00
});
});
2016-09-19 12:00:44 -03:00
});
};
2016-09-20 12:02:45 -03:00
var getAlternativeAmount = function() {
var satToBtc = 1 / 100000000;
2016-08-19 13:09:27 -03:00
wallet.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;
2016-09-27 12:57:46 -03:00
$timeout(function() {
$scope.$apply();
});
}
});
};
$scope.openExternalLink = function(url, optIn, title, message, okText, cancelText) {
externalLinkService.open(url, optIn, title, message, okText, cancelText);
};
$scope.getShortNetworkName = function() {
2016-08-19 13:09:27 -03:00
var n = wallet.credentials.network;
return n.substring(0, 4);
};
$scope.cancel = function() {
$scope.txDetailsModal.hide();
};
});