Abstract bitpayCardCredentials to appIdentity. Improve alert text on card removal.

This commit is contained in:
Andy Phillipson 2016-11-14 16:24:52 -05:00
commit 43f24ee35e
5 changed files with 87 additions and 60 deletions

View file

@ -0,0 +1,34 @@
'use strict';
angular.module('copayApp.services').factory('appIdentityService', function($log, lodash, storageService, bitauthService) {
var root = {};
root.getIdentity = function(network, cb) {
var pubkey, sin, isNew;
storageService.getAppIdentity(network, function(err, data) {
if (err) return cb(err);
if (lodash.isString(data)) {
data = JSON.parse(data);
}
var appIdentity = data || {};
if (lodash.isEmpty(appIdentity) || (appIdentity && !appIdentity.priv)) {
isNew = true;
appIdentity = bitauthService.generateSin();
}
try {
pubkey = bitauthService.getPublicKeyFromPrivateKey(appIdentity.priv);
sin = bitauthService.getSinFromPublicKey(pubkey);
if (isNew)
storageService.setAppIdentity(network, JSON.stringify(appIdentity), function(err) {});
}
catch (e) {
$log.error(e);
return cb(e);
};
return cb(null, appIdentity);
});
};
return root;
});