Wallet/js/controllers/create.js

71 lines
2.3 KiB
JavaScript
Raw Normal View History

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-10-14 15:35:46 -03:00
function($scope, $rootScope, $location, $timeout, walletFactory, controllerUtils, Passphrase, backupService, notification, defaults) {
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;
$scope.isMobile = !!window.cordova;
2014-08-21 14:54:36 -04:00
$scope.hideAdv = true;
$scope.networkName = config.networkName;
$scope.networkUrl = config.network[$scope.networkName].url;
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;
$scope.TCValues = _.range(1, config.limits.totalCopayers + 1);
2014-04-16 17:07:14 -03:00
var updateRCSelect = function(n) {
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-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
$scope.$watch('networkName', function(tc) {
$scope.networkUrl = config.network[$scope.networkName].url;
});
2014-10-14 15:33:52 -03:00
$scope.showNetwork = function(){
return $scope.networkUrl != defaults.livenetUrl && $scope.networkUrl != defaults.testnetUrl;
};
$scope.create = function(form) {
if (form && form.$invalid) {
2014-06-26 17:17:24 -03:00
notification.error('Error', 'Please enter the required fields');
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,
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
});