commit
72e53771ad
12 changed files with 98 additions and 37 deletions
|
|
@ -11,6 +11,7 @@ angular.module('copayApp.controllers').controller('disclaimerController',
|
|||
var create = function(opts) {
|
||||
opts = opts || {};
|
||||
$log.debug('Creating profile');
|
||||
|
||||
profileService.create(opts, function(err) {
|
||||
if (err) {
|
||||
$log.warn(err);
|
||||
|
|
@ -30,7 +31,6 @@ angular.module('copayApp.controllers').controller('disclaimerController',
|
|||
}
|
||||
}, 3000);
|
||||
};
|
||||
|
||||
$scope.error = "";
|
||||
ongoingProcess.set('creatingWallet', false);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -348,9 +348,9 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
};
|
||||
|
||||
$scope.setSeedSource = function() {
|
||||
|
||||
if (!$scope.seedSource) return;
|
||||
$scope.seedSourceId = $scope.seedSource.id;
|
||||
|
||||
$timeout(function() {
|
||||
$rootScope.$apply();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
ret.prevState = 'walletHome';
|
||||
ret.physicalScreenWidth = ((window.innerWidth > 0) ? window.innerWidth : screen.width);
|
||||
|
||||
// Only for testing
|
||||
//storageService.checkQuota();
|
||||
|
||||
ret.menu = [{
|
||||
'title': gettext('Receive'),
|
||||
'icon': {
|
||||
|
|
|
|||
|
|
@ -1,21 +1,23 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services')
|
||||
.factory('localStorageService', function(platformInfo, $timeout) {
|
||||
.factory('localStorageService', function(platformInfo, $timeout, $log) {
|
||||
var isNW = platformInfo.isNW;
|
||||
var isChromeApp = platformInfo.isChromeApp;
|
||||
var root = {};
|
||||
var ls = ((typeof window.localStorage !== "undefined") ? window.localStorage : null);
|
||||
|
||||
if (isChromeApp && !isNW && !ls) {
|
||||
$log.info('Using CHROME storage');
|
||||
ls = chrome.storage.local;
|
||||
}
|
||||
|
||||
|
||||
if (!ls)
|
||||
throw new Error('localstorage not available');
|
||||
|
||||
root.get = function(k, cb) {
|
||||
if (isChromeApp && !isNW) {
|
||||
if (isChromeApp || isNW) {
|
||||
chrome.storage.local.get(k,
|
||||
function(data) {
|
||||
//TODO check for errors
|
||||
|
|
@ -41,7 +43,7 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.set = function(k, v, cb) {
|
||||
if (isChromeApp && !isNW) {
|
||||
if (isChromeApp || isNW) {
|
||||
var obj = {};
|
||||
obj[k] = v;
|
||||
|
||||
|
|
@ -54,7 +56,7 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.remove = function(k, cb) {
|
||||
if (isChromeApp && !isNW) {
|
||||
if (isChromeApp || isNW) {
|
||||
chrome.storage.local.remove(k, cb);
|
||||
} else {
|
||||
ls.removeItem(k);
|
||||
|
|
@ -63,5 +65,37 @@ angular.module('copayApp.services')
|
|||
|
||||
};
|
||||
|
||||
|
||||
if (isNW) {
|
||||
$log.info('Overwritting localstorage with chrome storage for NW.JS');
|
||||
|
||||
var ts = ls.getItem('migrationToChromeStorage');
|
||||
var p = ls.getItem('profile');
|
||||
|
||||
// Need migration?
|
||||
if (!ts && p) {
|
||||
$log.info('### MIGRATING DATA! TO CHROME STORAGE');
|
||||
|
||||
var j = 0;
|
||||
for (var i = 0; i < localStorage.length; i++) {
|
||||
var k = ls.key(i);
|
||||
var v = ls.getItem(k);
|
||||
|
||||
$log.debug(' Key: ' + k);
|
||||
root.set(k, v, function() {
|
||||
j++;
|
||||
if (j == localStorage.length) {
|
||||
$log.info('### MIGRATION DONE');
|
||||
ls.setItem('migrationToChromeStorage', Date.now())
|
||||
ls = chrome.storage.local;
|
||||
}
|
||||
})
|
||||
}
|
||||
} else if (p) {
|
||||
$log.info('# Data already migrated to Chrome storage on ' + ts);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ angular.module('copayApp.services')
|
|||
var validationLock = false;
|
||||
|
||||
root.runValidation = function(client, delay, retryDelay) {
|
||||
|
||||
delay = delay || 500;
|
||||
retryDelay = retryDelay || 50;
|
||||
|
||||
|
|
@ -152,6 +153,7 @@ angular.module('copayApp.services')
|
|||
$log.warn('Key Derivation failed for wallet:' + walletId);
|
||||
storageService.clearLastAddress(walletId, function() {});
|
||||
}
|
||||
|
||||
root.storeProfileIfDirty();
|
||||
$rootScope.$emit('Local/ValidatingWalletEnded', walletId, isOK);
|
||||
});
|
||||
|
|
@ -663,9 +665,11 @@ angular.module('copayApp.services')
|
|||
root.createDefaultProfile(opts, function(err, p) {
|
||||
if (err) return cb(err);
|
||||
|
||||
root.bindProfile(p, function(err) {
|
||||
// ignore NONAGREEDDISCLAIMER
|
||||
storageService.storeNewProfile(p, function(err) {
|
||||
storageService.storeNewProfile(p, function(err) {
|
||||
if (err) return cb(err);
|
||||
root.bindProfile(p, function(err) {
|
||||
// ignore NONAGREEDDISCLAIMER
|
||||
if (err && err.toString().match('NONAGREEDDISCLAIMER')) return cb();
|
||||
return cb(err);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -264,8 +264,26 @@ angular.module('copayApp.services')
|
|||
storage.remove('addressbook-' + network, cb);
|
||||
};
|
||||
|
||||
|
||||
root.checkQuota = function() {
|
||||
var block = '';
|
||||
// 50MB
|
||||
for (var i = 0; i < 1024*1024; ++ i){
|
||||
block += '12345678901234567890123456789012345678901234567890';
|
||||
}
|
||||
storage.set('test', block, function(err) {
|
||||
$log.error('CheckQuota Return:'+ err);
|
||||
});
|
||||
};
|
||||
|
||||
root.setTxHistory = function(txs, walletId, cb) {
|
||||
storage.set('txsHistory-' + walletId, txs, cb);
|
||||
try {
|
||||
storage.set('txsHistory-' + walletId, txs, cb);
|
||||
} catch (e) {
|
||||
$log.error('Error saving tx History. Size:' + txs.length);
|
||||
$log.error(e);
|
||||
return cb(e);
|
||||
}
|
||||
}
|
||||
|
||||
root.getTxHistory = function(walletId, cb) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue