Skip to content

Commit

Permalink
Merge pull request #7923 from gabrielbazan7/feat/encrypt
Browse files Browse the repository at this point in the history
Encrypt wallet at create
  • Loading branch information
cmgustavo authored Jan 24, 2018
2 parents 8ffada3 + e3edbad commit 6995a34
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 354 deletions.
46 changes: 11 additions & 35 deletions src/js/controllers/create.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('copayApp.controllers').controller('createController',
function($scope, $rootScope, $timeout, $log, lodash, $state, $ionicScrollDelegate, $ionicHistory, profileService, configService, gettextCatalog, ledger, trezor, intelTEE, derivationPathHelper, ongoingProcess, walletService, storageService, popupService, appConfigService, pushNotificationsService) {
function ($scope, $rootScope, $timeout, $log, lodash, $state, $ionicScrollDelegate, $ionicHistory, profileService, configService, gettextCatalog, ledger, trezor, intelTEE, derivationPathHelper, ongoingProcess, walletService, storageService, popupService, appConfigService, pushNotificationsService) {

/* For compressed keys, m*73 + n*34 <= 496 */
var COPAYER_PAIR_LIMITS = {
Expand All @@ -19,7 +19,7 @@ angular.module('copayApp.controllers').controller('createController',
12: 1,
};

$scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.$on("$ionicView.beforeEnter", function (event, data) {
$scope.formData = {};
var defaults = configService.getDefaults();
var config = configService.getSync();
Expand All @@ -32,41 +32,17 @@ angular.module('copayApp.controllers').controller('createController',

$scope.setTotalCopayers(tc);
updateRCSelect(tc);
resetPasswordFields();
});

$scope.showAdvChange = function() {
$scope.showAdvChange = function () {
$scope.showAdv = !$scope.showAdv;
$scope.encrypt = null;
$scope.resizeView();
};

$scope.checkPassword = function(pw1, pw2) {
if (pw1 && pw1.length > 0) {
if (pw2 && pw2.length > 0) {
if (pw1 == pw2) $scope.result = 'correct';
else {
$scope.formData.passwordSaved = null;
$scope.result = 'incorrect';
}
} else
$scope.result = null;
} else
$scope.result = null;
};

$scope.resizeView = function() {
$timeout(function() {
$scope.resizeView = function () {
$timeout(function () {
$ionicScrollDelegate.resize();
}, 10);
resetPasswordFields();
};

function resetPasswordFields() {
$scope.formData.passphrase = $scope.formData.createPassphrase = $scope.formData.passwordSaved = $scope.formData.repeatPassword = $scope.result = null;
$timeout(function() {
$scope.$apply();
});
};

function updateRCSelect(n) {
Expand Down Expand Up @@ -123,13 +99,13 @@ angular.module('copayApp.controllers').controller('createController',
$scope.seedOptions = seedOptions;
};

$scope.setTotalCopayers = function(tc) {
$scope.setTotalCopayers = function (tc) {
$scope.formData.totalCopayers = tc;
updateRCSelect(tc);
updateSeedSourceSelect(tc);
};

$scope.create = function() {
$scope.create = function () {

var opts = {
name: $scope.formData.walletName,
Expand Down Expand Up @@ -207,7 +183,7 @@ angular.module('copayApp.controllers').controller('createController',
return;
}

src.getInfoForNewWallet(opts.n > 1, account, opts.networkName, function(err, lopts) {
src.getInfoForNewWallet(opts.n > 1, account, opts.networkName, function (err, lopts) {
ongoingProcess.set('connecting ' + $scope.formData.seedSource.id, false);
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
Expand All @@ -223,8 +199,8 @@ angular.module('copayApp.controllers').controller('createController',

function _create(opts) {
ongoingProcess.set('creatingWallet', true);
$timeout(function() {
profileService.createWallet(opts, function(err, client) {
$timeout(function () {
profileService.createWallet(opts, function (err, client) {
ongoingProcess.set('creatingWallet', false);
if (err) {
$log.warn(err);
Expand All @@ -246,7 +222,7 @@ angular.module('copayApp.controllers').controller('createController',
disableAnimate: true
});
$state.go('tabs.home');
$timeout(function() {
$timeout(function () {
$state.transitionTo('tabs.copayers', {
walletId: client.credentials.walletId
});
Expand Down
45 changes: 11 additions & 34 deletions src/js/controllers/join.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

angular.module('copayApp.controllers').controller('joinController',
function($scope, $rootScope, $timeout, $state, $ionicHistory, $ionicScrollDelegate, profileService, configService, storageService, applicationService, gettextCatalog, lodash, ledger, trezor, intelTEE, derivationPathHelper, ongoingProcess, walletService, $log, $stateParams, popupService, appConfigService) {
function ($scope, $rootScope, $timeout, $state, $ionicHistory, $ionicScrollDelegate, profileService, configService, storageService, applicationService, gettextCatalog, lodash, ledger, trezor, intelTEE, derivationPathHelper, ongoingProcess, walletService, $log, $stateParams, popupService, appConfigService) {

$scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.$on("$ionicView.beforeEnter", function (event, data) {
var defaults = configService.getDefaults();
var config = configService.getSync();
$scope.formData = {};
Expand All @@ -12,45 +12,22 @@ angular.module('copayApp.controllers').controller('joinController',
$scope.formData.account = 1;
$scope.formData.secret = null;
$scope.formData.coin = data.stateParams.coin;
resetPasswordFields();
updateSeedSourceSelect();
});

$scope.showAdvChange = function() {
$scope.showAdvChange = function () {
$scope.showAdv = !$scope.showAdv;
$scope.encrypt = null;
$scope.resizeView();
};

$scope.checkPassword = function(pw1, pw2) {
if (pw1 && pw1.length > 0) {
if (pw2 && pw2.length > 0) {
if (pw1 == pw2) $scope.result = 'correct';
else {
$scope.formData.passwordSaved = null;
$scope.result = 'incorrect';
}
} else
$scope.result = null;
} else
$scope.result = null;
};

$scope.resizeView = function() {
$timeout(function() {
$scope.resizeView = function () {
$timeout(function () {
$ionicScrollDelegate.resize();
}, 10);
resetPasswordFields();
};

function resetPasswordFields() {
$scope.formData.passphrase = $scope.formData.createPassphrase = $scope.formData.passwordSaved = $scope.formData.repeatPassword = $scope.result = null;
$timeout(function() {
$scope.$apply();
});
};

$scope.onQrCodeScannedJoin = function(data) {
$scope.onQrCodeScannedJoin = function (data) {
$scope.formData.secret = data;
$scope.$apply();
};
Expand Down Expand Up @@ -100,7 +77,7 @@ angular.module('copayApp.controllers').controller('joinController',
}
};

$scope.join = function() {
$scope.join = function () {

var opts = {
secret: $scope.formData.secret,
Expand Down Expand Up @@ -175,7 +152,7 @@ angular.module('copayApp.controllers').controller('joinController',
}

// TODO: cannot currently join an intelTEE testnet wallet (need to detect from the secret)
src.getInfoForNewWallet(true, account, 'livenet', function(err, lopts) {
src.getInfoForNewWallet(true, account, 'livenet', function (err, lopts) {
ongoingProcess.set('connecting' + $scope.formData.seedSource.id, false);
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
Expand All @@ -192,8 +169,8 @@ angular.module('copayApp.controllers').controller('joinController',

function _join(opts) {
ongoingProcess.set('joiningWallet', true);
$timeout(function() {
profileService.joinWallet(opts, function(err, client) {
$timeout(function () {
profileService.joinWallet(opts, function (err, client) {
ongoingProcess.set('joiningWallet', false);
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
Expand All @@ -208,7 +185,7 @@ angular.module('copayApp.controllers').controller('joinController',
disableAnimate: true
});
$state.go('tabs.home');
$timeout(function() {
$timeout(function () {
$state.transitionTo('tabs.copayers', {
walletId: client.credentials.walletId
});
Expand Down
38 changes: 19 additions & 19 deletions src/js/controllers/onboarding/tour.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('tourController',
function($scope, $state, $log, $timeout, $filter, ongoingProcess, profileService, rateService, popupService, gettextCatalog) {
function ($scope, $state, $log, $timeout, $filter, ongoingProcess, profileService, rateService, popupService, gettextCatalog) {

$scope.data = {
index: 0
Expand All @@ -13,44 +13,44 @@ angular.module('copayApp.controllers').controller('tourController',
spaceBetween: 100
}

$scope.$on("$ionicSlides.sliderInitialized", function(event, data) {
$scope.$on("$ionicSlides.sliderInitialized", function (event, data) {
$scope.slider = data.slider;
});

$scope.$on("$ionicSlides.slideChangeStart", function(event, data) {
$scope.$on("$ionicSlides.slideChangeStart", function (event, data) {
$scope.data.index = data.slider.activeIndex;
});

$scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {});
$scope.$on("$ionicSlides.slideChangeEnd", function (event, data) { });

$scope.$on("$ionicView.enter", function(event, data) {
rateService.whenAvailable(function() {
$scope.$on("$ionicView.enter", function (event, data) {
rateService.whenAvailable(function () {
var localCurrency = 'USD';
var btcAmount = 1;
var rate = rateService.toFiat(btcAmount * 1e8, localCurrency, 'btc');
$scope.localCurrencySymbol = '$';
$scope.localCurrencyPerBtc = $filter('formatFiatAmount')(parseFloat(rate.toFixed(2), 10));
$timeout(function() {
$timeout(function () {
$scope.$apply();
})
});
});

var retryCount = 0;
$scope.createDefaultWallet = function() {
$scope.createDefaultWallet = function () {
ongoingProcess.set('creatingWallet', true);
$timeout(function() {
profileService.createDefaultWallet(function(err, walletClient) {
$timeout(function () {
profileService.createDefaultWallet(function (err, walletClient) {
if (err) {
$log.warn(err);

return $timeout(function() {
return $timeout(function () {
$log.warn('Retrying to create default wallet.....:' + ++retryCount);
if (retryCount > 3) {
ongoingProcess.set('creatingWallet', false);
popupService.showAlert(
gettextCatalog.getString('Cannot Create Wallet'), err,
function() {
function () {
retryCount = 0;
return $scope.createDefaultWallet();
}, gettextCatalog.getString('Retry'));
Expand All @@ -67,21 +67,21 @@ angular.module('copayApp.controllers').controller('tourController',
walletId: walletId
});

/*
$state.go('onboarding.backupRequest', {
walletId: walletId
});
*/
/*
$state.go('onboarding.backupRequest', {
walletId: walletId
});
*/
});
}, 300);
};

$scope.goBack = function() {
$scope.goBack = function () {
if ($scope.data.index != 0) $scope.slider.slidePrev();
else $state.go('onboarding.welcome');
}

$scope.slideNext = function() {
$scope.slideNext = function () {
if ($scope.data.index != 2) $scope.slider.slideNext();
else $state.go('onboarding.welcome');
}
Expand Down
13 changes: 13 additions & 0 deletions src/js/services/onGoingProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;

var ongoingProcess = {};
var pausedOngoingProcess = {};

var processNames = {
'broadcastingTx': gettext('Broadcasting transaction'),
Expand Down Expand Up @@ -63,6 +64,18 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti
return ongoingProcess[processName];
};

root.pause = function() {
pausedOngoingProcess = ongoingProcess;
root.clear();
}

root.resume = function() {
lodash.forEach(pausedOngoingProcess, function(v, k) {
root.set(k, v);
});
pausedOngoingProcess = {};
}

root.set = function(processName, isOn, customHandler) {
$log.debug('ongoingProcess', processName, isOn);
root[processName] = isOn;
Expand Down
Loading

0 comments on commit 6995a34

Please sign in to comment.