Wallet/src/js/controllers/tx.js

74 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-02-09 16:48:53 -05:00
'use strict';
angular.module('copayApp.controllers').controller('txController',
2016-02-17 15:13:15 -05:00
function($rootScope, $scope, $timeout, $filter, lodash, profileService, isCordova, nodeWebkit, configService, animationService, gettextCatalog) {
2016-02-09 16:48:53 -05:00
var fc = profileService.focusedClient;
2016-02-10 15:35:26 -05:00
var config = configService.getSync();
var configWallet = config.wallet;
var walletSettings = configWallet.settings;
var m = angular.element(document.getElementsByClassName('txModal'));
m.addClass(animationService.modalAnimated.slideRight);
this.alternativeIsoCode = walletSettings.alternativeIsoCode;
2016-02-09 16:48:53 -05:00
this.color = fc.backgroundColor;
this.copayerId = fc.credentials.copayerId;
this.isShared = fc.credentials.n > 1;
if (isCordova) {
2016-02-10 15:35:26 -05:00
$rootScope.modalOpened = true;
var self = this;
var disableCloseModal = $rootScope.$on('closeModal', function() {
self.cancel();
});
2016-02-09 16:48:53 -05:00
}
this.getAlternativeAmount = function(btx) {
2016-02-10 15:35:26 -05:00
var self = this;
2016-02-09 16:48:53 -05:00
var satToBtc = 1 / 100000000;
fc.getFiatRate({
code: self.alternativeIsoCode,
ts: btx.time * 1000
}, function(err, res) {
if (err) {
$log.debug('Could not get historic rate');
return;
}
if (res && res.rate) {
var alternativeAmountBtc = (btx.amount * satToBtc).toFixed(8);
$scope.rateDate = res.fetchedOn;
$scope.rateStr = res.rate + ' ' + self.alternativeIsoCode;
$scope.alternativeAmountStr = $filter('noFractionNumber')(alternativeAmountBtc * res.rate, 2) + ' ' + self.alternativeIsoCode;
$scope.$apply();
}
});
};
this.getShortNetworkName = function() {
var n = fc.credentials.network;
return n.substring(0, 4);
};
2016-02-17 15:13:15 -05:00
this.copyToClipboard = function(value) {
2016-02-09 16:48:53 -05:00
if (isCordova) {
2016-02-17 15:13:15 -05:00
window.cordova.plugins.clipboard.copy(value);
2016-02-09 16:48:53 -05:00
window.plugins.toast.showShortCenter(gettextCatalog.getString('Copied to clipboard'));
} else if (nodeWebkit.isDefined()) {
2016-02-17 15:13:15 -05:00
nodeWebkit.writeToClipboard(value);
2016-02-09 16:48:53 -05:00
}
2016-02-10 15:35:26 -05:00
};
2016-02-09 16:48:53 -05:00
2016-02-10 15:35:26 -05:00
this.cancel = lodash.debounce(function() {
m.addClass(animationService.modalAnimated.slideOutRight);
2016-02-09 16:48:53 -05:00
if (isCordova) {
2016-02-10 15:35:26 -05:00
$rootScope.modalOpened = false;
disableCloseModal();
2016-02-09 16:48:53 -05:00
$timeout(function() {
$rootScope.$emit('Local/TxModal', null);
2016-02-10 15:35:26 -05:00
}, 350);
2016-02-09 16:48:53 -05:00
} else {
$rootScope.$emit('Local/TxModal', null);
}
2016-02-10 15:35:26 -05:00
}, 0, 1000);
2016-02-09 16:48:53 -05:00
});