diff --git a/css/main.css b/css/main.css index 8e2fc4089..079ac524c 100644 --- a/css/main.css +++ b/css/main.css @@ -999,4 +999,20 @@ a.text-white:hover {color: #ccc;} border: 0; } +.panel qrcode { + float: left; + width: 260px; + height: 260px; + padding: 5px 0 0 5px; + background-color: white; +} + +.panel .secret { + float: left; + margin-left: 10px; + overflow-wrap: break-word; + width: 50%; + text-align: center; +} + /*-----------------------------------------------------------------*/ diff --git a/js/controllers/join.js b/js/controllers/join.js index 13019b032..ea6d446a2 100644 --- a/js/controllers/join.js +++ b/js/controllers/join.js @@ -1,9 +1,104 @@ 'use strict'; angular.module('copayApp.controllers').controller('JoinController', - function($scope, $rootScope, walletFactory, controllerUtils, Passphrase, notification) { + function($scope, $rootScope, $timeout, walletFactory, controllerUtils, Passphrase, notification) { $scope.loading = false; - + + // QR code Scanner + var cameraInput; + var video; + var canvas; + var $video; + var context; + var localMediaStream; + + var _scan = function(evt) { + if (localMediaStream) { + context.drawImage(video, 0, 0, 300, 225); + + try { + qrcode.decode(); + } catch (e) { + //qrcodeError(e); + } + } + + $timeout(_scan, 500); + }; + + var _successCallback = function(stream) { + video.src = (window.URL && window.URL.createObjectURL(stream)) || stream; + localMediaStream = stream; + video.play(); + $timeout(_scan, 1000); + }; + + var _scanStop = function() { + $scope.showScanner = false; + if (!$scope.isMobile) { + if (localMediaStream && localMediaStream.stop) localMediaStream.stop(); + localMediaStream = null; + video.src = ''; + } + }; + + var _videoError = function(err) { + _scanStop(); + }; + + qrcode.callback = function(data) { + _scanStop(); + + $scope.$apply(function() { + $scope.connectionId = data; + }); + }; + + $scope.cancelScanner = function() { + _scanStop(); + }; + + $scope.openScanner = function() { + if (window.cordova) return $scope.scannerIntent(); + + $scope.showScanner = true; + + // Wait a moment until the canvas shows + $timeout(function() { + canvas = document.getElementById('qr-canvas'); + context = canvas.getContext('2d'); + + if ($scope.isMobile) { + cameraInput = document.getElementById('qrcode-camera'); + cameraInput.addEventListener('change', _scan, false); + } else { + video = document.getElementById('qrcode-scanner-video'); + $video = angular.element(video); + canvas.width = 300; + canvas.height = 225; + context.clearRect(0, 0, 300, 225); + + navigator.getUserMedia({ + video: true + }, _successCallback, _videoError); + } + }, 500); + }; + + $scope.scannerIntent = function() { + cordova.plugins.barcodeScanner.scan( + function onSuccess(result) { + if (result.cancelled) return; + + $scope.connectionId = result.text; + $rootScope.$digest(); + }, + function onError(error) { + alert('Scanning error'); + }); + } + + $scope.join = function(form) { if (form && form.$invalid) { notification.error('Error', 'Please enter the required fields'); diff --git a/js/controllers/send.js b/js/controllers/send.js index af3b819f4..cac79c111 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -30,10 +30,6 @@ angular.module('copayApp.controllers').controller('SendController', $scope.amount = amount; } - // Detect protocol - $scope.isHttp = ($window.location.protocol.indexOf('http') === 0); - $scope.isCordova = typeof(window.cordova) != 'undefined'; - navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL; $scope.isMobile = isMobile.any(); @@ -171,6 +167,8 @@ angular.module('copayApp.controllers').controller('SendController', }; $scope.openScanner = function() { + if (window.cordova) return $scope.scannerIntent(); + $scope.showScanner = true; // Wait a moment until the canvas shows diff --git a/views/copayers.html b/views/copayers.html index 9df0df307..3b567e57f 100644 --- a/views/copayers.html +++ b/views/copayers.html @@ -10,8 +10,9 @@

Waiting copayers

Share this secret with your other copayers

-
{{$root.wallet.getSecret()}}
+ +
{{$root.wallet.getSecret()}}
+

New Wallet Created

diff --git a/views/join.html b/views/join.html index 0b3367ef8..8a7d140c0 100644 --- a/views/join.html +++ b/views/join.html @@ -12,7 +12,32 @@

Join a Wallet in Creation

- + +
+   +
+
+   +
+ +
+
+ +
+
+ + + Get QR code + + +
+
+
+ +
+
+
+ -
+
-
+