join view and controller refactor

This commit is contained in:
Gabriel Bazán 2017-05-22 21:05:32 -03:00
commit b148332d9d
6 changed files with 35 additions and 46 deletions

View file

@ -126,11 +126,7 @@ angular.module('copayApp.controllers').controller('createController',
updateSeedSourceSelect(tc); updateSeedSourceSelect(tc);
}; };
$scope.create = function(form) { $scope.create = function() {
if (form && form.$invalid) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Please enter the required fields'));
return;
}
var opts = { var opts = {
name: $scope.formData.walletName, name: $scope.formData.walletName,

View file

@ -3,16 +3,17 @@
angular.module('copayApp.controllers').controller('joinController', 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.init = function() { $scope.$on("$ionicView.beforeEnter", function(event, data) {
var defaults = configService.getDefaults(); var defaults = configService.getDefaults();
$scope.bwsurl = defaults.bws.url;
$scope.derivationPath = derivationPathHelper.default;
$scope.account = 1;
$scope.formData = {}; $scope.formData = {};
$scope.formData.bwsurl = defaults.bws.url;
$scope.formData.derivationPath = derivationPathHelper.default;
$scope.formData.account = 1;
$scope.formData.secret = null;
resetPasswordFields(); resetPasswordFields();
updateSeedSourceSelect(); updateSeedSourceSelect();
$scope.setSeedSource(); $scope.setSeedSource();
}; });
$scope.showAdvChange = function() { $scope.showAdvChange = function() {
$scope.showAdv = !$scope.showAdv; $scope.showAdv = !$scope.showAdv;
@ -49,11 +50,7 @@ angular.module('copayApp.controllers').controller('joinController',
}; };
$scope.onQrCodeScannedJoin = function(data) { $scope.onQrCodeScannedJoin = function(data) {
$scope.secret = data; $scope.formData.secret = data;
if ($scope.formData) {
$scope.formData.secret.$setViewValue(data);
$scope.formData.secret.$render();
}
}; };
if ($stateParams.url) { if ($stateParams.url) {
@ -70,7 +67,7 @@ angular.module('copayApp.controllers').controller('joinController',
id: 'set', id: 'set',
label: gettextCatalog.getString('Specify Recovery Phrase...'), label: gettextCatalog.getString('Specify Recovery Phrase...'),
}]; }];
$scope.seedSource = $scope.seedOptions[0]; $scope.formData.seedSource = $scope.seedOptions[0];
/* /*
Disable Hardware Wallets Disable Hardware Wallets
@ -102,7 +99,7 @@ angular.module('copayApp.controllers').controller('joinController',
}; };
$scope.setSeedSource = function() { $scope.setSeedSource = function() {
$scope.seedSourceId = $scope.seedSource.id; $scope.seedSourceId = $scope.formData.seedSource.id;
$timeout(function() { $timeout(function() {
$rootScope.$apply(); $rootScope.$apply();
@ -111,28 +108,23 @@ angular.module('copayApp.controllers').controller('joinController',
$scope.join = function() { $scope.join = function() {
if ($scope.formData && $scope.formData.$invalid) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Please enter the required fields'));
return;
}
var opts = { var opts = {
secret: $scope.formData.secret.$modelValue, secret: $scope.formData.secret,
myName: $scope.formData.myName.$modelValue, myName: $scope.formData.myName,
bwsurl: $scope.bwsurl bwsurl: $scope.formData.bwsurl
} }
var setSeed = $scope.seedSourceId == 'set'; var setSeed = $scope.seedSourceId == 'set';
if (setSeed) { if (setSeed) {
var words = $scope.formData.privateKey.$modelValue; var words = $scope.formData.privateKey;
if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) { if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
opts.extendedPrivateKey = words; opts.extendedPrivateKey = words;
} else { } else {
opts.mnemonic = words; opts.mnemonic = words;
} }
opts.passphrase = $scope.formData.passphrase ? $scope.formData.passphrase.$modelValue : null; opts.passphrase = $scope.formData.passphrase;
var pathData = derivationPathHelper.parse($scope.derivationPath); var pathData = derivationPathHelper.parse($scope.formData.derivationPath);
if (!pathData) { if (!pathData) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Invalid derivation path')); popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Invalid derivation path'));
return; return;
@ -141,7 +133,7 @@ angular.module('copayApp.controllers').controller('joinController',
opts.networkName = pathData.networkName; opts.networkName = pathData.networkName;
opts.derivationStrategy = pathData.derivationStrategy; opts.derivationStrategy = pathData.derivationStrategy;
} else { } else {
opts.passphrase = $scope.formData.createPassphrase ? $scope.formData.createPassphrase.$modelValue : null; opts.passphrase = $scope.formData.createPassphrase;
} }
opts.walletPrivKey = $scope._walletPrivKey; // Only for testing opts.walletPrivKey = $scope._walletPrivKey; // Only for testing

View file

@ -323,7 +323,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
url: '/join/:url', url: '/join/:url',
views: { views: {
'tab-home@tabs': { 'tab-home@tabs': {
templateUrl: 'views/join.html' templateUrl: 'views/join.html',
controller: 'joinController'
}, },
} }
}) })

View file

@ -6,9 +6,9 @@
</ion-nav-bar> </ion-nav-bar>
<ion-content ng-controller="joinController" ng-init="init()"> <ion-content ng-init="init()">
<form name="formData" ng-submit="join()" novalidate> <form name="setupForm" ng-submit="join()" novalidate>
<div class="list settings-list settings-input-group"> <div class="list settings-list settings-input-group">
@ -17,22 +17,22 @@
<input type="text" <input type="text"
placeholder="{{'John'|translate}}" placeholder="{{'John'|translate}}"
name="myName" name="myName"
ng-model="myName" ng-model="formData.myName"
ng-required="true"> required>
</label> </label>
<div> <div>
<label class="item item-input item-stacked-label no-border"> <label class="item item-input item-stacked-label no-border">
<span class="input-label" translate>Wallet Invitation</span> <span class="input-label" translate>Wallet Invitation</span>
<div class="input-notification"> <div class="input-notification">
<i ng-show="!formData.secret.$invalid" class="icon ion-checkmark-circled valid"></i> <i ng-show="!setupForm.secret.$invalid" class="icon ion-checkmark-circled valid"></i>
<i ng-show="formData.secret.$invalid && secret" class="icon ion-close-circled invalid"></i> <i ng-show="setupForm.secret.$invalid && formData.secret" class="icon ion-close-circled invalid"></i>
</div> </div>
<input id="secret" <input id="secret"
type="text" type="text"
placeholder="{{'Paste invitation here'|translate}}" placeholder="{{'Paste invitation here'|translate}}"
name="secret" name="secret"
ng-model="secret" ng-model="formData.secret"
wallet-secret required> wallet-secret required>
</label> </label>
<div class="qr-scan-icon"> <div class="qr-scan-icon">
@ -50,7 +50,7 @@
<label class="item item-input item-stacked-label"> <label class="item item-input item-stacked-label">
<span class="input-label">Wallet Service URL</span> <span class="input-label">Wallet Service URL</span>
<input type="text" id="bwsurl" name="bwsurl" ng-model="bwsurl"> <input type="text" id="bwsurl" name="bwsurl" ng-model="formData.bwsurl">
</label> </label>
<label class="item item-input item-select"> <label class="item item-input item-select">
@ -58,7 +58,7 @@
Wallet Key Wallet Key
</div> </div>
<select class="m10t" <select class="m10t"
ng-model="seedSource" ng-model="formData.seedSource"
ng-options="seed as seed.label for seed in seedOptions" ng-options="seed as seed.label for seed in seedOptions"
ng-change="setSeedSource(); resizeView()"> ng-change="setSeedSource(); resizeView()">
</select> </select>
@ -67,7 +67,7 @@
<label class="item item-input item-stacked-label" <label class="item item-input item-stacked-label"
ng-show="seedSourceId == 'trezor' || seedSourceId == 'ledger'"> ng-show="seedSourceId == 'trezor' || seedSourceId == 'ledger'">
<span class="input-label" translate>Account Number</span> <span class="input-label" translate>Account Number</span>
<input type="number" id="account" ng-model="account" ignore-mouse-wheel> <input type="number" id="account" ng-model="formData.account" ignore-mouse-wheel>
</label> </label>
<label class="item item-input item-stacked-label" ng-show="seedSourceId=='set'"> <label class="item item-input item-stacked-label" ng-show="seedSourceId=='set'">
@ -77,7 +77,7 @@
autocapitalize="off" autocapitalize="off"
type="text" type="text"
name="privateKey" name="privateKey"
ng-model="privateKey"> ng-model="formData.privateKey">
</label> </label>
<ion-toggle class="has-comment" ng-model="encrypt" toggle-class="toggle-positive" ng-change="resizeView()" ng-show="seedSourceId == 'new' || seedSourceId == 'set'"> <ion-toggle class="has-comment" ng-model="encrypt" toggle-class="toggle-positive" ng-change="resizeView()" ng-show="seedSourceId == 'new' || seedSourceId == 'set'">
@ -130,7 +130,7 @@
<strong translate>This password cannot be recovered. If the password is lost, there is no way you could recover your funds.</strong> <strong translate>This password cannot be recovered. If the password is lost, there is no way you could recover your funds.</strong>
</div> </div>
<ion-checkbox ng-model="passwordSaved" class="checkbox-positive" ng-show="encrypt && result == 'correct'"> <ion-checkbox ng-model="formData.passwordSaved" class="checkbox-positive" ng-show="encrypt && result == 'correct'">
<span class="toggle-label" translate>I have written it down</span> <span class="toggle-label" translate>I have written it down</span>
</ion-checkbox> </ion-checkbox>
@ -139,14 +139,14 @@
<input type="text" <input type="text"
placeholder="{{'BIP32 path for address derivation'|translate}}" placeholder="{{'BIP32 path for address derivation'|translate}}"
name="derivationPath" name="derivationPath"
ng-model="derivationPath"> ng-model="formData.derivationPath">
</label> </label>
</div> <!-- advanced --> </div> <!-- advanced -->
</div> <!-- list --> </div> <!-- list -->
<button type="submit" class="button button-standard button-primary" <button type="submit" class="button button-standard button-primary"
ng-disabled="formData.$invalid || ((encrypt && !passwordSaved) || encrypt && ((seedSourceId == 'new' && !formData.createPassphrase) || (seedSourceId == 'set' && !formData.passphrase)))" ng-disabled="setupForm.$invalid || ((encrypt && !passwordSaved) || encrypt && ((seedSourceId == 'new' && !formData.createPassphrase) || (seedSourceId == 'set' && !formData.passphrase)))"
translate>Join translate>Join
</button> </button>
</form> </form>

View file

@ -6,7 +6,7 @@
</ion-nav-bar> </ion-nav-bar>
<ion-content ng-controller="createController" ng-init="init(1);"> <ion-content ng-controller="createController" ng-init="init(1);">
<form name="setupForm" ng-submit="create(setupForm)" novalidate> <form name="setupForm" ng-submit="create()" novalidate>
<div class="list settings-list settings-input-group"> <div class="list settings-list settings-input-group">
<label class="item item-input item-stacked-label"> <label class="item item-input item-stacked-label">
<span class="input-label" translate>Wallet name</span> <span class="input-label" translate>Wallet name</span>

View file

@ -6,7 +6,7 @@
</ion-nav-bar> </ion-nav-bar>
<ion-content ng-controller="createController" ng-init="init(3);"> <ion-content ng-controller="createController" ng-init="init(3);">
<form name="setupForm" ng-submit="create(setupForm)" novalidate> <form name="setupForm" ng-submit="create()" novalidate>
<div class="list settings-list settings-input-group"> <div class="list settings-list settings-input-group">
<label class="item item-input item-stacked-label"> <label class="item item-input item-stacked-label">
<span class="input-label" translate>Wallet name</span> <span class="input-label" translate>Wallet name</span>