Refactored copayers selection on create form
This commit is contained in:
parent
f0301aa12b
commit
33e115d0c2
3 changed files with 52 additions and 43 deletions
|
|
@ -1,37 +1,5 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('CreateController',
|
angular.module('copayApp.controllers').controller('CreateController',
|
||||||
function($scope, $rootScope, $location, $timeout, walletFactory, controllerUtils, Passphrase, backupService, notification) {
|
function($scope, $rootScope, $location, $timeout, walletFactory, controllerUtils, Passphrase, backupService, notification) {
|
||||||
controllerUtils.redirIfLogged();
|
controllerUtils.redirIfLogged();
|
||||||
|
|
@ -49,19 +17,12 @@ angular.module('copayApp.controllers').controller('CreateController',
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.totalCopayers = config.wallet.totalCopayers;
|
$scope.totalCopayers = config.wallet.totalCopayers;
|
||||||
$scope.TCValues = [];
|
$scope.TCValues = _.range(1, config.limits.totalCopayers + 1);
|
||||||
for (var n = 1; n <= config.limits.totalCopayers; n++)
|
|
||||||
$scope.TCValues.push(n);
|
|
||||||
|
|
||||||
var updateRCSelect = function(n) {
|
var updateRCSelect = function(n) {
|
||||||
$scope.requiredCopayers = (valid_pairs[[parseInt(n / 2 + 1), n]] > 0 || config.networkName === 'testnet') ?
|
var maxReq = copay.Wallet.getMaxRequiredCopayers(n);
|
||||||
parseInt(n / 2 + 1) : 1;
|
$scope.RCValues = _.range(1, maxReq + 1);
|
||||||
$scope.RCValues = [];
|
$scope.requiredCopayers = Math.min(parseInt(n / 2 + 1), maxReq);
|
||||||
for (var m = 1; m <= n; m++) {
|
|
||||||
if (valid_pairs[[m, n]] > 0 || config.networkName === 'testnet') {
|
|
||||||
$scope.RCValues.push(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
updateRCSelect($scope.totalCopayers);
|
updateRCSelect($scope.totalCopayers);
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,21 @@ Wallet.PERSISTED_PROPERTIES = [
|
||||||
'lastTimestamp',
|
'lastTimestamp',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Wallet.VALID_COPAYER_PAIRS = {
|
||||||
|
1: 1,
|
||||||
|
2: 2,
|
||||||
|
3: 3,
|
||||||
|
4: 4,
|
||||||
|
5: 4,
|
||||||
|
6: 3,
|
||||||
|
7: 3,
|
||||||
|
8: 2,
|
||||||
|
9: 2,
|
||||||
|
10: 2,
|
||||||
|
11: 1,
|
||||||
|
12: 1,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Retrieve a random id for the wallet
|
* @desc Retrieve a random id for the wallet
|
||||||
* @TODO: Discuss changing to a UUID
|
* @TODO: Discuss changing to a UUID
|
||||||
|
|
@ -151,6 +166,18 @@ Wallet.getRandomNumber = function() {
|
||||||
return r;
|
return r;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc
|
||||||
|
* Get the maximum allowed number of required copayers.
|
||||||
|
* This is a limit imposed by the maximum allowed size of the scriptSig.
|
||||||
|
* @param {number} totalCopayers - the total number of copayers
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
Wallet.getMaxRequiredCopayers = function(totalCopayers) {
|
||||||
|
return Wallet.VALID_COPAYER_PAIRS[totalCopayers];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Set the copayer id for the owner of this wallet
|
* @desc Set the copayer id for the owner of this wallet
|
||||||
* @param {string} pubkey - the pubkey to set to the {@link Wallet#seededCopayerId} property
|
* @param {string} pubkey - the pubkey to set to the {@link Wallet#seededCopayerId} property
|
||||||
|
|
|
||||||
|
|
@ -393,6 +393,27 @@ describe('Wallet model', function() {
|
||||||
w.maxRejectCount().should.equal(2);
|
w.maxRejectCount().should.equal(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#getMaxRequiredCopayers', function() {
|
||||||
|
it('should return ', function() {
|
||||||
|
var validPairs = {
|
||||||
|
1: 1,
|
||||||
|
2: 2,
|
||||||
|
3: 3,
|
||||||
|
4: 4,
|
||||||
|
5: 4,
|
||||||
|
6: 3,
|
||||||
|
7: 3,
|
||||||
|
8: 2,
|
||||||
|
9: 2,
|
||||||
|
10: 2,
|
||||||
|
11: 1,
|
||||||
|
12: 1,
|
||||||
|
};
|
||||||
|
_.each(validPairs, function(maxReq, total) {
|
||||||
|
Wallet.getMaxRequiredCopayers(total).should.equal(maxReq);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('#_onData', function() {
|
describe('#_onData', function() {
|
||||||
var w = cachedCreateW();
|
var w = cachedCreateW();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue