import now working with ledger

Signed-off-by: Matias Alejo Garcia <ematiu@gmail.com>
This commit is contained in:
Matias Alejo Garcia 2015-09-04 21:18:20 -03:00
commit 4d9a477ae5
10 changed files with 148 additions and 47 deletions

View file

@ -106,7 +106,7 @@ angular.module('copayApp.controllers').controller('createController',
});
}
else {
if ( ( opts.mnemonic && opts.n==1) || otps.externalSource ) {
if ( ( opts.mnemonic && opts.n==1) || opts.externalSource ) {
$rootScope.$emit('Local/WalletImported', walletId);
} else {
go.walletHome();

View file

@ -1,12 +1,14 @@
'use strict';
angular.module('copayApp.controllers').controller('importController',
function($scope, $rootScope, $location, $timeout, $log, profileService, notification, go, isMobile, isCordova, sjcl, gettext, lodash) {
function($scope, $rootScope, $location, $timeout, $log, profileService, notification, go, isMobile, isCordova, sjcl, gettext, lodash, ledger) {
var self = this;
this.isSafari = isMobile.Safari();
this.isCordova = isCordova;
this.externalIndexValues = lodash.range(0, ledger.MAX_SLOT);
$scope.externalIndex = 0;
var reader = new FileReader();
window.ignoreMobilePause = true;
@ -80,13 +82,6 @@ angular.module('copayApp.controllers').controller('importController',
}, 100);
};
// {
// network: opts.network,
// m: opts.m,
// n: opts.n,
// publicKeyRing: opts.publicKeyRing,
// },
//
$scope.getFile = function() {
// If we use onloadend, we need to check the readyState.
reader.onloadend = function(evt) {
@ -146,10 +141,12 @@ angular.module('copayApp.controllers').controller('importController',
if (!words) {
this.error = gettext('Please enter the backup words');
} else {
var wordList = words.split(/ /).filter(function(v){ return v.length>0; });
var wordList = words.split(/ /).filter(function(v) {
return v.length > 0;
});
if (wordList.length != 12)
this.error = gettext('Please enter 12 backup words');
else
else
words = wordList.join(' ');
}
@ -166,4 +163,41 @@ angular.module('copayApp.controllers').controller('importController',
_importMnemonic(words, opts);
};
this.importLedger = function(form) {
var self = this;
if (form.$invalid) {
this.error = gettext('There is an error in the form');
$timeout(function() {
$scope.$apply();
});
return;
}
self.ledger = true;
ledger.getInfoForNewWallet($scope.externalIndex, function(err, lopts) {
self.ledger = false;
if (err) {
self.error = err;
$scope.$apply();
return;
}
lopts.externalIndex = $scope.externalIndex;
lopts.externalSource = 'ledger';
self.loading = true;
$log.debug('Import opts', lopts);
profileService.importExtendedPublicKey(lopts, function(err, walletId) {
self.loading = false;
if (err) {
self.error = err;
return $timeout(function() {
$scope.$apply();
});
}
$rootScope.$emit('Local/WalletImported', walletId);
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
go.walletHome();
});
}, 100);
};
});

View file

@ -3,6 +3,7 @@
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettext, amMoment, nodeWebkit, addonManager, feeService, isChromeApp, bwsError, txFormatService, uxLanguage, $state, glideraService) {
var self = this;
self.isCordova = isCordova;
self.isChromeApp = isChromeApp;
self.onGoingProcess = {};
self.limitHistory = 5;
@ -653,16 +654,18 @@ angular.module('copayApp.controllers').controller('indexController', function($r
return str;
}
var step = 6;
function getHistory(skip, cb) {
skip = skip || 0;
fc.getTxHistory({
skip: skip,
limit: 100
limit: step,
}, function(err, txs) {
if (err) return cb(err);
if (txs && txs.length > 0) {
allTxs.push(txs);
return getHistory(skip + 100, cb);
return getHistory(skip + step, cb);
} else {
return cb(null, lodash.flatten(allTxs));
}

View file

@ -4,7 +4,7 @@ angular.module('copayApp.controllers').controller('joinController',
function($scope, $rootScope, $timeout, go, isMobile, notification, profileService, isCordova, isChromeApp, $modal, gettext, lodash, ledger) {
var self = this;
this.externalIndexValues = lodash.range(0,20);
this.externalIndexValues = lodash.range(0,ledger.MAX_SLOT);
$scope.externalIndex = 0;
this.isChromeApp = function() {

View file

@ -25,7 +25,7 @@ angular.module('copayApp.services')
body = gettextCatalog.getString('Copayer already in this wallet');
break;
case 'COPAYER_REGISTERED':
body = gettextCatalog.getString('Copayer already registered');
body = gettextCatalog.getString('Wallet already registered');
break;
case 'COPAYER_VOTED':
body = gettextCatalog.getString('Copayer already voted on this spend proposal');

View file

@ -179,8 +179,9 @@ angular.module('copayApp.services')
}
} else if (opts.extendedPublicKey) {
try {
walletClient.seedFromExternalWalletPublicKey(opts.extendedPublicKey, opts.externalSource, opts.externalIndex, opts.entropySource);
walletClient.seedFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.externalIndex, opts.entropySource);
} catch (ex) {
$log.warn(ex);
return cb(gettext('Could not create using the specified extended public key'));
}
} else {
@ -191,7 +192,7 @@ angular.module('copayApp.services')
$log.info('Error creating seed: ' + e.message);
if (e.message.indexOf('language') > 0) {
$log.info('Using default language for mnemonic');
walletClient.seedFromRandomWithMnemonic(network, opts.passphrase);
walletClient.seedFromRandomWithMnemonic(network, opts.passphrase);
} else {
return cb(e);
}
@ -358,6 +359,26 @@ angular.module('copayApp.services')
});
};
root.importExtendedPublicKey = function(opts, cb) {
var walletClient = bwcService.getClient();
$log.debug('Importing Wallet XPubKey');
walletClient.importFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.externalIndex, opts.entropySource, function(err) {
if (err) {
// in HW wallets, req key is always the same. They can't addAccess.
if (err.code == 'NOT_AUTHORIZED')
err.code = 'WALLET_DOES_NOT_EXIST';
return bwsError.cb(err, gettext('Could not import'), cb);
}
root._addWalletClient(walletClient, cb);
});
};
root.create = function(opts, cb) {
$log.info('Creating profile');
configService.get(function(err) {