Abstract bitpayCardCredentials to appIdentity. Improve alert text on card removal.
This commit is contained in:
parent
40f0901f2e
commit
43f24ee35e
5 changed files with 87 additions and 60 deletions
34
src/js/services/appIdentityService.js
Normal file
34
src/js/services/appIdentityService.js
Normal 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;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue