mirror of https://github.com/BTCPrivate/copay.git
get URI parsing into copay core
This commit is contained in:
parent
8acaca75fb
commit
1b780d268b
|
@ -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');
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue