From 1f6596a5ad5dce6119505a65fff3e4a8df925e96 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Fri, 24 Apr 2015 16:39:12 -0300 Subject: [PATCH 01/10] file api working. Migration script missing --- cordova/build.sh | 3 + cordova/config.xml | 3 + src/js/controllers/index.js | 18 +++++ src/js/routes.js | 7 +- src/js/services/configService.js | 13 ++-- src/js/services/fileStorage.js | 117 ++++++++++++++++++++++++++++++ src/js/services/localStorage.js | 38 +++------- src/js/services/profileService.js | 6 +- src/js/services/storageService.js | 25 ++++--- 9 files changed, 180 insertions(+), 50 deletions(-) create mode 100644 src/js/services/fileStorage.js diff --git a/cordova/build.sh b/cordova/build.sh index 4215be899..9858c897f 100755 --- a/cordova/build.sh +++ b/cordova/build.sh @@ -126,6 +126,9 @@ if [ ! -d $PROJECT ]; then cordova plugin add hu.dpal.phonegap.plugins.uniquedeviceid checkOK + cordova plugin add org.apache.cordova.file + checkOK + fi if $DBGJS diff --git a/cordova/config.xml b/cordova/config.xml index aabee9e98..07d568350 100644 --- a/cordova/config.xml +++ b/cordova/config.xml @@ -12,6 +12,9 @@ + + + diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 9ca748ad2..0971cf64e 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -426,6 +426,19 @@ angular.module('copayApp.controllers').controller('indexController', function($r } }; + self.deviceError = function (err) { + if (isCordova) { + navigator.notification.confirm( + err, + function() {}, + 'Device Error', ['OK'] + ); + } else { + alert(err); + } + }; + + self.recreate = function(cb) { var fc = profileService.focusedClient; self.setOngoingProcess('recreating', true); @@ -563,6 +576,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r $rootScope.$apply(); }); + $rootScope.$on('Local/DeviceError', function(event, err) { + self.deviceError(err); + $rootScope.$apply(); + }); + $rootScope.$on('Local/ClientError', function(event, err) { if (err.code && err.code === 'NOTAUTHORIZED') { // Show not error, just redirect to home (where the recreate option is shown) diff --git a/src/js/routes.js b/src/js/routes.js index d68255875..357e3f2f6 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -434,18 +434,21 @@ angular if (!profileService.profile && toState.needProfile) { + // Give us time to open / create the profile + event.preventDefault(); + // Try to open local profile profileService.loadAndBindProfile(function(err) { if (err) { if (err.message.match('NOPROFILE')) { $log.debug('No profile... redirecting'); $state.transitionTo('splash'); - event.preventDefault(); } else { throw new Error(err); // TODO } } else { - // Profile was loaded + console.log('Profile loaded ... resuming transition'); + $state.transitionTo('walletHome'); } }); } diff --git a/src/js/services/configService.js b/src/js/services/configService.js index 0e3ae3dad..baffdf8d4 100644 --- a/src/js/services/configService.js +++ b/src/js/services/configService.js @@ -1,8 +1,10 @@ 'use strict'; -angular.module('copayApp.services').factory('configService', function(localStorageService, lodash, bwcService) { +angular.module('copayApp.services').factory('configService', function(localStorageService, fileStorageService, isCordova, lodash, bwcService) { var root = {}; + var storage = isCordova ? fileStorageService : localStorageService; + var defaultConfig = { // wallet limits limits: { @@ -66,8 +68,7 @@ angular.module('copayApp.services').factory('configService', function(localStora }; root.get = function(cb) { - localStorageService.get('config', function(err, localConfig) { - + storage.get('config', function(err, localConfig) { if (localConfig) { configCache = JSON.parse(localConfig); @@ -89,7 +90,7 @@ angular.module('copayApp.services').factory('configService', function(localStora root.set = function(newOpts, cb) { var config = defaultConfig; - localStorageService.get('config', function(err, oldOpts) { + storage.get('config', function(err, oldOpts) { if (lodash.isString(oldOpts)) { oldOpts = JSON.parse(oldOpts); } @@ -102,12 +103,12 @@ angular.module('copayApp.services').factory('configService', function(localStora lodash.merge(config, oldOpts, newOpts); configCache = config; - localStorageService.set('config', JSON.stringify(config), cb); + storage.set('config', JSON.stringify(config), cb); }); }; root.reset = function(cb) { - localStorageService.remove('config', cb); + storage.remove('config', cb); }; root.getDefaults = function() { diff --git a/src/js/services/fileStorage.js b/src/js/services/fileStorage.js new file mode 100644 index 000000000..d745acbfe --- /dev/null +++ b/src/js/services/fileStorage.js @@ -0,0 +1,117 @@ +'use strict'; + +angular.module('copayApp.services') + .factory('fileStorageService', function(lodash, $log) { + var root = {}, fs; + + + root.init = function(cb) { + if (fs) return cb(null, fs); + + function onFileSystemSuccess(fileSystem) { + console.log('File system started: ', fileSystem.name, fileSystem.root.name); + fs = fileSystem; + return cb(null, fs); + } + + function fail(evt) { + var msg = 'Could not init file system: ' + evt.target.error.code; + console.log(msg); + return cb(msg); + }; + + window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail); + }; + + + root.get = function(k, cb) { + root.init(function(err, fs) { + if (err) return cb(err); + fs.root.getFile(k, { + create: false, + }, function(fileEntry) { + if (!fileEntry) return cb(); + fileEntry.file(function(file) { + var reader = new FileReader(); + + reader.onloadend = function(e) { + console.log("Read: " + this.result); + return cb(null, this.result) + } + + reader.readAsText(file); + }); + }, function(err) { + // Not found + if (err.code==1) return cb(); + else return cb(err); + }); + }) + }; + + root.set = function(k, v, cb) { + root.init(function(err, fs) { + if (err) return cb(err); + fs.root.getFile(k, { + create: true, + }, function(fileEntry) { + // Create a FileWriter object for our FileEntry (log.txt). + fileEntry.createWriter(function(fileWriter) { + + fileWriter.onwriteend = function(e) { + console.log('Write completed.'); + return cb(); + }; + + fileWriter.onerror = function(e) { + console.log('Write failed: ' + e.toString()); + return cb('Fail to write:', e.toString()); + }; + + if (lodash.isObject(v)) + v = JSON.stringify(v); + + var blob = new Blob([v], { + type: "application/json" + }); + + fileWriter.write(blob); + + }, cb); + }); + + }); + }; + + root.remove = function(k, cb) { + root.init(function(err, fs) { + if (err) return cb(err); + fs.root.getFile(k, { + create: false, + }, function(fileEntry) { + // Create a FileWriter object for our FileEntry (log.txt). + fileEntry.remove(function() { + console.log('File removed.'); + return cb(); + }, cb, cb); + }); + }); + }; + + /** + * Same as setItem, but fails if an item already exists + */ + root.create = function(name, value, callback) { + root.get(name, + function(err, data) { + if (data) { + return callback('EEXISTS'); + } else { + return root.set(name, value, callback); + } + }); + }; + + + return root; + }); diff --git a/src/js/services/localStorage.js b/src/js/services/localStorage.js index 462627df2..e4574351f 100644 --- a/src/js/services/localStorage.js +++ b/src/js/services/localStorage.js @@ -1,12 +1,9 @@ 'use strict'; angular.module('copayApp.services') - .factory('localStorageService', function() { - - var isChromeApp = typeof window !== "undefined" && window.chrome && chrome.runtime && chrome.runtime.id; + .factory('localStorageService', function(isChromeApp, $timeout) { var root = {}; - - var ls = ((typeof localStorage !== "undefined") ? localStorage : null); + var ls = ((typeof window.localStorage !== "undefined") ? window.localStorage : null); if (isChromeApp && !ls) { ls = localStorage = chrome.storage.local; @@ -14,9 +11,7 @@ angular.module('copayApp.services') } if (!ls) - throw new Error('localstorage not available, cannot run plugin'); - - root.init = function() {}; + throw new Error('localstorage not available'); root.get = function(k, cb) { if (isChromeApp) { @@ -26,7 +21,13 @@ angular.module('copayApp.services') return cb(null, data[k]); }); } else { +console.log('[localStorage.js.24]',k); //TODO +console.log('[localStorage.js.25:TODO:]'); //TODO +console.log('[localStorage.js.26:TODO:]'); //TODO +console.log('[localStorage.js.27:TODO:]'); //TODO + $timeout(function() { return cb(null, ls.getItem(k)); + }, 1000); } }; @@ -67,26 +68,5 @@ angular.module('copayApp.services') }; - root.clear = function(cb) { - // NOP - return cb(); - }; - - root.list = function(cb) { - if (isChromeApp) { - chrome.storage.local.get(null, function(items) { - return cb(null, lodash.keys(items)); - }); - } else { - var ret = []; - var l = ls.length; - - for (var i = 0; i < l; i++) - ret.push(ls.key(i)); - - return cb(null, ret); - } - }; - return root; }); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 769274428..88225bfcb 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -111,6 +111,8 @@ angular.module('copayApp.services') root.bindProfile = function(profile, cb) { + +console.log('[profileService.js.114] Bind profile', profile); //TODO root.profile = profile; configService.get(function(err) { @@ -127,12 +129,14 @@ angular.module('copayApp.services') root.loadAndBindProfile = function(cb) { storageService.getProfile(function(err, profile) { +console.log('[profileService.js.129:err:]',err); //TODO if (err) { - notification.error('CRITICAL ERROR: ' + err); + $rootScope.$emit('Local/DeviceError', err); return cb(err); } if (!profile) return cb(new Error('NOPROFILE: No profile')); +console.log('[profileService.js.135] BIND'); //TODO return root.bindProfile(profile, cb); }); }; diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index 7422a3650..671525ee1 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -1,8 +1,9 @@ 'use strict'; angular.module('copayApp.services') - .factory('storageService', function(localStorageService, sjcl, $log, lodash) { + .factory('storageService', function(fileStorageService, localStorageService, sjcl, $log, lodash, isCordova) { var root = {}; + var storage = isCordova ? fileStorageService : localStorageService; var getUUID = function(cb) { // TO SIMULATE MOBILE @@ -48,18 +49,18 @@ angular.module('copayApp.services') root.storeNewProfile = function(profile, cb) { encryptOnMobile(profile.toObj(), function(err, x) { - localStorageService.create('profile', x, cb); + storage.create('profile', x, cb); }); }; root.storeProfile = function(profile, cb) { encryptOnMobile(profile.toObj(), function(err, x) { - localStorageService.set('profile', x, cb); + storage.set('profile', x, cb); }); }; root.getProfile = function(cb) { - localStorageService.get('profile', function(err, str) { + storage.get('profile', function(err, str) { if (err || !str) return cb(err); decryptOnMobile(str, function(err, str) { @@ -76,35 +77,35 @@ angular.module('copayApp.services') }; root.deleteProfile = function(cb) { - localStorageService.remove('profile', cb); + storage.remove('profile', cb); }; root.storeFocusedWalletId = function(id, cb) { - localStorageService.set('focusedWalletId', id, cb); + storage.set('focusedWalletId', id, cb); }; root.getFocusedWalletId = function(cb) { - localStorageService.get('focusedWalletId', cb); + storage.get('focusedWalletId', cb); }; root.getLastAddress = function(walletId, cb) { - localStorageService.get('lastAddress-' + walletId, cb); + storage.get('lastAddress-' + walletId, cb); }; root.storeLastAddress = function(walletId, address, cb) { - localStorageService.set('lastAddress-' + walletId, address, cb); + storage.set('lastAddress-' + walletId, address, cb); }; root.clearLastAddress = function(walletId, cb) { - localStorageService.remove('lastAddress-' + walletId, cb); + storage.remove('lastAddress-' + walletId, cb); }; root.setBackupFlag = function(walletId, cb) { - localStorageService.set('backup-' + walletId, Date.now(), cb); + storage.set('backup-' + walletId, Date.now(), cb); }; root.getBackupFlag = function(walletId, cb) { - localStorageService.get('backup-' + walletId, cb); + storage.get('backup-' + walletId, cb); }; return root; From 6723cba56a8b9d9d55ce5eb2842302c25352f176 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Fri, 24 Apr 2015 18:06:04 -0300 Subject: [PATCH 02/10] rm logs --- src/js/services/localStorage.js | 6 ------ src/js/services/profileService.js | 5 ----- src/js/services/storageService.js | 5 ++++- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/js/services/localStorage.js b/src/js/services/localStorage.js index e4574351f..1d8c55b11 100644 --- a/src/js/services/localStorage.js +++ b/src/js/services/localStorage.js @@ -21,13 +21,7 @@ angular.module('copayApp.services') return cb(null, data[k]); }); } else { -console.log('[localStorage.js.24]',k); //TODO -console.log('[localStorage.js.25:TODO:]'); //TODO -console.log('[localStorage.js.26:TODO:]'); //TODO -console.log('[localStorage.js.27:TODO:]'); //TODO - $timeout(function() { return cb(null, ls.getItem(k)); - }, 1000); } }; diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 88225bfcb..4f90edb5c 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -111,8 +111,6 @@ angular.module('copayApp.services') root.bindProfile = function(profile, cb) { - -console.log('[profileService.js.114] Bind profile', profile); //TODO root.profile = profile; configService.get(function(err) { @@ -129,14 +127,12 @@ console.log('[profileService.js.114] Bind profile', profile); //TODO root.loadAndBindProfile = function(cb) { storageService.getProfile(function(err, profile) { -console.log('[profileService.js.129:err:]',err); //TODO if (err) { $rootScope.$emit('Local/DeviceError', err); return cb(err); } if (!profile) return cb(new Error('NOPROFILE: No profile')); -console.log('[profileService.js.135] BIND'); //TODO return root.bindProfile(profile, cb); }); }; @@ -192,7 +188,6 @@ console.log('[profileService.js.135] BIND'); //TODO return cb('Could not join using the specified extended private key'); } } - // TODO name walletClient.joinWallet(opts.secret, opts.myName || 'me', function(err) { if (err) return cb(err); diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index 671525ee1..37ee76731 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -61,7 +61,10 @@ angular.module('copayApp.services') root.getProfile = function(cb) { storage.get('profile', function(err, str) { - if (err || !str) return cb(err); + + if (err || !str) + // Migrate ? + return cb(err); decryptOnMobile(str, function(err, str) { if (err) return cb(err); From f47d6b0564eba6a2310ac33c395f88503cd77ba9 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 25 Apr 2015 12:37:04 -0300 Subject: [PATCH 03/10] view logs in UX --- public/views/includes/version.html | 1 - public/views/preferences.html | 6 ++ public/views/preferencesAbout.html | 34 +++++++++ public/views/preferencesLogs.html | 10 +++ src/css/main.css | 1 + src/js/controllers/index.js | 7 +- src/js/controllers/preferencesAbout.js | 4 + src/js/controllers/preferencesAltCurrency.js | 2 +- src/js/controllers/preferencesBwsUrl.js | 2 +- src/js/controllers/preferencesLogs.js | 7 ++ src/js/controllers/preferencesUnit.js | 2 +- src/js/routes.js | 79 +++++++++++++++++--- src/js/services/configService.js | 38 ++-------- src/js/services/historicLog.js | 19 +++++ src/js/services/profileService.js | 11 ++- src/js/services/storageService.js | 12 +++ 16 files changed, 188 insertions(+), 47 deletions(-) create mode 100644 public/views/preferencesAbout.html create mode 100644 public/views/preferencesLogs.html create mode 100644 src/js/controllers/preferencesAbout.js create mode 100644 src/js/controllers/preferencesLogs.js create mode 100644 src/js/services/historicLog.js 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 @@

    {{index.walletName}} settings

    +
  • Color @@ -58,6 +59,11 @@ {{preferences.bwsurl}}
  • +
  • + + About Copay +
  • +
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 @@ +
+
    +
    + Copay +
    +

    Release Information

    + +
    +
  • + Version + + v{{v.version}} + +
  • +
  • + Commit hash + + #{{v.commitHash}} + + +
  • +
    + +

     

    +
  • + View session logs + + + +
  • + +
+ +
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 @@ +
+
    +
  • + + + {{l.msg}} + +
  • +
+
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; }); From cf557fe0182cd90730f024df96d05a7ead9d7f2d Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 25 Apr 2015 14:42:17 -0300 Subject: [PATCH 04/10] migration from localStorage to fileStorege --- src/js/routes.js | 11 ++++++++--- src/js/services/configService.js | 7 ++++--- src/js/services/profileService.js | 33 +++++++++++++++++++++++-------- src/js/services/storageService.js | 30 ++++++++++++++++++++++++++-- 4 files changed, 65 insertions(+), 16 deletions(-) diff --git a/src/js/routes.js b/src/js/routes.js index 6eefe1a6d..c0e7f3e9c 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -27,9 +27,14 @@ angular ['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)+'...'; + var args = [].slice.call(arguments); + args = args.map(function(v) { + if (typeof v == 'undefined') v = 'undefined'; + if (typeof v == 'object') { + v = JSON.stringify(v); + if (v.length > 200) + v = v.substr(0, 197) + '...'; + } return v; }); historicLog.add(level, args.join(' ')); diff --git a/src/js/services/configService.js b/src/js/services/configService.js index 9174b5055..835e2aa8c 100644 --- a/src/js/services/configService.js +++ b/src/js/services/configService.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.services').factory('configService', function(storageService, lodash) { +angular.module('copayApp.services').factory('configService', function(storageService, lodash, $log) { var root = {}; var defaultConfig = { @@ -48,6 +48,7 @@ angular.module('copayApp.services').factory('configService', function(storageSer }; root.get = function(cb) { + storageService.getConfig(function(err, localConfig) { if (localConfig) { configCache = JSON.parse(localConfig); @@ -61,9 +62,9 @@ angular.module('copayApp.services').factory('configService', function(storageSer } } else { - configCache = defaultConfig; + configCache = lodash.clone(defaultConfig); }; - + $log.debug('Preferences read:', configCache) return cb(err, configCache); }); }; diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 3305abaad..08e9ec4b8 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -139,10 +139,21 @@ angular.module('copayApp.services') $rootScope.$emit('Local/DeviceError', err); return cb(err); } - if (!profile) return cb(new Error('NOPROFILE: No profile')); - $log.debug('Profile read'); + if (!profile) { + // Migration?? + storageService.tryToMigrate(function(err, migratedProfile) { + if (err) return cb(err); + if (!migratedProfile) + return cb(new Error('NOPROFILE: No profile')); + + profile = migratedProfile; + return root.bindProfile(profile, cb); + }) + } else { + $log.debug('Profile read'); + return root.bindProfile(profile, cb); + } - return root.bindProfile(profile, cb); }); }; @@ -268,11 +279,17 @@ angular.module('copayApp.services') root.create = function(cb) { - root._createNewProfile(function(err, p) { - if (err) return cb(err); - root.bindProfile(p, function(err) { - storageService.storeNewProfile(p, function(err) { - return cb(err); + $log.info('Creating profile'); + configService.get(function(err) { + root.applyConfig(); + root._createNewProfile(function(err, p) { + if (err) return cb(err); + +console.log('[profileService.js.287]'); //TODO + root.bindProfile(p, function(err) { + storageService.storeNewProfile(p, function(err) { + return cb(err); + }); }); }); }); diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index aa138372b..db72bf7c8 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -47,6 +47,32 @@ angular.module('copayApp.services') }); }; + + + root.tryToMigrate = function(cb) { + if (!isCordova) return cb(); + + localStorageService.get('profile', function(err, p) { + if (err) cb(err); + if (!p) return cb(); + $log.info('Starting Migration profile to File storage...') + fileStorageService.create('profile', p, function(err) { + if (err) cb(err); + $log.info('Profile Migrated successfully'); + + localStorageService.get('config', function(err, c) { + if (err) cb(err); + if (!c) return cb(null, p); + fileStorageService.create('config', c, function(err) { + if (err) cb(err); + $log.info('Config Migrated successfully'); + return cb(null, p) + }); + }); + }); + }); + }; + root.storeNewProfile = function(profile, cb) { encryptOnMobile(profile.toObj(), function(err, x) { storage.create('profile', x, cb); @@ -62,8 +88,8 @@ angular.module('copayApp.services') root.getProfile = function(cb) { storage.get('profile', function(err, str) { - if (err || !str) - // Migrate ? + if (err || !str) + // Migrate ? return cb(err); decryptOnMobile(str, function(err, str) { From 648d7545568eb1549b0c84efd2355d5a31d05417 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 25 Apr 2015 15:09:13 -0300 Subject: [PATCH 05/10] migration tested --- src/js/routes.js | 3 +++ src/js/services/profileService.js | 2 +- src/js/services/storageService.js | 23 +++++++++++++++-------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/js/routes.js b/src/js/routes.js index c0e7f3e9c..f369a1618 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -38,6 +38,9 @@ angular return v; }); historicLog.add(level, args.join(' ')); + if (window.cordova) + console.log(args.join(' ')); + orig.apply(null, args) }; }); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 08e9ec4b8..7d488952a 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -285,7 +285,7 @@ angular.module('copayApp.services') root._createNewProfile(function(err, p) { if (err) return cb(err); -console.log('[profileService.js.287]'); //TODO + console.log('[profileService.js.287]'); //TODO root.bindProfile(p, function(err) { storageService.storeNewProfile(p, function(err) { return cb(err); diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index db72bf7c8..99a7f5fe7 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -52,21 +52,28 @@ angular.module('copayApp.services') root.tryToMigrate = function(cb) { if (!isCordova) return cb(); - localStorageService.get('profile', function(err, p) { - if (err) cb(err); - if (!p) return cb(); + localStorageService.get('profile', function(err, str) { + if (err) return cb(err); + if (!str) return cb(); + $log.info('Starting Migration profile to File storage...') - fileStorageService.create('profile', p, function(err) { + + fileStorageService.create('profile', str, function(err) { if (err) cb(err); $log.info('Profile Migrated successfully'); localStorageService.get('config', function(err, c) { - if (err) cb(err); - if (!c) return cb(null, p); + if (err) return cb(err); + if (!c) return root.getProfile(cb); + fileStorageService.create('config', c, function(err) { - if (err) cb(err); + + if (err) { + $log.info('Error migrating config: ignoring', err); + return root.getProfile(cb); + } $log.info('Config Migrated successfully'); - return cb(null, p) + return root.getProfile(cb); }); }); }); From 55d8c006587269c94db3ef59371d6192c9429fbc Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 25 Apr 2015 20:53:31 -0300 Subject: [PATCH 06/10] fix storing files at dataDirectory --- src/js/routes.js | 14 +++-- src/js/services/fileStorage.js | 101 ++++++++++++++++++--------------- 2 files changed, 65 insertions(+), 50 deletions(-) diff --git a/src/js/routes.js b/src/js/routes.js index f369a1618..4fd6fc8da 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -29,11 +29,17 @@ angular $delegate[level] = function() { var args = [].slice.call(arguments); args = args.map(function(v) { - if (typeof v == 'undefined') v = 'undefined'; - if (typeof v == 'object') { - v = JSON.stringify(v); - if (v.length > 200) + try { + if (typeof v == 'undefined') v = 'undefined'; + if (typeof v == 'object') { + v = JSON.stringify(v); + } + v = v.toString(); + if (v.length > 200) v = v.substr(0, 197) + '...'; + } catch (e) { + console.log('Error at log decorator:', e); + v = 'undefined'; } return v; }); diff --git a/src/js/services/fileStorage.js b/src/js/services/fileStorage.js index d745acbfe..a8b09c54d 100644 --- a/src/js/services/fileStorage.js +++ b/src/js/services/fileStorage.js @@ -2,7 +2,8 @@ angular.module('copayApp.services') .factory('fileStorageService', function(lodash, $log) { - var root = {}, fs; + var root = {}, + fs; root.init = function(cb) { @@ -27,24 +28,28 @@ angular.module('copayApp.services') root.get = function(k, cb) { root.init(function(err, fs) { if (err) return cb(err); - fs.root.getFile(k, { - create: false, - }, function(fileEntry) { - if (!fileEntry) return cb(); - fileEntry.file(function(file) { - var reader = new FileReader(); + window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) { + $log.debug(".get: Got main dir:", dir.nativeURL); + dir.getFile(k, { + create: false, + }, function(fileEntry) { + if (!fileEntry) return cb(); + fileEntry.file(function(file) { + var reader = new FileReader(); - reader.onloadend = function(e) { - console.log("Read: " + this.result); - return cb(null, this.result) - } + reader.onloadend = function(e) { + if (this.result) + $log.debug("Read: ", this.result); + return cb(null, this.result) + } - reader.readAsText(file); + reader.readAsText(file); + }); + }, function(err) { + // Not found + if (err.code == 1) return cb(); + else return cb(err); }); - }, function(err) { - // Not found - if (err.code==1) return cb(); - else return cb(err); }); }) }; @@ -52,48 +57,52 @@ angular.module('copayApp.services') root.set = function(k, v, cb) { root.init(function(err, fs) { if (err) return cb(err); - fs.root.getFile(k, { - create: true, - }, function(fileEntry) { - // Create a FileWriter object for our FileEntry (log.txt). - fileEntry.createWriter(function(fileWriter) { + window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) { + $log.debug(".set: Got main dir:", dir.nativeURL); + dir.getFile(k, { + create: true, + }, function(fileEntry) { + // Create a FileWriter object for our FileEntry (log.txt). + fileEntry.createWriter(function(fileWriter) { - fileWriter.onwriteend = function(e) { - console.log('Write completed.'); - return cb(); - }; + fileWriter.onwriteend = function(e) { + console.log('Write completed.'); + return cb(); + }; - fileWriter.onerror = function(e) { - console.log('Write failed: ' + e.toString()); - return cb('Fail to write:', e.toString()); - }; + fileWriter.onerror = function(e) { + console.log('Write failed: ' + e.toString()); + return cb('Fail to write:', e.toString()); + }; - if (lodash.isObject(v)) - v = JSON.stringify(v); + if (lodash.isObject(v)) + v = JSON.stringify(v); - var blob = new Blob([v], { - type: "application/json" - }); + $log.debug('Writing:', k, v); + var blob = new Blob([v], { + type: "text/plain" + }); + fileWriter.write(blob); - fileWriter.write(blob); - - }, cb); + }, cb); + }); }); - }); }; root.remove = function(k, cb) { root.init(function(err, fs) { if (err) return cb(err); - fs.root.getFile(k, { - create: false, - }, function(fileEntry) { - // Create a FileWriter object for our FileEntry (log.txt). - fileEntry.remove(function() { - console.log('File removed.'); - return cb(); - }, cb, cb); + window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) { + dir.getFile(k, { + create: false, + }, function(fileEntry) { + // Create a FileWriter object for our FileEntry (log.txt). + fileEntry.remove(function() { + console.log('File removed.'); + return cb(); + }, cb, cb); + }); }); }); }; From 3abfb65087a7d465d873d4874ba9f2a76a1f83ae Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 25 Apr 2015 21:08:19 -0300 Subject: [PATCH 07/10] add send logs by email --- public/views/preferencesLogs.html | 6 ++++++ src/js/controllers/preferencesLogs.js | 23 +++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/public/views/preferencesLogs.html b/public/views/preferencesLogs.html index 293082cbf..f5bcd7f0f 100644 --- a/public/views/preferencesLogs.html +++ b/public/views/preferencesLogs.html @@ -1,4 +1,10 @@
+ + +
  • diff --git a/src/js/controllers/preferencesLogs.js b/src/js/controllers/preferencesLogs.js index 43a38b7b4..15ff13159 100644 --- a/src/js/controllers/preferencesLogs.js +++ b/src/js/controllers/preferencesLogs.js @@ -1,7 +1,22 @@ 'use strict'; angular.module('copayApp.controllers').controller('preferencesLogs', - function(historicLog) { - this.logs = historicLog.get(); -console.log('[preferencesLogs.js.5:historicLog:]',this.logs); //TODO - }); +function(historicLog, isCordova) { + this.logs = historicLog.get(); + this.isCordova = isCordova; + + this.sendLogs = function() { + var body = 'Copay Session Logs\n Be careful, this could contain sensitive private data\n\n Copay v' + window.version + ' #' + window.commitHash; + body += '\n\n' + body += this.logs.map(function(v) { + return v.msg; + }).join('\n'); + + var properties = { + subject: 'Copay Logs', + body: body, + isHtml: false + }; + window.plugin.email.open(properties); + }; +}); From 7f6b41e11d5e09598c11dd550289fae8dad17140 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sun, 26 Apr 2015 11:41:25 -0300 Subject: [PATCH 08/10] no file storage from WP --- src/js/controllers/index.js | 1 + src/js/controllers/preferencesLogs.js | 4 ++-- src/js/routes.js | 3 --- src/js/services/fileStorage.js | 25 ++++++++++++++++++++++--- src/js/services/isChromeApp.js | 2 +- src/js/services/logHeader.js | 9 +++++++++ src/js/services/profileService.js | 2 +- src/js/services/storageService.js | 13 ++++++++++--- 8 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 src/js/services/logHeader.js diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 648a0b10b..6acefe57d 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -1,6 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, gettextCatalog, amMoment) { + var self = this; self.isCordova = isCordova; self.onGoingProcess = {}; diff --git a/src/js/controllers/preferencesLogs.js b/src/js/controllers/preferencesLogs.js index 15ff13159..8444c3ae0 100644 --- a/src/js/controllers/preferencesLogs.js +++ b/src/js/controllers/preferencesLogs.js @@ -6,8 +6,8 @@ function(historicLog, isCordova) { this.isCordova = isCordova; this.sendLogs = function() { - var body = 'Copay Session Logs\n Be careful, this could contain sensitive private data\n\n Copay v' + window.version + ' #' + window.commitHash; - body += '\n\n' + var body = 'Copay Session Logs\n Be careful, this could contain sensitive private data\n\n'; + body += '\n\n'; body += this.logs.map(function(v) { return v.msg; }).join('\n'); diff --git a/src/js/routes.js b/src/js/routes.js index 4fd6fc8da..5bfa59519 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -447,11 +447,8 @@ angular }); }) .run(function($rootScope, $state, $log, gettextCatalog, uriHandler, isCordova, amMoment, profileService) { - - $log.debug('Attaching FastClick'); FastClick.attach(document.body); - // Auto-detect browser language var userLang, androidLang; diff --git a/src/js/services/fileStorage.js b/src/js/services/fileStorage.js index a8b09c54d..2a14db7a5 100644 --- a/src/js/services/fileStorage.js +++ b/src/js/services/fileStorage.js @@ -28,7 +28,8 @@ angular.module('copayApp.services') root.get = function(k, cb) { root.init(function(err, fs) { if (err) return cb(err); - window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) { + root.getDir(function(err, dir) { + if (err) return cb(err); $log.debug(".get: Got main dir:", dir.nativeURL); dir.getFile(k, { create: false, @@ -57,7 +58,8 @@ angular.module('copayApp.services') root.set = function(k, v, cb) { root.init(function(err, fs) { if (err) return cb(err); - window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) { + root.getDir(function(err, dir) { + if (err) return cb(err); $log.debug(".set: Got main dir:", dir.nativeURL); dir.getFile(k, { create: true, @@ -90,10 +92,27 @@ angular.module('copayApp.services') }); }; + + // See https://github.com/apache/cordova-plugin-file/#where-to-store-files + root.getDir = function(cb) { + if (!cordova.file) { + return cb('Could not write on device storage'); + } + + var url = cordova.file.dataDirectory; + // This could be needed for windows + // if (cordova.file === undefined) { + // url = 'ms-appdata:///local/'; + window.resolveLocalFileSystemURL(url, function(dir) { + return cb(null, dir); + }); + }; + root.remove = function(k, cb) { root.init(function(err, fs) { if (err) return cb(err); - window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) { + root.getDir(function(err, dir) { + if (err) return cb(err); dir.getFile(k, { create: false, }, function(fileEntry) { diff --git a/src/js/services/isChromeApp.js b/src/js/services/isChromeApp.js index 22c0c13b8..72a8e275e 100644 --- a/src/js/services/isChromeApp.js +++ b/src/js/services/isChromeApp.js @@ -1,4 +1,4 @@ 'use strict'; -angular.module('copayApp.services').value('isChromeApp', window.chrome && chrome.runtime && chrome.runtime.id); +angular.module('copayApp.services').value('isChromeApp', !!(window.chrome && chrome.runtime && chrome.runtime.id)); diff --git a/src/js/services/logHeader.js b/src/js/services/logHeader.js new file mode 100644 index 000000000..ef64fb45b --- /dev/null +++ b/src/js/services/logHeader.js @@ -0,0 +1,9 @@ +'use strict'; +angular.module('copayApp.services') + .factory('logHeader', function($log, isChromeApp, isCordova) { + $log.info('Starting Copay v' + window.version + ' #' + window.commitHash); + $log.info('Client: isCordova:', isCordova, 'isChromeApp:', isChromeApp); + $log.info('Navigator:', navigator.userAgent); + + return {}; + }); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 7d488952a..dc9d353ab 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -1,6 +1,6 @@ 'use strict'; angular.module('copayApp.services') - .factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, lodash, pluginManager, balanceService, applicationService, storageService, bwcService, configService, notificationService, notification, isChromeApp) { + .factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, lodash, storageService, bwcService, configService, notificationService, isChromeApp, isCordova) { var root = {}; diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index 99a7f5fe7..65387942c 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -1,9 +1,16 @@ 'use strict'; angular.module('copayApp.services') - .factory('storageService', function(fileStorageService, localStorageService, sjcl, $log, lodash, isCordova) { + .factory('storageService', function(logHeader, fileStorageService, localStorageService, sjcl, $log, lodash, isCordova) { var root = {}; - var storage = isCordova ? fileStorageService : localStorageService; + + // File storage is not supported for writting according to + // https://github.com/apache/cordova-plugin-file/#supported-platforms + var shouldUseFileStorage = isCordova && !isMobile.Windows(); + $log.debug('Using file storage:', shouldUseFileStorage); + + + var storage = shouldUseFileStorage ? fileStorageService : localStorageService; var getUUID = function(cb) { // TO SIMULATE MOBILE @@ -50,7 +57,7 @@ angular.module('copayApp.services') root.tryToMigrate = function(cb) { - if (!isCordova) return cb(); + if (!shouldUseFileStorage) return cb(); localStorageService.get('profile', function(err, str) { if (err) return cb(err); From e38f9a4611a439aefa4306bb6810d56744b732ad Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sun, 26 Apr 2015 20:13:02 -0300 Subject: [PATCH 09/10] fix store config --- src/js/controllers/preferencesColor.js | 5 ++++- src/js/routes.js | 13 ++++++++----- src/js/services/configService.js | 2 +- src/js/services/logHeader.js | 1 - src/js/services/storageService.js | 1 + 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/js/controllers/preferencesColor.js b/src/js/controllers/preferencesColor.js index cea2165d4..754d8fb9e 100644 --- a/src/js/controllers/preferencesColor.js +++ b/src/js/controllers/preferencesColor.js @@ -29,7 +29,10 @@ angular.module('copayApp.controllers').controller('preferencesColorController', opts.colorFor[walletId] = color; configService.set(opts, function(err) { - if (err) console.log(err); + if (err) { + $scope.$emit('Local/DeviceError', err); + return; + } self.color = color; $scope.$emit('Local/ColorUpdated'); }); diff --git a/src/js/routes.js b/src/js/routes.js index 5bfa59519..b03013a13 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -43,11 +43,14 @@ angular } return v; }); - historicLog.add(level, args.join(' ')); - if (window.cordova) - console.log(args.join(' ')); - - orig.apply(null, args) + try { + if (window.cordova) + console.log(args.join(' ')); + orig.apply(null, args) + historicLog.add(level, args.join(' ')); + } catch (e) { + console.log('Error at log decorator:', e); + } }; }); return $delegate; diff --git a/src/js/services/configService.js b/src/js/services/configService.js index 835e2aa8c..5666b56ae 100644 --- a/src/js/services/configService.js +++ b/src/js/services/configService.js @@ -84,7 +84,7 @@ angular.module('copayApp.services').factory('configService', function(storageSer lodash.merge(config, oldOpts, newOpts); configCache = config; - storageService.setConfig(JSON.stringify(config), cb); + storageService.storeConfig(JSON.stringify(config), cb); }); }; diff --git a/src/js/services/logHeader.js b/src/js/services/logHeader.js index ef64fb45b..698c442a2 100644 --- a/src/js/services/logHeader.js +++ b/src/js/services/logHeader.js @@ -4,6 +4,5 @@ angular.module('copayApp.services') $log.info('Starting Copay v' + window.version + ' #' + window.commitHash); $log.info('Client: isCordova:', isCordova, 'isChromeApp:', isChromeApp); $log.info('Navigator:', navigator.userAgent); - return {}; }); diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index 65387942c..51c12537f 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -156,6 +156,7 @@ angular.module('copayApp.services') }; root.storeConfig = function(val, cb) { + $log.debug('Storing Preferences', val); storage.set('config', val, cb); }; From 6f1721d7c1007d9ffba3a707efb3e0490e0ad916 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sun, 26 Apr 2015 20:30:09 -0300 Subject: [PATCH 10/10] no backup warning for TESTNET wallets --- src/js/controllers/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 6acefe57d..71edde1f4 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -97,7 +97,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.copayers = []; storageService.getBackupFlag(self.walletId, function(err, val) { - self.needsBackup = !val; + self.needsBackup = self.network == 'testnet' ? false : !val; self.openWallet(); }); }); @@ -415,7 +415,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r }; - self.clientError = function (err) { + self.clientError = function(err) { if (isCordova) { navigator.notification.confirm( err, @@ -427,7 +427,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r } }; - self.deviceError = function (err) { + self.deviceError = function(err) { if (isCordova) { navigator.notification.confirm( err, @@ -562,7 +562,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r $rootScope.$on('Local/Offline', function(event) { $log.debug('Offline event'); self.isOffline = true; - $timeout(function(){ + $timeout(function() { $rootScope.$apply(); }); }); @@ -599,7 +599,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r var msg = 'Error at Wallet Service: '; if (err.message) msg = msg + err.message; else if (err.error) msg = msg + err.error; - else msg = msg + err; + else msg = msg + err; self.clientError(msg); } $rootScope.$apply();