2016-05-20 11:37:13 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-11-04 17:03:20 -03:00
|
|
|
angular.module('copayApp.controllers').controller('txDetailsController', function($log, $timeout, $ionicHistory, $scope, $stateParams, walletService, lodash, gettextCatalog, profileService, configService, externalLinkService, popupService) {
|
|
|
|
|
|
|
|
|
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
|
|
|
|
$scope.title = gettextCatalog.getString('Transaction');
|
|
|
|
|
$scope.wallet = profileService.getWallet(data.stateParams.walletId);
|
|
|
|
|
$scope.color = $scope.wallet.color;
|
|
|
|
|
$scope.copayerId = $scope.wallet.credentials.copayerId;
|
|
|
|
|
$scope.isShared = $scope.wallet.credentials.n > 1;
|
|
|
|
|
|
|
|
|
|
walletService.getTx($scope.wallet, $stateParams.txid, function(err, tx) {
|
2016-10-22 17:43:05 -03:00
|
|
|
if (err) {
|
|
|
|
|
$log.warn('Could not get tx');
|
|
|
|
|
$ionicHistory.goBack();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$scope.btx = tx;
|
|
|
|
|
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-20 16:21:05 -03:00
|
|
|
|
2016-10-22 17:43:05 -03:00
|
|
|
$scope.displayAmount = getDisplayAmount($scope.btx.amountStr);
|
|
|
|
|
$scope.displayUnit = getDisplayUnit($scope.btx.amountStr);
|
2016-10-21 17:16:35 -04:00
|
|
|
|
2016-10-22 17:43:05 -03:00
|
|
|
updateMemo();
|
|
|
|
|
initActionList();
|
|
|
|
|
});
|
2016-11-04 17:03:20 -03:00
|
|
|
});
|
2016-09-21 10:49:56 -03:00
|
|
|
|
2016-10-21 17:16:35 -04:00
|
|
|
function getDisplayAmount(amountStr) {
|
|
|
|
|
return amountStr.split(' ')[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getDisplayUnit(amountStr) {
|
|
|
|
|
return amountStr.split(' ')[1];
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 10:49:56 -03:00
|
|
|
function updateMemo() {
|
2016-11-04 17:03:20 -03:00
|
|
|
walletService.getTxNote($scope.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;
|
2016-11-04 17:03:20 -03:00
|
|
|
$scope.$apply();
|
2016-09-21 10:49:56 -03:00
|
|
|
});
|
2016-10-21 18:06:51 -04: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-10-21 19:13:14 -04:00
|
|
|
}
|
2016-06-23 18:46:48 -03:00
|
|
|
|
2016-05-31 14:51:17 -03:00
|
|
|
$scope.showCommentPopup = function() {
|
2016-09-21 14:55:56 -03:00
|
|
|
var opts = {};
|
2016-10-22 17:43:05 -03:00
|
|
|
if ($scope.btx.message) {
|
2016-10-21 17:16:35 -04:00
|
|
|
opts.defaultText = $scope.btx.message;
|
|
|
|
|
}
|
2016-09-21 14:55:56 -03:00
|
|
|
if ($scope.btx.note && $scope.btx.note.body) opts.defaultText = $scope.btx.note.body;
|
|
|
|
|
|
2016-11-04 17:03:20 -03:00
|
|
|
popupService.showPrompt($scope.wallet.name, gettextCatalog.getString('Memo'), opts, function(text) {
|
2016-09-21 14:55:56 -03:00
|
|
|
if (typeof text == "undefined") return;
|
|
|
|
|
|
2016-11-08 09:58:48 -03:00
|
|
|
$scope.btx.note = {
|
|
|
|
|
body: text
|
|
|
|
|
};
|
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 = {
|
2016-05-31 14:51:17 -03:00
|
|
|
txid: $scope.btx.txid,
|
2016-09-21 10:49:56 -03:00
|
|
|
body: text
|
2016-06-04 17:52:34 -03:00
|
|
|
};
|
|
|
|
|
|
2016-11-04 17:03:20 -03:00
|
|
|
walletService.editTxNote($scope.wallet, args, function(err, res) {
|
2016-06-03 14:44:03 -03:00
|
|
|
if (err) {
|
2016-10-12 10:19:27 -03:00
|
|
|
$log.debug('Could not save tx comment ' + err);
|
2016-06-03 14:44:03 -03:00
|
|
|
}
|
|
|
|
|
});
|
2016-09-19 12:00:44 -03:00
|
|
|
});
|
2016-05-31 14:51:17 -03:00
|
|
|
};
|
|
|
|
|
|
2016-10-21 18:40:37 -04:00
|
|
|
$scope.viewOnBlockchain = function() {
|
|
|
|
|
var btx = $scope.btx;
|
|
|
|
|
var url = 'https://' + ($scope.getShortNetworkName() == 'test' ? 'test-' : '') + 'insight.bitpay.com/tx/' + btx.txid;
|
|
|
|
|
var title = 'View Transaction on Insight';
|
|
|
|
|
var message = 'Would you like to view this transaction on the Insight blockchain explorer?';
|
|
|
|
|
$scope.openExternalLink(url, true, title, message, 'Open Insight', 'Go back');
|
|
|
|
|
};
|
|
|
|
|
|
2016-10-12 15:29:06 -04:00
|
|
|
$scope.openExternalLink = function(url, optIn, title, message, okText, cancelText) {
|
|
|
|
|
externalLinkService.open(url, optIn, title, message, okText, cancelText);
|
2016-09-02 14:50:50 -03:00
|
|
|
};
|
|
|
|
|
|
2016-05-31 14:51:17 -03:00
|
|
|
$scope.getShortNetworkName = function() {
|
2016-11-04 17:03:20 -03:00
|
|
|
var n = $scope.wallet.credentials.network;
|
2016-05-31 14:51:17 -03:00
|
|
|
return n.substring(0, 4);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.cancel = function() {
|
|
|
|
|
$scope.txDetailsModal.hide();
|
|
|
|
|
};
|
2016-10-21 16:56:19 -04:00
|
|
|
|
2016-05-31 14:51:17 -03:00
|
|
|
});
|