diff --git a/js/controllers/home.js b/js/controllers/home.js index 2aac5071f..2ac3e7381 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -6,8 +6,5 @@ angular.module('copayApp.controllers').controller('HomeController', controllerUtils.redirIfLogged(); $scope.loading = false; - if ($rootScope.pendingPayment) { - notification.info('Login Required', 'Please open wallet to complete payment'); - } $scope.hasWallets = (walletFactory.getWallets() && walletFactory.getWallets().length > 0) ? true : false; }); diff --git a/js/controllers/open.js b/js/controllers/open.js index 3dbcc2a50..af7b0ad10 100644 --- a/js/controllers/open.js +++ b/js/controllers/open.js @@ -3,6 +3,10 @@ angular.module('copayApp.controllers').controller('OpenController', function($scope, $rootScope, $location, walletFactory, controllerUtils, Passphrase, notification) { controllerUtils.redirIfLogged(); + if ($rootScope.pendingPayment) { + notification.info('Login Required', 'Please open wallet to complete payment'); + } + var cmp = function(o1, o2) { var v1 = o1.show.toLowerCase(), v2 = o2.show.toLowerCase(); diff --git a/js/controllers/send.js b/js/controllers/send.js index 07b50dfa2..f242dd82d 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -37,10 +37,10 @@ angular.module('copayApp.controllers').controller('SendController', if ($rootScope.pendingPayment) { var pp = $rootScope.pendingPayment; - $scope.address = pp.address; - var amount = pp.amount / config.unitToSatoshi * 100000000; + $scope.address = pp.address + ''; + var amount = pp.data.amount / config.unitToSatoshi * 100000000; $scope.amount = amount; - $scope.commentText = pp.message; + $scope.commentText = pp.data.message; } navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; @@ -261,12 +261,12 @@ angular.module('copayApp.controllers').controller('SendController', function onSuccess(result) { if (result.cancelled) return; - debugger; - var bip21 = copay.HDPath.parseBitcoinURI(result.text); - $scope.address = bip21.address; + var bip21 = new bitcore.BIP21(result.text); + $scope.address = bip21.address + ''; + $scope.commentText = bip21.data.message; - if (bip21.amount) { - $scope.amount = bip21.amount * bitcore.util.COIN * satToUnit; + if (bip21.data.amount) { + $scope.amount = bip21.data.amount * bitcore.util.COIN * satToUnit; } $rootScope.$digest(); diff --git a/js/controllers/uriPayment.js b/js/controllers/uriPayment.js index c6bd02f8d..fe38ed7b6 100644 --- a/js/controllers/uriPayment.js +++ b/js/controllers/uriPayment.js @@ -1,16 +1,13 @@ 'use strict'; +var bitcore = require('bitcore'); + angular.module('copayApp.controllers').controller('UriPaymentController', function($rootScope, $scope, $routeParams, $timeout, $location) { var data = decodeURIComponent($routeParams.data); - $rootScope.pendingPayment = copay.HDPath.parseBitcoinURI($routeParams.data); - - $scope.protocol = $rootScope.pendingPayment.protocol; - $scope.address = $rootScope.pendingPayment.address; - $scope.amount = $rootScope.pendingPayment.amount; - $scope.message = $rootScope.pendingPayment.message; + $rootScope.pendingPayment = new bitcore.BIP21($routeParams.data); $timeout(function() { - $location.path('/'); + $location.path('/open'); }, 1000); diff --git a/js/directives.js b/js/directives.js index d704b6073..620eeded5 100644 --- a/js/directives.js +++ b/js/directives.js @@ -47,8 +47,9 @@ angular.module('copayApp.directives') var val = function(value) { var availableBalanceNum = Number(($rootScope.availableBalance * config.unitToSatoshi).toFixed(0)); var vNum = Number((value * config.unitToSatoshi).toFixed(0)) + feeSat; + if (typeof vNum == "number" && vNum > 0) { - if (availableBalanceNum < vNum) { + if (availableBalanceNum < vNum || isNaN(availableBalanceNum)) { ctrl.$setValidity('enoughAmount', false); scope.notEnoughAmount = true; } else { diff --git a/test/test.HDPath.js b/test/test.HDPath.js index 1bf5bf0b0..22f6959d0 100644 --- a/test/test.HDPath.js +++ b/test/test.HDPath.js @@ -76,13 +76,4 @@ describe('HDPath model', function() { i.isChange.should.equal(result.isChange); }); }); - it('should get the correct result for bitcoin uri', function() { - var uri = 'bitcoin:19mP9FKrXqL46Si58pHdhGKow88SUPy1V8%3Famount=0.1&message=a%20bitcoin%20donation'; - var result = HDPath.parseBitcoinURI(uri); - result.address.should.equal('19mP9FKrXqL46Si58pHdhGKow88SUPy1V8'); - result.amount.should.equal(0.1); - result.message.should.equal('a bitcoin donation'); - result.protocol.should.equal('bitcoin'); - }); - }); diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index ed257b8ef..5cee6da41 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -422,7 +422,7 @@ describe("Unit: Controllers", function() { beforeEach(inject(function($controller, $rootScope) { scope = $rootScope.$new(); var routeParams = { - data: 'bitcoin:19mP9FKrXqL46Si58pHdhGKow88SUPy1V8%3Famount=0.1&message=a%20bitcoin%20donation' + data: 'bitcoin:19mP9FKrXqL46Si58pHdhGKow88SUPy1V8?amount=0.1&message=a%20bitcoin%20donation' }; what = $controller('UriPaymentController', { $scope: scope, @@ -436,10 +436,10 @@ describe("Unit: Controllers", function() { it('should parse url correctly', function() { should.exist(what); - scope.protocol.should.equal('bitcoin'); - scope.address.should.equal('19mP9FKrXqL46Si58pHdhGKow88SUPy1V8'); - scope.amount.should.equal(0.1); - scope.message.should.equal('a bitcoin donation'); + should.exist(scope.pendingPayment); + scope.pendingPayment.address.data.should.equal('19mP9FKrXqL46Si58pHdhGKow88SUPy1V8'); + scope.pendingPayment.data.amount.should.equal(0.1); + scope.pendingPayment.data.message.should.equal('a bitcoin donation'); }); }); diff --git a/views/uri-payment.html b/views/uri-payment.html index 64390d478..7f53becb5 100644 --- a/views/uri-payment.html +++ b/views/uri-payment.html @@ -1,11 +1,7 @@ -

-Preparing payment... -

-

Protocol: {{protocol}}

-

To: {{address}}

-

Amount: {{amount}}

-

Message:

-
{{message}}
+ +
+ + Preparing payment...