Ledger hardware wallet support
This commit is contained in:
parent
e3831fe9c6
commit
d3f77b37ad
9 changed files with 693 additions and 23 deletions
|
|
@ -1,12 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('createController',
|
||||
function($scope, $rootScope, $location, $timeout, $log, lodash, go, profileService, configService, isMobile, isCordova, gettext) {
|
||||
function($scope, $rootScope, $location, $timeout, $log, lodash, go, profileService, configService, isMobile, isCordova, gettext, isChromeApp, ledger) {
|
||||
|
||||
var self = this;
|
||||
var defaults = configService.getDefaults();
|
||||
this.isWindowsPhoneApp = isMobile.Windows() && isCordova;
|
||||
|
||||
|
||||
/* For compressed keys, m*73 + n*34 <= 496 */
|
||||
var COPAYER_PAIR_LIMITS = {
|
||||
1: 1,
|
||||
|
|
@ -35,6 +35,8 @@ angular.module('copayApp.controllers').controller('createController',
|
|||
$scope.requiredCopayers = Math.min(parseInt(n / 2 + 1), maxReq);
|
||||
};
|
||||
|
||||
this.externatIndexValues = lodash.range(0,20);
|
||||
$scope.externalIndex = 0;
|
||||
this.TCValues = lodash.range(2, defaults.limits.totalCopayers + 1);
|
||||
$scope.totalCopayers = defaults.wallet.totalCopayers;
|
||||
|
||||
|
|
@ -42,6 +44,10 @@ angular.module('copayApp.controllers').controller('createController',
|
|||
updateRCSelect(tc);
|
||||
};
|
||||
|
||||
this.isChromeApp = function() {
|
||||
return isChromeApp;
|
||||
};
|
||||
|
||||
this.create = function(form) {
|
||||
if (form && form.$invalid) {
|
||||
this.error = gettext('Please enter the required fields');
|
||||
|
|
@ -53,14 +59,40 @@ angular.module('copayApp.controllers').controller('createController',
|
|||
name: form.walletName.$modelValue,
|
||||
extendedPrivateKey: form.privateKey.$modelValue,
|
||||
myName: $scope.totalCopayers > 1 ? form.myName.$modelValue : null,
|
||||
networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet'
|
||||
networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet',
|
||||
};
|
||||
self.loading = true;
|
||||
|
||||
if (form.hwLedger.$modelValue) {
|
||||
self.ledger = true;
|
||||
ledger.getXPubKey($scope.externalIndex, function(data) {
|
||||
self.ledger = false;
|
||||
$scope.$apply();
|
||||
if (data.success) {
|
||||
opts.extendedPublicKey = data.xpubkey;
|
||||
opts.externalSource = 'ledger';
|
||||
opts.externalIndex = $scope.externalIndex;
|
||||
self._create(opts);
|
||||
} else {
|
||||
self.loading = false;
|
||||
$log.debug(data.message);
|
||||
self.error = data.message;
|
||||
$scope.$apply();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
self._create(opts);
|
||||
}
|
||||
};
|
||||
|
||||
this._create = function (opts) {
|
||||
$timeout(function() {
|
||||
profileService.createWallet(opts, function(err, secret) {
|
||||
self.loading = false;
|
||||
if (err) {
|
||||
if (err == "Error creating wallet" && opts.extendedPublicKey) {
|
||||
err = "This xpub index is already used by another wallet. Please select another index."
|
||||
}
|
||||
$log.debug(err);
|
||||
self.error = err;
|
||||
$timeout(function() {
|
||||
|
|
@ -72,7 +104,7 @@ angular.module('copayApp.controllers').controller('createController',
|
|||
}
|
||||
});
|
||||
}, 100);
|
||||
};
|
||||
}
|
||||
|
||||
this.formFocus = function(what) {
|
||||
if (!this.isWindowsPhoneApp) return
|
||||
|
|
@ -82,7 +114,7 @@ angular.module('copayApp.controllers').controller('createController',
|
|||
this.hideTabs = true;
|
||||
}
|
||||
else if (what && what == 'wallet-name'){
|
||||
this.hideTabs = true;
|
||||
this.hideTabs = true;
|
||||
}
|
||||
else {
|
||||
this.hideWalletName = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue