Bug/select wallet incomplete / Refactor wallet Services (#4159)

* Addressbook: display error if select an incomplete wallet

* Check if wallet is complete/needs_backup for Glidera and Coinbase

* Ref/create a walletService

* Ref. walletService

* Fix Glidera and Coinbase

* Removes txService

* Fix glidera connection for mobile. Fix bitcode for xcode

* Fix duplicated entry

* Revert "Bump bwc version 2.3.1"

* adds karma-mocha

* Refactor

* Refactor lock function

* Refactor reject, remove and broadcast tx

* add walletService tests WIP

* add walletService tests WIP 2

* merge

* update tests to mocha

* fix tests. Angular 1.5?

* Fix test

* Generate angular-bwc before testing

* Rever gitignore

* Wording
This commit is contained in:
Gustavo Maximiliano Cortez 2016-05-09 15:56:44 -03:00
commit 98471e952a
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
27 changed files with 698 additions and 628 deletions

View file

@ -1,37 +1,39 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesController',
function($scope, $rootScope, $timeout, $log, configService, profileService, txService) {
function($scope, $rootScope, $timeout, $log, configService, profileService, fingerprintService, walletService) {
var fc = profileService.focusedClient;
var config = configService.getSync();
$scope.deleted = false;
if (fc.credentials && !fc.credentials.mnemonicEncrypted && !fc.credentials.mnemonic) {
$scope.deleted = true;
}
this.init = function() {
var config = configService.getSync();
var fc = profileService.focusedClient;
if (fc) {
$scope.encrypt = fc.hasPrivKeyEncrypted();
$scope.encrypt = walletService.isEncrypted(fc);
this.externalSource = fc.getPrivKeyExternalSourceName() == 'ledger' ? "Ledger" : null;
// TODO externalAccount
//this.externalIndex = fc.getExternalIndex();
}
var walletId = fc.credentials.walletId;
config.touchIdFor = config.touchIdFor || {};
$scope.touchid = config.touchIdFor[walletId];
this.touchidAvailable = fingerprintService.isAvailable();
$scope.touchid = config.touchIdFor ? config.touchIdFor[fc.credentials.walletId] : null;
};
if (window.touchidAvailable)
this.touchidAvailable = true;
var handleEncryptedWallet = function(client, cb) {
$rootScope.$emit('Local/NeedsPassword', false, function(err, password) {
if (err) return cb(err);
return cb(walletService.unlock(client, password));
});
};
var unwatchEncrypt = $scope.$watch('encrypt', function(val) {
var fc = profileService.focusedClient;
if (!fc) return;
if (val && !fc.hasPrivKeyEncrypted()) {
if (val && !walletService.isEncrypted(fc)) {
$rootScope.$emit('Local/NeedsPassword', true, function(err, password) {
if (err || !password) {
$scope.encrypt = false;
@ -43,8 +45,8 @@ angular.module('copayApp.controllers').controller('preferencesController',
});
});
} else {
if (!val && fc.hasPrivKeyEncrypted()) {
profileService.unlockFC({}, function(err) {
if (!val && walletService.isEncrypted(fc)) {
handleEncryptedWallet(fc, function(err) {
if (err) {
$scope.encrypt = true;
return;
@ -68,29 +70,29 @@ angular.module('copayApp.controllers').controller('preferencesController',
$scope.touchidError = false;
return;
}
var walletId = profileService.focusedClient.credentials.walletId;
var walletId = fc.credentials.walletId;
var opts = {
touchIdFor: {}
};
opts.touchIdFor[walletId] = newVal;
txService.setTouchId(function(err) {
fingerprintService.check(fc, function(err) {
if (err) {
$log.debug(err);
$timeout(function() {
$scope.touchidError = true;
$scope.touchid = oldVal;
}, 100);
} else {
configService.set(opts, function(err) {
if (err) {
$log.debug(err);
$scope.touchidError = true;
$scope.touchid = oldVal;
}
});
return;
}
configService.set(opts, function(err) {
if (err) {
$log.debug(err);
$scope.touchidError = true;
$scope.touchid = oldVal;
}
});
});
});