Skip to content

Commit 6995a34

Browse files
authored
Merge pull request #7923 from gabrielbazan7/feat/encrypt
Encrypt wallet at create
2 parents 8ffada3 + e3edbad commit 6995a34

File tree

8 files changed

+170
-354
lines changed

8 files changed

+170
-354
lines changed

src/js/controllers/create.js

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

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

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

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

3333
$scope.setTotalCopayers(tc);
3434
updateRCSelect(tc);
35-
resetPasswordFields();
3635
});
3736

38-
$scope.showAdvChange = function() {
37+
$scope.showAdvChange = function () {
3938
$scope.showAdv = !$scope.showAdv;
40-
$scope.encrypt = null;
4139
$scope.resizeView();
4240
};
4341

44-
$scope.checkPassword = function(pw1, pw2) {
45-
if (pw1 && pw1.length > 0) {
46-
if (pw2 && pw2.length > 0) {
47-
if (pw1 == pw2) $scope.result = 'correct';
48-
else {
49-
$scope.formData.passwordSaved = null;
50-
$scope.result = 'incorrect';
51-
}
52-
} else
53-
$scope.result = null;
54-
} else
55-
$scope.result = null;
56-
};
57-
58-
$scope.resizeView = function() {
59-
$timeout(function() {
42+
$scope.resizeView = function () {
43+
$timeout(function () {
6044
$ionicScrollDelegate.resize();
6145
}, 10);
62-
resetPasswordFields();
63-
};
64-
65-
function resetPasswordFields() {
66-
$scope.formData.passphrase = $scope.formData.createPassphrase = $scope.formData.passwordSaved = $scope.formData.repeatPassword = $scope.result = null;
67-
$timeout(function() {
68-
$scope.$apply();
69-
});
7046
};
7147

7248
function updateRCSelect(n) {
@@ -123,13 +99,13 @@ angular.module('copayApp.controllers').controller('createController',
12399
$scope.seedOptions = seedOptions;
124100
};
125101

126-
$scope.setTotalCopayers = function(tc) {
102+
$scope.setTotalCopayers = function (tc) {
127103
$scope.formData.totalCopayers = tc;
128104
updateRCSelect(tc);
129105
updateSeedSourceSelect(tc);
130106
};
131107

132-
$scope.create = function() {
108+
$scope.create = function () {
133109

134110
var opts = {
135111
name: $scope.formData.walletName,
@@ -207,7 +183,7 @@ angular.module('copayApp.controllers').controller('createController',
207183
return;
208184
}
209185

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

224200
function _create(opts) {
225201
ongoingProcess.set('creatingWallet', true);
226-
$timeout(function() {
227-
profileService.createWallet(opts, function(err, client) {
202+
$timeout(function () {
203+
profileService.createWallet(opts, function (err, client) {
228204
ongoingProcess.set('creatingWallet', false);
229205
if (err) {
230206
$log.warn(err);
@@ -246,7 +222,7 @@ angular.module('copayApp.controllers').controller('createController',
246222
disableAnimate: true
247223
});
248224
$state.go('tabs.home');
249-
$timeout(function() {
225+
$timeout(function () {
250226
$state.transitionTo('tabs.copayers', {
251227
walletId: client.credentials.walletId
252228
});

src/js/controllers/join.js

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

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

6-
$scope.$on("$ionicView.beforeEnter", function(event, data) {
6+
$scope.$on("$ionicView.beforeEnter", function (event, data) {
77
var defaults = configService.getDefaults();
88
var config = configService.getSync();
99
$scope.formData = {};
@@ -12,45 +12,22 @@ angular.module('copayApp.controllers').controller('joinController',
1212
$scope.formData.account = 1;
1313
$scope.formData.secret = null;
1414
$scope.formData.coin = data.stateParams.coin;
15-
resetPasswordFields();
1615
updateSeedSourceSelect();
1716
});
1817

19-
$scope.showAdvChange = function() {
18+
$scope.showAdvChange = function () {
2019
$scope.showAdv = !$scope.showAdv;
2120
$scope.encrypt = null;
2221
$scope.resizeView();
2322
};
2423

25-
$scope.checkPassword = function(pw1, pw2) {
26-
if (pw1 && pw1.length > 0) {
27-
if (pw2 && pw2.length > 0) {
28-
if (pw1 == pw2) $scope.result = 'correct';
29-
else {
30-
$scope.formData.passwordSaved = null;
31-
$scope.result = 'incorrect';
32-
}
33-
} else
34-
$scope.result = null;
35-
} else
36-
$scope.result = null;
37-
};
38-
39-
$scope.resizeView = function() {
40-
$timeout(function() {
24+
$scope.resizeView = function () {
25+
$timeout(function () {
4126
$ionicScrollDelegate.resize();
4227
}, 10);
43-
resetPasswordFields();
44-
};
45-
46-
function resetPasswordFields() {
47-
$scope.formData.passphrase = $scope.formData.createPassphrase = $scope.formData.passwordSaved = $scope.formData.repeatPassword = $scope.result = null;
48-
$timeout(function() {
49-
$scope.$apply();
50-
});
5128
};
5229

53-
$scope.onQrCodeScannedJoin = function(data) {
30+
$scope.onQrCodeScannedJoin = function (data) {
5431
$scope.formData.secret = data;
5532
$scope.$apply();
5633
};
@@ -100,7 +77,7 @@ angular.module('copayApp.controllers').controller('joinController',
10077
}
10178
};
10279

103-
$scope.join = function() {
80+
$scope.join = function () {
10481

10582
var opts = {
10683
secret: $scope.formData.secret,
@@ -175,7 +152,7 @@ angular.module('copayApp.controllers').controller('joinController',
175152
}
176153

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

193170
function _join(opts) {
194171
ongoingProcess.set('joiningWallet', true);
195-
$timeout(function() {
196-
profileService.joinWallet(opts, function(err, client) {
172+
$timeout(function () {
173+
profileService.joinWallet(opts, function (err, client) {
197174
ongoingProcess.set('joiningWallet', false);
198175
if (err) {
199176
popupService.showAlert(gettextCatalog.getString('Error'), err);
@@ -208,7 +185,7 @@ angular.module('copayApp.controllers').controller('joinController',
208185
disableAnimate: true
209186
});
210187
$state.go('tabs.home');
211-
$timeout(function() {
188+
$timeout(function () {
212189
$state.transitionTo('tabs.copayers', {
213190
walletId: client.credentials.walletId
214191
});

src/js/controllers/onboarding/tour.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
angular.module('copayApp.controllers').controller('tourController',
3-
function($scope, $state, $log, $timeout, $filter, ongoingProcess, profileService, rateService, popupService, gettextCatalog) {
3+
function ($scope, $state, $log, $timeout, $filter, ongoingProcess, profileService, rateService, popupService, gettextCatalog) {
44

55
$scope.data = {
66
index: 0
@@ -13,44 +13,44 @@ angular.module('copayApp.controllers').controller('tourController',
1313
spaceBetween: 100
1414
}
1515

16-
$scope.$on("$ionicSlides.sliderInitialized", function(event, data) {
16+
$scope.$on("$ionicSlides.sliderInitialized", function (event, data) {
1717
$scope.slider = data.slider;
1818
});
1919

20-
$scope.$on("$ionicSlides.slideChangeStart", function(event, data) {
20+
$scope.$on("$ionicSlides.slideChangeStart", function (event, data) {
2121
$scope.data.index = data.slider.activeIndex;
2222
});
2323

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

26-
$scope.$on("$ionicView.enter", function(event, data) {
27-
rateService.whenAvailable(function() {
26+
$scope.$on("$ionicView.enter", function (event, data) {
27+
rateService.whenAvailable(function () {
2828
var localCurrency = 'USD';
2929
var btcAmount = 1;
3030
var rate = rateService.toFiat(btcAmount * 1e8, localCurrency, 'btc');
3131
$scope.localCurrencySymbol = '$';
3232
$scope.localCurrencyPerBtc = $filter('formatFiatAmount')(parseFloat(rate.toFixed(2), 10));
33-
$timeout(function() {
33+
$timeout(function () {
3434
$scope.$apply();
3535
})
3636
});
3737
});
3838

3939
var retryCount = 0;
40-
$scope.createDefaultWallet = function() {
40+
$scope.createDefaultWallet = function () {
4141
ongoingProcess.set('creatingWallet', true);
42-
$timeout(function() {
43-
profileService.createDefaultWallet(function(err, walletClient) {
42+
$timeout(function () {
43+
profileService.createDefaultWallet(function (err, walletClient) {
4444
if (err) {
4545
$log.warn(err);
4646

47-
return $timeout(function() {
47+
return $timeout(function () {
4848
$log.warn('Retrying to create default wallet.....:' + ++retryCount);
4949
if (retryCount > 3) {
5050
ongoingProcess.set('creatingWallet', false);
5151
popupService.showAlert(
5252
gettextCatalog.getString('Cannot Create Wallet'), err,
53-
function() {
53+
function () {
5454
retryCount = 0;
5555
return $scope.createDefaultWallet();
5656
}, gettextCatalog.getString('Retry'));
@@ -67,21 +67,21 @@ angular.module('copayApp.controllers').controller('tourController',
6767
walletId: walletId
6868
});
6969

70-
/*
71-
$state.go('onboarding.backupRequest', {
72-
walletId: walletId
73-
});
74-
*/
70+
/*
71+
$state.go('onboarding.backupRequest', {
72+
walletId: walletId
73+
});
74+
*/
7575
});
7676
}, 300);
7777
};
7878

79-
$scope.goBack = function() {
79+
$scope.goBack = function () {
8080
if ($scope.data.index != 0) $scope.slider.slidePrev();
8181
else $state.go('onboarding.welcome');
8282
}
8383

84-
$scope.slideNext = function() {
84+
$scope.slideNext = function () {
8585
if ($scope.data.index != 2) $scope.slider.slideNext();
8686
else $state.go('onboarding.welcome');
8787
}

src/js/services/onGoingProcess.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti
66
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
77

88
var ongoingProcess = {};
9+
var pausedOngoingProcess = {};
910

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

67+
root.pause = function() {
68+
pausedOngoingProcess = ongoingProcess;
69+
root.clear();
70+
}
71+
72+
root.resume = function() {
73+
lodash.forEach(pausedOngoingProcess, function(v, k) {
74+
root.set(k, v);
75+
});
76+
pausedOngoingProcess = {};
77+
}
78+
6679
root.set = function(processName, isOn, customHandler) {
6780
$log.debug('ongoingProcess', processName, isOn);
6881
root[processName] = isOn;

0 commit comments

Comments
 (0)