copay/js/controllers/create.js

60 lines
1.9 KiB
JavaScript
Raw Normal View History

'use strict';
angular.module('copayApp.controllers').controller('CreateController',
2014-11-29 13:35:48 -08:00
function($scope, $rootScope, $location, $timeout, identityService, backupService, notification, defaults) {
$rootScope.fromSetup = true;
$scope.loading = false;
$scope.walletPassword = $rootScope.walletPassword;
$scope.isMobile = !!window.cordova;
$scope.hideAdv = true;
$scope.networkName = config.networkName;
2014-11-13 10:33:14 -08:00
$rootScope.title = 'Create new wallet';
// ng-repeat defined number of times instead of repeating over array?
$scope.getNumber = function(num) {
return new Array(num);
}
$scope.totalCopayers = config.wallet.totalCopayers;
$scope.TCValues = _.range(1, config.limits.totalCopayers + 1);
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);
};
updateRCSelect($scope.totalCopayers);
$scope.$watch('totalCopayers', function(tc) {
updateRCSelect(tc);
});
2014-10-16 06:30:49 -07:00
$scope.$watch('networkName', function(tc) {
$scope.networkUrl = config.network[$scope.networkName].url;
});
$scope.showNetwork = function() {
return $scope.networkUrl != defaults.network.livenet.url && $scope.networkUrl != defaults.network.testnet.url;
};
$scope.create = function(form) {
if (form && form.$invalid) {
notification.error('Error', 'Please enter the required fields');
return;
}
$scope.loading = true;
var opts = {
requiredCopayers: $scope.requiredCopayers,
totalCopayers: $scope.totalCopayers,
name: $scope.walletName,
privateKeyHex: $scope.private,
networkName: $scope.networkName,
};
2014-11-29 13:35:48 -08:00
identityService.createWallet(opts, function(){
2014-10-07 14:33:55 -07:00
$scope.loading = false;
});
};
});