Merge pull request #69 from maraoz/feature/setup-view

Feature/setup view
This commit is contained in:
Ryan X. Charles 2014-04-16 21:54:50 -03:00
commit e7fbc29ccb
8 changed files with 95 additions and 6 deletions

View File

@ -96,6 +96,40 @@
</div>
</script>
<script type="text/ng-template" id="setup.html">
<div ng-controller="SetupController">
<div class="panel callout radius" ng-show="loading">
Connecting to wallet...
</div>
<div ng-show="!loading">
<h2>Create new multisig wallet</h2>
<div class="row">
<div class="large-6 columns">
<h3>Select total number of copayers</h3>
<select ng-model="totalCopayers"
ng-options="totalCopayers as totalCopayers for totalCopayers in TCValues">
</select>
</div>
</div>
<hr>
<div class="row">
<div class="large-6 columns">
<h3>Select required number of copayers</h3>
<select ng-model="requiredCopayers"
ng-options="requiredCopayers as requiredCopayers for requiredCopayers in RCValues">
</select>
</div>
<div class="large-3 columns">
<button class="button primary expand round" type="button"
ng-click="create(totalCopayers, requiredCopayers)">
Create {{requiredCopayers}}-of-{{totalCopayers}} wallet
</button>
</div>
</div>
</div>
</div>
</script>
<script type="text/ng-template" id="peer.html">
<div class="row" ng-controller="PeerController" ng-init="init()">
<div class="large-6 columns">
@ -298,6 +332,7 @@
<script src="js/controllers/send.js"></script>
<script src="js/controllers/backup.js"></script>
<script src="js/controllers/signin.js"></script>
<script src="js/controllers/setup.js"></script>
<script src="js/controllers/peer.js"></script>
<script src="js/init.js"></script>

View File

@ -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', []);

View File

@ -7,6 +7,10 @@ var config = {
maxPeers: 3,
debug: 3,
},
limits: {
totalCopayers: 10,
mPlusN: 15
},
wallet: {
requiredCopayers: 2,
totalCopayers: 3,

48
js/controllers/setup.js Normal file
View File

@ -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();
};
});

View File

@ -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) {

View File

@ -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;

View File

@ -12,6 +12,9 @@ angular
.when('/signin', {
templateUrl: 'signin.html'
})
.when('/setup', {
templateUrl: 'setup.html'
})
.when('/home', {
templateUrl: 'home.html'
})