get URI parsing into copay core

This commit is contained in:
Manuel Araoz 2014-07-03 12:52:28 -03:00
parent 8acaca75fb
commit 1b780d268b
2 changed files with 24 additions and 18 deletions

View File

@ -2,25 +2,12 @@
angular.module('copayApp.controllers').controller('UriPaymentController', function($rootScope, $scope, $routeParams, $timeout, $location) {
var data = decodeURIComponent($routeParams.data);
var splitDots = data.split(':');
$scope.protocol = splitDots[0];
data = splitDots[1];
var splitQuestion = data.split('?');
$scope.address = splitQuestion[0];
var search = splitQuestion[1];
data = JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}',
function(key, value) {
return key === "" ? value : decodeURIComponent(value);
});
$scope.amount = parseFloat(data.amount);
$scope.message = data.message;
$rootScope.pendingPayment = copay.Structure.parseBitcoinURI($routeParams.data);
$rootScope.pendingPayment = {
protocol: $scope.protocol,
address: $scope.address,
amount: $scope.amount,
message: $scope.message
};
$scope.protocol = $rootScope.pendingPayment.protocol;
$scope.address = $rootScope.pendingPayment.address;
$scope.amount = $rootScope.pendingPayment.amount;
$scope.message = $rootScope.pendingPayment.message;
$timeout(function() {
$location.path('signin');

View File

@ -50,4 +50,23 @@ Structure.MAX_NON_HARDENED = MAX_NON_HARDENED;
Structure.SHARED_INDEX = SHARED_INDEX;
Structure.ID_INDEX = ID_INDEX;
Structure.parseBitcoinURI = function(uri) {
var ret = {};
var data = decodeURIComponent(uri);
var splitDots = data.split(':');
ret.protocol = splitDots[0];
data = splitDots[1];
var splitQuestion = data.split('?');
ret.address = splitQuestion[0];
var search = splitQuestion[1];
data = JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}',
function(key, value) {
return key === "" ? value : decodeURIComponent(value);
});
ret.amount = parseFloat(data.amount);
ret.message = data.message;
return ret;
};
module.exports = require('soop')(Structure);