controllers refactor to handle identities
This commit is contained in:
parent
622c3da68c
commit
0b7e9be611
14 changed files with 190 additions and 227 deletions
|
|
@ -45,8 +45,8 @@ angular.module('copayApp.controllers').controller('CreateController',
|
|||
};
|
||||
$rootScope.iden.createWallet(opts, function(err, w) {
|
||||
$scope.loading = false;
|
||||
$rootScope.wallet = w;
|
||||
controllerUtils.bindWallet(w, $scope);
|
||||
controllerUtils.installWalletHandlers($scope, w);
|
||||
controllerUtils.setFocusedWallet(w);
|
||||
});
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,10 +12,8 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
|||
networkName: config.networkName,
|
||||
walletDefaults: config.wallet,
|
||||
passphrase: config.passphrase,
|
||||
}, function(err, iden ,w) {
|
||||
$rootScope.iden = iden;
|
||||
$rootScope.wallet = w;
|
||||
controllerUtils.bindWallet(w, $scope);
|
||||
}, function(err, iden , firstWallet) {
|
||||
controllerUtils.bindProfile($scope, iden, firstWallet);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,15 +12,13 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
networkName: config.networkName,
|
||||
walletDefaults: config.wallet,
|
||||
passphrase: config.passphrase,
|
||||
}, function(err, iden, w) {
|
||||
if (err && !w) {
|
||||
}, function(err, iden, firstWallet) {
|
||||
if (err && !iden) {
|
||||
console.log('Error:' + err)
|
||||
controllerUtils.onErrorDigest(
|
||||
$scope, (err.toString()||'').match('PNOTFOUND') ? 'Profile not found' : 'Unknown error');
|
||||
} else {
|
||||
$rootScope.iden = iden;
|
||||
$rootScope.wallet = w;
|
||||
controllerUtils.bindWallet(w, $scope);
|
||||
controllerUtils.bindProfile($scope, iden, firstWallet);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,64 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('OpenController', function($scope, $rootScope, $location, controllerUtils, Passphrase, notification) {
|
||||
controllerUtils.redirIfLogged();
|
||||
|
||||
if ($rootScope.pendingPayment) {
|
||||
notification.info('Login Required', 'Please open wallet to complete payment');
|
||||
}
|
||||
|
||||
var cmp = function(o1, o2) {
|
||||
var v1 = o1.show.toLowerCase(),
|
||||
v2 = o2.show.toLowerCase();
|
||||
return v1 > v2 ? 1 : (v1 < v2) ? -1 : 0;
|
||||
};
|
||||
$rootScope.fromSetup = false;
|
||||
$scope.loading = false;
|
||||
$scope.retreiving = true;
|
||||
|
||||
identity.getWallets(function(err, wallets) {
|
||||
|
||||
if (err || !wallets || !wallets.length) {
|
||||
$location.path('/');
|
||||
} else {
|
||||
$scope.retreiving = false;
|
||||
$scope.wallets = wallets.sort(cmp);
|
||||
var lastOpened = _.findWhere($scope.wallets, {
|
||||
lastOpened: true
|
||||
});
|
||||
$scope.selectedWalletId = lastOpened ? lastOpened.id : ($scope.wallets[0] && $scope.wallets[0].id);
|
||||
|
||||
setTimeout(function() {
|
||||
$rootScope.$digest();
|
||||
}, 0);
|
||||
}
|
||||
});
|
||||
|
||||
$scope.openPassword = '';
|
||||
$scope.isMobile = !!window.cordova;
|
||||
|
||||
$scope.open = function(form) {
|
||||
if (form && form.$invalid) {
|
||||
notification.error('Error', 'Please enter the required fields');
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.loading = true;
|
||||
var password = form.openPassword.$modelValue;
|
||||
|
||||
Passphrase.getBase64Async(password, function(passphrase) {
|
||||
var w, errMsg;
|
||||
identity.open($scope.selectedWalletId, passphrase, function(err, w) {
|
||||
if (!w) {
|
||||
$scope.loading = false;
|
||||
notification.error('Error', err.errMsg || 'Wrong password');
|
||||
$rootScope.$digest();
|
||||
} else {
|
||||
$rootScope.updatingBalance = true;
|
||||
controllerUtils.startNetwork(w, $scope);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
|
|
@ -57,6 +57,8 @@ angular.module('copayApp.controllers').controller('SidebarController', function(
|
|||
return new Array(num);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($rootScope.wallet) {
|
||||
$scope.$on('$idleWarn', function(a, countdown) {
|
||||
if (!(countdown % 5))
|
||||
|
|
@ -72,18 +74,7 @@ angular.module('copayApp.controllers').controller('SidebarController', function(
|
|||
});
|
||||
}
|
||||
|
||||
$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 {
|
||||
$scope.loading = false;
|
||||
$rootScope.wallet = w;
|
||||
controllerUtils.bindWallet(w, $scope);
|
||||
}
|
||||
});
|
||||
$scope.switchWallet = function(wid) {
|
||||
controllerUtils.setFocusedWallet(wid);
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue