create working for ledger

This commit is contained in:
Matias Alejo Garcia 2015-11-04 01:54:54 -03:00
parent d1c1638b14
commit f633a15a2d
6 changed files with 56 additions and 52 deletions

View File

@ -100,7 +100,16 @@
</div>
<div ng-hide="hideAdv" class="row">
<div class="large-12 medium-12 columns">
<div class="large-12 columns">
<label for="bws" class="oh">
<span>Wallet Service URL</span>
<input type="text" id="bwsurl" name="bwsurl" ng-model="bwsurl">
</label>
</div>
<div class="large-12 columns">
<label><span translate>Wallet Seed</span>
<select class="m10t" ng-model="seedSource"
ng-options="seed as seed.label for seed in create.seedOptions"
@ -110,29 +119,14 @@
</div>
<div class="large-12 columns">
<label ng-show="index.isChromeApp && totalCopayers > 1 " for="hw-ledger" class="oh">
<span translate>Use Ledger hardware wallet</span>
<switch id="hw-ledger" name="hwLedger" ng-model="hwLedger" ng-change="isTestnet=false" class="green right m5t m10b"></switch>
</label>
<!-- -->
<label ng-show="!index.isCordova && 0" for="hw-trezor" class="oh">
<span translate>Use TREZOR hardware wallet</span>
<switch id="hw-trezor" name="hwTrezor" ng-model="hwTrezor" class="green right m5t m10b"></switch>
</label>
<!-- TODO account
<div ng-show="hwLedger">
<label class="oh"><span translate>Ledger Slot</span>
<select class="m10t" ng-model="externalIndex" ng-options="externalIndex as externalIndex for externalIndex in create.externalIndexValues">
<div ng-show="create.seedSourceId == 'trezor' || create.seedSourceId == 'ledger'">
<label class="oh"><span translate>Account</span>
<select class="m10t" ng-model="account" ng-options="externalIndex as externalIndex for externalIndex in create.accountValues">
</select>
</label>
<div class="oh text-gray line-b size-12 p10b m20b"><span translate>Ledger supports up to 20 Copay wallets simultaneously. Select which slot should be used to host this wallet</div>
<div class="oh text-gray line-b size-12 p10b m20b"><span translate>Multiple wallets accounts are supported on the device simultaneously. Select which account should be used for this wallet</div>
</div>
-->
<label for="network-name" class="oh" ng-show="!hwLedger && !hwTrezor">
<span translate>Testnet</span>
<switch id="network-name" name="isTestnet" ng-model="isTestnet" class="green right m5t m10b"></switch>
</label>
<label for="createPassphrase" class="oh" ng-show="create.seedSourceId=='new' " ><span translate>Add a Seed Passphrase</span> <small translate>Add an optional passphrase to secure the seed</small>
<div class="input">
<input type="text" class="form-control"
@ -152,15 +146,15 @@
<input type="text" class="form-control" name="passphrase" ng-model="passphrase">
</div>
</label>
<label for="bws" class="oh">
<span>Wallet Service URL</span>
<input type="text" id="bwsurl" name="bwsurl" ng-model="bwsurl">
<label for="network-name" class="oh" ng-show="create.seedSourceId == 'set' || create.seedSourceId == 'new'">
<span translate>Testnet</span>
<switch id="network-name" name="isTestnet" ng-model="isTestnet" class="green right m5t m10b"></switch>
</label>
</div>
</div>
<div class="box-notification" ng-show="!setSeed && createPassphrase">
</div>
<div class="box-notification" ng-show="create.seedSourceId=='new' && createPassphrase">
<span class="text-warning size-14">
<i class="fi-alert"></i>
<span translate>
@ -168,8 +162,7 @@
</span>
</span>
</div>
</div>
<button type="submit" class="button round black expand m0" ng-show="totalCopayers != 1" ng-disabled="setupForm.$invalid || create.loading || create.hwWallet">
<span translate>Create {{requiredCopayers}}-of-{{totalCopayers}} wallet</span>

View File

@ -49,9 +49,8 @@ angular.module('copayApp.controllers').controller('createController',
}];
$scope.seedSource = self.seedOptions[0];
// TODO
// if (!isChromeApp) return;
// TODO
// if (!isChromeApp) return;
if (n > 1)
self.seedOptions.push({
@ -63,6 +62,7 @@ angular.module('copayApp.controllers').controller('createController',
id: 'trezor',
label: gettext('Trezor Hardware Wallet'),
});
};
this.TCValues = lodash.range(2, defaults.limits.totalCopayers + 1);
@ -71,12 +71,18 @@ angular.module('copayApp.controllers').controller('createController',
this.setTotalCopayers = function(tc) {
updateRCSelect(tc);
updateSeedSourceSelect(tc);
self.seedSourceId = $scope.seedSource.id;
};
this.setSeedSource = function(src) {
self.seedSourceId = $scope.seedSource.id;
console.log('[create.js.78:seedSourceId:]',self.seedSourceId); //TODO
if (self.seedSourceId == 'ledger')
self.accountValues = lodash.range(0, 99);
else
self.accountValues = lodash.range(1, 100);
$timeout(function() {
$rootScope.$apply();
});
@ -95,7 +101,7 @@ console.log('[create.js.78:seedSourceId:]',self.seedSourceId); //TODO
networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet',
bwsurl: $scope.bwsurl
};
var setSeed = form.setSeed.$modelValue;
var setSeed = self.seedSourceId =='set';
if (setSeed) {
var words = form.privateKey.$modelValue;
if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
@ -113,12 +119,16 @@ console.log('[create.js.78:seedSourceId:]',self.seedSourceId); //TODO
return;
}
if (form.hwLedger.$modelValue || form.hwTrezor.$modelValue) {
self.hwWallet = form.hwLedger.$modelValue ? 'Ledger' : 'TREZOR';
var src = form.hwLedger.$modelValue ? ledger : trezor;
if (self.seedSourceId == 'ledger' || self.seedSourceId == 'trezor') {
var account = $scope.account;
if (!account) {
this.error = gettext('Please select account');
return;
}
self.hwWallet = self.seedSourceId == 'ledger' ? 'Ledger' : 'Trezor';
var src = self.seedSourceId == 'ledger' ? ledger : trezor;
var account = form.account.$modelValue;
src.getInfoForNewWallet(opts.n > 1, account, function(err, lopts) {
self.hwWallet = false;
if (err) {
@ -178,4 +188,5 @@ console.log('[create.js.78:seedSourceId:]',self.seedSourceId); //TODO
$rootScope.hideWalletNavigation = false;
});
updateSeedSourceSelect(1);
self.seedSourceId = 'new'
});

View File

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.services')
.factory('hwWallet', function($log) {
.factory('hwWallet', function($log, bwcService) {
var root = {};
// Ledger magic number to get xPub without user confirmation
@ -11,7 +11,7 @@ angular.module('copayApp.services')
root.LIVENET_PATH = 0;
root._err = function(data) {
var msg = 'HW WALLET Error: ' + (data.error || data.message || 'unknown');
var msg = 'Hardware Wallet Error: ' + (data.error || data.message || 'unknown');
$log.warn(msg);
return msg;
};
@ -23,8 +23,7 @@ angular.module('copayApp.services')
root.getEntropyPath = function(isMultisig, account) {
var rootPath = isMultisig ? root.MULTISIG_ROOTPATH : root.UNISIG_ROOTPATH;
var path = hwWallet.ENTROPY_INDEX_PATH + rootPath + "'/"
account + "'";
var path = root.ENTROPY_INDEX_PATH + rootPath + "'/" + account + "'";
return path;
};

View File

@ -40,7 +40,7 @@ angular.module('copayApp.services')
root.getInfoForNewWallet = function(isMultisig, account, callback) {
var opts = {};
root.getEntropySource(isMultisig, account, function(entropySource) {
root.getEntropySource(isMultisig, account, function(err, entropySource) {
if (err) return callback(err);
opts.entropySource = entropySource;
@ -51,7 +51,7 @@ angular.module('copayApp.services')
}
opts.extendedPublicKey = data.xpubkey;
opts.externalSource = 'ledger';
opts.externalIndex = account;
opts.account = account;
return callback(null, opts);
});
});

View File

@ -181,7 +181,7 @@ angular.module('copayApp.services')
walletClient.seedFromMnemonic(opts.mnemonic, {
network: network,
passphrase: opts.passphrase,
account: 0,
account: opts.account || 0,
});
} catch (ex) {
$log.info(ex);
@ -197,7 +197,7 @@ angular.module('copayApp.services')
} else if (opts.extendedPublicKey) {
try {
walletClient.seedFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, {
account: 0
account: opts.account || 0,
});
} catch (ex) {
$log.warn("Creating wallet from Extended Public Key Arg:", ex, opts);
@ -420,7 +420,7 @@ angular.module('copayApp.services')
walletClient.importFromMnemonic(words, {
network: opts.networkName,
passphrase: opts.passphrase,
account: 0,
account: opts.account,
}, function(err) {
if (err)
return bwsError.cb(err, gettext('Could not import'), cb);
@ -437,7 +437,7 @@ angular.module('copayApp.services')
$log.debug('Importing Wallet XPubKey');
walletClient.importFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, {
account: 0
account: opts.account || 0,
}, function(err) {
if (err) {

View File

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.services')
.factory('trezor', function($log, $timeout, bwcService, gettext, lodash, bitcore, hwWallet) {
.factory('trezor', function($log, $timeout, gettext, lodash, bitcore, hwWallet) {
var root = {};
var SETTLE_TIME = 3000;
@ -24,10 +24,11 @@ angular.module('copayApp.services')
root.getInfoForNewWallet = function(isMultisig, account, callback) {
account = account - 1;
var opts = {};
root.getEntropySource(isMultisig, account, function(err, data) {
if (err) return callback(err);
opts.entropySource = data.entropySource;
opts.entropySource = data;
$log.debug('Waiting TREZOR to settle...');
$timeout(function() {
@ -37,7 +38,7 @@ angular.module('copayApp.services')
opts.extendedPublicKey = data.xpubkey;
opts.externalSource = 'trezor';
opts.externalIndex = account;
opts.account = account;
return callback(null, opts);
});
}, SETTLE_TIME);