Merge pull request #3239 from matiu/feat/trezor

Trezor Support
This commit is contained in:
Gustavo Maximiliano Cortez 2015-10-02 19:29:03 -03:00
commit 006377d38f
12 changed files with 779 additions and 96 deletions

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('createController',
function($scope, $rootScope, $location, $timeout, $log, lodash, go, profileService, configService, isMobile, isCordova, gettext, isChromeApp, ledger) {
function($scope, $rootScope, $location, $timeout, $log, lodash, go, profileService, configService, isCordova, gettext, ledger, trezor, isMobile) {
var self = this;
var defaults = configService.getDefaults();
@ -42,10 +42,6 @@ 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');
@ -76,11 +72,15 @@ angular.module('copayApp.controllers').controller('createController',
return;
}
if (form.hwLedger.$modelValue) {
self.ledger = true;
if (form.hwLedger.$modelValue || form.hwTrezor.$modelValue) {
self.hwWallet = form.hwLedger.$modelValue ? 'Ledger' : 'TREZOR';
var src= form.hwLedger.$modelValue ? ledger : trezor;
// TODO : account
ledger.getInfoForNewWallet(0, function(err, lopts) {
self.ledger = false;
var account = 0;
src.getInfoForNewWallet(account, function(err, lopts) {
self.hwWallet = false;
if (err) {
self.error = err;
$scope.$apply();

View file

@ -1,12 +1,11 @@
'use strict';
angular.module('copayApp.controllers').controller('importController',
function($scope, $rootScope, $location, $timeout, $log, profileService, notification, go, isMobile, isCordova, sjcl, gettext, lodash, ledger) {
function($scope, $rootScope, $location, $timeout, $log, profileService, notification, go, isMobile, sjcl, gettext, lodash, ledger, trezor) {
var self = this;
this.isSafari = isMobile.Safari();
this.isCordova = isCordova;
var reader = new FileReader();
window.ignoreMobilePause = true;
@ -182,6 +181,44 @@ angular.module('copayApp.controllers').controller('importController',
_importMnemonic(words, opts);
};
this.importTrezor = function(form) {
var self = this;
if (form.$invalid) {
this.error = gettext('There is an error in the form');
$timeout(function() {
$scope.$apply();
});
return;
}
self.hwWallet = 'Trezor';
// TODO account
trezor.getInfoForNewWallet(0, function(err, lopts) {
self.hwWallet = false;
if (err) {
self.error = err;
$scope.$apply();
return;
}
lopts.externalSource = 'trezor';
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);
};
this.importLedger = function(form) {
var self = this;
if (form.$invalid) {
@ -191,16 +228,15 @@ angular.module('copayApp.controllers').controller('importController',
});
return;
}
self.ledger = true;
self.hwWallet = 'Ledger';
// TODO account
ledger.getInfoForNewWallet(0, function(err, lopts) {
self.ledger = false;
self.hwWallet = false;
if (err) {
self.error = err;
$scope.$apply();
return;
}
lopts.externalIndex = $scope.externalIndex;
lopts.externalSource = 'ledger';
self.loading = true;
$log.debug('Import opts', lopts);

View file

@ -1,14 +1,10 @@
'use strict';
angular.module('copayApp.controllers').controller('joinController',
function($scope, $rootScope, $timeout, go, isMobile, notification, profileService, isCordova, isChromeApp, $modal, gettext, lodash, ledger) {
function($scope, $rootScope, $timeout, go, notification, profileService, isCordova, $modal, gettext, lodash, ledger, trezor) {
var self = this;
this.isChromeApp = function() {
return isChromeApp;
};
this.onQrCodeScanned = function(data) {
$scope.secret = data;
$scope.joinForm.secret.$setViewValue(data);
@ -45,11 +41,13 @@ angular.module('copayApp.controllers').controller('joinController',
return;
}
if (form.hwLedger.$modelValue) {
self.ledger = true;
// TODO account
ledger.getInfoForNewWallet(0, function(err, lopts) {
self.ledger = false;
if (form.hwLedger.$modelValue || form.hwTrezor.$modelValue) {
self.hwWallet = form.hwLedger.$modelValue ? 'Ledger' : 'TREZOR';
var src= form.hwLedger.$modelValue ? ledger : trezor;
var account = 0;
src.getInfoForNewWallet(account, function(err, lopts) {
self.hwWallet = false;
if (err) {
self.error = err;
$scope.$apply();

View file

@ -1220,4 +1220,5 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this.setAddress();
this.setSendFormInputs();
}
});