switch between wallets in profile working
This commit is contained in:
parent
ff44897922
commit
ac491d10b0
19 changed files with 293 additions and 179 deletions
54
js/controllers/create.js
Normal file
54
js/controllers/create.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('CreateController',
|
||||
function($scope, $rootScope, $location, $timeout, controllerUtils, backupService, notification) {
|
||||
|
||||
$rootScope.fromSetup = true;
|
||||
$scope.loading = false;
|
||||
$scope.walletPassword = $rootScope.walletPassword;
|
||||
$scope.isMobile = !!window.cordova;
|
||||
$scope.hideAdv = true;
|
||||
$scope.networkName = config.networkName;
|
||||
|
||||
// ng-repeat defined number of times instead of repeating over array?
|
||||
$scope.getNumber = function(num) {
|
||||
return new Array(num);
|
||||
}
|
||||
|
||||
$scope.totalCopayers = config.wallet.totalCopayers;
|
||||
$scope.TCValues = _.range(1, config.limits.totalCopayers + 1);
|
||||
|
||||
var updateRCSelect = function(n) {
|
||||
var maxReq = copay.Wallet.getMaxRequiredCopayers(n);
|
||||
$scope.RCValues = _.range(1, maxReq + 1);
|
||||
$scope.requiredCopayers = Math.min(parseInt(n / 2 + 1), maxReq);
|
||||
};
|
||||
|
||||
updateRCSelect($scope.totalCopayers);
|
||||
|
||||
$scope.$watch('totalCopayers', function(tc) {
|
||||
updateRCSelect(tc);
|
||||
});
|
||||
|
||||
$scope.create = function(form) {
|
||||
if (form && form.$invalid) {
|
||||
notification.error('Error', 'Please enter the required fields');
|
||||
return;
|
||||
}
|
||||
$scope.loading = true;
|
||||
var opts = {
|
||||
requiredCopayers: $scope.requiredCopayers,
|
||||
totalCopayers: $scope.totalCopayers,
|
||||
name: $scope.walletName,
|
||||
privateKeyHex: $scope.private,
|
||||
networkName: $scope.networkName,
|
||||
};
|
||||
$rootScope.iden.createWallet(opts, function(err, w) {
|
||||
$rootScope.iden.closeWallet($rootScope.wallet.id, function() {
|
||||
$scope.loading = false;
|
||||
$rootScope.wallet = w;
|
||||
controllerUtils.bindWallet(w, $scope);
|
||||
});
|
||||
});
|
||||
};
|
||||
});
|
||||
|
|
@ -13,10 +13,8 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
|||
walletDefaults: config.wallet,
|
||||
passphrase: config.passphrase,
|
||||
}, function(err, iden ,w) {
|
||||
$scope.loading = false;
|
||||
$rootScope.iden = iden;
|
||||
$rootScope.wallet = w;
|
||||
|
||||
controllerUtils.bindWallet(w, $scope);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
controllerUtils.onErrorDigest(
|
||||
$scope, (err.toString()||'').match('PNOTFOUND') ? 'Profile not found' : 'Unknown error');
|
||||
} else {
|
||||
$scope.loading = false;
|
||||
$rootScope.iden = iden;
|
||||
$rootScope.wallet = w;
|
||||
controllerUtils.bindWallet(w, $scope);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('JoinController',
|
||||
function($scope, $rootScope, $timeout, identity, controllerUtils, Passphrase, notification) {
|
||||
controllerUtils.redirIfLogged();
|
||||
function($scope, $rootScope, $timeout, controllerUtils, notification) {
|
||||
$rootScope.fromSetup = false;
|
||||
$scope.loading = false;
|
||||
$scope.isMobile = !!window.cordova;
|
||||
|
|
@ -120,31 +119,32 @@ angular.module('copayApp.controllers').controller('JoinController',
|
|||
|
||||
$scope.loading = true;
|
||||
|
||||
Passphrase.getBase64Async($scope.joinPassword, function(passphrase) {
|
||||
identity.joinCreateSession({
|
||||
secret: $scope.connectionId,
|
||||
nickname: $scope.nickname,
|
||||
passphrase: passphrase,
|
||||
privateHex: $scope.private,
|
||||
}, function(err, w) {
|
||||
$rootScope.iden.joinWallet({
|
||||
secret: $scope.connectionId,
|
||||
nickname: $scope.nickname,
|
||||
privateHex: $scope.private,
|
||||
}, function(err, w) {
|
||||
|
||||
$scope.loading = false;
|
||||
if (err || !w) {
|
||||
if (err === 'joinError')
|
||||
notification.error('Fatal error connecting to Insight server');
|
||||
else if (err === 'walletFull')
|
||||
notification.error('The wallet is full');
|
||||
else if (err === 'badNetwork')
|
||||
notification.error('Network Error', 'Wallet network configuration missmatch');
|
||||
else if (err === 'badSecret')
|
||||
notification.error('Bad secret', 'The secret string you entered is invalid');
|
||||
else
|
||||
notification.error('Unknown error');
|
||||
controllerUtils.onErrorDigest();
|
||||
} else {
|
||||
controllerUtils.startNetwork(w, $scope);
|
||||
}
|
||||
});
|
||||
$scope.loading = false;
|
||||
if (err || !w) {
|
||||
if (err === 'joinError')
|
||||
notification.error('Fatal error connecting to Insight server');
|
||||
else if (err === 'walletFull')
|
||||
notification.error('The wallet is full');
|
||||
else if (err === 'badNetwork')
|
||||
notification.error('Network Error', 'Wallet network configuration missmatch');
|
||||
else if (err === 'badSecret')
|
||||
notification.error('Bad secret', 'The secret string you entered is invalid');
|
||||
else
|
||||
notification.error('Unknown error');
|
||||
controllerUtils.onErrorDigest();
|
||||
} else {
|
||||
$rootScope.iden.closeWallet($rootScope.wallet.id, function() {
|
||||
$scope.loading = false;
|
||||
$rootScope.wallet = w;
|
||||
controllerUtils.bindWallet(w, $scope);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('MoreController',
|
||||
function($scope, $rootScope, $location, $filter, backupService, identity, controllerUtils, notification, rateService) {
|
||||
function($scope, $rootScope, $location, $filter, backupService, controllerUtils, notification, rateService) {
|
||||
var w = $rootScope.wallet;
|
||||
$scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ angular.module('copayApp.controllers').controller('MoreController',
|
|||
};
|
||||
|
||||
$scope.deleteWallet = function() {
|
||||
identity.delete(w.id, function() {
|
||||
$rootScope.iden.deleteWallet(w.id, function() {
|
||||
controllerUtils.logout();
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('OpenController', function($scope, $rootScope, $location, identity, controllerUtils, Passphrase, notification) {
|
||||
angular.module('copayApp.controllers').controller('OpenController', function($scope, $rootScope, $location, controllerUtils, Passphrase, notification) {
|
||||
controllerUtils.redirIfLogged();
|
||||
|
||||
if ($rootScope.pendingPayment) {
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ angular.module('copayApp.controllers').controller('SidebarController', function(
|
|||
}
|
||||
|
||||
if ($rootScope.wallet) {
|
||||
$scope.$on('$idleWarn', function(a,countdown) {
|
||||
if (!(countdown%5))
|
||||
notification.warning('Session will be closed', $filter('translate')('Your session is about to expire due to inactivity in') + ' ' + countdown + ' ' + $filter('translate')('seconds'));
|
||||
$scope.$on('$idleWarn', function(a, countdown) {
|
||||
if (!(countdown % 5))
|
||||
notification.warning('Session will be closed', $filter('translate')('Your session is about to expire due to inactivity in') + ' ' + countdown + ' ' + $filter('translate')('seconds'));
|
||||
});
|
||||
|
||||
$scope.$on('$idleTimeout', function() {
|
||||
|
|
@ -71,4 +71,21 @@ angular.module('copayApp.controllers').controller('SidebarController', function(
|
|||
$rootScope.wallet.keepAlive();
|
||||
});
|
||||
}
|
||||
|
||||
$scope.switchWallet = function(id) {
|
||||
var iden = $rootScope.iden;
|
||||
controllerUtils.unbindWallet($scope);
|
||||
|
||||
iden.openWallet(id, null, function(err, w) {
|
||||
if (err) {
|
||||
notification.warning('Could not open wallet');
|
||||
} else {
|
||||
iden.closeWallet($rootScope.wallet.id, function() {
|
||||
$scope.loading = false;
|
||||
$rootScope.wallet = w;
|
||||
controllerUtils.bindWallet(w, $scope);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue