diff --git a/index.html b/index.html index 0300f7588..25796ab8e 100644 --- a/index.html +++ b/index.html @@ -96,6 +96,40 @@ + + + diff --git a/js/app.js b/js/app.js index 21859c3ff..f1fff46a0 100644 --- a/js/app.js +++ b/js/app.js @@ -11,6 +11,7 @@ angular.module('copay',[ 'copay.backup', 'copay.walletFactory', 'copay.signin', + 'copay.setup', 'copay.peer' ]); @@ -21,5 +22,6 @@ angular.module('copay.send', []); angular.module('copay.backup', []); angular.module('copay.walletFactory', []); angular.module('copay.signin', []); +angular.module('copay.setup', []); angular.module('copay.peer', []); diff --git a/js/config.js b/js/config.js index cbc46bab8..d73f23cdb 100644 --- a/js/config.js +++ b/js/config.js @@ -7,6 +7,10 @@ var config = { maxPeers: 3, debug: 3, }, + limits: { + totalCopayers: 10, + mPlusN: 15 + }, wallet: { requiredCopayers: 2, totalCopayers: 3, diff --git a/js/controllers/setup.js b/js/controllers/setup.js new file mode 100644 index 000000000..a8f25cb3e --- /dev/null +++ b/js/controllers/setup.js @@ -0,0 +1,48 @@ +'use strict'; + +angular.module('copay.setup').controller('SetupController', + function($scope, $rootScope, $location, walletFactory) { + + $scope.loading = false; + + $scope.totalCopayers = config.wallet.totalCopayers; + $scope.TCValues = []; + for (var n = 1; n <= config.limits.totalCopayers; n++) + $scope.TCValues.push(n); + + var updateRCSelect = function(n) { + $scope.requiredCopayers = parseInt(Math.min(n / 2 + 1, config.limits.mPlusN-n)); + $scope.RCValues = []; + for (var m = 1; m <= n; m++) { + if (n + m <= config.limits.mPlusN) { + $scope.RCValues.push(m); + } + } + }; + updateRCSelect($scope.totalCopayers); + + $scope.$watch('totalCopayers', function(tc) { + updateRCSelect(tc); + }) + + $scope.create = function(totalCopayers, requiredCopayers) { + $scope.loading = true; + var opts = { + requiredCopayers: requiredCopayers, + totalCopayers: totalCopayers + }; + var w = walletFactory.create(opts); + w.on('created', function(){ + $location.path('peer'); + $rootScope.wallet = w; + $rootScope.$digest(); + }); + w.on('openError', function(){ + $scope.loading = false; + $rootScope.flashMessage = {type:'error', message: 'Wallet not found'}; + $location.path('signin'); + }); + w.netStart(); + }; + + }); diff --git a/js/controllers/signin.js b/js/controllers/signin.js index 122cdc02a..4b25c800f 100644 --- a/js/controllers/signin.js +++ b/js/controllers/signin.js @@ -27,12 +27,7 @@ angular.module('copay.signin').controller('SigninController', }; $scope.create = function() { -console.log('[signin.js.42:create:]'); //TODO - $scope.loading = true; - - var w = walletFactory.create(); - _setupUxHandlers(w); - w.netStart(); + $location.path('setup'); }; $scope.open = function(walletId) { diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 1d2141117..98bc6faba 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -22,6 +22,8 @@ function Wallet(opts) { self[k] = opts[k]; }); + console.log('creating '+opts.requiredCopayers+' of '+opts.totalCopayers+' wallet'); + this.id = opts.id || Wallet.getRandomId(); this.publicKeyRing.walletId = this.id; this.txProposals.walletId = this.id; diff --git a/js/routes.js b/js/routes.js index 3793d88bd..5c655b208 100644 --- a/js/routes.js +++ b/js/routes.js @@ -12,6 +12,9 @@ angular .when('/signin', { templateUrl: 'signin.html' }) + .when('/setup', { + templateUrl: 'setup.html' + }) .when('/home', { templateUrl: 'home.html' }) diff --git a/test/test.walletfactory.js b/test/test.Walletfactory.js similarity index 100% rename from test/test.walletfactory.js rename to test/test.Walletfactory.js