This commit is contained in:
Matias Alejo Garcia 2016-08-24 18:06:17 -03:00
commit 6764af0a40
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
3 changed files with 68 additions and 3 deletions

View file

@ -13,7 +13,7 @@
<label class="item item-input">
<i class="icon ion-search placeholder-icon"></i>
<input type="text" placeholder="Search" ng-model="search" ng-model-onblur ng-change="findContact(search)">
<input type="text" placeholder="Recipient" ng-model="search" ng-model-onblur ng-change="findContact(search)">
</label>
</div>

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $ionicModal, $log, $timeout, addressbookService, profileService, lodash, $state, walletService) {
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $ionicModal, $log, $timeout, addressbookService, profileService, lodash, $state, walletService, bitcore) {
var originalList;
@ -41,9 +41,73 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
});
};
var setFromUri = function(uri) {
function sanitizeUri(uri) {
// Fixes when a region uses comma to separate decimals
var regex = /[\?\&]amount=(\d+([\,\.]\d+)?)/i;
var match = regex.exec(uri);
if (!match || match.length === 0) {
return uri;
}
var value = match[0].replace(',', '.');
var newUri = uri.replace(regex, value);
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=', ''));
setFromPayPro(uri, function(err) {
if (err) {
return err;
}
});
} else {
uri = sanitizeUri(uri);
if (!bitcore.URI.isValid(uri)) {
return uri;
}
var parsed = new bitcore.URI(uri);
var addr = parsed.address ? parsed.address.toString() : '';
var message = parsed.message;
var amount = parsed.amount ?
(parsed.amount.toFixed(0) * satToUnit).toFixed(this.unitDecimals) : 0;
if (parsed.r) {
setFromPayPro(parsed.r, function(err) {
if (err && addr && amount) {
// TODO
$state.go('confirm', {toAmount: amount, toAddress: addr, message:message})
return addr;
}
});
} else {
//
$state.go('confirm', {toAmount: amount, toAddress: addr, message:message})
return addr;
}
}
};
$scope.findContact = function(search, opts) {
opts = opts || {};
if (search.indexOf('bitcoin:') === 0) {
return setFromUri(search);
} else if (/^https?:\/\//.test(search)) {
return setFromPayPro(search);
}
if (!search || search.length < 2) {
$scope.list = originalList;
$timeout(function() {
@ -148,5 +212,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
$scope.addressbookModal.remove();
});
$scope.$watch('')
});

View file

@ -356,7 +356,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
})
.state('send.confirm', {
url: '/confirm/:toAddress/:toName/:toAmount',
url: '/confirm/:toAddress/:toName/:toAmount/:message',
views: {
'send': {
templateUrl: 'views/confirm.html'