mirror of https://github.com/BTCPrivate/copay.git
Display a message for users whose have wallet:: but not profile::
This commit is contained in:
parent
bfdfc68d83
commit
2c07ad6dd7
|
@ -2,7 +2,9 @@
|
|||
|
||||
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager, identityService) {
|
||||
controllerUtils.redirIfLogged();
|
||||
$scope.retreiving = false;
|
||||
$scope.retreiving = true;
|
||||
|
||||
identityService.check($scope);
|
||||
|
||||
$scope.createProfile = function(form) {
|
||||
if (form && form.$invalid) {
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager, identityService) {
|
||||
controllerUtils.redirIfLogged();
|
||||
$scope.retreiving = false;
|
||||
$scope.retreiving = true;
|
||||
|
||||
identityService.check($scope);
|
||||
|
||||
$scope.openProfile = function(form) {
|
||||
if (form && form.$invalid) {
|
||||
|
|
|
@ -59,8 +59,12 @@ function Identity(opts) {
|
|||
this.wallets = opts.wallets || {};
|
||||
};
|
||||
|
||||
Identity.getStoragePrefix = function() {
|
||||
return 'profile::';
|
||||
};
|
||||
|
||||
Identity.getKeyForEmail = function(email) {
|
||||
return 'profile::' + bitcore.util.sha256ripe160(email).toString('hex');
|
||||
return Identity.getStoragePrefix() + bitcore.util.sha256ripe160(email).toString('hex');
|
||||
};
|
||||
|
||||
Identity.prototype.getId = function() {
|
||||
|
@ -482,6 +486,19 @@ Identity.prototype.addWallet = function(wallet, cb) {
|
|||
this.storage.setItem(wallet.getStorageKey(), wallet.toObj(), cb);
|
||||
};
|
||||
|
||||
/**
|
||||
* check if any profile exists on storage
|
||||
* @param opts.storageOpts
|
||||
* @param cb
|
||||
*/
|
||||
Identity.checkIfExistsAny = function(opts, cb) {
|
||||
var storage = opts.storage || opts.pluginManager.get('DB');
|
||||
storage.getFirst(Identity.getStoragePrefix(), {
|
||||
onlyKey: true
|
||||
}, function(err, v, k) {
|
||||
return cb(k ? true : false);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @desc Checks if a version is compatible with the current version
|
||||
|
|
|
@ -165,14 +165,32 @@ Wallet.COPAYER_PAIR_LIMITS = {
|
|||
12: 1,
|
||||
};
|
||||
|
||||
Wallet.getStoragePrefix = function() {
|
||||
return 'wallet::';
|
||||
};
|
||||
|
||||
Wallet.getStorageKey = function(str) {
|
||||
return 'wallet::' + str;
|
||||
return Wallet.getStoragePrefix() + str;
|
||||
};
|
||||
|
||||
Wallet.prototype.getStorageKey = function() {
|
||||
return Wallet.getStorageKey(this.getId());
|
||||
};
|
||||
|
||||
/**
|
||||
* check if any wallet exists on storage
|
||||
* @param opts.storageOpts
|
||||
* @param cb
|
||||
*/
|
||||
Wallet.checkIfExistsAny = function(opts, cb) {
|
||||
var storage = opts.storage || opts.pluginManager.get('DB');
|
||||
storage.getFirst(Wallet.getStoragePrefix(), {
|
||||
onlyKey: true
|
||||
}, function(err, v, k) {
|
||||
return cb(k ? true : false);
|
||||
});
|
||||
};
|
||||
|
||||
/* for stubbing */
|
||||
Wallet._newInsight = function(opts) {
|
||||
return new Insight(opts);
|
||||
|
|
|
@ -78,9 +78,13 @@ InsightStorage.prototype.clear = function(callback) {
|
|||
};
|
||||
|
||||
InsightStorage.prototype.allKeys = function(callback) {
|
||||
// NOOP
|
||||
// TODO: Add functionality?
|
||||
callback();
|
||||
// TODO: compatibility with localStorage
|
||||
return callback(null);
|
||||
};
|
||||
|
||||
InsightStorage.prototype.getFirst = function(prefix, opts, callback) {
|
||||
// TODO: compatibility with localStorage
|
||||
return callback(null, true, true);
|
||||
};
|
||||
|
||||
module.exports = InsightStorage;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
var _ = require('lodash');
|
||||
|
||||
function LocalStorage() {
|
||||
this.type = 'DB';
|
||||
|
@ -51,4 +52,28 @@ LocalStorage.prototype.allKeys = function(cb) {
|
|||
return cb(null, ret);
|
||||
};
|
||||
|
||||
LocalStorage.prototype.getFirst = function(prefix, opts, cb) {
|
||||
opts = opts || {};
|
||||
var that = this;
|
||||
|
||||
this.allKeys(function(err, allKeys) {
|
||||
var keys = _.filter(allKeys, function(k) {
|
||||
if ((k === prefix) || k.indexOf(prefix) === 0) return true;
|
||||
});
|
||||
|
||||
if (keys.length === 0)
|
||||
return cb(new Error('not found'));
|
||||
|
||||
if (opts.onlyKey)
|
||||
return cb(null, null, keys[0]);
|
||||
|
||||
that.getItem(keys[0], function(err, data) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
return cb(null, data, keys[0]);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = LocalStorage;
|
||||
|
|
|
@ -4,6 +4,24 @@ angular.module('copayApp.services')
|
|||
.factory('identityService', function($rootScope, $location, pluginManager, controllerUtils) {
|
||||
var root = {};
|
||||
|
||||
root.check = function (scope) {
|
||||
copay.Identity.checkIfExistsAny({
|
||||
pluginManager: pluginManager,
|
||||
}, function(anyProfile) {
|
||||
copay.Wallet.checkIfExistsAny({
|
||||
pluginManager: pluginManager,
|
||||
}, function(anyWallet) {
|
||||
scope.retreiving = false;
|
||||
scope.anyProfile = anyProfile ? true : false;
|
||||
scope.anyWallet = anyWallet ? true : false;
|
||||
|
||||
if (!scope.anyProfile) {
|
||||
$location.path('/createProfile');
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
root.create = function(scope, form) {
|
||||
var iden = copay.Identity.create({
|
||||
email: form.email.$modelValue,
|
||||
|
@ -60,7 +78,7 @@ angular.module('copayApp.services')
|
|||
}
|
||||
scope.loading = false;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue