import working

This commit is contained in:
Matias Alejo Garcia 2015-11-04 15:45:33 -03:00
commit aef26ed992
9 changed files with 413 additions and 322 deletions

View file

@ -48,9 +48,8 @@ angular.module('copayApp.controllers').controller('createController',
label: gettext('Specify Seed...'),
}];
$scope.seedSource = self.seedOptions[0];
// TODO
// if (!isChromeApp) return;
// TODO
// if (!isChromeApp) return;
if (n > 1)
self.seedOptions.push({
@ -187,6 +186,7 @@ angular.module('copayApp.controllers').controller('createController',
$scope.$on("$destroy", function() {
$rootScope.hideWalletNavigation = false;
});
updateSeedSourceSelect(1);
self.seedSourceId = 'new'
self.setSeedSource('new');
});

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('importController',
function($scope, $rootScope, $location, $timeout, $log, profileService, configService, notification, go, sjcl, gettext, lodash, ledger, trezor) {
function($scope, $rootScope, $location, $timeout, $log, profileService, configService, notification, go, sjcl, gettext, lodash, ledger, trezor, isChromeApp) {
var self = this;
var reader = new FileReader();
@ -15,6 +15,25 @@ angular.module('copayApp.controllers').controller('importController',
}, 100);
});
var updateSeedSourceSelect = function() {
self.seedOptions = [];
// TODO
// if (!isChromeApp) return;
self.seedOptions.push({
id: 'ledger',
label: gettext('Ledger Hardware Wallet'),
});
self.seedOptions.push({
id: 'trezor',
label: gettext('Trezor Hardware Wallet'),
});
$scope.seedSource = self.seedOptions[0];
};
this.setType = function(type) {
$scope.type = type;
this.error = null;
@ -178,19 +197,8 @@ angular.module('copayApp.controllers').controller('importController',
_importMnemonic(words, opts);
};
this.importTrezor = function(form) {
this.importTrezor = function(account, isMultisig) {
var self = this;
if (form.$invalid) {
this.error = gettext('There is an error in the form');
$timeout(function() {
$scope.$apply();
});
return;
}
self.hwWallet = 'Trezor';
var account = form.account.$modelValue;
var isMultisig = form.isMultisig.$modelValue;
trezor.getInfoForNewWallet(isMultisig, account, function(err, lopts) {
self.hwWallet = false;
if (err) {
@ -219,8 +227,7 @@ angular.module('copayApp.controllers').controller('importController',
}, 100);
};
this.importLedger = function(form) {
var self = this;
this.importHW = function(form) {
if (form.$invalid) {
this.error = gettext('There is an error in the form');
$timeout(function() {
@ -228,8 +235,40 @@ angular.module('copayApp.controllers').controller('importController',
});
return;
}
self.hwWallet = 'Ledger';
var account = form.account.$modelValue;
var account = $scope.account;
var isMultisig = form.isMultisig.$modelValue;
switch (self.seedSourceId) {
case ('ledger'):
self.hwWallet = 'Ledger';
self.importLedger(account);
break;
case ('trezor'):
self.hwWallet = 'Trezor';
self.importTrezor(account, isMultisig);
break;
default:
throw ('Error: bad source id');
};
};
this.setSeedSource = function() {
if (!$scope.seedSource) return;
self.seedSourceId = $scope.seedSource.id;
if (self.seedSourceId == 'ledger')
self.accountValues = lodash.range(0, 99);
else
self.accountValues = lodash.range(1, 100);
$timeout(function() {
$rootScope.$apply();
});
};
this.importLedger = function(account) {
var self = this;
ledger.getInfoForNewWallet(true, account, function(err, lopts) {
self.hwWallet = false;
if (err) {
@ -257,4 +296,6 @@ angular.module('copayApp.controllers').controller('importController',
}, 100);
};
updateSeedSourceSelect();
self.setSeedSource('new');
});

View file

@ -107,6 +107,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.canSign = fc.canSign();
self.isPrivKeyExternal = fc.isPrivKeyExternal();
self.externalSource = fc.getPrivKeyExternalSourceName();
self.account = fc.credentials.account;
if (self.externalSource == 'trezor')
self.account++;
self.txps = [];
self.copayers = [];
self.updateColor();

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('joinController',
function($scope, $rootScope, $timeout, go, notification, profileService, configService, isCordova, storageService, applicationService, $modal, gettext, lodash, ledger, trezor) {
function($scope, $rootScope, $timeout, go, notification, profileService, configService, isCordova, storageService, applicationService, $modal, gettext, lodash, ledger, trezor, isChromeApp) {
var self = this;
var defaults = configService.getDefaults();
@ -13,6 +13,44 @@ angular.module('copayApp.controllers').controller('joinController',
$scope.joinForm.secret.$render();
};
var updateSeedSourceSelect = function() {
self.seedOptions = [{
id: 'new',
label: gettext('New Random Seed'),
}, {
id: 'set',
label: gettext('Specify Seed...'),
}];
$scope.seedSource = self.seedOptions[0];
// TODO
// if (!isChromeApp) return;
self.seedOptions.push({
id: 'ledger',
label: gettext('Ledger Hardware Wallet'),
});
self.seedOptions.push({
id: 'trezor',
label: gettext('Trezor Hardware Wallet'),
});
};
this.setSeedSource = function(src) {
self.seedSourceId = $scope.seedSource.id;
if (self.seedSourceId == 'ledger')
self.accountValues = lodash.range(0, 99);
else
self.accountValues = lodash.range(1, 100);
$timeout(function() {
$rootScope.$apply();
});
};
this.join = function(form) {
if (form && form.$invalid) {
self.error = gettext('Please enter the required fields');
@ -26,7 +64,7 @@ angular.module('copayApp.controllers').controller('joinController',
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) {
@ -44,10 +82,14 @@ angular.module('copayApp.controllers').controller('joinController',
return;
}
if (form.hwLedger.$modelValue || form.hwTrezor.$modelValue) {
self.hwWallet = form.hwLedger.$modelValue ? 'Ledger' : 'TREZOR';
var src = form.hwLedger.$modelValue ? ledger : trezor;
var account = form.account.$modelValue;
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;
src.getInfoForNewWallet(true, account, function(err, lopts) {
self.hwWallet = false;
@ -82,4 +124,7 @@ angular.module('copayApp.controllers').controller('joinController',
});
}, 100);
};
updateSeedSourceSelect();
self.setSeedSource('new');
});

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.services')
.factory('ledger', function($log, bwcService, gettext) {
.factory('ledger', function($log, bwcService, gettext, hwWallet) {
var root = {};
var LEDGER_CHROME_ID = "kkdpmhnladdopljabkgpacgpliggeeaf";