copay/js/controllers/create.js

99 lines
2.4 KiB
JavaScript
Raw Normal View History

2014-04-16 13:07:14 -07:00
'use strict';
2014-05-23 13:22:24 -07:00
var valid_pairs = {
'1,1': 112,
'1,2': 147,
'2,2': 220,
'1,3': 182,
'2,3': 256,
'3,3': 329,
'1,4': 216,
'2,4': 290,
'3,4': 363,
'4,4': 436,
'1,5': 250,
'2,5': 324,
'3,5': 398,
'4,5': 470,
'1,6': 284,
'2,6': 358,
'3,6': 432,
'1,7': 318,
'2,7': 392,
'3,7': 465,
'1,8': 353,
'2,8': 427,
'1,9': 387,
'2,9': 461,
'1,10': 421,
'2,10': 495,
'1,11': 455,
'1,12': 489
};
2014-08-29 09:20:47 -07:00
angular.module('copayApp.controllers').controller('CreateController',
2014-06-26 14:22:32 -07:00
function($scope, $rootScope, $location, $timeout, walletFactory, controllerUtils, Passphrase, backupService, notification) {
2014-08-06 14:41:37 -07:00
controllerUtils.redirIfLogged();
2014-04-16 13:07:14 -07:00
2014-08-06 14:21:14 -07:00
$rootScope.fromSetup = true;
2014-04-16 13:07:14 -07:00
$scope.loading = false;
2014-05-01 10:21:55 -07:00
$scope.walletPassword = $rootScope.walletPassword;
$scope.isMobile = !!window.cordova;
2014-08-21 11:54:36 -07:00
$scope.hideAdv = true;
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) {
2014-05-23 13:22:24 -07:00
return new Array(num);
2014-04-30 14:47:44 -07:00
}
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) {
2014-05-23 13:22:24 -07:00
$scope.requiredCopayers = (valid_pairs[[parseInt(n / 2 + 1), n]] > 0 || config.networkName === 'testnet') ?
parseInt(n / 2 + 1) : 1;
2014-04-16 13:07:14 -07:00
$scope.RCValues = [];
for (var m = 1; m <= n; m++) {
2014-05-23 13:22:24 -07:00
if (valid_pairs[[m, n]] > 0 || config.networkName === 'testnet') {
2014-04-16 13:07:14 -07:00
$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-06-26 13:17:24 -07:00
notification.error('Error', 'Please enter the required fields');
return;
}
2014-05-07 14:48:56 -07:00
$scope.loading = true;
2014-05-23 13:22:24 -07:00
Passphrase.getBase64Async($scope.walletPassword, function(passphrase) {
2014-05-07 14:48:56 -07:00
var opts = {
requiredCopayers: $scope.requiredCopayers,
totalCopayers: $scope.totalCopayers,
2014-05-23 13:22:24 -07:00
name: $scope.walletName,
2014-05-07 14:48:56 -07:00
nickname: $scope.myNickname,
passphrase: passphrase,
2014-08-21 11:54:36 -07:00
privateKeyHex: $scope.private,
2014-05-07 14:48:56 -07:00
};
var w = walletFactory.create(opts);
2014-06-12 07:03:24 -07:00
controllerUtils.startNetwork(w, $scope);
2014-05-07 14:48:56 -07:00
});
2014-04-16 13:07:14 -07:00
};
2014-07-17 12:00:58 -07:00
$scope.isSetupWalletPage = 0;
$scope.setupWallet = function() {
$scope.isSetupWalletPage = !$scope.isSetupWalletPage;
};
2014-04-16 13:07:14 -07:00
});