diff --git a/public/views/includes/version.html b/public/views/includes/version.html index e0fd0393f..c190141fe 100644 --- a/public/views/includes/version.html +++ b/public/views/includes/version.html @@ -1,5 +1,4 @@ v{{v.version}} - #{{v.commitHash}} diff --git a/public/views/preferences.html b/public/views/preferences.html index 75f6269a5..c027c9531 100644 --- a/public/views/preferences.html +++ b/public/views/preferences.html @@ -2,6 +2,7 @@ diff --git a/public/views/preferencesAbout.html b/public/views/preferencesAbout.html new file mode 100644 index 000000000..a2f1ae95a --- /dev/null +++ b/public/views/preferencesAbout.html @@ -0,0 +1,34 @@ +
+ + +
diff --git a/public/views/preferencesLogs.html b/public/views/preferencesLogs.html new file mode 100644 index 000000000..293082cbf --- /dev/null +++ b/public/views/preferencesLogs.html @@ -0,0 +1,10 @@ +
+ +
diff --git a/src/css/main.css b/src/css/main.css index 42e52ec4f..d84d5129c 100644 --- a/src/css/main.css +++ b/src/css/main.css @@ -881,6 +881,7 @@ input.ng-invalid-match, input.ng-invalid-match:focus { .text-secondary {color: #3498DB;} .text-white {color: #fff;} .text-warning {color: #ED4A43;} +.text-alert {color: red;} .text-success {color: #1ABC9C;} .panel { diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 0971cf64e..648a0b10b 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -534,11 +534,16 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.updateColor(); }); - $rootScope.$on('Local/ConfigurationUpdated', function(event) { + $rootScope.$on('Local/UnitSettingUpdated', function(event) { self.updateAll(); self.updateTxHistory(); }); + + $rootScope.$on('Local/BWSUpdated', function(event) { + profileService.applyConfig(); + }); + $rootScope.$on('Local/WalletCompleted', function(event) { self.setFocusedWallet(); go.walletHome(); diff --git a/src/js/controllers/preferencesAbout.js b/src/js/controllers/preferencesAbout.js new file mode 100644 index 000000000..9a88ccbb9 --- /dev/null +++ b/src/js/controllers/preferencesAbout.js @@ -0,0 +1,4 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('preferencesAbout', + function() {}); diff --git a/src/js/controllers/preferencesAltCurrency.js b/src/js/controllers/preferencesAltCurrency.js index 4653483cd..1a5d9a725 100644 --- a/src/js/controllers/preferencesAltCurrency.js +++ b/src/js/controllers/preferencesAltCurrency.js @@ -49,7 +49,7 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl configService.set(opts, function(err) { if (err) console.log(err); - $scope.$emit('Local/ConfigurationUpdated'); + $scope.$emit('Local/UnitSettingUpdated'); }); }; diff --git a/src/js/controllers/preferencesBwsUrl.js b/src/js/controllers/preferencesBwsUrl.js index 882e78f7f..fd0d5c8bd 100644 --- a/src/js/controllers/preferencesBwsUrl.js +++ b/src/js/controllers/preferencesBwsUrl.js @@ -23,9 +23,9 @@ angular.module('copayApp.controllers').controller('preferencesBwsUrlController', configService.set(opts, function(err) { if (err) console.log(err); + $scope.$emit('Local/BWSUpdated'); applicationService.restart(true); go.walletHome(); - $scope.$emit('Local/ConfigurationUpdated'); }); }; diff --git a/src/js/controllers/preferencesLogs.js b/src/js/controllers/preferencesLogs.js new file mode 100644 index 000000000..43a38b7b4 --- /dev/null +++ b/src/js/controllers/preferencesLogs.js @@ -0,0 +1,7 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('preferencesLogs', + function(historicLog) { + this.logs = historicLog.get(); +console.log('[preferencesLogs.js.5:historicLog:]',this.logs); //TODO + }); diff --git a/src/js/controllers/preferencesUnit.js b/src/js/controllers/preferencesUnit.js index 1d7238fb5..23821e8f1 100644 --- a/src/js/controllers/preferencesUnit.js +++ b/src/js/controllers/preferencesUnit.js @@ -52,7 +52,7 @@ angular.module('copayApp.controllers').controller('preferencesUnitController', configService.set(opts, function(err) { if (err) console.log(err); - $scope.$emit('Local/ConfigurationUpdated'); + $scope.$emit('Local/UnitSettingUpdated'); }); }; diff --git a/src/js/routes.js b/src/js/routes.js index 357e3f2f6..6eefe1a6d 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -16,9 +16,30 @@ if (window && window.navigator) { //Setting up route angular .module('copayApp') - .config(function(bwcServiceProvider, $stateProvider, $urlRouterProvider) { + .config(function(historicLogProvider, $provide, $logProvider, $stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise('/'); + $logProvider.debugEnabled(true); + $provide.decorator('$log', ['$delegate', + function($delegate) { + var historicLog = historicLogProvider.$get(); + + ['debug', 'info', 'warn', 'error', 'log'].forEach(function(level) { + var orig = $delegate[level]; + $delegate[level] = function() { + var args = [].slice.call(arguments).map(function(v){ + if (typeof v == 'undefined') return 'undefined'; + if (typeof v == 'object') return JSON.stringify(v).substr(0,200)+'...'; + return v; + }); + historicLog.add(level, args.join(' ')); + orig.apply(null, args) + }; + }); + return $delegate; + } + ]); + $stateProvider .state('splash', { url: '/splash', @@ -305,6 +326,42 @@ angular } } }) + .state('about', { + url: '/about', + templateUrl: 'views/preferencesAbout.html', + walletShouldBeComplete: true, + needProfile: true, + views: { + 'main': { + templateUrl: 'views/preferencesAbout.html' + }, + 'topbar': { + templateUrl: 'views/includes/topbar.html', + controller: function($scope) { + $scope.titleSection = 'About'; + $scope.goBackToState = 'preferences'; + } + } + } + }) + .state('logs', { + url: '/logs', + templateUrl: 'views/preferencesLogs.html', + walletShouldBeComplete: true, + needProfile: true, + views: { + 'main': { + templateUrl: 'views/preferencesLogs.html' + }, + 'topbar': { + templateUrl: 'views/includes/topbar.html', + controller: function($scope) { + $scope.titleSection = 'Logs'; + $scope.goBackToState = 'about'; + } + } + } + }) .state('backup', { url: '/backup', templateUrl: 'views/backup.html', @@ -361,9 +418,9 @@ angular case 'resume': $scope.$emit('Local/Resume'); break; - // case 'online': - // // $scope.$emit('Local/Online'); - // break; + // case 'online': + // // $scope.$emit('Local/Online'); + // break; case 'offline': $scope.$emit('Local/Offline'); break; @@ -376,10 +433,10 @@ angular }); }) .run(function($rootScope, $state, $log, gettextCatalog, uriHandler, isCordova, amMoment, profileService) { - - console.log('Attaching FastClick'); + + $log.debug('Attaching FastClick'); FastClick.attach(document.body); - + // Auto-detect browser language var userLang, androidLang; @@ -413,6 +470,8 @@ angular preferencesUnit: 12, preferencesAltCurrency: 12, preferencesBwsUrl: 12, + about: 12, + logs: 13, add: 0, create: 12, join: 12, @@ -435,7 +494,7 @@ angular if (!profileService.profile && toState.needProfile) { // Give us time to open / create the profile - event.preventDefault(); + event.preventDefault(); // Try to open local profile profileService.loadAndBindProfile(function(err) { @@ -447,8 +506,8 @@ angular throw new Error(err); // TODO } } else { - console.log('Profile loaded ... resuming transition'); - $state.transitionTo('walletHome'); + $log.debug('Profile loaded ... Starting UX.'); + $state.transitionTo(toState, toParams); } }); } diff --git a/src/js/services/configService.js b/src/js/services/configService.js index baffdf8d4..9174b5055 100644 --- a/src/js/services/configService.js +++ b/src/js/services/configService.js @@ -1,10 +1,8 @@ 'use strict'; -angular.module('copayApp.services').factory('configService', function(localStorageService, fileStorageService, isCordova, lodash, bwcService) { +angular.module('copayApp.services').factory('configService', function(storageService, lodash) { var root = {}; - var storage = isCordova ? fileStorageService : localStorageService; - var defaultConfig = { // wallet limits limits: { @@ -17,18 +15,6 @@ angular.module('copayApp.services').factory('configService', function(localStora url: 'https://bws.bitpay.com/bws/api', }, - // insight - insight: { - testnet: { - url: 'https://test-insight.bitpay.com:443', - transports: ['polling'], - }, - livenet: { - url: 'https://insight.bitpay.com:443', - transports: ['polling'], - }, - }, - // wallet default config wallet: { requiredCopayers: 2, @@ -46,12 +32,6 @@ angular.module('copayApp.services').factory('configService', function(localStora } }, - // local encryption/security config - passphraseConfig: { - iterations: 5000, - storageSalt: 'mjuBtGybi/4=', - }, - rates: { url: 'https://insight.bitpay.com:443/api/rates', }, @@ -68,7 +48,7 @@ angular.module('copayApp.services').factory('configService', function(localStora }; root.get = function(cb) { - storage.get('config', function(err, localConfig) { + storageService.getConfig(function(err, localConfig) { if (localConfig) { configCache = JSON.parse(localConfig); @@ -90,7 +70,7 @@ angular.module('copayApp.services').factory('configService', function(localStora root.set = function(newOpts, cb) { var config = defaultConfig; - storage.get('config', function(err, oldOpts) { + storageService.getConfig(function(err, oldOpts) { if (lodash.isString(oldOpts)) { oldOpts = JSON.parse(oldOpts); } @@ -103,23 +83,19 @@ angular.module('copayApp.services').factory('configService', function(localStora lodash.merge(config, oldOpts, newOpts); configCache = config; - storage.set('config', JSON.stringify(config), cb); + storageService.setConfig(JSON.stringify(config), cb); }); }; root.reset = function(cb) { - storage.remove('config', cb); + configCache = lodash.clone(defaultConfig); + storageService.removeConfig(cb); }; root.getDefaults = function() { - return defaultConfig; + return lodash.clone(defaultConfig); }; - root.get(function(err, c) { - if (err) throw Error(err); - bwcService.setBaseUrl(c.bws.url); - bwcService.setTransports(['polling']); - }); return root; }); diff --git a/src/js/services/historicLog.js b/src/js/services/historicLog.js new file mode 100644 index 000000000..f0cd8e5a5 --- /dev/null +++ b/src/js/services/historicLog.js @@ -0,0 +1,19 @@ +'use strict'; +var logs = []; +angular.module('copayApp.services') + .factory('historicLog', function historicLog() { + var root = {}; + + root.add = function(level, msg) { + logs.push({ + level: level, + msg: msg, + }); + }; + + root.get = function() { + return logs; + }; + + return root; + }); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 4f90edb5c..3305abaad 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -110,11 +110,20 @@ angular.module('copayApp.services') }; + root.applyConfig = function() { + var config = configService.getSync(); + $log.debug('Applying preferences'); + bwcService.setBaseUrl(config.bws.url); + bwcService.setTransports(['polling']); + }; + root.bindProfile = function(profile, cb) { root.profile = profile; configService.get(function(err) { + $log.debug('Preferences read'); if (err) return cb(err); + root.applyConfig(); $rootScope.$emit('Local/DefaultLanguage'); root.setWalletClients(); storageService.getFocusedWalletId(function(err, focusedWalletId) { @@ -124,7 +133,6 @@ angular.module('copayApp.services') }); }; - root.loadAndBindProfile = function(cb) { storageService.getProfile(function(err, profile) { if (err) { @@ -132,6 +140,7 @@ angular.module('copayApp.services') return cb(err); } if (!profile) return cb(new Error('NOPROFILE: No profile')); + $log.debug('Profile read'); return root.bindProfile(profile, cb); }); diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index 37ee76731..aa138372b 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -111,5 +111,17 @@ angular.module('copayApp.services') storage.get('backup-' + walletId, cb); }; + root.getConfig = function(cb) { + storage.get('config', cb); + }; + + root.storeConfig = function(val, cb) { + storage.set('config', val, cb); + }; + + root.clearConfig = function(cb) { + storage.remove('config', cb); + }; + return root; });