Merge pull request #3516 from gabrielbazan7/feat/firstFlow1

Fix disclaimer bug
This commit is contained in:
Gustavo Maximiliano Cortez 2015-11-30 19:21:59 -03:00
commit c9824cd656
13 changed files with 167 additions and 99 deletions

View file

@ -1,12 +1,19 @@
'use strict';
angular.module('copayApp.controllers').controller('disclaimerController',
function($scope, $timeout, $log, profileService, isCordova, storageService, gettextCatalog, uxLanguage, go) {
function($scope, $timeout, $log, profileService, isCordova, storageService, applicationService, gettextCatalog, uxLanguage, go) {
self = this;
$scope.lang = uxLanguage.currentLanguage;
$scope.goHome = function() {
go.walletHome();
$scope.error = "";
profileService.storeDisclaimer(function(err) {
if (err) {
$scope.error = err;
$log.warn(err);
$scope.$apply();
} else go.walletHome();
});
};
var create = function() {
@ -14,10 +21,6 @@ angular.module('copayApp.controllers').controller('disclaimerController',
profileService.create({}, function(err) {
if (err) {
if (err == 'EEXISTS')
return go.walletHome();
$log.warn(err);
$scope.error = err;
$scope.$apply();
@ -32,6 +35,13 @@ angular.module('copayApp.controllers').controller('disclaimerController',
});
};
create();
storageService.getProfile(function(err, profile) {
if (!profile) create();
else $scope.creatingProfile = false;
//compatible
storageService.getCopayDisclaimerFlag(function(err, val) {
if (val) go.walletHome();
});
});
});

View file

@ -138,6 +138,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
});
};
self.agreeDisclaimer = function() {
storageService.getProfile(function(err, profile) {
if (profile && profile.agreeDisclaimer)
return profile.agreeDisclaimer;
return null;
});
};
self.setCustomBWSFlag = function() {
var defaults = configService.getDefaults();
var config = configService.getSync();
@ -729,7 +737,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
_creator = '';
if (it.actions && it.actions.length > 1) {
for (var i = 0; i < it.actions.length; i++) {
for (var i = 0; i < it.actions.length; i++) {
_copayers += it.actions[i].copayerName + ':' + it.actions[i].type + ' - ';
}
_creator = (it.creatorName && it.creatorName != 'undefined') ? it.creatorName : '';
@ -1325,14 +1333,17 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$on('Local/NewFocusedWallet', function() {
self.setFocusedWallet();
self.updateTxHistory();
storageService.getCleanAndScanAddresses(function(err, walletId) {
if (walletId && profileService.walletClients[walletId]) {
$log.debug('Clear last address cache and Scan ', walletId);
addressService.expireAddress(walletId, function(err) {
self.startScan(walletId);
});
storageService.removeCleanAndScanAddresses(function() {});
}
storageService.getProfile(function(err, profile) {
if (profile && profile.agreeDisclaimer) go.walletHome();
storageService.getCleanAndScanAddresses(function(err, walletId) {
if (walletId && profileService.walletClients[walletId]) {
$log.debug('Clear last address cache and Scan ', walletId);
addressService.expireAddress(walletId, function(err) {
self.startScan(walletId);
});
storageService.removeCleanAndScanAddresses(function() {});
}
});
});
});

View file

@ -15,15 +15,16 @@ Profile.create = function(opts) {
var x = new Profile();
x.createdOn = Date.now();
x.credentials = opts.credentials || [];
x.agreeDisclaimer = false;
return x;
};
Profile.fromObj = function(obj) {
var x = new Profile();
x.createdOn = obj.createdOn;
x.credentials = obj.credentials;
x.agreeDisclaimer = obj.agreeDisclaimer;
if (x.credentials[0] && typeof x.credentials[0] != 'object')
throw ("credentials should be an object");
@ -31,7 +32,6 @@ Profile.fromObj = function(obj) {
return x;
};
Profile.fromString = function(str) {
return Profile.fromObj(JSON.parse(str));
};
@ -39,5 +39,3 @@ Profile.fromString = function(str) {
Profile.prototype.toObj = function() {
return JSON.stringify(this);
};

View file

@ -263,43 +263,39 @@ angular
},
}
})
.state('preferencesGlidera', {
url: '/preferencesGlidera',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/preferencesGlidera.html'
},
}
})
.state('preferencesAdvanced', {
url: '/preferencesAdvanced',
templateUrl: 'views/preferencesAdvanced.html',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/preferencesAdvanced.html'
},
}
})
.state('preferencesColor', {
url: '/preferencesColor',
templateUrl: 'views/preferencesColor.html',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/preferencesColor.html'
},
}
})
.state('preferencesAltCurrency', {
.state('preferencesGlidera', {
url: '/preferencesGlidera',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/preferencesGlidera.html'
},
}
})
.state('preferencesAdvanced', {
url: '/preferencesAdvanced',
templateUrl: 'views/preferencesAdvanced.html',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/preferencesAdvanced.html'
},
}
})
.state('preferencesColor', {
url: '/preferencesColor',
templateUrl: 'views/preferencesColor.html',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/preferencesColor.html'
},
}
})
.state('preferencesAltCurrency', {
url: '/preferencesAltCurrency',
templateUrl: 'views/preferencesAltCurrency.html',
walletShouldBeComplete: true,
@ -378,8 +374,7 @@ angular
},
}
})
.state('about', {
.state('about', {
url: '/about',
templateUrl: 'views/preferencesAbout.html',
walletShouldBeComplete: true,
@ -443,14 +438,22 @@ angular
},
}
})
.state('termOfUse', {
url: '/termOfUse',
needProfile: true,
views: {
'main': {
templateUrl: 'views/termOfUse.html',
},
}
})
.state('warning', {
url: '/warning',
controller: 'warningController',
templateUrl: 'views/warning.html',
needProfile: false
})
.state('add', {
.state('add', {
url: '/add',
needProfile: true,
views: {
@ -516,13 +519,15 @@ angular
// Give us time to open / create the profile
event.preventDefault();
// Try to open local profile
profileService.loadAndBindProfile(function(err) {
if (err) {
if (err.message && err.message.match('NOPROFILE')) {
$log.debug('No profile... redirecting');
$state.transitionTo('disclaimer');
} else if (err.message && err.message.match('NONAGREEDDISCLAIMER')) {
$log.debug('Display disclaimer... redirecting');
$state.transitionTo('disclaimer');
} else {
throw new Error(err); // TODO
}

View file

@ -42,8 +42,8 @@ angular.module('copayApp.services').factory('animationService', function(isCordo
paperWallet: 13,
logs: 13,
information: 13,
termOfUse: 13,
translators: 13,
disclaimer: 13,
add: 11,
create: 12,
join: 12,

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.services').factory('go', function($window, $rootScope, $location, $state, profileService, nodeWebkit) {
angular.module('copayApp.services').factory('go', function($window, $rootScope, $location, $state, $timeout, profileService, nodeWebkit) {
var root = {};
var hideSidebars = function() {
@ -32,8 +32,7 @@ angular.module('copayApp.services').factory('go', function($window, $rootScope,
root.openExternalLink = function(url, target) {
if (nodeWebkit.isDefined()) {
nodeWebkit.openExternalLink(url);
}
else {
} else {
target = target || '_blank';
var ref = window.open(url, target, 'location=no');
}
@ -53,7 +52,7 @@ angular.module('copayApp.services').factory('go', function($window, $rootScope,
toggleSidebar(invert);
};
root.walletHome = function() {
root.walletHome = function(delayed) {
var fc = profileService.focusedClient;
if (fc && !fc.isComplete()) {
root.path('copayers');

View file

@ -140,7 +140,7 @@ angular.module('copayApp.services')
return cb(err);
}
if (!profile) {
// Migration??
// Migration??
storageService.tryToMigrate(function(err, migratedProfile) {
if (err) return cb(err);
if (!migratedProfile)
@ -150,10 +150,14 @@ angular.module('copayApp.services')
return root.bindProfile(profile, cb);
})
} else {
$log.debug('Profile read');
return root.bindProfile(profile, cb);
storageService.getCopayDisclaimerFlag(function(err, val) {
if (!profile.agreeDisclaimer) {
if (!val) return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
}
$log.debug('Profile read');
return root.bindProfile(profile, cb);
});
}
});
};
@ -270,8 +274,8 @@ angular.module('copayApp.services')
// check if exist
if (lodash.find(root.profile.credentials, {
'walletId': walletData.walletId
})) {
'walletId': walletData.walletId
})) {
return cb(gettext('Cannot join the same wallet more that once'));
}
} catch (ex) {
@ -375,14 +379,14 @@ angular.module('copayApp.services')
var handleImport = function(cb) {
var isImport = opts.mnemonic || opts.externalSource || opts.extendedPrivateKey;
var isImport = opts.mnemonic || opts.externalSource || opts.extendedPrivateKey;
if (!isImport)
if (!isImport)
return cb();
$rootScope.$emit('Local/BackupDone', walletId);
if (!walletClient.isComplete())
if (!walletClient.isComplete())
return cb();
storageService.setCleanAndScanAddresses(walletId, cb);
@ -514,6 +518,15 @@ angular.module('copayApp.services')
});
};
root.storeDisclaimer = function(cb) {
storageService.getProfile(function(err, profile) {
profile.agreeDisclaimer = true;
storageService.storeProfile(profile, function() {
return cb(err);
});
});
}
root.importLegacyWallet = function(username, password, blob, cb) {
var walletClient = bwcService.getClient();

View file

@ -65,7 +65,7 @@ angular.module('copayApp.services')
return storage.set('profile', text, function(err) {
return cb(err, text);
});
} catch(e) {
} catch (e) {
$log.warn('Decrypt error: ', e);
return cb('Could not decrypt storage: device ID mismatch');
};
@ -120,7 +120,6 @@ angular.module('copayApp.services')
root.getProfile = function(cb) {
storage.get('profile', function(err, str) {
if (err || !str)
return cb(err);
@ -199,6 +198,11 @@ angular.module('copayApp.services')
storage.remove('config', cb);
};
//for compatibility
root.getCopayDisclaimerFlag = function(cb) {
storage.get('agreeDisclaimer', cb);
};
root.setRemotePrefsStoredFlag = function(cb) {
storage.set('remotePrefStored', true, cb);
};