copay/js/controllers/setup.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-04-16 13:07:14 -07:00
'use strict';
angular.module('copay.setup').controller('SetupController',
2014-05-07 14:48:56 -07:00
function($scope, $rootScope, $location, $timeout, walletFactory, controllerUtils, Passphrase) {
2014-04-16 13:07:14 -07:00
$rootScope.videoInfo = {};
2014-04-16 13:07:14 -07:00
$scope.loading = false;
2014-05-01 10:21:55 -07:00
$scope.walletPassword = $rootScope.walletPassword;
2014-04-16 13:07:14 -07:00
2014-04-30 14:47:44 -07:00
// ng-repeat defined number of times instead of repeating over array?
$scope.getNumber = function(num) {
return new Array(num);
}
2014-04-16 13:07:14 -07:00
$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);
}
}
};
2014-04-16 13:07:14 -07:00
updateRCSelect($scope.totalCopayers);
$scope.$watch('totalCopayers', function(tc) {
updateRCSelect(tc);
2014-04-18 15:08:01 -07:00
});
2014-04-16 13:07:14 -07:00
$scope.create = function(form) {
if (form && form.$invalid) {
2014-05-20 08:30:20 -07:00
$rootScope.$flashMessage = { message: 'Please, enter required fields', type: 'error'};
return;
}
2014-05-07 14:48:56 -07:00
$scope.loading = true;
Passphrase.getBase64Async($scope.walletPassword, function(passphrase){
var opts = {
requiredCopayers: $scope.requiredCopayers,
totalCopayers: $scope.totalCopayers,
name: $scope.walletName,
nickname: $scope.myNickname,
passphrase: passphrase,
};
var w = walletFactory.create(opts);
controllerUtils.startNetwork(w);
});
2014-04-16 13:07:14 -07:00
};
});