commit
5bba50b18d
21 changed files with 547 additions and 226 deletions
14
js/app.js
14
js/app.js
|
|
@ -2,16 +2,17 @@
|
|||
|
||||
var copay = require('copay');
|
||||
var _ = require('lodash');
|
||||
var config = defaultConfig;
|
||||
var LS = require('../js/plugins/LocalStorage');
|
||||
var ls = new LS();
|
||||
|
||||
var localConfig;
|
||||
var defaults = JSON.parse(JSON.stringify(defaultConfig));
|
||||
|
||||
|
||||
// TODO move this to configService !
|
||||
var config = copay.defaultConfig;
|
||||
ls.getItem('config', function(err, data) {
|
||||
var localConfig;
|
||||
try {
|
||||
localConfig = JSON.parse(data);
|
||||
} catch(e) {};
|
||||
if (localConfig) {
|
||||
var cmv = copay.version.split('.')[1];
|
||||
var lmv = localConfig.version ? localConfig.version.split('.')[1] : '-1';
|
||||
|
|
@ -38,12 +39,9 @@ var modules = [
|
|||
'copayApp.directives',
|
||||
];
|
||||
|
||||
if (Object.keys(config.plugins).length)
|
||||
modules.push('angularLoad');
|
||||
|
||||
|
||||
var copayApp = window.copayApp = angular.module('copayApp', modules);
|
||||
|
||||
var defaults = JSON.parse(JSON.stringify(copay.defaultConfig));
|
||||
copayApp.value('defaults', defaults);
|
||||
|
||||
copayApp.config(function($sceDelegateProvider) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, $timeout, notification, pluginManager, identityService, pinService, isMobile) {
|
||||
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, $timeout, notification, pluginManager, identityService, pinService, isMobile, configService) {
|
||||
|
||||
var _credentials, _firstpin;
|
||||
|
||||
|
|
@ -8,6 +8,9 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
|||
identityService.goWalletHome();
|
||||
$scope.isMobile = isMobile.any();
|
||||
|
||||
$scope.createStep = 'storage';
|
||||
$scope.useLocalstorage = false;
|
||||
|
||||
pinService.makePinInput($scope, 'newpin', function(newValue) {
|
||||
_firstpin = newValue;
|
||||
$scope.askForPin = 2;
|
||||
|
|
@ -47,10 +50,43 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
$scope.setStep = function(step) {
|
||||
$scope.error = null;
|
||||
$scope.createStep = step;
|
||||
$timeout(function() {
|
||||
$scope.$digest();
|
||||
}, 1);
|
||||
};
|
||||
|
||||
$scope.selectStorage = function(storage) {
|
||||
$scope.useLocalstorage = storage == 'local';
|
||||
$timeout(function() {
|
||||
$scope.$digest();
|
||||
}, 1);
|
||||
};
|
||||
|
||||
$scope.goToEmail = function() {
|
||||
$scope.createStep = 'email';
|
||||
$scope.useEmail = !$scope.useLocalstorage;
|
||||
};
|
||||
|
||||
$scope.setEmailOrUsername = function(form) {
|
||||
$scope.userOrEmail = $scope.useLocalstorage ? form.username.$modelValue : form.email.$modelValue;
|
||||
preconditions.checkState($scope.userOrEmail);
|
||||
|
||||
$scope.createStep = 'pass';
|
||||
$timeout(function() {
|
||||
$scope.$digest();
|
||||
}, 1);
|
||||
};
|
||||
|
||||
|
||||
|
||||
$scope.createDefaultWallet = function() {
|
||||
$rootScope.hideNavigation = false;
|
||||
identityService.createDefaultWallet(function(err) {
|
||||
$scope.askForPin =0 ;
|
||||
$scope.askForPin = 0;
|
||||
$scope.loading = false;
|
||||
|
||||
if (err) {
|
||||
|
|
@ -60,34 +96,24 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
|||
});
|
||||
};
|
||||
|
||||
$scope.createProfile = function(form) {
|
||||
$rootScope.hideNavigation = false;
|
||||
if (form && form.$invalid) {
|
||||
$scope.error = 'Please enter the required fields';
|
||||
return;
|
||||
}
|
||||
$scope.loading = true;
|
||||
identityService.create(form.email.$modelValue, form.password.$modelValue, function(err) {
|
||||
$scope.loading = false;
|
||||
|
||||
$scope._doCreateProfile = function(emailOrUsername, password, cb) {
|
||||
preconditions.checkArgument(_.isString(emailOrUsername));
|
||||
preconditions.checkArgument(_.isString(password));
|
||||
|
||||
$rootScope.hideNavigation = false;
|
||||
$scope.loading = true;
|
||||
|
||||
identityService.create(emailOrUsername, password, function(err) {
|
||||
$scope.loading = false;
|
||||
$scope.error = null;
|
||||
if (err) {
|
||||
var msg = err.toString();
|
||||
if (msg.indexOf('EEXIST') >= 0 || msg.indexOf('BADC') >= 0) {
|
||||
msg = 'This profile already exists'
|
||||
}
|
||||
$timeout(function() {
|
||||
form.email.$setViewValue('');
|
||||
form.email.$render();
|
||||
form.password.$setViewValue('');
|
||||
form.password.$render();
|
||||
form.repeatpassword.$setViewValue('');
|
||||
form.repeatpassword.$render();
|
||||
form.$setPristine();
|
||||
$scope.error = msg;
|
||||
},1);
|
||||
$scope.error = msg;
|
||||
} else {
|
||||
$scope.error = null;
|
||||
// mobile
|
||||
if ($scope.isMobile) {
|
||||
_credentials = {
|
||||
|
|
@ -99,12 +125,47 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
|||
$timeout(function() {
|
||||
$rootScope.$digest();
|
||||
}, 1);
|
||||
|
||||
return;
|
||||
} else {
|
||||
$scope.createDefaultWallet();
|
||||
}
|
||||
}
|
||||
return cb();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$scope.saveSettings = function(cb) {
|
||||
var plugins = config.plugins;
|
||||
|
||||
plugins.EncryptedLocalStorage = false;
|
||||
plugins.EncryptedInsightStorage = false;
|
||||
|
||||
var pluginName = $scope.useLocalstorage ? 'EncryptedLocalStorage' : 'EncryptedInsightStorage';
|
||||
plugins[pluginName] = true;
|
||||
|
||||
configService.set({
|
||||
plugins: plugins
|
||||
}, cb);
|
||||
};
|
||||
|
||||
|
||||
$scope.createProfile = function(form) {
|
||||
if (form && form.$invalid) {
|
||||
$scope.error = 'Please enter the required fields';
|
||||
return;
|
||||
}
|
||||
$scope.saveSettings(function(err) {
|
||||
$scope._doCreateProfile($scope.userOrEmail, form.password.$modelValue, function(err) {
|
||||
$timeout(function() {
|
||||
form.password.$setViewValue('');
|
||||
form.password.$render();
|
||||
form.repeatpassword.$setViewValue('');
|
||||
form.repeatpassword.$render();
|
||||
form.$setPristine();
|
||||
}, 1);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
|
||||
|
||||
var _credentials, _firstpin;
|
||||
|
||||
$scope.init = function() {
|
||||
$scope.isMobile = isMobile.any();
|
||||
$scope.attempt=0;
|
||||
|
||||
// This is only for backwards compat, insight api should link to #!/confirmed directly
|
||||
if (getParam('confirmed')) {
|
||||
|
|
@ -28,6 +28,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
pinService.check(function(err, value) {
|
||||
$rootScope.hasPin = value;
|
||||
});
|
||||
$scope.usingLocalStorage = config.plugins.EncryptedLocalStorage;
|
||||
};
|
||||
|
||||
pinService.makePinInput($scope, 'pin', function(newValue) {
|
||||
|
|
@ -139,8 +140,13 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
copay.logger.warn(err);
|
||||
if ((err.toString() || '').match('PNOTFOUND')) {
|
||||
$scope.error = 'Invalid email or password';
|
||||
|
||||
if($scope.attempt++>1) {
|
||||
var storage = $scope.usingLocalStorage ? 'this device storage' : 'cloud storage';
|
||||
$scope.error = 'Invalid email or password. You are trying to sign in using ' + storage + '. Change it on settings is necessary.';
|
||||
};
|
||||
|
||||
pinService.clear(function() {
|
||||
copay.logger.debug('PIN erased');
|
||||
});
|
||||
} else if ((err.toString() || '').match('Connection')) {
|
||||
$scope.error = 'Could not connect to Insight Server';
|
||||
|
|
@ -150,7 +156,9 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
$scope.error = 'Unknown error';
|
||||
}
|
||||
$rootScope.starting = false;
|
||||
$rootScope.$digest();
|
||||
$timeout(function(){
|
||||
$rootScope.$digest();
|
||||
},1)
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,8 +64,10 @@ angular.module('copayApp.controllers').controller('HomeWalletController', functi
|
|||
|
||||
$scope.$on("$destroy", function() {
|
||||
var w = $rootScope.wallet;
|
||||
removeWatch();
|
||||
w.removeListener('txProposalEvent', _updateTxs);
|
||||
if (w) {
|
||||
removeWatch();
|
||||
w.removeListener('txProposalEvent', _updateTxs);
|
||||
};
|
||||
});
|
||||
|
||||
$scope.setAlternativeAmount = function(w, tx, cb) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $route, $location, $anchorScroll, notification, applicationService, localstorageService) {
|
||||
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $route, $location, notification, configService) {
|
||||
$scope.title = 'Settings';
|
||||
$scope.defaultLanguage = config.defaultLanguage || 'en';
|
||||
$scope.insightLivenet = config.network.livenet.url;
|
||||
|
|
@ -18,10 +18,10 @@ angular.module('copayApp.controllers').controller('SettingsController', function
|
|||
}
|
||||
|
||||
$scope.availableStorages = [{
|
||||
name: 'Insight',
|
||||
name: 'In the cloud (Insight server)',
|
||||
pluginName: 'EncryptedInsightStorage',
|
||||
}, {
|
||||
name: 'Localstorage',
|
||||
name: 'In this device (localstorage)',
|
||||
pluginName: 'EncryptedLocalStorage',
|
||||
},
|
||||
// {
|
||||
|
|
@ -57,7 +57,6 @@ angular.module('copayApp.controllers').controller('SettingsController', function
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
$scope.save = function() {
|
||||
$scope.insightLivenet = copay.Insight.setCompleteUrl($scope.insightLivenet);
|
||||
$scope.insightTestnet = copay.Insight.setCompleteUrl($scope.insightTestnet);
|
||||
|
|
@ -73,33 +72,32 @@ angular.module('copayApp.controllers').controller('SettingsController', function
|
|||
},
|
||||
}
|
||||
|
||||
|
||||
var plugins = {};
|
||||
plugins[$scope.selectedStorage.pluginName] = true;
|
||||
copay.logger.setLevel($scope.selectedLogLevel.name);
|
||||
|
||||
localstorageService.setItem('config', JSON.stringify({
|
||||
network: insightSettings,
|
||||
version: copay.version,
|
||||
defaultLanguage: $scope.selectedLanguage.isoCode,
|
||||
plugins: plugins,
|
||||
logLevel: $scope.selectedLogLevel.name,
|
||||
EncryptedInsightStorage: _.extend(config.EncryptedInsightStorage, {
|
||||
url: insightSettings.livenet.url + '/api/email'
|
||||
}),
|
||||
rates: _.extend(config.rates, {
|
||||
url: insightSettings.livenet.url + '/api/rates'
|
||||
}),
|
||||
}), function() {
|
||||
applicationService.restart();
|
||||
});
|
||||
|
||||
configService.set({
|
||||
network: insightSettings,
|
||||
version: copay.version,
|
||||
defaultLanguage: $scope.selectedLanguage.isoCode,
|
||||
plugins: plugins,
|
||||
logLevel: $scope.selectedLogLevel.name,
|
||||
EncryptedInsightStorage: _.extend(config.EncryptedInsightStorage, {
|
||||
url: insightSettings.livenet.url + '/api/email'
|
||||
}),
|
||||
rates: _.extend(config.rates, {
|
||||
url: insightSettings.livenet.url + '/api/rates'
|
||||
}),
|
||||
},
|
||||
function() {
|
||||
notification.success('Settings saved');
|
||||
$location.path('/');
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
$scope.reset = function() {
|
||||
localstorageService.removeItem('config', function() {
|
||||
applicationService.reload();
|
||||
configService.reset(function() {
|
||||
notification.success('Settings reseted');
|
||||
$location.path('/');
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
38
js/services/configService.js
Normal file
38
js/services/configService.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('configService', function(localstorageService, gettextCatalog) {
|
||||
var root = {};
|
||||
|
||||
root.set = function(opts, cb) {
|
||||
|
||||
if (opts.logLevel)
|
||||
copay.logger.setLevel(opts.logLevel);
|
||||
|
||||
if (opts.defaultLanguage)
|
||||
gettextCatalog.currentLanguage = opts.defaultLanguage;
|
||||
|
||||
localstorageService.getItem('config', function(err, oldOpsStr) {
|
||||
|
||||
var oldOpts = {};
|
||||
|
||||
try {
|
||||
oldOpts = JSON.parse(oldOpsStr);
|
||||
} catch (e) {};
|
||||
|
||||
var newOpts = {};
|
||||
_.extend(newOpts, copay.defaultConfig, oldOpts, opts);
|
||||
|
||||
// TODO remove this gloval variable.
|
||||
config = newOpts;
|
||||
|
||||
localstorageService.setItem('config', JSON.stringify(newOpts), cb);
|
||||
});
|
||||
};
|
||||
|
||||
root.reset = function(cb) {
|
||||
config = copay.defaultConfig;
|
||||
localstorageService.removeItem('config', cb);
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
@ -11,10 +11,10 @@ angular.module('copayApp.services')
|
|||
var root = {};
|
||||
root.check = function(scope) {
|
||||
copay.Identity.checkIfExistsAny({
|
||||
pluginManager: pluginManager,
|
||||
pluginManager: pluginManager.getInstance(config),
|
||||
}, function(anyProfile) {
|
||||
copay.Wallet.checkIfExistsAny({
|
||||
pluginManager: pluginManager,
|
||||
pluginManager: pluginManager.getInstance(config),
|
||||
}, function(anyWallet) {
|
||||
scope.loading = false;
|
||||
scope.anyProfile = anyProfile ? true : false;
|
||||
|
|
@ -47,7 +47,7 @@ angular.module('copayApp.services')
|
|||
copay.Identity.create({
|
||||
email: email,
|
||||
password: password,
|
||||
pluginManager: pluginManager,
|
||||
pluginManager: pluginManager.getInstance(config),
|
||||
network: config.network,
|
||||
networkName: config.networkName,
|
||||
walletDefaults: config.wallet,
|
||||
|
|
@ -99,7 +99,7 @@ angular.module('copayApp.services')
|
|||
var opts = {
|
||||
email: email,
|
||||
password: password,
|
||||
pluginManager: pluginManager,
|
||||
pluginManager: pluginManager.getInstance(config),
|
||||
network: config.network,
|
||||
networkName: config.networkName,
|
||||
walletDefaults: config.wallet,
|
||||
|
|
@ -348,7 +348,7 @@ angular.module('copayApp.services')
|
|||
|
||||
root.importProfile = function(str, password, cb) {
|
||||
copay.Identity.importFromEncryptedFullJson(str, password, {
|
||||
pluginManager: pluginManager,
|
||||
pluginManager: pluginManager.getInstance(config),
|
||||
network: config.network,
|
||||
networkName: config.networkName,
|
||||
walletDefaults: config.wallet,
|
||||
|
|
|
|||
|
|
@ -1,18 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('pluginManager', function(angularLoad) {
|
||||
var pm = new copay.PluginManager(config);
|
||||
var scripts = pm.scripts;
|
||||
angular.module('copayApp.services').factory('pluginManager', function() {
|
||||
var root = {};
|
||||
root.getInstance = function(config){
|
||||
return new copay.PluginManager(config);
|
||||
};
|
||||
|
||||
for(var ii in scripts){
|
||||
var src = scripts[ii].src;
|
||||
|
||||
console.log('\tLoading ',src); //TODO
|
||||
angularLoad.loadScript(src)
|
||||
.then(scripts[ii].then || null)
|
||||
.catch(function() {
|
||||
throw new Error('Loading ' + src);
|
||||
})
|
||||
}
|
||||
return pm;
|
||||
return root;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue