Merge pull request #4467 from matiu/bug/ios-profile

Bug/ios profile
This commit is contained in:
Matias Alejo Garcia 2016-06-21 12:06:45 -03:00 committed by GitHub
commit 6e069bd797
4 changed files with 63 additions and 19 deletions

View file

@ -1407,16 +1407,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
});
$rootScope.$on('Local/ValidatingWallet', function(ev, walletId) {
if (self.isInFocus(walletId)) {
ongoingProcess.set('validatingWallet', true);
}
ongoingProcess.set('validatingWallet', true);
});
$rootScope.$on('Local/ValidatingWalletEnded', function(ev, walletId, isOK) {
profileService.storeProfileIfDirty();
ongoingProcess.set('validatingWallet', false);
if (self.isInFocus(walletId)) {
// NOTE: If the user changed the wallet, the flag is already turn off.
ongoingProcess.set('validatingWallet', false);
self.incorrectDerivation = isOK === false;
}
});

View file

@ -52,9 +52,25 @@ angular.module('copayApp.services')
})
};
root.set = function(k, v, cb) {
var writelock = {};
root.set = function(k, v, cb, delay) {
delay = delay || 100;
if (writelock[k]) {
return setTimeout(function() {
console.log('## Writelock for:' + k + ' Retrying in ' + delay);
return root.set(k, v, cb, delay + 100);
}, delay);
}
writelock[k] = true;
root.init(function(err, fs, dir) {
if (err) return cb(err);
if (err) {
writelock[k] = false;
return cb(err);
}
dir.getFile(k, {
create: true,
}, function(fileEntry) {
@ -62,13 +78,15 @@ angular.module('copayApp.services')
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) {
console.log('Write completed.');
console.log('Write completed:' + k);
writelock[k] = false;
return cb();
};
fileWriter.onerror = function(e) {
var err = e.error ? e.error : JSON.stringify(e);
console.log('Write failed: ' + err);
writelock[k] = false;
return cb('Fail to write:' + err);
};

View file

@ -117,20 +117,32 @@ angular.module('copayApp.services')
return true;
};
root.runValidation = function(client) {
var validationLock = false;
root.runValidation = function(client, delay, retryDelay) {
delay = delay || 500;
retryDelay = retryDelay || 50;
if (validationLock) {
return $timeout(function() {
$log.debug('ValidatingWallet Locked: Retrying in: ' + retryDelay);
return root.runValidation(client, delay, retryDelay);
}, retryDelay);
}
validationLock = true;
// IOS devices are already checked
var skipDeviceValidation = isIOS || root.profile.isDeviceChecked(platformInfo.ua);
var walletId = client.credentials.walletId;
$log.debug('ValidatingWallet: ' + walletId + ' skip Device:' + skipDeviceValidation);
$rootScope.$emit('Local/ValidatingWallet', walletId);
$timeout(function() {
$log.debug('ValidatingWallet: ' + walletId + ' skip Device:' + skipDeviceValidation);
$rootScope.$emit('Local/ValidatingWallet', walletId);
client.validateKeyDerivation({
skipDeviceValidation: skipDeviceValidation,
}, function(err, isOK) {
validationLock = false;
$log.debug('ValidatingWallet End: ' + walletId + ' isOK:' + isOK);
if (isOK) {
root.profile.setChecked(platformInfo.ua, walletId);
@ -138,9 +150,10 @@ angular.module('copayApp.services')
$log.warn('Key Derivation failed for wallet:' + walletId);
storageService.clearLastAddress(walletId, function() {});
}
root.storeProfileIfDirty();
$rootScope.$emit('Local/ValidatingWalletEnded', walletId, isOK);
});
}, 5000);
}, delay);
};
// Used when reading wallets from the profile
@ -163,7 +176,7 @@ angular.module('copayApp.services')
var skipKeyValidation = root.profile.isChecked(platformInfo.ua, credentials.walletId);
if (!skipKeyValidation)
root.runValidation(client);
root.runValidation(client, 500);
$log.info('Binding wallet:' + credentials.walletId + ' Validating?:' + !skipKeyValidation);
return cb(null, root.bindWalletClient(client));
@ -390,8 +403,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) {
@ -512,7 +525,6 @@ angular.module('copayApp.services')
saveBwsUrl(function() {
root.setAndStoreFocus(walletId, function() {
storageService.storeProfile(root.profile, function(err) {
var config = configService.getSync();
if (config.pushNotifications.enabled)
pushNotificationsService.enableNotifications(root.walletClients);

View file

@ -28,7 +28,23 @@ angular.module('copayApp.services')
var json;
try {
json = JSON.parse(text);
} catch (e) {};
} catch (e) {
$log.warn('Could not open profile:' + text);
var i = text.lastIndexOf('}{');
if (i > 0) {
text = text.substr(i + 1);
$log.warn('trying last part only:' + text);
try {
json = JSON.parse(text);
$log.warn('Worked... saving.');
storage.set('profile', text, function() {});
} catch (e) {
$log.warn('Could not open profile (2nd try):' + e);
};
};
};
if (!json) return cb('Could not access storage')