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);
};
$scope.create = function(form) {
if (form && form.$invalid) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Please enter the required fields'));
return;
}
$scope.create = function() {
var opts = {
name: $scope.formData.walletName,

View file

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

View file

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

View file

@ -6,9 +6,9 @@
</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">
@ -17,22 +17,22 @@
<input type="text"
placeholder="{{'John'|translate}}"
name="myName"
ng-model="myName"
ng-required="true">
ng-model="formData.myName"
required>
</label>
<div>
<label class="item item-input item-stacked-label no-border">
<span class="input-label" translate>Wallet Invitation</span>
<div class="input-notification">
<i ng-show="!formData.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" class="icon ion-checkmark-circled valid"></i>
<i ng-show="setupForm.secret.$invalid && formData.secret" class="icon ion-close-circled invalid"></i>
</div>
<input id="secret"
type="text"
placeholder="{{'Paste invitation here'|translate}}"
name="secret"
ng-model="secret"
ng-model="formData.secret"
wallet-secret required>
</label>
<div class="qr-scan-icon">
@ -50,7 +50,7 @@
<label class="item item-input item-stacked-label">
<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 class="item item-input item-select">
@ -58,7 +58,7 @@
Wallet Key
</div>
<select class="m10t"
ng-model="seedSource"
ng-model="formData.seedSource"
ng-options="seed as seed.label for seed in seedOptions"
ng-change="setSeedSource(); resizeView()">
</select>
@ -67,7 +67,7 @@
<label class="item item-input item-stacked-label"
ng-show="seedSourceId == 'trezor' || seedSourceId == 'ledger'">
<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 class="item item-input item-stacked-label" ng-show="seedSourceId=='set'">
@ -77,7 +77,7 @@
autocapitalize="off"
type="text"
name="privateKey"
ng-model="privateKey">
ng-model="formData.privateKey">
</label>
<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>
</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>
</ion-checkbox>
@ -139,14 +139,14 @@
<input type="text"
placeholder="{{'BIP32 path for address derivation'|translate}}"
name="derivationPath"
ng-model="derivationPath">
ng-model="formData.derivationPath">
</label>
</div> <!-- advanced -->
</div> <!-- list -->
<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
</button>
</form>

View file

@ -6,7 +6,7 @@
</ion-nav-bar>
<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">
<label class="item item-input item-stacked-label">
<span class="input-label" translate>Wallet name</span>

View file

@ -6,7 +6,7 @@
</ion-nav-bar>
<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">
<label class="item item-input item-stacked-label">
<span class="input-label" translate>Wallet name</span>