mirror of https://github.com/BTCPrivate/copay.git
NW v0.16. Migrate localstorage data to chrome.storage
This commit is contained in:
parent
fa39cee3b6
commit
a50f3fb50c
|
@ -15,10 +15,9 @@
|
||||||
"window": {
|
"window": {
|
||||||
"title": "Copay - A multisignature bitcoin wallet",
|
"title": "Copay - A multisignature bitcoin wallet",
|
||||||
"icon": "./public/img/icons/icon-256.png",
|
"icon": "./public/img/icons/icon-256.png",
|
||||||
"toolbar": false,
|
|
||||||
"show": true,
|
"show": true,
|
||||||
"visible": true,
|
"visible": true,
|
||||||
"resizable": false,
|
"resizable": true,
|
||||||
"frame": true,
|
"frame": true,
|
||||||
"width": 800,
|
"width": 800,
|
||||||
"height": 600,
|
"height": 600,
|
||||||
|
@ -30,7 +29,7 @@
|
||||||
"java": false,
|
"java": false,
|
||||||
"plugin": false
|
"plugin": false
|
||||||
},
|
},
|
||||||
"dom_storage_quota": 100,
|
"dom_storage_quota": 200,
|
||||||
"id": "jid1-x7bV5evAaI1P9Q",
|
"id": "jid1-x7bV5evAaI1P9Q",
|
||||||
"homepage": "https://github.com/bitpay/copay",
|
"homepage": "https://github.com/bitpay/copay",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
@ -20,6 +20,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
ret.prevState = 'walletHome';
|
ret.prevState = 'walletHome';
|
||||||
ret.physicalScreenWidth = ((window.innerWidth > 0) ? window.innerWidth : screen.width);
|
ret.physicalScreenWidth = ((window.innerWidth > 0) ? window.innerWidth : screen.width);
|
||||||
|
|
||||||
|
// Only for testing
|
||||||
|
//storageService.checkQuota();
|
||||||
|
|
||||||
ret.menu = [{
|
ret.menu = [{
|
||||||
'title': gettext('Receive'),
|
'title': gettext('Receive'),
|
||||||
'icon': {
|
'icon': {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('localStorageService', function(platformInfo, $timeout) {
|
.factory('localStorageService', function(platformInfo, $timeout, $log) {
|
||||||
var isNW = platformInfo.isNW;
|
var isNW = platformInfo.isNW;
|
||||||
var isChromeApp = platformInfo.isChromeApp;
|
var isChromeApp = platformInfo.isChromeApp;
|
||||||
var root = {};
|
var root = {};
|
||||||
|
@ -11,11 +11,12 @@ angular.module('copayApp.services')
|
||||||
ls = chrome.storage.local;
|
ls = chrome.storage.local;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!ls)
|
if (!ls)
|
||||||
throw new Error('localstorage not available');
|
throw new Error('localstorage not available');
|
||||||
|
|
||||||
root.get = function(k, cb) {
|
root.get = function(k, cb) {
|
||||||
if (isChromeApp && !isNW) {
|
if (isChromeApp || isNW) {
|
||||||
chrome.storage.local.get(k,
|
chrome.storage.local.get(k,
|
||||||
function(data) {
|
function(data) {
|
||||||
//TODO check for errors
|
//TODO check for errors
|
||||||
|
@ -41,7 +42,7 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root.set = function(k, v, cb) {
|
root.set = function(k, v, cb) {
|
||||||
if (isChromeApp && !isNW) {
|
if (isChromeApp || isNW) {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
obj[k] = v;
|
obj[k] = v;
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root.remove = function(k, cb) {
|
root.remove = function(k, cb) {
|
||||||
if (isChromeApp && !isNW) {
|
if (isChromeApp || isNW) {
|
||||||
chrome.storage.local.remove(k, cb);
|
chrome.storage.local.remove(k, cb);
|
||||||
} else {
|
} else {
|
||||||
ls.removeItem(k);
|
ls.removeItem(k);
|
||||||
|
@ -63,5 +64,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;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
|
@ -264,8 +264,26 @@ angular.module('copayApp.services')
|
||||||
storage.remove('addressbook-' + network, cb);
|
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) {
|
root.setTxHistory = function(txs, walletId, cb) {
|
||||||
|
try {
|
||||||
storage.set('txsHistory-' + walletId, txs, cb);
|
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) {
|
root.getTxHistory = function(walletId, cb) {
|
||||||
|
|
Loading…
Reference in New Issue