This commit is contained in:
Matias Alejo Garcia 2016-08-24 19:12:11 -03:00
commit d6a99781fa
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
6 changed files with 105 additions and 99 deletions

View file

@ -1,8 +1,9 @@
'use strict';
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, $ionicPopup, txStatus, gettext, txFormatService) {
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, $ionicPopup, txStatus, gettext, txFormatService, ongoingProcess, $ionicModal) {
var cachedTxp = {};
var isChromeApp = platformInfo.isChromeApp;
// An alert dialog
var showAlert = function(title, msg, cb) {
@ -31,7 +32,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.description = $scope.data.comment;
$scope.txp = null;
createTx($scope.wallet, $scope.toAddress, $scope.toAmount, $scope.data.comment, function(err, txp) {
createTx($scope.wallet, function(err, txp) {
if (err) return;
cachedTxp[$scope.wallet.id] = txp;
apply(txp);
@ -40,9 +41,68 @@ angular.module('copayApp.controllers').controller('confirmController', function(
};
};
var setFromPayPro = function(uri, cb) {
if (!cb) cb = function() {};
var wallet = profileService.getWallets({
onlyComplete: true
})[0];
if (!wallet) return cb();
if (isChromeApp) {
showAlert(gettext('Payment Protocol not supported on Chrome App'));
return cb(true);
}
$log.debug('Fetch PayPro Request...', uri);
ongoingProcess.set('fetchingPayPro', true);
wallet.fetchPayPro({
payProUrl: uri,
}, function(err, paypro) {
ongoingProcess.set('fetchingPayPro', false);
if (err) {
$log.warn('Could not fetch payment request:', err);
var msg = err.toString();
if (msg.match('HTTP')) {
msg = gettext('Could not fetch payment information');
}
showAlert(msg);
return cb(true);
}
if (!paypro.verified) {
$log.warn('Failed to verify payment protocol signatures');
showAlert(gettext('Payment Protocol Invalid'));
return cb(true);
}
$stateParams.toAmount = paypro.amount;
$stateParams.toAddress = paypro.toAddress;
$stateParams.description = paypro.memo;
$stateParams.paypro = null;
$scope._paypro = paypro;
return $scope.init();
});
};
$scope.init = function() {
// TODO (URL , etc)
if ($stateParams.paypro) {
return setFromPayPro($stateParams.paypro, function(err) {
if (err && !isChromeApp) {
showAlert(gettext('Could not fetch payment'));
}
});
}
if (!$stateParams.toAddress || !$stateParams.toAmount) {
$log.error('Bad params at amount')
throw ('bad params');
@ -96,7 +156,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
apply(cachedTxp[wallet.id]);
} else {
stop = $timeout(function() {
createTx(wallet, $scope.toAddress, $scope.toAmount, $scope.description, function(err, txp) {
createTx(wallet, function(err, txp) {
if (err) return;
cachedTxp[wallet.id] = txp;
apply(txp);
@ -131,14 +191,15 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.$apply();
};
var createTx = function(wallet, toAddress, toAmount, description, cb) {
var createTx = function(wallet, cb) {
var config = configService.getSync().wallet;
//
var currentSpendUnconfirmed = config.spendUnconfirmed;
var outputs = [];
var paypro = $scope.paypro;
var toAddress = $scope.toAddress;
var toAmount = $scope.toAmount;
var description = $scope.description;
// ToDo: use a credential's (or fc's) function for this
if (description && !wallet.credentials.sharedEncryptingKey) {
@ -170,7 +231,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
txp.outputs = outputs;
txp.message = description;
txp.payProUrl = paypro ? paypro.url : null;
txp.payProUrl = paypro;
txp.excludeUnconfirmedUtxos = config.spendUnconfirmed ? false : true;
txp.feeLevel = config.settings.feeLevel || 'normal';
@ -183,6 +244,17 @@ angular.module('copayApp.controllers').controller('confirmController', function(
};
$scope.openPPModal = function() {
$ionicModal.fromTemplateUrl('views/modals/paypro.html', {
scope: $scope
}).then(function(modal) {
$scope.payproModal = modal;
$scope.payproModal.show();
});
};
$scope.approve = function() {
var wallet = $scope.wallet;
var txp = $scope.txp;

View file

@ -3,12 +3,6 @@
angular.module('copayApp.controllers').controller('payproController', function($scope) {
var self = $scope.self;
$scope.alternative = self.alternativeAmount;
$scope.alternativeIsoCode = self.alternativeIsoCode;
$scope.isRateAvailable = self.isRateAvailable;
$scope.unitTotal = ($scope.paypro.amount * self.satToUnit).toFixed(self.unitDecimals);
$scope.unitName = self.unitName;
$scope.cancel = function() {
$scope.payproModal.hide();
};

View file

@ -1,9 +1,8 @@
'use strict';
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $ionicModal, $log, $timeout, addressbookService, profileService, lodash, $state, walletService, bitcore, platformInfo, ongoingProcess) {
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $ionicModal, $log, $timeout, addressbookService, profileService, lodash, $state, walletService, bitcore ) {
var originalList;
var isChromeApp = platformInfo.isChromeApp;
// An alert dialog
@ -52,47 +51,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
};
var setFromPayPro = function(uri, cb) {
if (!cb) cb = function() {};
var wallet = profileService.getWallets({onlyComplete: true})[0];
if (!wallet) return cb();
if (isChromeApp) {
showAlert(gettext('Payment Protocol not supported on Chrome App'));
return cb(true);
}
$log.debug('Fetch PayPro Request...', uri);
ongoingProcess.set('fetchingPayPro', true);
wallet.fetchPayPro({
payProUrl: uri,
}, function(err, paypro) {
ongoingProcess.set('fetchingPayPro', false);
if (err) {
$log.warn('Could not fetch payment request:', err);
var msg = err.toString();
if (msg.match('HTTP')) {
msg = gettext('Could not fetch payment information');
}
showAlert(msg);
return cb(true);
}
if (!paypro.verified) {
$log.warn('Failed to verify payment protocol signatures');
showAlert(gettext('Payment Protocol Invalid'));
return cb(true);
}
$state.go('send.confirm', {toAmount: paypro.amount, toAddress: paypro.toAddress, message:paypro.memo, paypro: uri})
return cb();
});
};
var setFromUri = function(uri) {
function sanitizeUri(uri) {
@ -129,20 +87,13 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
var amount = parsed.amount ? parsed.amount : '';
if (parsed.r) {
setFromPayPro(parsed.r, function(err) {
if (err && addr && amount) {
// TODO
$state.go('send.confirm', {toAmount: amount, toAddress: addr, message:message})
return addr;
}
});
$state.go('send.confirm', {paypro: parsed.r})
} else {
if (amount) {
$state.go('send.confirm', {toAmount: amount, toAddress: addr, message:message})
$state.go('send.confirm', {toAmount: amount, toAddress: addr, description:message})
} else {
$state.go('send.amount', {toAddress: addr})
}
return addr;
}
}
};
@ -155,7 +106,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
if (search.indexOf('bitcoin:') === 0) {
return setFromUri(search);
} else if (/^https?:\/\//.test(search)) {
return setFromPayPro(search);
return $state.go('send.confirm', {paypro: search})
}
if (!search || search.length < 2) {