paypro
This commit is contained in:
parent
6743243bab
commit
ba3c834ea5
3 changed files with 62 additions and 11 deletions
|
|
@ -58,6 +58,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
|
||||
$scope.toAddress = $stateParams.toAddress;
|
||||
$scope.toName = $stateParams.toName;
|
||||
$scope.description = $stateParams.description;
|
||||
$scope.paypro = $stateParams.paypro;
|
||||
|
||||
var network = (new bitcore.Address($scope.toAddress)).network.name;
|
||||
$scope.network = network;
|
||||
|
|
@ -136,7 +138,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
var currentSpendUnconfirmed = config.spendUnconfirmed;
|
||||
var outputs = [];
|
||||
|
||||
// TODO
|
||||
var paypro = $scope.paypro;
|
||||
|
||||
// ToDo: use a credential's (or fc's) function for this
|
||||
|
|
|
|||
|
|
@ -1,8 +1,18 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $ionicModal, $log, $timeout, addressbookService, profileService, lodash, $state, walletService, bitcore) {
|
||||
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $ionicModal, $log, $timeout, addressbookService, profileService, lodash, $state, walletService, bitcore, platformInfo, ongoingProcess) {
|
||||
|
||||
var originalList;
|
||||
var isChromeApp = platformInfo.isChromeApp;
|
||||
|
||||
|
||||
// An alert dialog
|
||||
var showAlert = function(title, msg) {
|
||||
$log.warn(title + ": " + msg);
|
||||
var alertPopup = $ionicPopup.alert({
|
||||
title: title,
|
||||
});
|
||||
};
|
||||
|
||||
$scope.init = function() {
|
||||
originalList = [];
|
||||
|
|
@ -42,6 +52,47 @@ 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) {
|
||||
|
|
@ -56,8 +107,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
return newUri;
|
||||
};
|
||||
|
||||
var satToUnit = 1 / this.unitToSatoshi;
|
||||
|
||||
// URI extensions for Payment Protocol with non-backwards-compatible request
|
||||
if ((/^bitcoin:\?r=[\w+]/).exec(uri)) {
|
||||
uri = decodeURIComponent(uri.replace('bitcoin:?r=', ''));
|
||||
|
|
@ -77,24 +126,25 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
var addr = parsed.address ? parsed.address.toString() : '';
|
||||
var message = parsed.message;
|
||||
|
||||
var amount = parsed.amount ?
|
||||
(parsed.amount.toFixed(0) * satToUnit).toFixed(this.unitDecimals) : 0;
|
||||
var amount = parsed.amount ? parsed.amount : '';
|
||||
|
||||
if (parsed.r) {
|
||||
setFromPayPro(parsed.r, function(err) {
|
||||
if (err && addr && amount) {
|
||||
// TODO
|
||||
$state.go('confirm', {toAmount: amount, toAddress: addr, message:message})
|
||||
$state.go('send.confirm', {toAmount: amount, toAddress: addr, message:message})
|
||||
return addr;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
//
|
||||
$state.go('confirm', {toAmount: amount, toAddress: addr, message:message})
|
||||
if (amount) {
|
||||
$state.go('send.confirm', {toAmount: amount, toAddress: addr, message:message})
|
||||
} else {
|
||||
$state.go('send.amount', {toAddress: addr})
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -353,7 +353,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
}
|
||||
})
|
||||
.state('send.confirm', {
|
||||
url: '/confirm/:toAddress/:toName/:toAmount/:message',
|
||||
url: '/confirm/:toAddress/:toName/:toAmount/:description/:paypro',
|
||||
views: {
|
||||
'send': {
|
||||
templateUrl: 'views/confirm.html'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue