mirror of https://github.com/BTCPrivate/copay.git
file api working. Migration script missing
This commit is contained in:
parent
a8f882472d
commit
1f6596a5ad
|
@ -126,6 +126,9 @@ if [ ! -d $PROJECT ]; then
|
||||||
cordova plugin add hu.dpal.phonegap.plugins.uniquedeviceid
|
cordova plugin add hu.dpal.phonegap.plugins.uniquedeviceid
|
||||||
checkOK
|
checkOK
|
||||||
|
|
||||||
|
cordova plugin add org.apache.cordova.file
|
||||||
|
checkOK
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $DBGJS
|
if $DBGJS
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
</author>
|
</author>
|
||||||
<content src="index.html" />
|
<content src="index.html" />
|
||||||
<access origin="*" />
|
<access origin="*" />
|
||||||
|
<preference name="AndroidPersistentFileLocation" value="Internal" />
|
||||||
|
<preference name="iosPersistentFileLocation" value="Library" />
|
||||||
|
|
||||||
<preference name="DisallowOverscroll" value="true"/>
|
<preference name="DisallowOverscroll" value="true"/>
|
||||||
<preference name="HideKeyboardFormAccessoryBar" value="true"/>
|
<preference name="HideKeyboardFormAccessoryBar" value="true"/>
|
||||||
<preference name="SplashScreen" value="copayscreen" />
|
<preference name="SplashScreen" value="copayscreen" />
|
||||||
|
|
|
@ -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) {
|
self.recreate = function(cb) {
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
self.setOngoingProcess('recreating', true);
|
self.setOngoingProcess('recreating', true);
|
||||||
|
@ -563,6 +576,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
$rootScope.$apply();
|
$rootScope.$apply();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$rootScope.$on('Local/DeviceError', function(event, err) {
|
||||||
|
self.deviceError(err);
|
||||||
|
$rootScope.$apply();
|
||||||
|
});
|
||||||
|
|
||||||
$rootScope.$on('Local/ClientError', function(event, err) {
|
$rootScope.$on('Local/ClientError', function(event, err) {
|
||||||
if (err.code && err.code === 'NOTAUTHORIZED') {
|
if (err.code && err.code === 'NOTAUTHORIZED') {
|
||||||
// Show not error, just redirect to home (where the recreate option is shown)
|
// Show not error, just redirect to home (where the recreate option is shown)
|
||||||
|
|
|
@ -434,18 +434,21 @@ angular
|
||||||
|
|
||||||
if (!profileService.profile && toState.needProfile) {
|
if (!profileService.profile && toState.needProfile) {
|
||||||
|
|
||||||
|
// Give us time to open / create the profile
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
// Try to open local profile
|
// Try to open local profile
|
||||||
profileService.loadAndBindProfile(function(err) {
|
profileService.loadAndBindProfile(function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (err.message.match('NOPROFILE')) {
|
if (err.message.match('NOPROFILE')) {
|
||||||
$log.debug('No profile... redirecting');
|
$log.debug('No profile... redirecting');
|
||||||
$state.transitionTo('splash');
|
$state.transitionTo('splash');
|
||||||
event.preventDefault();
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error(err); // TODO
|
throw new Error(err); // TODO
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Profile was loaded
|
console.log('Profile loaded ... resuming transition');
|
||||||
|
$state.transitionTo('walletHome');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
'use strict';
|
'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 root = {};
|
||||||
|
|
||||||
|
var storage = isCordova ? fileStorageService : localStorageService;
|
||||||
|
|
||||||
var defaultConfig = {
|
var defaultConfig = {
|
||||||
// wallet limits
|
// wallet limits
|
||||||
limits: {
|
limits: {
|
||||||
|
@ -66,8 +68,7 @@ angular.module('copayApp.services').factory('configService', function(localStora
|
||||||
};
|
};
|
||||||
|
|
||||||
root.get = function(cb) {
|
root.get = function(cb) {
|
||||||
localStorageService.get('config', function(err, localConfig) {
|
storage.get('config', function(err, localConfig) {
|
||||||
|
|
||||||
if (localConfig) {
|
if (localConfig) {
|
||||||
configCache = JSON.parse(localConfig);
|
configCache = JSON.parse(localConfig);
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ angular.module('copayApp.services').factory('configService', function(localStora
|
||||||
|
|
||||||
root.set = function(newOpts, cb) {
|
root.set = function(newOpts, cb) {
|
||||||
var config = defaultConfig;
|
var config = defaultConfig;
|
||||||
localStorageService.get('config', function(err, oldOpts) {
|
storage.get('config', function(err, oldOpts) {
|
||||||
if (lodash.isString(oldOpts)) {
|
if (lodash.isString(oldOpts)) {
|
||||||
oldOpts = JSON.parse(oldOpts);
|
oldOpts = JSON.parse(oldOpts);
|
||||||
}
|
}
|
||||||
|
@ -102,12 +103,12 @@ angular.module('copayApp.services').factory('configService', function(localStora
|
||||||
lodash.merge(config, oldOpts, newOpts);
|
lodash.merge(config, oldOpts, newOpts);
|
||||||
configCache = config;
|
configCache = config;
|
||||||
|
|
||||||
localStorageService.set('config', JSON.stringify(config), cb);
|
storage.set('config', JSON.stringify(config), cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.reset = function(cb) {
|
root.reset = function(cb) {
|
||||||
localStorageService.remove('config', cb);
|
storage.remove('config', cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getDefaults = function() {
|
root.getDefaults = function() {
|
||||||
|
|
|
@ -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;
|
||||||
|
});
|
|
@ -1,12 +1,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('localStorageService', function() {
|
.factory('localStorageService', function(isChromeApp, $timeout) {
|
||||||
|
|
||||||
var isChromeApp = typeof window !== "undefined" && window.chrome && chrome.runtime && chrome.runtime.id;
|
|
||||||
var root = {};
|
var root = {};
|
||||||
|
var ls = ((typeof window.localStorage !== "undefined") ? window.localStorage : null);
|
||||||
var ls = ((typeof localStorage !== "undefined") ? localStorage : null);
|
|
||||||
|
|
||||||
if (isChromeApp && !ls) {
|
if (isChromeApp && !ls) {
|
||||||
ls = localStorage = chrome.storage.local;
|
ls = localStorage = chrome.storage.local;
|
||||||
|
@ -14,9 +11,7 @@ angular.module('copayApp.services')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ls)
|
if (!ls)
|
||||||
throw new Error('localstorage not available, cannot run plugin');
|
throw new Error('localstorage not available');
|
||||||
|
|
||||||
root.init = function() {};
|
|
||||||
|
|
||||||
root.get = function(k, cb) {
|
root.get = function(k, cb) {
|
||||||
if (isChromeApp) {
|
if (isChromeApp) {
|
||||||
|
@ -26,7 +21,13 @@ angular.module('copayApp.services')
|
||||||
return cb(null, data[k]);
|
return cb(null, data[k]);
|
||||||
});
|
});
|
||||||
} else {
|
} 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));
|
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;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
|
@ -111,6 +111,8 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
|
|
||||||
root.bindProfile = function(profile, cb) {
|
root.bindProfile = function(profile, cb) {
|
||||||
|
|
||||||
|
console.log('[profileService.js.114] Bind profile', profile); //TODO
|
||||||
root.profile = profile;
|
root.profile = profile;
|
||||||
|
|
||||||
configService.get(function(err) {
|
configService.get(function(err) {
|
||||||
|
@ -127,12 +129,14 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
root.loadAndBindProfile = function(cb) {
|
root.loadAndBindProfile = function(cb) {
|
||||||
storageService.getProfile(function(err, profile) {
|
storageService.getProfile(function(err, profile) {
|
||||||
|
console.log('[profileService.js.129:err:]',err); //TODO
|
||||||
if (err) {
|
if (err) {
|
||||||
notification.error('CRITICAL ERROR: ' + err);
|
$rootScope.$emit('Local/DeviceError', err);
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
if (!profile) return cb(new Error('NOPROFILE: No profile'));
|
if (!profile) return cb(new Error('NOPROFILE: No profile'));
|
||||||
|
|
||||||
|
console.log('[profileService.js.135] BIND'); //TODO
|
||||||
return root.bindProfile(profile, cb);
|
return root.bindProfile(profile, cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('storageService', function(localStorageService, sjcl, $log, lodash) {
|
.factory('storageService', function(fileStorageService, localStorageService, sjcl, $log, lodash, isCordova) {
|
||||||
|
|
||||||
var root = {};
|
var root = {};
|
||||||
|
var storage = isCordova ? fileStorageService : localStorageService;
|
||||||
|
|
||||||
var getUUID = function(cb) {
|
var getUUID = function(cb) {
|
||||||
// TO SIMULATE MOBILE
|
// TO SIMULATE MOBILE
|
||||||
|
@ -48,18 +49,18 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
root.storeNewProfile = function(profile, cb) {
|
root.storeNewProfile = function(profile, cb) {
|
||||||
encryptOnMobile(profile.toObj(), function(err, x) {
|
encryptOnMobile(profile.toObj(), function(err, x) {
|
||||||
localStorageService.create('profile', x, cb);
|
storage.create('profile', x, cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.storeProfile = function(profile, cb) {
|
root.storeProfile = function(profile, cb) {
|
||||||
encryptOnMobile(profile.toObj(), function(err, x) {
|
encryptOnMobile(profile.toObj(), function(err, x) {
|
||||||
localStorageService.set('profile', x, cb);
|
storage.set('profile', x, cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getProfile = function(cb) {
|
root.getProfile = function(cb) {
|
||||||
localStorageService.get('profile', function(err, str) {
|
storage.get('profile', function(err, str) {
|
||||||
if (err || !str) return cb(err);
|
if (err || !str) return cb(err);
|
||||||
|
|
||||||
decryptOnMobile(str, function(err, str) {
|
decryptOnMobile(str, function(err, str) {
|
||||||
|
@ -76,35 +77,35 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root.deleteProfile = function(cb) {
|
root.deleteProfile = function(cb) {
|
||||||
localStorageService.remove('profile', cb);
|
storage.remove('profile', cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.storeFocusedWalletId = function(id, cb) {
|
root.storeFocusedWalletId = function(id, cb) {
|
||||||
localStorageService.set('focusedWalletId', id, cb);
|
storage.set('focusedWalletId', id, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getFocusedWalletId = function(cb) {
|
root.getFocusedWalletId = function(cb) {
|
||||||
localStorageService.get('focusedWalletId', cb);
|
storage.get('focusedWalletId', cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getLastAddress = function(walletId, cb) {
|
root.getLastAddress = function(walletId, cb) {
|
||||||
localStorageService.get('lastAddress-' + walletId, cb);
|
storage.get('lastAddress-' + walletId, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.storeLastAddress = function(walletId, address, cb) {
|
root.storeLastAddress = function(walletId, address, cb) {
|
||||||
localStorageService.set('lastAddress-' + walletId, address, cb);
|
storage.set('lastAddress-' + walletId, address, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.clearLastAddress = function(walletId, cb) {
|
root.clearLastAddress = function(walletId, cb) {
|
||||||
localStorageService.remove('lastAddress-' + walletId, cb);
|
storage.remove('lastAddress-' + walletId, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setBackupFlag = function(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) {
|
root.getBackupFlag = function(walletId, cb) {
|
||||||
localStorageService.get('backup-' + walletId, cb);
|
storage.get('backup-' + walletId, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
|
|
Loading…
Reference in New Issue