diff --git a/js/controllers/uriPayment.js b/js/controllers/uriPayment.js index ccc701205..9cbc383c6 100644 --- a/js/controllers/uriPayment.js +++ b/js/controllers/uriPayment.js @@ -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'); diff --git a/js/models/core/Structure.js b/js/models/core/Structure.js index 88543f966..aafee4c0f 100644 --- a/js/models/core/Structure.js +++ b/js/models/core/Structure.js @@ -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);