Wallet/src/js/controllers/preferences.js

101 lines
3 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'use strict';
angular.module('copayApp.controllers').controller('preferencesController',
2016-02-11 14:06:30 -05:00
function($scope, $rootScope, $timeout, $log, configService, profileService, txService) {
var fc = profileService.focusedClient;
$scope.deleted = false;
if (fc.credentials && !fc.credentials.mnemonicEncrypted && !fc.credentials.mnemonic) {
$scope.deleted = true;
}
2015-10-07 16:17:19 -03:00
this.init = function() {
var config = configService.getSync();
var fc = profileService.focusedClient;
if (fc) {
$scope.encrypt = fc.hasPrivKeyEncrypted();
this.externalSource = fc.getPrivKeyExternalSourceName() == 'ledger' ? "Ledger" : null;
// TODO externalAccount
//this.externalIndex = fc.getExternalIndex();
}
2016-04-18 09:33:48 -03:00
var walletId = fc.credentials.walletId;
config.touchIdFor = config.touchIdFor || {};
$scope.touchid = config.touchIdFor[walletId];
if (window.touchidAvailable)
2015-10-07 16:17:19 -03:00
this.touchidAvailable = true;
};
2015-03-06 12:00:10 -03:00
var unwatchEncrypt = $scope.$watch('encrypt', function(val) {
2015-03-06 12:00:10 -03:00
var fc = profileService.focusedClient;
2015-05-13 12:41:05 -03:00
if (!fc) return;
2015-03-06 12:00:10 -03:00
if (val && !fc.hasPrivKeyEncrypted()) {
$rootScope.$emit('Local/NeedsPassword', true, function(err, password) {
if (err || !password) {
$scope.encrypt = false;
return;
}
profileService.setPrivateKeyEncryptionFC(password, function() {
2015-11-10 20:05:05 -03:00
$rootScope.$emit('Local/NewEncryptionSetting');
2015-03-06 12:00:10 -03:00
$scope.encrypt = true;
});
});
} else {
if (!val && fc.hasPrivKeyEncrypted()) {
Feat/coinbase integration (#4012) * Oauth2 and first view * Connect with Coinbase using mobile * Buy and Sell through Coinbase * Fix buy * Receive and send bitcoin to Coinbase account * Receive bitcoin from Coinbase to Copay * Complete user and account information. Connection errors * Improves error handler * Removes console.log * Coinbase background color. Send to Coinbase form validation * Fix send from different wallet * Send and receive using Coinbase * Pagination activity * Fix Buy and Sell * One option in the sidebar to Buy and Sell * Native balance on Coinbase homepage * Rename receive and send * Auto-close window after authenticate * Reorder * Get payment methods * Fix when token expired * Fix token expired * Integration: sell and send to Coinbase * Store pending transaction before sell * Sell flow completed * Removing files * Fix sell * Fix sell * Fix sell * Sell completed * Buy bitcoin through coinbase * Buy auto * Currency set to USD * Select payment methods. Limits * Removes payment methods from preferences * Fix signs. Tx ordered by updated. Minor fixes * Removes console.log * Improving ux-language things * Fix selectedpaymentmethod if not verified * Set error if tx not found * Price sensitivity. Minor fixes * Adds coinbase api key to gitignore * Coinbase production ready * Fix sell in usd * Bug fixes * New Sensitivity step * Refresh token with a simple click * Refresh token * Refactor * Fix auto reconnect if token expired Signed-off-by: Gustavo Maximiliano Cortez <cmgustavo83@gmail.com> * Fix calls if token expired
2016-04-13 14:08:03 -03:00
profileService.unlockFC({}, function(err) {
2015-03-06 12:00:10 -03:00
if (err) {
$scope.encrypt = true;
return;
}
profileService.disablePrivateKeyEncryptionFC(function(err) {
2015-11-10 20:05:05 -03:00
$rootScope.$emit('Local/NewEncryptionSetting');
2015-03-06 12:00:10 -03:00
if (err) {
$scope.encrypt = true;
$log.error(err);
return;
}
$scope.encrypt = false;
});
});
}
}
});
2015-10-07 16:17:19 -03:00
var unwatchRequestTouchid = $scope.$watch('touchid', function(newVal, oldVal) {
if (newVal == oldVal || $scope.touchidError) {
$scope.touchidError = false;
return;
}
var walletId = profileService.focusedClient.credentials.walletId;
var opts = {
touchIdFor: {}
};
opts.touchIdFor[walletId] = newVal;
2016-02-11 14:06:30 -05:00
txService.setTouchId(function(err) {
if (err) {
2015-10-07 16:17:19 -03:00
$log.debug(err);
$timeout(function() {
$scope.touchidError = true;
$scope.touchid = oldVal;
}, 100);
} else {
2015-10-07 16:17:19 -03:00
configService.set(opts, function(err) {
if (err) {
$log.debug(err);
$scope.touchidError = true;
$scope.touchid = oldVal;
}
});
}
});
});
2015-03-06 12:00:10 -03:00
$scope.$on('$destroy', function() {
unwatchEncrypt();
2015-10-07 16:17:19 -03:00
unwatchRequestTouchid();
2015-03-06 12:00:10 -03:00
});
});