2014-04-16 17:07:14 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2014-08-29 13:20:47 -03:00
|
|
|
angular.module('copayApp.controllers').controller('CreateController',
|
2014-06-26 18:22:32 -03:00
|
|
|
function($scope, $rootScope, $location, $timeout, walletFactory, controllerUtils, Passphrase, backupService, notification) {
|
2014-08-06 18:41:37 -03:00
|
|
|
controllerUtils.redirIfLogged();
|
2014-04-16 17:07:14 -03:00
|
|
|
|
2014-08-06 18:21:14 -03:00
|
|
|
$rootScope.fromSetup = true;
|
2014-04-16 17:07:14 -03:00
|
|
|
$scope.loading = false;
|
2014-05-01 14:21:55 -03:00
|
|
|
$scope.walletPassword = $rootScope.walletPassword;
|
2014-08-15 15:47:13 -03:00
|
|
|
$scope.isMobile = !!window.cordova;
|
2014-08-21 14:54:36 -04:00
|
|
|
$scope.hideAdv = true;
|
2014-09-09 13:00:30 -07:00
|
|
|
$scope.networkName = config.networkName;
|
2014-04-16 17:07:14 -03:00
|
|
|
|
2014-04-30 18:47:44 -03:00
|
|
|
// ng-repeat defined number of times instead of repeating over array?
|
|
|
|
|
$scope.getNumber = function(num) {
|
2014-05-23 17:22:24 -03:00
|
|
|
return new Array(num);
|
2014-04-30 18:47:44 -03:00
|
|
|
}
|
|
|
|
|
|
2014-04-16 17:07:14 -03:00
|
|
|
$scope.totalCopayers = config.wallet.totalCopayers;
|
2014-09-30 13:04:48 -03:00
|
|
|
$scope.TCValues = _.range(1, config.limits.totalCopayers + 1);
|
2014-04-16 17:07:14 -03:00
|
|
|
|
|
|
|
|
var updateRCSelect = function(n) {
|
2014-09-30 13:04:48 -03:00
|
|
|
var maxReq = copay.Wallet.getMaxRequiredCopayers(n);
|
|
|
|
|
$scope.RCValues = _.range(1, maxReq + 1);
|
|
|
|
|
$scope.requiredCopayers = Math.min(parseInt(n / 2 + 1), maxReq);
|
2014-04-16 17:07:14 -03:00
|
|
|
};
|
2014-04-18 15:22:02 -03:00
|
|
|
|
2014-04-16 17:07:14 -03:00
|
|
|
updateRCSelect($scope.totalCopayers);
|
|
|
|
|
|
|
|
|
|
$scope.$watch('totalCopayers', function(tc) {
|
|
|
|
|
updateRCSelect(tc);
|
2014-04-18 19:08:01 -03:00
|
|
|
});
|
2014-04-16 17:07:14 -03:00
|
|
|
|
2014-05-06 15:06:37 -03:00
|
|
|
$scope.create = function(form) {
|
|
|
|
|
if (form && form.$invalid) {
|
2014-06-26 17:17:24 -03:00
|
|
|
notification.error('Error', 'Please enter the required fields');
|
2014-05-06 15:06:37 -03:00
|
|
|
return;
|
|
|
|
|
}
|
2014-05-07 18:48:56 -03:00
|
|
|
$scope.loading = true;
|
2014-05-23 17:22:24 -03:00
|
|
|
Passphrase.getBase64Async($scope.walletPassword, function(passphrase) {
|
2014-05-07 18:48:56 -03:00
|
|
|
var opts = {
|
|
|
|
|
requiredCopayers: $scope.requiredCopayers,
|
|
|
|
|
totalCopayers: $scope.totalCopayers,
|
2014-05-23 17:22:24 -03:00
|
|
|
name: $scope.walletName,
|
2014-05-07 18:48:56 -03:00
|
|
|
nickname: $scope.myNickname,
|
|
|
|
|
passphrase: passphrase,
|
2014-08-21 14:54:36 -04:00
|
|
|
privateKeyHex: $scope.private,
|
2014-09-09 17:15:52 -07:00
|
|
|
networkName: $scope.networkName,
|
2014-05-07 18:48:56 -03:00
|
|
|
};
|
2014-09-03 15:43:27 -03:00
|
|
|
walletFactory.create(opts, function(err, w) {
|
|
|
|
|
controllerUtils.startNetwork(w, $scope);
|
|
|
|
|
});
|
2014-05-07 18:48:56 -03:00
|
|
|
});
|
2014-04-16 17:07:14 -03:00
|
|
|
};
|
|
|
|
|
|
2014-07-17 16:00:58 -03:00
|
|
|
$scope.isSetupWalletPage = 0;
|
|
|
|
|
|
|
|
|
|
$scope.setupWallet = function() {
|
|
|
|
|
$scope.isSetupWalletPage = !$scope.isSetupWalletPage;
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-16 17:07:14 -03:00
|
|
|
});
|