adding verification option to passphrase on join wallet
This commit is contained in:
parent
505f0e67d0
commit
399edf0291
2 changed files with 103 additions and 66 deletions
|
|
@ -3,57 +3,74 @@
|
|||
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) {
|
||||
|
||||
var self = this;
|
||||
var defaults = configService.getDefaults();
|
||||
$scope.bwsurl = defaults.bws.url;
|
||||
$scope.derivationPath = derivationPathHelper.default;
|
||||
$scope.account = 1;
|
||||
$scope.init = function() {
|
||||
var defaults = configService.getDefaults();
|
||||
$scope.bwsurl = defaults.bws.url;
|
||||
$scope.derivationPath = derivationPathHelper.default;
|
||||
$scope.account = 1;
|
||||
$scope.formData = {};
|
||||
resetPasswordFields();
|
||||
updateSeedSourceSelect();
|
||||
$scope.setSeedSource();
|
||||
};
|
||||
|
||||
$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() {
|
||||
$ionicScrollDelegate.resize();
|
||||
}, 10);
|
||||
checkPasswordFields();
|
||||
resetPasswordFields();
|
||||
};
|
||||
|
||||
function checkPasswordFields() {
|
||||
if (!$scope.encrypt) {
|
||||
$scope.passphrase = $scope.createPassphrase = $scope.passwordSaved = null;
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
}
|
||||
function resetPasswordFields() {
|
||||
$scope.formData.passphrase = $scope.formData.createPassphrase = $scope.formData.passwordSaved = $scope.formData.repeatpassword = $scope.result = null;
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
this.onQrCodeScannedJoin = function(data) {
|
||||
$scope.onQrCodeScannedJoin = function(data) {
|
||||
$scope.secret = data;
|
||||
if ($scope.joinForm) {
|
||||
$scope.joinForm.secret.$setViewValue(data);
|
||||
$scope.joinForm.secret.$render();
|
||||
if ($scope.formData) {
|
||||
$scope.formData.secret.$setViewValue(data);
|
||||
$scope.formData.secret.$render();
|
||||
}
|
||||
};
|
||||
|
||||
if ($stateParams.url) {
|
||||
var data = $stateParams.url;
|
||||
data = data.replace('copay:', '');
|
||||
this.onQrCodeScannedJoin(data);
|
||||
$scope.onQrCodeScannedJoin(data);
|
||||
}
|
||||
|
||||
var updateSeedSourceSelect = function() {
|
||||
self.seedOptions = [{
|
||||
function updateSeedSourceSelect() {
|
||||
$scope.seedOptions = [{
|
||||
id: 'new',
|
||||
label: gettextCatalog.getString('Random'),
|
||||
}, {
|
||||
id: 'set',
|
||||
label: gettextCatalog.getString('Specify Recovery Phrase...'),
|
||||
}];
|
||||
$scope.seedSource = self.seedOptions[0];
|
||||
|
||||
$scope.seedSource = $scope.seedOptions[0];
|
||||
/*
|
||||
|
||||
Disable Hardware Wallets
|
||||
|
|
@ -62,21 +79,21 @@ angular.module('copayApp.controllers').controller('joinController',
|
|||
|
||||
if (appConfigService.name == 'copay') {
|
||||
if (walletService.externalSource.ledger.supported) {
|
||||
self.seedOptions.push({
|
||||
$scope.seedOptions.push({
|
||||
id: walletService.externalSource.ledger.id,
|
||||
label: walletService.externalSource.ledger.longName
|
||||
});
|
||||
}
|
||||
|
||||
if (walletService.externalSource.trezor.supported) {
|
||||
self.seedOptions.push({
|
||||
$scope.seedOptions.push({
|
||||
id: walletService.externalSource.trezor.id,
|
||||
label: walletService.externalSource.trezor.longName
|
||||
});
|
||||
}
|
||||
|
||||
if (walletService.externalSource.intelTEE.supported) {
|
||||
seedOptions.push({
|
||||
$scope.seedOptions.push({
|
||||
id: walletService.externalSource.intelTEE.id,
|
||||
label: walletService.externalSource.intelTEE.longName
|
||||
});
|
||||
|
|
@ -84,35 +101,36 @@ angular.module('copayApp.controllers').controller('joinController',
|
|||
}
|
||||
};
|
||||
|
||||
this.setSeedSource = function() {
|
||||
self.seedSourceId = $scope.seedSource.id;
|
||||
$scope.setSeedSource = function() {
|
||||
$scope.seedSourceId = $scope.seedSource.id;
|
||||
|
||||
$timeout(function() {
|
||||
$rootScope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
this.join = function(form) {
|
||||
if (form && form.$invalid) {
|
||||
$scope.join = function() {
|
||||
|
||||
if ($scope.formData && $scope.formData.$invalid) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Please enter the required fields'));
|
||||
return;
|
||||
}
|
||||
|
||||
var opts = {
|
||||
secret: form.secret.$modelValue,
|
||||
myName: form.myName.$modelValue,
|
||||
secret: $scope.formData.secret.$modelValue,
|
||||
myName: $scope.formData.myName.$modelValue,
|
||||
bwsurl: $scope.bwsurl
|
||||
}
|
||||
|
||||
var setSeed = self.seedSourceId == 'set';
|
||||
var setSeed = $scope.seedSourceId == 'set';
|
||||
if (setSeed) {
|
||||
var words = form.privateKey.$modelValue;
|
||||
var words = $scope.formData.privateKey.$modelValue;
|
||||
if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
|
||||
opts.extendedPrivateKey = words;
|
||||
} else {
|
||||
opts.mnemonic = words;
|
||||
}
|
||||
opts.passphrase = form.passphrase.$modelValue;
|
||||
opts.passphrase = $scope.formData.passphrase ? $scope.formData.passphrase.$modelValue : null;
|
||||
|
||||
var pathData = derivationPathHelper.parse($scope.derivationPath);
|
||||
if (!pathData) {
|
||||
|
|
@ -123,7 +141,7 @@ angular.module('copayApp.controllers').controller('joinController',
|
|||
opts.networkName = pathData.networkName;
|
||||
opts.derivationStrategy = pathData.derivationStrategy;
|
||||
} else {
|
||||
opts.passphrase = form.createPassphrase.$modelValue;
|
||||
opts.passphrase = $scope.formData.createPassphrase ? $scope.formData.createPassphrase.$modelValue : null;
|
||||
}
|
||||
|
||||
opts.walletPrivKey = $scope._walletPrivKey; // Only for testing
|
||||
|
|
@ -134,22 +152,22 @@ angular.module('copayApp.controllers').controller('joinController',
|
|||
return;
|
||||
}
|
||||
|
||||
if (self.seedSourceId == walletService.externalSource.ledger.id || self.seedSourceId == walletService.externalSource.trezor.id || self.seedSourceId == walletService.externalSource.intelTEE.id) {
|
||||
if ($scope.seedSourceId == walletService.externalSource.ledger.id || $scope.seedSourceId == walletService.externalSource.trezor.id || $scope.seedSourceId == walletService.externalSource.intelTEE.id) {
|
||||
var account = $scope.account;
|
||||
if (!account || account < 1) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Invalid account number'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.seedSourceId == walletService.externalSource.trezor.id || self.seedSourceId == walletService.externalSource.intelTEE.id)
|
||||
if ($scope.seedSourceId == walletService.externalSource.trezor.id || $scope.seedSourceId == walletService.externalSource.intelTEE.id)
|
||||
account = account - 1;
|
||||
|
||||
opts.account = account;
|
||||
opts.isMultisig = true;
|
||||
ongoingProcess.set('connecting' + self.seedSourceId, true);
|
||||
ongoingProcess.set('connecting' + $scope.seedSourceId, true);
|
||||
|
||||
var src;
|
||||
switch (self.seedSourceId) {
|
||||
switch ($scope.seedSourceId) {
|
||||
case walletService.externalSource.ledger.id:
|
||||
src = ledger;
|
||||
break;
|
||||
|
|
@ -166,21 +184,21 @@ 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) {
|
||||
ongoingProcess.set('connecting' + self.seedSourceId, false);
|
||||
ongoingProcess.set('connecting' + $scope.seedSourceId, false);
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
return;
|
||||
}
|
||||
opts = lodash.assign(lopts, opts);
|
||||
self._join(opts);
|
||||
_join(opts);
|
||||
});
|
||||
} else {
|
||||
|
||||
self._join(opts);
|
||||
_join(opts);
|
||||
}
|
||||
};
|
||||
|
||||
this._join = function(opts) {
|
||||
function _join(opts) {
|
||||
ongoingProcess.set('joiningWallet', true);
|
||||
$timeout(function() {
|
||||
profileService.joinWallet(opts, function(err, client) {
|
||||
|
|
@ -207,7 +225,4 @@ angular.module('copayApp.controllers').controller('joinController',
|
|||
});
|
||||
});
|
||||
};
|
||||
|
||||
updateSeedSourceSelect();
|
||||
self.setSeedSource();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue