mirror of https://github.com/BTCPrivate/copay.git
identity now emits!
This commit is contained in:
parent
57299d675e
commit
3ae6378678
|
@ -50,7 +50,7 @@
|
||||||
<span translate> <strong class="size-16">Network Error</strong>.<br> Attempting to reconnect..</span>
|
<span translate> <strong class="size-16">Network Error</strong>.<br> Attempting to reconnect..</span>
|
||||||
</span>
|
</span>
|
||||||
<nav class="tab-bar" ng-if="$root.wallet &&
|
<nav class="tab-bar" ng-if="$root.wallet &&
|
||||||
$root.wallet.isReady() && !$root.wallet.isLocked">
|
$root.wallet.isComplete() && !$root.wallet.isLocked">
|
||||||
<section class="left-small">
|
<section class="left-small">
|
||||||
<a class="left-off-canvas-toggle menu-icon" ><span></span></a>
|
<a class="left-off-canvas-toggle menu-icon" ><span></span></a>
|
||||||
</section>
|
</section>
|
||||||
|
@ -91,7 +91,7 @@
|
||||||
<section ng-class="{'main':$root.iden && !$root.starting}" ng-view></section>
|
<section ng-class="{'main':$root.iden && !$root.starting}" ng-view></section>
|
||||||
|
|
||||||
<div class="bottom-bar" ng-if="$root.wallet &&
|
<div class="bottom-bar" ng-if="$root.wallet &&
|
||||||
$root.wallet.isReady() && !$root.wallet.isLocked">
|
$root.wallet.isComplete() && !$root.wallet.isLocked">
|
||||||
<div ng-include="'views/includes/bottombar-mobile.html'"></div>
|
<div ng-include="'views/includes/bottombar-mobile.html'"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
angular.module('copayApp.controllers').controller('CopayersController',
|
angular.module('copayApp.controllers').controller('CopayersController',
|
||||||
function($scope, $rootScope, $location) {
|
function($scope, $rootScope, $location) {
|
||||||
|
|
||||||
if (!$rootScope.wallet.isReady()) {
|
if (!$rootScope.wallet.isComplete()) {
|
||||||
$rootScope.title = 'Waiting copayers for ' + $rootScope.wallet.getName();
|
$rootScope.title = 'Waiting copayers for ' + $rootScope.wallet.getName();
|
||||||
}
|
}
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
|
|
|
@ -44,7 +44,6 @@ angular.module('copayApp.controllers').controller('CreateController',
|
||||||
notification.error('Error', 'Please enter the required fields');
|
notification.error('Error', 'Please enter the required fields');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$scope.loading = true;
|
|
||||||
var opts = {
|
var opts = {
|
||||||
requiredCopayers: $scope.requiredCopayers,
|
requiredCopayers: $scope.requiredCopayers,
|
||||||
totalCopayers: $scope.totalCopayers,
|
totalCopayers: $scope.totalCopayers,
|
||||||
|
@ -52,8 +51,14 @@ angular.module('copayApp.controllers').controller('CreateController',
|
||||||
privateKeyHex: $scope.private,
|
privateKeyHex: $scope.private,
|
||||||
networkName: $scope.networkName,
|
networkName: $scope.networkName,
|
||||||
};
|
};
|
||||||
identityService.createWallet(opts, function(){
|
$rootScope.starting = true;
|
||||||
$scope.loading = false;
|
identityService.createWallet(opts, function(err, wallet){
|
||||||
|
$rootScope.starting = false;
|
||||||
|
if (err || !wallet) {
|
||||||
|
copay.logger.debug(err);
|
||||||
|
$scope.error = 'Could not create wallet.' + err;
|
||||||
|
}
|
||||||
|
$rootScope.$digest()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,7 +10,12 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun
|
||||||
$scope.error('Error', 'Please enter the required fields');
|
$scope.error('Error', 'Please enter the required fields');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
identityService.create($scope, form);
|
identityService.create(
|
||||||
|
form.email.$modelValue, form.password.$modelValue, function(err) {
|
||||||
|
if (err) $scope.error('Error', err.toString());
|
||||||
|
|
||||||
|
$rootScope.$digest();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,14 +14,14 @@ angular.module('copayApp.controllers').controller('HeadController', function($sc
|
||||||
|
|
||||||
$scope.signout = function() {
|
$scope.signout = function() {
|
||||||
$rootScope.signingOut = true;
|
$rootScope.signingOut = true;
|
||||||
identityService.logout();
|
identityService.signout();
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.refresh = function() {
|
$scope.refresh = function() {
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
if (!w) return;
|
if (!w) return;
|
||||||
|
|
||||||
if (w.isReady()) {
|
if (w.isComplete()) {
|
||||||
w.sendWalletReady();
|
w.sendWalletReady();
|
||||||
balanceService.clearBalanceCache(w);
|
balanceService.clearBalanceCache(w);
|
||||||
balanceService.update(w, function() {
|
balanceService.update(w, function() {
|
||||||
|
|
|
@ -22,7 +22,19 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
||||||
$scope.error = 'Please enter the required fields';
|
$scope.error = 'Please enter the required fields';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
identityService.open($scope, form);
|
$rootScope.starting = true;
|
||||||
|
identityService.open(form.email.$modelValue, form.password.$modelValue, function(err) {
|
||||||
|
$rootScope.starting = false;
|
||||||
|
if (err) {
|
||||||
|
copay.logger.warn(err);
|
||||||
|
if ((err.toString() || '').match('PNOTFOUND')) {
|
||||||
|
$scope.error = 'Invalid email or password';
|
||||||
|
} else {
|
||||||
|
$scope.error = 'Unknown error';
|
||||||
|
}
|
||||||
|
$rootScope.$digest()
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getParam(sname) {
|
function getParam(sname) {
|
||||||
|
|
|
@ -125,6 +125,19 @@ angular.module('copayApp.controllers').controller('JoinController',
|
||||||
privateHex: $scope.private,
|
privateHex: $scope.private,
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
|
if (err) {
|
||||||
|
if (err === 'joinError')
|
||||||
|
notification.error('Fatal error connecting to Insight server');
|
||||||
|
else if (err === 'walletFull')
|
||||||
|
notification.error('The wallet is full');
|
||||||
|
else if (err === 'badNetwork')
|
||||||
|
notification.error('Network Error', 'Wallet network configuration missmatch');
|
||||||
|
else if (err === 'badSecret')
|
||||||
|
notification.error('Bad secret', 'The secret string you entered is invalid');
|
||||||
|
else {
|
||||||
|
notification.error('Error', err.message || err);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,7 +20,6 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
|
||||||
|
|
||||||
identityService.deleteWallet(w.id,function() {
|
identityService.deleteWallet(w.id,function() {
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
$scope.getWallets();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $route, $location, $anchorScroll, notification) {
|
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $route, $location, $anchorScroll, notification, applicationService) {
|
||||||
$scope.title = 'Settings';
|
$scope.title = 'Settings';
|
||||||
$scope.defaultLanguage = config.defaultLanguage || 'en';
|
$scope.defaultLanguage = config.defaultLanguage || 'en';
|
||||||
$scope.insightLivenet = config.network.livenet.url;
|
$scope.insightLivenet = config.network.livenet.url;
|
||||||
|
@ -94,16 +94,13 @@ angular.module('copayApp.controllers').controller('SettingsController', function
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Go home reloading the application
|
applicationService.restart();
|
||||||
var hashIndex = window.location.href.indexOf('#!/');
|
|
||||||
window.location = window.location.href.substr(0, hashIndex);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
$scope.reset = function() {
|
$scope.reset = function() {
|
||||||
localStorage.removeItem('config');
|
localStorage.removeItem('config');
|
||||||
// Go home reloading the application
|
applicationService.reload();
|
||||||
window.location.reload();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,7 +8,7 @@ angular.module('copayApp.controllers').controller('WarningController', function(
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.signout = function() {
|
$scope.signout = function() {
|
||||||
identityService.logout();
|
identityService.signout();
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.ignoreLock = function() {
|
$scope.ignoreLock = function() {
|
||||||
|
|
|
@ -28,7 +28,6 @@ function Network(opts) {
|
||||||
if (opts.transports) {
|
if (opts.transports) {
|
||||||
this.socketOptions['transports'] = opts.transports;
|
this.socketOptions['transports'] = opts.transports;
|
||||||
}
|
}
|
||||||
this.socket = this.createSocket();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeUtil.inherits(Network, EventEmitter);
|
nodeUtil.inherits(Network, EventEmitter);
|
||||||
|
@ -236,7 +235,7 @@ Network.prototype._onMessage = function(enc) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Network.prototype._setupConnectionHandlers = function(opts, cb) {
|
Network.prototype._setupSocketHandlers = function(opts, cb) {
|
||||||
preconditions.checkState(this.socket);
|
preconditions.checkState(this.socket);
|
||||||
log.debug('setting up connection', opts);
|
log.debug('setting up connection', opts);
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -274,10 +273,7 @@ Network.prototype._setupConnectionHandlers = function(opts, cb) {
|
||||||
});
|
});
|
||||||
self.socket.on('error', self._onError.bind(self));
|
self.socket.on('error', self._onError.bind(self));
|
||||||
|
|
||||||
self.socket.on('no messages', self.emit.bind(self, 'no messages'));
|
self.socket.on('no_messages', self.emit.bind(self, 'no_messages'));
|
||||||
|
|
||||||
|
|
||||||
var pubkey = self.getKey().public.toString('hex');
|
|
||||||
self.socket.on('connect', function() {
|
self.socket.on('connect', function() {
|
||||||
var pubkey = self.getKey().public.toString('hex');
|
var pubkey = self.getKey().public.toString('hex');
|
||||||
log.debug('Async subscribing to pubkey:', pubkey);
|
log.debug('Async subscribing to pubkey:', pubkey);
|
||||||
|
@ -287,13 +283,8 @@ Network.prototype._setupConnectionHandlers = function(opts, cb) {
|
||||||
self.socket.on('disconnect', function() {
|
self.socket.on('disconnect', function() {
|
||||||
self.socket.emit('subscribe', pubkey);
|
self.socket.emit('subscribe', pubkey);
|
||||||
});
|
});
|
||||||
|
|
||||||
log.debug('Async subs done');
|
|
||||||
|
|
||||||
if (typeof cb === 'function') cb();
|
if (typeof cb === 'function') cb();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Network.prototype._onError = function(err) {
|
Network.prototype._onError = function(err) {
|
||||||
|
@ -350,7 +341,9 @@ Network.prototype.start = function(opts, openCallback) {
|
||||||
this.privkey = opts.privkey;
|
this.privkey = opts.privkey;
|
||||||
this.setCopayerId(opts.copayerId);
|
this.setCopayerId(opts.copayerId);
|
||||||
this.maxPeers = opts.maxPeers || this.maxPeers;
|
this.maxPeers = opts.maxPeers || this.maxPeers;
|
||||||
this._setupConnectionHandlers(opts, openCallback);
|
|
||||||
|
this.socket = this.createSocket();
|
||||||
|
this._setupSocketHandlers(opts, openCallback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Network.prototype.createSocket = function() {
|
Network.prototype.createSocket = function() {
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
var preconditions = require('preconditions').singleton();
|
|
||||||
|
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var bitcore = require('bitcore');
|
var preconditions = require('preconditions').singleton();
|
||||||
|
var inherits = require('inherits');
|
||||||
|
var events = require('events');
|
||||||
var log = require('../log');
|
var log = require('../log');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var cryptoUtil = require('../util/crypto');
|
|
||||||
|
|
||||||
var version = require('../../version').version;
|
var bitcore = require('bitcore');
|
||||||
|
|
||||||
var TxProposals = require('./TxProposals');
|
var TxProposals = require('./TxProposals');
|
||||||
var PublicKeyRing = require('./PublicKeyRing');
|
var PublicKeyRing = require('./PublicKeyRing');
|
||||||
var PrivateKey = require('./PrivateKey');
|
var PrivateKey = require('./PrivateKey');
|
||||||
var Wallet = require('./Wallet');
|
var Wallet = require('./Wallet');
|
||||||
var PluginManager = require('./PluginManager');
|
var PluginManager = require('./PluginManager');
|
||||||
var Async = module.exports.Async = require('./Async');
|
var Async = require('./Async');
|
||||||
|
|
||||||
|
var version = require('../../version').version;
|
||||||
|
var cryptoUtil = require('../util/crypto');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc
|
* @desc
|
||||||
|
@ -56,9 +59,14 @@ function Identity(opts) {
|
||||||
this.walletDefaults = opts.walletDefaults || {};
|
this.walletDefaults = opts.walletDefaults || {};
|
||||||
this.version = opts.version || version;
|
this.version = opts.version || version;
|
||||||
|
|
||||||
|
this.walletIds = opts.walletIds || {};
|
||||||
this.wallets = opts.wallets || {};
|
this.wallets = opts.wallets || {};
|
||||||
|
this.focusedTimestamps = opts.focusedTimestamps || {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inherits(Identity, events.EventEmitter);
|
||||||
|
|
||||||
Identity.getStoragePrefix = function() {
|
Identity.getStoragePrefix = function() {
|
||||||
return 'profile::';
|
return 'profile::';
|
||||||
};
|
};
|
||||||
|
@ -96,7 +104,11 @@ Identity.create = function(opts, cb) {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open an Identity from the given storage
|
* Open an Identity from the given storage.
|
||||||
|
*
|
||||||
|
* After opening a profile, and setting its wallet event handlers,
|
||||||
|
* the client must run .netStart on each
|
||||||
|
* wallet (or call Identity.netStart())
|
||||||
*
|
*
|
||||||
* @param {Object} opts
|
* @param {Object} opts
|
||||||
* @param {Object} opts.storage
|
* @param {Object} opts.storage
|
||||||
|
@ -105,62 +117,96 @@ Identity.create = function(opts, cb) {
|
||||||
* @param {Function} cb
|
* @param {Function} cb
|
||||||
*/
|
*/
|
||||||
Identity.open = function(opts, cb) {
|
Identity.open = function(opts, cb) {
|
||||||
|
preconditions.checkArgument(_.isObject(opts));
|
||||||
|
preconditions.checkArgument(_.isFunction(cb));
|
||||||
|
|
||||||
var storage = opts.storage || opts.pluginManager.get('DB');
|
var storage = opts.storage || opts.pluginManager.get('DB');
|
||||||
storage.setCredentials(opts.email, opts.password, opts);
|
storage.setCredentials(opts.email, opts.password, opts);
|
||||||
storage.getItem(Identity.getKeyForEmail(opts.email), function(err, data) {
|
storage.getItem(Identity.getKeyForEmail(opts.email), function(err, data) {
|
||||||
|
var exported;
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
return Identity.createFromPartialJson(data, opts, cb);
|
try {
|
||||||
|
exported = JSON.parse(data);
|
||||||
|
} catch (e) {
|
||||||
|
return cb(e);
|
||||||
|
}
|
||||||
|
return cb(null, new Identity(_.extend(opts, exported)));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an Identity, retrieves all Wallets remotely, and activates network
|
|
||||||
*
|
|
||||||
* @param {string} jsonString - a string containing a json object with options to rebuild the identity
|
|
||||||
* @param {Object} opts
|
|
||||||
* @param {Function} cb
|
|
||||||
*/
|
|
||||||
Identity.createFromPartialJson = function(jsonString, opts, callback) {
|
|
||||||
var exported;
|
|
||||||
try {
|
|
||||||
exported = JSON.parse(jsonString);
|
|
||||||
} catch (e) {
|
|
||||||
return callback('Invalid JSON');
|
|
||||||
}
|
|
||||||
var identity = new Identity(_.extend(opts, exported));
|
|
||||||
async.map(exported.walletIds, function(walletId, callback) {
|
|
||||||
identity.retrieveWalletFromStorage(walletId, {}, function(error, wallet) {
|
|
||||||
if (!error) {
|
|
||||||
|
|
||||||
console.log('[Identity.js.136] GOT:', wallet.getName()); //TODO
|
/**
|
||||||
identity.wallets[wallet.getId()] = wallet;
|
* readAndBindWallet
|
||||||
identity.bindWallet(wallet);
|
*
|
||||||
wallet.netStart();
|
* @param {string} wid walletId to be readed
|
||||||
console.log('[Identity.js.136] STARTED:', wallet.getName()); //TODO
|
* @param {function} cb
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Identity.prototype.readAndBindWallet = function(walletId, cb) {
|
||||||
|
var self = this;
|
||||||
|
self.retrieveWalletFromStorage(walletId, {}, function(error, wallet) {
|
||||||
|
if (!error) {
|
||||||
|
self.bindWallet(wallet);
|
||||||
}
|
}
|
||||||
callback(error, wallet);
|
return cb(error);
|
||||||
});
|
});
|
||||||
}, function(err) {
|
};
|
||||||
return callback(err, identity);
|
|
||||||
|
|
||||||
|
Identity.prototype.emitAndKeepAlive = function(args) {
|
||||||
|
var args = Array.prototype.slice.call(arguments);
|
||||||
|
log.debug('Ident Emitting:', args);
|
||||||
|
//this.keepAlive(); // TODO
|
||||||
|
this.emit.apply(this, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc open profile's wallets. Call it AFTER setting
|
||||||
|
* the proper even listeners
|
||||||
|
*
|
||||||
|
* @param cb
|
||||||
|
*/
|
||||||
|
Identity.prototype.openWallets = function(cb) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
|
||||||
|
if (_.isEmpty(self.walletIds)) {
|
||||||
|
self.emitAndKeepAlive('noWallets')
|
||||||
|
return cb();
|
||||||
|
}
|
||||||
|
|
||||||
|
// First read the lastFocused wallet
|
||||||
|
self.walletIds.sort(function(a, b) {
|
||||||
|
var va = self.focusedTimestamps[a] || 0;
|
||||||
|
var vb = self.focusedTimestamps[b] || 0;
|
||||||
|
|
||||||
|
return va < vb ? 1 : (va === vb ? 0 : -1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('[Identity.js.188]', self.walletIds, self.focusedTimestamps); //TODO
|
||||||
|
// Then read the rest of the wallets...
|
||||||
|
async.eachSeries(self.walletIds, function(walletId, a_cb) {
|
||||||
|
self.readAndBindWallet(walletId, a_cb);
|
||||||
|
}, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} walletId
|
* @param {string} walletId
|
||||||
* @param {} opts
|
* @param {} opts
|
||||||
* opts.importWallet
|
* opts.importWallet
|
||||||
* @param {Function} callback
|
* @param {Function} cb
|
||||||
*/
|
*/
|
||||||
Identity.prototype.retrieveWalletFromStorage = function(walletId, opts, callback) {
|
Identity.prototype.retrieveWalletFromStorage = function(walletId, opts, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var importFunction = opts.importWallet || Wallet.fromUntrustedObj;
|
var importFunction = opts.importWallet || Wallet.fromUntrustedObj;
|
||||||
|
|
||||||
this.storage.getItem(Wallet.getStorageKey(walletId), function(error, walletData) {
|
this.storage.getItem(Wallet.getStorageKey(walletId), function(error, walletData) {
|
||||||
if (error) {
|
if (error) {
|
||||||
return callback(error);
|
return cb(error);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
log.info('## OPENING Wallet:', walletId);
|
log.info('## OPENING Wallet:', walletId);
|
||||||
|
@ -175,12 +221,12 @@ Identity.prototype.retrieveWalletFromStorage = function(walletId, opts, callback
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.debug("ERROR: ", e.message);
|
log.debug("ERROR: ", e.message);
|
||||||
if (e && e.message && e.message.indexOf('MISSOPTS') !== -1) {
|
if (e && e.message && e.message.indexOf('MISSOPTS') !== -1) {
|
||||||
return callback(new Error('WERROR: Could not read: ' + walletId + ': ' + e.message));
|
return cb(new Error('WERROR: Could not read: ' + walletId + ': ' + e.message));
|
||||||
} else {
|
} else {
|
||||||
return callback(e);
|
return cb(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return callback(null, importFunction(walletData, readOpts));
|
return cb(null, importFunction(walletData, readOpts));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -219,9 +265,9 @@ Identity.storeWalletDebounced = _.debounce(function(identity, wallet, cb) {
|
||||||
|
|
||||||
Identity.prototype.toObj = function() {
|
Identity.prototype.toObj = function() {
|
||||||
return _.extend({
|
return _.extend({
|
||||||
walletIds: _.keys(this.wallets)
|
walletIds: _.isEmpty(this.wallets) ? this.walletsIds : _.keys(this.wallets),
|
||||||
},
|
},
|
||||||
_.pick(this, 'version', 'fullName', 'password', 'email'));
|
_.pick(this, 'version', 'fullName', 'password', 'email', 'focusedTimestamps'));
|
||||||
};
|
};
|
||||||
|
|
||||||
Identity.prototype.exportEncryptedWithWalletInfo = function(opts) {
|
Identity.prototype.exportEncryptedWithWalletInfo = function(opts) {
|
||||||
|
@ -270,15 +316,15 @@ Identity.prototype._cleanUp = function() {
|
||||||
/**
|
/**
|
||||||
* @desc Closes the wallet and disconnects all services
|
* @desc Closes the wallet and disconnects all services
|
||||||
*/
|
*/
|
||||||
Identity.prototype.close = function(cb) {
|
Identity.prototype.close = function() {
|
||||||
async.map(this.wallets, function(wallet, callback) {
|
var self = this;
|
||||||
wallet.close(callback);
|
self.store({}, function(err) {
|
||||||
}, cb);
|
self.emitAndKeepAlive('closed');
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// TODO: Add feedback function
|
// TODO: Add feedback function
|
||||||
//
|
|
||||||
Identity.prototype.importWalletFromObj = function(obj, opts, cb) {
|
Identity.prototype.importWalletFromObj = function(obj, opts, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
preconditions.checkArgument(cb);
|
preconditions.checkArgument(cb);
|
||||||
|
@ -298,7 +344,7 @@ Identity.prototype.importWalletFromObj = function(obj, opts, cb) {
|
||||||
log.debug('Updating Indexes for wallet:' + w.getName());
|
log.debug('Updating Indexes for wallet:' + w.getName());
|
||||||
w.updateIndexes(function(err) {
|
w.updateIndexes(function(err) {
|
||||||
log.debug('Adding wallet to profile:' + w.getName());
|
log.debug('Adding wallet to profile:' + w.getName());
|
||||||
self.addWallet(w);
|
self.updateFocusedTimestamp(w.getId());
|
||||||
self.bindWallet(w);
|
self.bindWallet(w);
|
||||||
|
|
||||||
var writeOpts = _.extend({
|
var writeOpts = _.extend({
|
||||||
|
@ -321,8 +367,8 @@ Identity.prototype.importWalletFromObj = function(obj, opts, cb) {
|
||||||
Identity.prototype.closeWallet = function(wallet, cb) {
|
Identity.prototype.closeWallet = function(wallet, cb) {
|
||||||
preconditions.checkState(wallet, 'Wallet not found');
|
preconditions.checkState(wallet, 'Wallet not found');
|
||||||
|
|
||||||
|
var self = this;
|
||||||
wallet.close(function(err) {
|
wallet.close(function(err) {
|
||||||
delete self.wallets[wid];
|
|
||||||
return cb(err);
|
return cb(err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -371,15 +417,15 @@ Identity.importFromFullJson = function(str, password, opts, cb) {
|
||||||
if (err) return cb(err); //profile already exists
|
if (err) return cb(err); //profile already exists
|
||||||
|
|
||||||
opts.failIfExists = false;
|
opts.failIfExists = false;
|
||||||
async.map(json.wallets, function(walletData, callback) {
|
async.map(json.wallets, function(walletData, cb) {
|
||||||
|
|
||||||
if (!walletData)
|
if (!walletData)
|
||||||
return callback();
|
return cb();
|
||||||
|
|
||||||
iden.importWalletFromObj(walletData, opts, function(err, w) {
|
iden.importWalletFromObj(walletData, opts, function(err, w) {
|
||||||
if (err) return callback(err);
|
if (err) return cb(err);
|
||||||
log.debug('Wallet ' + w.getId() + ' imported');
|
log.debug('Wallet ' + w.getId() + ' imported');
|
||||||
callback();
|
cb();
|
||||||
});
|
});
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
@ -394,10 +440,13 @@ Identity.importFromFullJson = function(str, password, opts, cb) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc binds a wallet's events and emits 'newWallet'
|
||||||
|
* @param {string} walletId Wallet id to be binded
|
||||||
|
* @emits newWallet (walletId)
|
||||||
|
*/
|
||||||
Identity.prototype.bindWallet = function(w) {
|
Identity.prototype.bindWallet = function(w) {
|
||||||
var self = this;
|
this.wallets[w.getId()] = w;
|
||||||
|
|
||||||
self.wallets[w.getId()] = w;
|
|
||||||
log.debug('Binding wallet:' + w.getName());
|
log.debug('Binding wallet:' + w.getName());
|
||||||
|
|
||||||
w.on('txProposalsUpdated', function() {
|
w.on('txProposalsUpdated', function() {
|
||||||
|
@ -421,6 +470,8 @@ Identity.prototype.bindWallet = function(w) {
|
||||||
w.on('publicKeyRingUpdated', function() {
|
w.on('publicKeyRingUpdated', function() {
|
||||||
Identity.storeWalletDebounced(self, w);
|
Identity.storeWalletDebounced(self, w);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.emitAndKeepAlive('newWallet', w.getId());
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -494,12 +545,10 @@ Identity.prototype.createWallet = function(opts, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var w = new walletClass(opts);
|
var w = new walletClass(opts);
|
||||||
this.addWallet(w);
|
self.updateFocusedTimestamp(w.getId());
|
||||||
self.bindWallet(w);
|
self.bindWallet(w);
|
||||||
w.netStart();
|
|
||||||
self.storeWallet(w, function(err) {
|
self.storeWallet(w, function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
self.store({
|
self.store({
|
||||||
noWallets: true
|
noWallets: true
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
|
@ -508,12 +557,6 @@ Identity.prototype.createWallet = function(opts, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Identity.prototype.addWallet = function(wallet) {
|
|
||||||
preconditions.checkArgument(wallet);
|
|
||||||
preconditions.checkArgument(wallet.getId);
|
|
||||||
this.wallets[wallet.getId()] = wallet;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Checks if a version is compatible with the current version
|
* @desc Checks if a version is compatible with the current version
|
||||||
* @param {string} inVersion - a version, with major, minor, and revision, period-separated (x.y.z)
|
* @param {string} inVersion - a version, with major, minor, and revision, period-separated (x.y.z)
|
||||||
|
@ -565,10 +608,13 @@ Identity.prototype.deleteWallet = function(walletId, cb) {
|
||||||
w.close();
|
w.close();
|
||||||
|
|
||||||
delete this.wallets[walletId];
|
delete this.wallets[walletId];
|
||||||
|
delete this.focusedTimestamps[walletId];
|
||||||
|
|
||||||
this.storage.removeItem(Wallet.getStorageKey(walletId), function(err) {
|
this.storage.removeItem(Wallet.getStorageKey(walletId), function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
self.emitAndKeepAlive('deletedWallet', walletId);
|
||||||
self.store(null, cb);
|
self.store(null, cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -584,11 +630,26 @@ Identity.prototype.decodeSecret = function(secret) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Identity.prototype.getLastFocusedWallet = function() {
|
/**
|
||||||
if (_.keys(this.wallets).length == 0) return;
|
* getLastFocusedWalletId
|
||||||
return _.max(this.wallets, function(wallet) {
|
*
|
||||||
return wallet.focusedTimestamp || 0;
|
* @return {string} walletId
|
||||||
});
|
*/
|
||||||
|
Identity.prototype.getLastFocusedWalletId = function() {
|
||||||
|
var max = _.max(this.focusedTimestamp);
|
||||||
|
var aId = this.wallets[0] ? this.wallets[0].getId() : this.walletIds[0];
|
||||||
|
|
||||||
|
if (!max)
|
||||||
|
return aId;
|
||||||
|
|
||||||
|
return _.findKey(this.focusedTimestamps, function(ts) {
|
||||||
|
return ts == max;
|
||||||
|
}) || aId;
|
||||||
|
};
|
||||||
|
|
||||||
|
Identity.prototype.updateFocusedTimestamp = function(wid) {
|
||||||
|
preconditions.checkArgument(wid && this.wallets[wid]);
|
||||||
|
this.focusedTimestamps[wid] = Date.now();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -226,9 +226,6 @@ Insight.prototype.subscribe = function(addresses) {
|
||||||
s.on(address, handler);
|
s.on(address, handler);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
console.log('[Insight.js.202] subscribe ENDED'); //TODO
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Insight.prototype.getSubscriptions = function(addresses) {
|
Insight.prototype.getSubscriptions = function(addresses) {
|
||||||
|
@ -291,7 +288,6 @@ Insight.prototype.getTransactions = function(addresses, from, to, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Insight.prototype.getUnspent = function(addresses, cb) {
|
Insight.prototype.getUnspent = function(addresses, cb) {
|
||||||
console.log('[Insight.js.296:addresses:]',addresses); //TODO
|
|
||||||
preconditions.shouldBeArray(addresses);
|
preconditions.shouldBeArray(addresses);
|
||||||
preconditions.shouldBeFunction(cb);
|
preconditions.shouldBeFunction(cb);
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,6 @@ function Wallet(opts) {
|
||||||
this.registeredPeerIds = [];
|
this.registeredPeerIds = [];
|
||||||
this.addressBook = opts.addressBook || {};
|
this.addressBook = opts.addressBook || {};
|
||||||
this.publicKey = this.privateKey.publicHex;
|
this.publicKey = this.privateKey.publicHex;
|
||||||
this.focusedTimestamp = opts.focusedTimestamp || 0;
|
|
||||||
this.syncedTimestamp = opts.syncedTimestamp || 0;
|
this.syncedTimestamp = opts.syncedTimestamp || 0;
|
||||||
this.lastMessageFrom = {};
|
this.lastMessageFrom = {};
|
||||||
|
|
||||||
|
@ -126,7 +125,7 @@ Wallet.TX_SIGNED_AND_BROADCASTED = 'txSignedAndBroadcasted';
|
||||||
|
|
||||||
Wallet.prototype.emitAndKeepAlive = function(args) {
|
Wallet.prototype.emitAndKeepAlive = function(args) {
|
||||||
var args = Array.prototype.slice.call(arguments);
|
var args = Array.prototype.slice.call(arguments);
|
||||||
log.debug('Wallet Emitting:', args);
|
log.debug('Wallet:'+ this.getName() + ' Emitting:', args);
|
||||||
this.keepAlive();
|
this.keepAlive();
|
||||||
this.emit.apply(this, arguments);
|
this.emit.apply(this, arguments);
|
||||||
};
|
};
|
||||||
|
@ -158,7 +157,6 @@ Wallet.PERSISTED_PROPERTIES = [
|
||||||
'txProposals',
|
'txProposals',
|
||||||
'privateKey',
|
'privateKey',
|
||||||
'addressBook',
|
'addressBook',
|
||||||
'focusedTimestamp',
|
|
||||||
'syncedTimestamp',
|
'syncedTimestamp',
|
||||||
'secretNumber',
|
'secretNumber',
|
||||||
];
|
];
|
||||||
|
@ -647,18 +645,6 @@ Wallet.prototype._onAddressBook = function(senderId, data) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @desc Updates the wallet's last modified timestamp and triggers a save
|
|
||||||
* @param {number} ts - the timestamp
|
|
||||||
*/
|
|
||||||
Wallet.prototype.updateFocusedTimestamp = function(ts) {
|
|
||||||
preconditions.checkArgument(ts);
|
|
||||||
preconditions.checkArgument(_.isNumber(ts));
|
|
||||||
preconditions.checkArgument(ts > 2999999999, 'use miliseconds');
|
|
||||||
this.focusedTimestamp = ts;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype.updateSyncedTimestamp = function(ts) {
|
Wallet.prototype.updateSyncedTimestamp = function(ts) {
|
||||||
preconditions.checkArgument(ts);
|
preconditions.checkArgument(ts);
|
||||||
preconditions.checkArgument(_.isNumber(ts));
|
preconditions.checkArgument(_.isNumber(ts));
|
||||||
|
@ -877,15 +863,8 @@ Wallet.decodeSecret = function(secretB) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @desc Locks other sessions from connecting to the wallet
|
|
||||||
* @see Async#lockIncommingConnections
|
|
||||||
*/
|
|
||||||
Wallet.prototype._lockIncomming = function() {
|
|
||||||
this.network.lockIncommingConnections(this.publicKeyRing.getAllCopayerIds());
|
|
||||||
};
|
|
||||||
|
|
||||||
Wallet.prototype._setBlockchainListeners = function() {
|
Wallet.prototype._setupBlockchainHandlers = function() {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
self.blockchain.removeAllListeners();
|
self.blockchain.removeAllListeners();
|
||||||
|
@ -915,7 +894,18 @@ Wallet.prototype._setBlockchainListeners = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Wallet.prototype._setupNetworkHandlers = function() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
var net = this.network;
|
||||||
|
net.removeAllListeners();
|
||||||
|
net.on('connect', self._onConnect.bind(self));
|
||||||
|
net.on('data', self._onData.bind(self));
|
||||||
|
net.on('no_messages', self._onNoMessages.bind(self));
|
||||||
|
net.on('connect_error', function() {
|
||||||
|
self.emitAndKeepAlive('connectionError');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Sets up the networking with other peers.
|
* @desc Sets up the networking with other peers.
|
||||||
|
@ -926,43 +916,26 @@ Wallet.prototype._setBlockchainListeners = function() {
|
||||||
* @emits ready
|
* @emits ready
|
||||||
* @emits txProposalsUpdated
|
* @emits txProposalsUpdated
|
||||||
*
|
*
|
||||||
* @TODO: FIX PROTOCOL -- emit with a space is shitty
|
|
||||||
* @emits no messages
|
|
||||||
*/
|
*/
|
||||||
Wallet.prototype.netStart = function() {
|
Wallet.prototype.netStart = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
if (self.netStarted)
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
self._setupBlockchainHandlers();
|
||||||
|
self.netStarted= true;
|
||||||
|
|
||||||
if (!this.isShared()) {
|
if (!this.isShared()) {
|
||||||
self.emitAndKeepAlive('ready');
|
self.emitAndKeepAlive('ready');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var net = this.network;
|
self._setupNetworkHandlers();
|
||||||
net.removeAllListeners();
|
|
||||||
net.on('connect', self._onConnect.bind(self));
|
|
||||||
net.on('data', self._onData.bind(self));
|
|
||||||
net.on('no messages', self._onNoMessages.bind(self));
|
|
||||||
net.on('connect_error', function() {
|
|
||||||
self.emitAndKeepAlive('connectionError');
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.publicKeyRing.isComplete()) {
|
|
||||||
this._lockIncomming();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (net.started) {
|
|
||||||
log.debug('Wallet:' + self.getName() + ': Wallet networking was ready')
|
|
||||||
self.emitAndKeepAlive('ready', net.getPeer());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var myId = self.getMyCopayerId();
|
var myId = self.getMyCopayerId();
|
||||||
var myIdPriv = self.getMyCopayerIdPriv();
|
var myIdPriv = self.getMyCopayerIdPriv();
|
||||||
|
|
||||||
var startOpts = {
|
var startOpts = {
|
||||||
copayerId: myId,
|
copayerId: myId,
|
||||||
privkey: myIdPriv,
|
privkey: myIdPriv,
|
||||||
|
@ -971,11 +944,12 @@ Wallet.prototype.netStart = function() {
|
||||||
secretNumber: self.secretNumber,
|
secretNumber: self.secretNumber,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (this.publicKeyRing.isComplete()) {
|
||||||
|
this.network.lockIncommingConnections(this.publicKeyRing.getAllCopayerIds());
|
||||||
|
}
|
||||||
log.debug('Wallet:' + self.id + ' Starting network.');
|
log.debug('Wallet:' + self.id + ' Starting network.');
|
||||||
net.start(startOpts, function() {
|
this.network.start(startOpts, function() {
|
||||||
self._setBlockchainListeners();
|
self.emitAndKeepAlive('ready');
|
||||||
self.emitAndKeepAlive('ready', net.getPeer());
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1059,7 +1033,6 @@ Wallet.prototype.toObj = function() {
|
||||||
privateKey: this.privateKey ? this.privateKey.toObj() : undefined,
|
privateKey: this.privateKey ? this.privateKey.toObj() : undefined,
|
||||||
addressBook: this.addressBook,
|
addressBook: this.addressBook,
|
||||||
syncedTimestamp: this.syncedTimestamp || 0,
|
syncedTimestamp: this.syncedTimestamp || 0,
|
||||||
focusedTimestamp: this.focusedTimestamp || 0,
|
|
||||||
secretNumber: this.secretNumber,
|
secretNumber: this.secretNumber,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1103,7 +1076,6 @@ Wallet.fromUntrustedObj = function(obj, readOpts) {
|
||||||
* @param {string} o.networkName - 'livenet' or 'testnet'
|
* @param {string} o.networkName - 'livenet' or 'testnet'
|
||||||
* @param {Object} o.publicKeyRing - PublicKeyRing to be deserialized by {@link PublicKeyRing#fromObj}
|
* @param {Object} o.publicKeyRing - PublicKeyRing to be deserialized by {@link PublicKeyRing#fromObj}
|
||||||
* @param {number} o.syncedTimestamp - ts of the last synced message with insifht (in microseconds, as insight returns ts)
|
* @param {number} o.syncedTimestamp - ts of the last synced message with insifht (in microseconds, as insight returns ts)
|
||||||
* @param {number} o.focusedTimestamp - last time this wallet was focused (open) by a user (in miliseconds)
|
|
||||||
* @param {Object} o.txProposals - TxProposals to be deserialized by {@link TxProposals#fromObj}
|
* @param {Object} o.txProposals - TxProposals to be deserialized by {@link TxProposals#fromObj}
|
||||||
* @param {string} o.nickname - user's nickname
|
* @param {string} o.nickname - user's nickname
|
||||||
*
|
*
|
||||||
|
@ -1180,8 +1152,6 @@ Wallet.fromObj = function(o, readOpts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.syncedTimestamp = o.syncedTimestamp || 0;
|
opts.syncedTimestamp = o.syncedTimestamp || 0;
|
||||||
opts.focusedTimestamp = o.focusedTimestamp || 0;
|
|
||||||
|
|
||||||
opts.blockchainOpts = readOpts.blockchainOpts;
|
opts.blockchainOpts = readOpts.blockchainOpts;
|
||||||
opts.networkOpts = readOpts.networkOpts;
|
opts.networkOpts = readOpts.networkOpts;
|
||||||
|
|
||||||
|
@ -2114,7 +2084,11 @@ Wallet.prototype.maxRejectCount = function() {
|
||||||
// TODO: Can we add cache to getUnspent?
|
// TODO: Can we add cache to getUnspent?
|
||||||
Wallet.prototype.getUnspent = function(cb) {
|
Wallet.prototype.getUnspent = function(cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.blockchain.getUnspent(this.getAddresses(), function(err, unspentList) {
|
var addresses = this.getAddresses();
|
||||||
|
|
||||||
|
|
||||||
|
log.debug('Wallet ' + this.getName() + ': Getting unspents from ' + addresses.length + ' addresses');
|
||||||
|
this.blockchain.getUnspent(addresses, function(err, unspentList) {
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
|
@ -2322,7 +2296,7 @@ Wallet.prototype._createTxProposal = function(toAddress, amountSat, comment, utx
|
||||||
*/
|
*/
|
||||||
Wallet.prototype.updateIndexes = function(callback) {
|
Wallet.prototype.updateIndexes = function(callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (!self.isReady())
|
if (!self.isComplete())
|
||||||
return callback();
|
return callback();
|
||||||
log.debug('Wallet:' + this.id + ' Updating indexes...');
|
log.debug('Wallet:' + this.id + ' Updating indexes...');
|
||||||
var tasks = this.publicKeyRing.indexes.map(function(index) {
|
var tasks = this.publicKeyRing.indexes.map(function(index) {
|
||||||
|
@ -2440,12 +2414,12 @@ Wallet.prototype.indexDiscovery = function(start, change, copayerIndex, gap, cb)
|
||||||
* @desc Closes the wallet and disconnects all services
|
* @desc Closes the wallet and disconnects all services
|
||||||
*/
|
*/
|
||||||
Wallet.prototype.close = function(cb) {
|
Wallet.prototype.close = function(cb) {
|
||||||
|
log.debug('## CLOSING Wallet: ' + this.id);
|
||||||
this.network.removeAllListeners();
|
this.network.removeAllListeners();
|
||||||
this.network.cleanUp();
|
this.network.cleanUp();
|
||||||
this.blockchain.removeAllListeners();
|
this.blockchain.removeAllListeners();
|
||||||
this.blockchain.destroy();
|
this.blockchain.destroy();
|
||||||
|
|
||||||
log.debug('## CLOSING Wallet: ' + this.id);
|
|
||||||
// TODO
|
// TODO
|
||||||
// this.lock.release(function() {
|
// this.lock.release(function() {
|
||||||
if (cb) return cb();
|
if (cb) return cb();
|
||||||
|
@ -2521,7 +2495,7 @@ Wallet.prototype.requiresMultipleSignatures = function() {
|
||||||
* @desc Returns true if the keyring is complete
|
* @desc Returns true if the keyring is complete
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
Wallet.prototype.isReady = function() {
|
Wallet.prototype.isComplete = function() {
|
||||||
return this.publicKeyRing.isComplete();
|
return this.publicKeyRing.isComplete();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,6 @@ InsightStorage.prototype._makeGetRequest = function(passphrase, key, callback) {
|
||||||
'Authorization': authHeader
|
'Authorization': authHeader
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
log.debug('Insight request', getParams);
|
|
||||||
this.request.get(getParams,
|
this.request.get(getParams,
|
||||||
function(err, response, body) {
|
function(err, response, body) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
14
js/routes.js
14
js/routes.js
|
@ -47,32 +47,32 @@ angular
|
||||||
})
|
})
|
||||||
.when('/homeWallet', {
|
.when('/homeWallet', {
|
||||||
templateUrl: 'views/homeWallet.html',
|
templateUrl: 'views/homeWallet.html',
|
||||||
walletShouldBeReady: true,
|
walletShouldBeComplete: true,
|
||||||
logged: true
|
logged: true
|
||||||
})
|
})
|
||||||
.when('/receive', {
|
.when('/receive', {
|
||||||
templateUrl: 'views/receive.html',
|
templateUrl: 'views/receive.html',
|
||||||
walletShouldBeReady: true,
|
walletShouldBeComplete: true,
|
||||||
logged: true
|
logged: true
|
||||||
})
|
})
|
||||||
.when('/history', {
|
.when('/history', {
|
||||||
templateUrl: 'views/history.html',
|
templateUrl: 'views/history.html',
|
||||||
walletShouldBeReady: true,
|
walletShouldBeComplete: true,
|
||||||
logged: true
|
logged: true
|
||||||
})
|
})
|
||||||
.when('/send', {
|
.when('/send', {
|
||||||
templateUrl: 'views/send.html',
|
templateUrl: 'views/send.html',
|
||||||
walletShouldBeReady: true,
|
walletShouldBeComplete: true,
|
||||||
logged: true
|
logged: true
|
||||||
})
|
})
|
||||||
.when('/more', {
|
.when('/more', {
|
||||||
templateUrl: 'views/more.html',
|
templateUrl: 'views/more.html',
|
||||||
walletShouldBeReady: true,
|
walletShouldBeComplete: true,
|
||||||
logged: true
|
logged: true
|
||||||
})
|
})
|
||||||
.when('/settings', {
|
.when('/settings', {
|
||||||
templateUrl: 'views/settings.html',
|
templateUrl: 'views/settings.html',
|
||||||
walletShouldBeReady: true,
|
walletShouldBeComplete: true,
|
||||||
logged: false
|
logged: false
|
||||||
})
|
})
|
||||||
.when('/warning', {
|
.when('/warning', {
|
||||||
|
@ -125,7 +125,7 @@ angular
|
||||||
$idle.unwatch();
|
$idle.unwatch();
|
||||||
$location.path('/');
|
$location.path('/');
|
||||||
}
|
}
|
||||||
if ($rootScope.wallet && !$rootScope.wallet.isReady() && next.walletShouldBeReady) {
|
if ($rootScope.wallet && !$rootScope.wallet.isComplete() && next.walletShouldBeComplete) {
|
||||||
$location.path('/copayers');
|
$location.path('/copayers');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
'use strict';
|
||||||
|
angular.module('copayApp.services')
|
||||||
|
.factory('applicationService', function() {
|
||||||
|
var root = {};
|
||||||
|
|
||||||
|
root.restart = function() {
|
||||||
|
// Go home reloading the application
|
||||||
|
var hashIndex = window.location.href.indexOf('#!/');
|
||||||
|
window.location = window.location.href.substr(0, hashIndex);
|
||||||
|
};
|
||||||
|
|
||||||
|
root.reload = function() {
|
||||||
|
window.location.reload();
|
||||||
|
};
|
||||||
|
|
||||||
|
return root;
|
||||||
|
});
|
|
@ -13,8 +13,6 @@ angular.module('copayApp.services')
|
||||||
cb = cb || function() {};
|
cb = cb || function() {};
|
||||||
var satToUnit = 1 / w.settings.unitToSatoshi;
|
var satToUnit = 1 / w.settings.unitToSatoshi;
|
||||||
var COIN = bitcore.util.COIN;
|
var COIN = bitcore.util.COIN;
|
||||||
|
|
||||||
console.log('[balanceS.js.257] FETCH BALANCE: ', w.getName()); //TODO
|
|
||||||
w.getBalance(function(err, balanceSat, balanceByAddrSat, safeBalanceSat, safeUnspentCount) {
|
w.getBalance(function(err, balanceSat, balanceByAddrSat, safeBalanceSat, safeUnspentCount) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
|
@ -55,26 +53,32 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root.update = function(w, cb, isFocused) {
|
root.update = function(w, cb, isFocused) {
|
||||||
console.log(' UPDATE BALANCE!!!!', w ? w.getName() : 'current'); //TODO
|
|
||||||
|
|
||||||
w = w || $rootScope.wallet;
|
w = w || $rootScope.wallet;
|
||||||
if (!w || !w.isReady()) return;
|
if (!w || !w.isComplete()) return;
|
||||||
|
|
||||||
console.log('DO UPDATE BALANCE!!!!', w.getName()); //TODO
|
copay.logger.debug('Updating balance of:', w.getName(), isFocused);
|
||||||
var wid = w.getId();
|
var wid = w.getId();
|
||||||
|
|
||||||
|
|
||||||
|
// cache available? Set the cached values until we updated them
|
||||||
if (_balanceCache[wid]) {
|
if (_balanceCache[wid]) {
|
||||||
w.balanceInfo = _balanceCache[wid];
|
w.balanceInfo = _balanceCache[wid];
|
||||||
} else {
|
} else {
|
||||||
|
if (isFocused)
|
||||||
$rootScope.updatingBalance = true;
|
$rootScope.updatingBalance = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.balanceInfo = w.balanceInfo || {};
|
||||||
|
w.balanceInfo.updating = true;
|
||||||
|
|
||||||
root._fetchBalance(w, function(err, res) {
|
root._fetchBalance(w, function(err, res) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
w.balanceInfo=_balanceCache[wid] = res;
|
w.balanceInfo=_balanceCache[wid] = res;
|
||||||
$rootScope.updatingBalance = false;
|
w.balanceInfo.updating = false;
|
||||||
|
|
||||||
if (isFocused) {
|
if (isFocused) {
|
||||||
_.extend($rootScope, w.balanceInfo);
|
_.extend($rootScope, w.balanceInfo);
|
||||||
|
$rootScope.updatingBalance = false;
|
||||||
}
|
}
|
||||||
if (cb) cb();
|
if (cb) cb();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('identityService', function($rootScope, $location, $timeout, $filter, pluginManager, notification, pendingTxsService, balanceService) {
|
.factory('identityService', function($rootScope, $location, $timeout, $filter, pluginManager, notification, pendingTxsService, balanceService, applicationService) {
|
||||||
var root = {};
|
notification.enableHtml5Mode(); // for chrome: if support, enable it
|
||||||
|
|
||||||
|
var root = {};
|
||||||
root.check = function(scope) {
|
root.check = function(scope) {
|
||||||
copay.Identity.checkIfExistsAny({
|
copay.Identity.checkIfExistsAny({
|
||||||
pluginManager: pluginManager,
|
pluginManager: pluginManager,
|
||||||
|
@ -25,7 +25,7 @@ angular.module('copayApp.services')
|
||||||
root.goWalletHome = function() {
|
root.goWalletHome = function() {
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
if (w) {
|
if (w) {
|
||||||
if (!w.isReady()) {
|
if (!w.isComplete()) {
|
||||||
$location.path('/copayers');
|
$location.path('/copayers');
|
||||||
} else {
|
} else {
|
||||||
if ($rootScope.pendingPayment) {
|
if ($rootScope.pendingPayment) {
|
||||||
|
@ -37,8 +37,7 @@ angular.module('copayApp.services')
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
root.create = function(scope, form) {
|
root.create = function(email, password) {
|
||||||
$rootScope.starting = true;
|
|
||||||
copay.Identity.create({
|
copay.Identity.create({
|
||||||
email: form.email.$modelValue,
|
email: form.email.$modelValue,
|
||||||
password: form.password.$modelValue,
|
password: form.password.$modelValue,
|
||||||
|
@ -49,19 +48,9 @@ angular.module('copayApp.services')
|
||||||
passphraseConfig: config.passphraseConfig,
|
passphraseConfig: config.passphraseConfig,
|
||||||
failIfExists: true,
|
failIfExists: true,
|
||||||
}, function(err, iden) {
|
}, function(err, iden) {
|
||||||
if (err || !iden) {
|
if (err) return cb(err);
|
||||||
copay.logger.debug(err);
|
preconditions.checkState(iden);
|
||||||
if (err && (err.match('EEXISTS') || err.match('BADCREDENTIALS'))) {
|
|
||||||
scope.error = 'User already exists!';
|
|
||||||
} else {
|
|
||||||
scope.error = 'Unknown error when connecting Insight Server';
|
|
||||||
}
|
|
||||||
$rootScope.starting = false;
|
|
||||||
$timeout(function() {
|
|
||||||
$rootScope.$digest()
|
|
||||||
}, 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var walletOptions = {
|
var walletOptions = {
|
||||||
nickname: iden.fullName,
|
nickname: iden.fullName,
|
||||||
networkName: config.networkName,
|
networkName: config.networkName,
|
||||||
|
@ -71,61 +60,37 @@ angular.module('copayApp.services')
|
||||||
name: 'My wallet',
|
name: 'My wallet',
|
||||||
};
|
};
|
||||||
iden.createWallet(walletOptions, function(err, wallet) {
|
iden.createWallet(walletOptions, function(err, wallet) {
|
||||||
if (err || !wallet) {
|
if (err) return cb(err);
|
||||||
copay.logger.debug(err);
|
root.bind(iden);
|
||||||
scope.error = 'Could not create default wallet';
|
|
||||||
$rootScope.starting = false;
|
return cb();
|
||||||
$timeout(function() {
|
|
||||||
$rootScope.$digest()
|
|
||||||
}, 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
root.bind(scope, iden, wallet.id);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
root.open = function(scope, form) {
|
root.open = function(email, password, cb) {
|
||||||
$rootScope.starting = true;
|
var opts = {
|
||||||
copay.Identity.open({
|
email: email,
|
||||||
email: form.email.$modelValue,
|
password: password,
|
||||||
password: form.password.$modelValue,
|
|
||||||
pluginManager: pluginManager,
|
pluginManager: pluginManager,
|
||||||
network: config.network,
|
network: config.network,
|
||||||
networkName: config.networkName,
|
networkName: config.networkName,
|
||||||
walletDefaults: config.wallet,
|
walletDefaults: config.wallet,
|
||||||
passphraseConfig: config.passphraseConfig,
|
passphraseConfig: config.passphraseConfig,
|
||||||
}, function(err, iden) {
|
};
|
||||||
$rootScope.starting = false;
|
|
||||||
if (err && !iden) {
|
|
||||||
if ((err.toString() || '').match('PNOTFOUND')) {
|
|
||||||
scope.error = 'Invalid email or password';
|
|
||||||
} else {
|
|
||||||
scope.error = 'Unknown error';
|
|
||||||
}
|
|
||||||
$timeout(function() {
|
|
||||||
$rootScope.$digest()
|
|
||||||
}, 1);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
|
copay.Identity.open(opts, function(err, iden) {
|
||||||
|
if (err) return cb(err);
|
||||||
console.log('[identityService.js.95] LISTO OPEN!!'); //TODO
|
console.log('[identityService.js.95] LISTO OPEN!!'); //TODO
|
||||||
var firstWallet = iden.getLastFocusedWallet();
|
root.bind(iden);
|
||||||
root.bind(scope, iden, firstWallet);
|
return iden.openWallets(cb);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.deleteWallet = function($scope, iden, w) {
|
root.deleteWallet = function($scope, iden, w) {
|
||||||
$rootScope.iden.deleteWallet(w.id, function() {
|
$rootScope.iden.deleteWallet(w.id);
|
||||||
notification.info(name + ' deleted', $filter('translate')('This wallet was deleted'));
|
|
||||||
if ($rootScope.wallet.id === w.id) {
|
|
||||||
$rootScope.wallet = null;
|
|
||||||
var lastFocused = $rootScope.iden.getLastFocusedWallet();
|
|
||||||
root.bind($scope, $rootScope.iden, lastFocused);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
root.isFocused = function(wid) {
|
root.isFocused = function(wid) {
|
||||||
|
@ -133,13 +98,8 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setupGlobalVariables = function(iden) {
|
root.setupGlobalVariables = function(iden) {
|
||||||
notification.enableHtml5Mode(); // for chrome: if support, enable it
|
|
||||||
$rootScope.unitName = config.unitName;
|
|
||||||
$rootScope.pendingTxCount = 0;
|
$rootScope.pendingTxCount = 0;
|
||||||
$rootScope.initialConnection = true;
|
|
||||||
$rootScope.reconnecting = false;
|
$rootScope.reconnecting = false;
|
||||||
$rootScope.isCollapsed = true;
|
|
||||||
|
|
||||||
$rootScope.iden = iden;
|
$rootScope.iden = iden;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -151,20 +111,20 @@ angular.module('copayApp.services')
|
||||||
root.setFocusedWallet = function(w) {
|
root.setFocusedWallet = function(w) {
|
||||||
if (!_.isObject(w))
|
if (!_.isObject(w))
|
||||||
w = $rootScope.iden.getWalletById(w);
|
w = $rootScope.iden.getWalletById(w);
|
||||||
|
|
||||||
preconditions.checkState(w && _.isObject(w));
|
preconditions.checkState(w && _.isObject(w));
|
||||||
|
|
||||||
|
copay.logger.debug('Set focus:', w.getName());
|
||||||
$rootScope.wallet = w;
|
$rootScope.wallet = w;
|
||||||
w.updateFocusedTimestamp(Date.now());
|
|
||||||
root.goWalletHome();
|
$rootScope.iden.updateFocusedTimestamp(w.getId());
|
||||||
pendingTxsService.update();
|
pendingTxsService.update();
|
||||||
|
|
||||||
console.log('[controllerUtils.js.221] SET FOCUS'); //TODO
|
$timeout(function() {
|
||||||
balanceService.update(w, function() {
|
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
}, true)
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
root.installWalletHandlers = function($scope, w) {
|
root.installWalletHandlers = function(w) {
|
||||||
var wid = w.getId();
|
var wid = w.getId();
|
||||||
w.on('connectionError', function() {
|
w.on('connectionError', function() {
|
||||||
console.log('err', w.getName()); //TODO
|
console.log('err', w.getName()); //TODO
|
||||||
|
@ -181,12 +141,12 @@ angular.module('copayApp.services')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
w.on('ready', function() {
|
w.on('ready', function() {
|
||||||
console.log('read', w.getName()); //TODO
|
var isFocused = root.isFocused(wid);
|
||||||
$scope.loading = false;
|
console.log('GOT READY [identityService.js.184:isFocused:]', w.getName(), isFocused); //TODO
|
||||||
if ($rootScope.initialConnection) {
|
|
||||||
$rootScope.initialConnection = false;
|
balanceService.update(w, function() {
|
||||||
root.goWalletHome();
|
$rootScope.$digest();
|
||||||
}
|
}, isFocused);
|
||||||
});
|
});
|
||||||
|
|
||||||
w.on('tx', function(address, isChange) {
|
w.on('tx', function(address, isChange) {
|
||||||
|
@ -282,85 +242,79 @@ angular.module('copayApp.services')
|
||||||
// w.on('locked',);
|
// w.on('locked',);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.rebindWallets = function($scope, iden) {
|
root.bind = function(iden) {
|
||||||
_.each(iden.listWallets(), function(wallet) {
|
|
||||||
preconditions.checkState(wallet);
|
|
||||||
root.installWalletHandlers($scope, wallet);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
root.bind = function($scope, iden, w) {
|
console.log('[identityService.js.250] PROFILE BINE'); //TODO
|
||||||
console.log('ident bind Globals'); //TODO
|
preconditions.checkArgument(_.isObject(iden));
|
||||||
|
|
||||||
|
var self = this;
|
||||||
root.setupGlobalVariables(iden);
|
root.setupGlobalVariables(iden);
|
||||||
root.rebindWallets($scope, iden);
|
|
||||||
if (w) {
|
iden.on('newWallet', function(wid) {
|
||||||
|
var w = iden.getWalletById(wid);
|
||||||
|
copay.logger.debug('newWallet:', w.getName());
|
||||||
|
root.installWalletHandlers(w);
|
||||||
|
w.netStart();
|
||||||
|
if (wid == iden.getLastFocusedWalletId()) {
|
||||||
|
copay.logger.debug('GOT Focused wallet!', w.getName());
|
||||||
root.setFocusedWallet(w);
|
root.setFocusedWallet(w);
|
||||||
} else {
|
root.goWalletHome();
|
||||||
$location.path('/create');
|
|
||||||
}
|
|
||||||
$timeout(function() {
|
|
||||||
console.log('[controllerUtils.js.242] DIGEST'); //TODO
|
|
||||||
$rootScope.$digest()
|
$rootScope.$digest()
|
||||||
console.log('[controllerUtils.js.242] DIGEST DONE'); //TODO
|
}
|
||||||
}, 1);
|
});
|
||||||
};
|
|
||||||
|
|
||||||
root.logout = function() {
|
iden.on('noWallets', function() {
|
||||||
if ($rootScope.iden) {
|
$location.path('/create');
|
||||||
$rootScope.iden.store(null, function() {
|
$rootScope.$digest()
|
||||||
$rootScope.iden.close();
|
});
|
||||||
|
|
||||||
|
iden.on('deletedWallet', function(wid) {
|
||||||
|
notification.info('Wallet deleted', $filter('translate')('This wallet was deleted'));
|
||||||
|
if ($rootScope.wallet.id === wid) {
|
||||||
|
$rootScope.wallet = null;
|
||||||
|
var lastFocused = iden.getLastFocusedWalletId();
|
||||||
|
self.setFocusedWallet(lastFocused);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
iden.on('closed', function() {
|
||||||
delete $rootScope['wallet'];
|
delete $rootScope['wallet'];
|
||||||
delete $rootScope['iden'];
|
delete $rootScope['iden'];
|
||||||
|
applicationService.restart();
|
||||||
// Go home reloading the application
|
|
||||||
var hashIndex = window.location.href.indexOf('#!/');
|
|
||||||
window.location = window.location.href.substr(0, hashIndex);
|
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
root.signout = function() {
|
||||||
|
if ($rootScope.iden) {
|
||||||
|
$rootScope.iden.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
root.createWallet = function(opts, cb) {
|
root.createWallet = function(opts, cb) {
|
||||||
$rootScope.iden.createWallet(opts, function(err, w) {
|
$rootScope.iden.createWallet(opts, cb);
|
||||||
root.installWalletHandlers($scope, w);
|
|
||||||
root.setFocusedWallet(w);
|
|
||||||
return cb();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
root.importWallet = function(encryptedObj, pass, opts, cb) {
|
root.importWallet = function(encryptedObj, pass, opts, cb) {
|
||||||
copay.Compatibility.importEncryptedWallet($rootScope.iden, encryptedObj,
|
copay.Compatibility.importEncryptedWallet($rootScope.iden, encryptedObj, pass, opts);
|
||||||
pass, opts, function(err, wallet) {
|
|
||||||
if (err) return cb(err);
|
|
||||||
root.installWalletHandlers($scope, wallet);
|
|
||||||
root.setFocusedWallet(wallet);
|
|
||||||
return cb();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
root.joinWallet = function(opts, cb) {
|
root.joinWallet = function(opts, cb) {
|
||||||
$rootScope.iden.joinWallet(opts, function(err, w) {
|
$rootScope.iden.joinWallet(opts, function(err, w) {
|
||||||
$scope.loading = false;
|
|
||||||
if (err || !w) {
|
|
||||||
if (err === 'joinError')
|
|
||||||
notification.error('Fatal error connecting to Insight server');
|
|
||||||
else if (err === 'walletFull')
|
|
||||||
notification.error('The wallet is full');
|
|
||||||
else if (err === 'badNetwork')
|
|
||||||
notification.error('Network Error', 'Wallet network configuration missmatch');
|
|
||||||
else if (err === 'badSecret')
|
|
||||||
notification.error('Bad secret', 'The secret string you entered is invalid');
|
|
||||||
else {
|
|
||||||
notification.error('Error', err.message || err);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
root.installWalletHandlers($scope, w);
|
|
||||||
root.setFocusedWallet(w);
|
|
||||||
}
|
|
||||||
return cb(err);
|
return cb(err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
root.importProfile = function(str, password, cb){
|
||||||
|
copay.Identity.importFromEncryptedFullJson(str, password, {
|
||||||
|
pluginManager: pluginManager,
|
||||||
|
network: config.network,
|
||||||
|
networkName: config.networkName,
|
||||||
|
walletDefaults: config.wallet,
|
||||||
|
passphraseConfig: config.passphraseConfig,
|
||||||
|
}, function(err, iden) {
|
||||||
|
if (err) return cb(err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('copayApp.services')
|
||||||
|
.factory('pendingTxsService', function($rootScope, $sce, $location, $filter, notification, $timeout, rateService) {
|
||||||
|
var root = {};
|
||||||
|
root.update = function(w) {
|
||||||
|
console.log('[pendingTxsService.js.8] TODO updade pending Txs'); //TODO
|
||||||
|
};
|
||||||
|
return root;
|
||||||
|
});
|
|
@ -524,14 +524,14 @@ describe('Wallet model', function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it('#isReady', function() {
|
it('#isComplete', function() {
|
||||||
var w = createW();
|
var w = createW();
|
||||||
w.publicKeyRing.isComplete().should.equal(false);
|
w.publicKeyRing.isComplete().should.equal(false);
|
||||||
w.isReady().should.equal(false);
|
w.isComplete().should.equal(false);
|
||||||
|
|
||||||
var w2 = createW2();
|
var w2 = createW2();
|
||||||
w2.publicKeyRing.isComplete().should.equal(true);
|
w2.publicKeyRing.isComplete().should.equal(true);
|
||||||
w2.isReady().should.equal(true);
|
w2.isComplete().should.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handle network indexes correctly', function() {
|
it('handle network indexes correctly', function() {
|
||||||
|
@ -2497,7 +2497,7 @@ describe('Wallet model', function() {
|
||||||
blockchainOpts: {},
|
blockchainOpts: {},
|
||||||
}, function(err, w) {
|
}, function(err, w) {
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
w.isReady().should.equal(true);
|
w.isComplete().should.equal(true);
|
||||||
var wo = w.toObj();
|
var wo = w.toObj();
|
||||||
wo.opts.id.should.equal('48ba2f1ffdfe9708');
|
wo.opts.id.should.equal('48ba2f1ffdfe9708');
|
||||||
wo.opts.spendUnconfirmed.should.equal(true);
|
wo.opts.spendUnconfirmed.should.equal(true);
|
||||||
|
|
|
@ -50,7 +50,7 @@ describe("Unit: Controllers", function() {
|
||||||
|
|
||||||
var w = {};
|
var w = {};
|
||||||
w.id = 1234;
|
w.id = 1234;
|
||||||
w.isReady = sinon.stub().returns(true);
|
w.isComplete = sinon.stub().returns(true);
|
||||||
w.privateKey = {};
|
w.privateKey = {};
|
||||||
w.settings = {
|
w.settings = {
|
||||||
unitToSatoshi: 100,
|
unitToSatoshi: 100,
|
||||||
|
|
|
@ -10,7 +10,7 @@ describe("Unit: Testing Directives", function() {
|
||||||
beforeEach(inject(function($rootScope) {
|
beforeEach(inject(function($rootScope) {
|
||||||
|
|
||||||
var w = {};
|
var w = {};
|
||||||
w.isReady = sinon.stub().returns(true);
|
w.isComplete = sinon.stub().returns(true);
|
||||||
w.privateKey = {};
|
w.privateKey = {};
|
||||||
w.settings = {
|
w.settings = {
|
||||||
unitToSatoshi: 100,
|
unitToSatoshi: 100,
|
||||||
|
|
|
@ -9,7 +9,7 @@ describe('Angular Filters', function() {
|
||||||
beforeEach(inject(function($rootScope) {
|
beforeEach(inject(function($rootScope) {
|
||||||
|
|
||||||
var w = {};
|
var w = {};
|
||||||
w.isReady = sinon.stub().returns(true);
|
w.isComplete = sinon.stub().returns(true);
|
||||||
w.privateKey = {};
|
w.privateKey = {};
|
||||||
w.settings = {
|
w.settings = {
|
||||||
unitToSatoshi: 100,
|
unitToSatoshi: 100,
|
||||||
|
|
|
@ -26,7 +26,7 @@ describe("Angular services", function() {
|
||||||
beforeEach(inject(function($rootScope) {
|
beforeEach(inject(function($rootScope) {
|
||||||
|
|
||||||
var w = {};
|
var w = {};
|
||||||
w.isReady = sinon.stub().returns(true);
|
w.isComplete = sinon.stub().returns(true);
|
||||||
w.privateKey = {};
|
w.privateKey = {};
|
||||||
w.settings = {
|
w.settings = {
|
||||||
unitToSatoshi: 100,
|
unitToSatoshi: 100,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<div ng-controller="CopayersController">
|
<div ng-controller="CopayersController">
|
||||||
<div ng-if='$root.wallet && $root.wallet.isReady()' ng-init="goToWallet()"></div>
|
<div ng-if='$root.wallet && $root.wallet.isComplete()' ng-init="goToWallet()"></div>
|
||||||
|
|
||||||
<div class="row hide-for-large-up">
|
<div class="row hide-for-large-up">
|
||||||
<div class="medium-12 small-12 columns">
|
<div class="medium-12 small-12 columns">
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="large-12 columns">
|
<div class="large-12 columns">
|
||||||
<div ng-if="!$root.wallet.isReady()">
|
<div ng-if="!$root.wallet.isComplete()">
|
||||||
<div class="panel oh">
|
<div class="panel oh">
|
||||||
<h2 class="line-b">
|
<h2 class="line-b">
|
||||||
Share this secret with your other copayers
|
Share this secret with your other copayers
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="panel oh">
|
<div class="panel oh">
|
||||||
<div ng-include="'views/includes/copayer.html'"></div>
|
<div ng-include="'views/includes/copayer.html'"></div>
|
||||||
<div class="copay-box" ng-if="!$root.wallet.isReady()">
|
<div class="copay-box" ng-if="!$root.wallet.isComplete()">
|
||||||
<span ng-include="'views/includes/photo.html'"></span>
|
<span ng-include="'views/includes/photo.html'"></span>
|
||||||
<p class="size-12 text-white text-light m0">
|
<p class="size-12 text-white text-light m0">
|
||||||
<i class="fi-loop icon-rotate spinner"></i>
|
<i class="fi-loop icon-rotate spinner"></i>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<div class="transactions" data-ng-controller="HistoryController" data-ng-init="update()">
|
<div class="transactions" data-ng-controller="HistoryController" data-ng-init="update()">
|
||||||
<div ng-show='$root.wallet.isReady()'>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="large-12 medium-12 small-12 columns">
|
<div class="large-12 medium-12 small-12 columns">
|
||||||
<h1 class="hide-for-large-up">{{$root.title}}</h1>
|
<h1 class="hide-for-large-up">{{$root.title}}</h1>
|
||||||
|
@ -141,4 +140,3 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<div class="home-wallet" ng-controller="HomeWalletController">
|
<div class="home-wallet" ng-controller="HomeWalletController">
|
||||||
<div ng-show='$root.wallet.isReady()'>
|
|
||||||
<div class="row hide-for-large-up">
|
<div class="row hide-for-large-up">
|
||||||
<div class="medium-12 small-12 columns">
|
<div class="medium-12 small-12 columns">
|
||||||
<h1 translate>Home</h1>
|
<h1 translate>Home</h1>
|
||||||
|
@ -60,7 +59,5 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="founds size-12">
|
<div class="founds size-12">
|
||||||
<span ng-if="!$root.wallet.isReady()">Waiting for copayers...</span>
|
<span ng-if="!$root.wallet.isComplete()">Waiting for copayers...</span>
|
||||||
<div ng-if="$root.wallet.isReady()">
|
<div ng-if="$root.wallet.isComplete()">
|
||||||
<span ng-if="$root.updatingBalance"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
|
<span ng-if="$root.updatingBalance"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
|
||||||
<div ng-if="$root.wallet && !$root.updatingBalance" data-options="disable_for_touch:true">
|
<div ng-if="$root.wallet && !$root.updatingBalance" data-options="disable_for_touch:true">
|
||||||
<b class="m5r">{{totalBalance || 0 |noFractionNumber}} {{$root.wallet.settings.unitName}}</b>
|
<b class="m5r">{{totalBalance || 0 |noFractionNumber}} {{$root.wallet.settings.unitName}}</b>
|
||||||
|
@ -56,12 +56,12 @@
|
||||||
<div class="ellipsis name-wallet">{{item.name || item.id}}</div>
|
<div class="ellipsis name-wallet">{{item.name || item.id}}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="oh">
|
<div class="oh">
|
||||||
<span ng-if="item.isReady() && item.balanceInfo.updatingBalance"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
|
<span ng-if="item.isComplete() && item.balanceInfo.updatingBalance"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
|
||||||
<div ng-if="item.isReady() && !item.balanceInfo.updatingBalance" data-options="disable_for_touch:true">
|
<div ng-if="item.isComplete() && !item.balanceInfo.updatingBalance" data-options="disable_for_touch:true">
|
||||||
<b class="m5r size-12">{{item.balanceInfo.totalBalance || 0 |noFractionNumber}} {{item.settings.unitName}}</b>
|
<b class="m5r size-12">{{item.balanceInfo.totalBalance || 0 |noFractionNumber}} {{item.settings.unitName}}</b>
|
||||||
<span class="alt-currency size-10">{{item.balanceInfo.totalBalanceAlternative |noFractionNumber:2}} {{item.balanceInfo.alternativeIsoCode}}</span>
|
<span class="alt-currency size-10">{{item.balanceInfo.totalBalanceAlternative |noFractionNumber:2}} {{item.balanceInfo.alternativeIsoCode}}</span>
|
||||||
</div>
|
</div>
|
||||||
<span ng-if="!item.isReady()">Waiting for copayers...</span>
|
<span ng-if="!item.isComplete()">Waiting for copayers...</span>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="founds size-12">
|
<div class="founds size-12">
|
||||||
<span ng-if="!$root.wallet.isReady()">Waiting for copayers...</span>
|
<span ng-if="!$root.wallet.isComplete()">Waiting for copayers...</span>
|
||||||
<div ng-if="$root.wallet.isReady()">
|
<div ng-if="$root.wallet.isComplete()">
|
||||||
<span ng-if="$root.updatingBalance"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
|
<span ng-if="$root.updatingBalance"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
|
||||||
<div ng-if="$root.wallet && !$root.updatingBalance" data-options="disable_for_touch:true">
|
<div ng-if="$root.wallet && !$root.updatingBalance" data-options="disable_for_touch:true">
|
||||||
<b class="m5r">{{totalBalance || 0 |noFractionNumber}} {{$root.wallet.settings.unitName}}</b>
|
<b class="m5r">{{totalBalance || 0 |noFractionNumber}} {{$root.wallet.settings.unitName}}</b>
|
||||||
|
@ -62,12 +62,12 @@
|
||||||
<div class="ellipsis name-wallet">{{item.name || item.id}}</div>
|
<div class="ellipsis name-wallet">{{item.name || item.id}}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="oh">
|
<div class="oh">
|
||||||
<span ng-if="item.isReady() && item.balanceInfo.updatingBalance"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
|
<span ng-if="item.isComplete() && item.balanceInfo.updatingBalance"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
|
||||||
<div ng-if="item.isReady() && !item.balanceInfo.updatingBalance" data-options="disable_for_touch:true">
|
<div ng-if="item.isComplete() && !item.balanceInfo.updatingBalance" data-options="disable_for_touch:true">
|
||||||
<b class="m5r size-12">{{item.balanceInfo.totalBalance || 0 |noFractionNumber}} {{item.settings.unitName}}</b>
|
<b class="m5r size-12">{{item.balanceInfo.totalBalance || 0 |noFractionNumber}} {{item.settings.unitName}}</b>
|
||||||
<span class="alt-currency size-10">{{item.balanceInfo.totalBalanceAlternative |noFractionNumber:2}} {{item.balanceInfo.alternativeIsoCode}}</span>
|
<span class="alt-currency size-10">{{item.balanceInfo.totalBalanceAlternative |noFractionNumber:2}} {{item.balanceInfo.alternativeIsoCode}}</span>
|
||||||
</div>
|
</div>
|
||||||
<span ng-if="!item.isReady()">Waiting for copayers...</span>
|
<span ng-if="!item.isComplete()">Waiting for copayers...</span>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul class="side-nav" ng-if="(!walletSelection || !wallets[0]) && $root.wallet.isReady()">
|
<ul class="side-nav" ng-if="(!walletSelection || !wallets[0]) && $root.wallet.isComplete()">
|
||||||
<li data-ng-repeat="item in menu" ui-route="{{item.link}}" class="nav-item" data-ng-class="{active: isActive(item)}">
|
<li data-ng-repeat="item in menu" ui-route="{{item.link}}" class="nav-item" data-ng-class="{active: isActive(item)}">
|
||||||
<a href="#!/{{item.link}}" ng-click="toggleCollapse()" class="db p20h">
|
<a href="#!/{{item.link}}" ng-click="toggleCollapse()" class="db p20h">
|
||||||
<i class="size-21 m20r {{item.icon}}"></i> {{item.title|translate}}
|
<i class="size-21 m20r {{item.icon}}"></i> {{item.title|translate}}
|
||||||
|
|
|
@ -55,17 +55,17 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr
|
<tr
|
||||||
data-ng-repeat="item in wallets | orderBy:'name'"
|
data-ng-repeat="item in wallets | orderBy:'name'"
|
||||||
ng-init="isReady = item.isReady();
|
ng-init="isComplete = item.isComplete();
|
||||||
networkName = item.getNetworkName()"
|
networkName = item.getNetworkName()"
|
||||||
ng-class="{'deleting':loading==item.id}">
|
ng-class="{'deleting':loading==item.id}">
|
||||||
<td>{{item.name || item.id }}</td>
|
<td>{{item.name || item.id }}</td>
|
||||||
<td>{{item.requiredCopayers}} of {{item.totalCopayers}} - {{networkName}}</td>
|
<td>{{item.requiredCopayers}} of {{item.totalCopayers}} - {{networkName}}</td>
|
||||||
<td class="hide-for-small-only">
|
<td class="hide-for-small-only">
|
||||||
{{isReady ? 'Complete' : 'Waiting for copayers...'}}
|
{{isComplete ? 'Complete' : 'Waiting for copayers...'}}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<span ng-if="!isReady">-</span>
|
<span ng-if="!isComplete">-</span>
|
||||||
<span ng-if="isReady">
|
<span ng-if="isComplete">
|
||||||
{{item.balanceInfo.totalBalance || 0 |noFractionNumber}} {{item.settings.unitName}}
|
{{item.balanceInfo.totalBalance || 0 |noFractionNumber}} {{item.settings.unitName}}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<div class="addresses" ng-controller="ReceiveController">
|
<div class="addresses" ng-controller="ReceiveController">
|
||||||
<div ng-show='$root.wallet.isReady()'>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="large-12 medium-12 small-12 columns">
|
<div class="large-12 medium-12 small-12 columns">
|
||||||
<h1 class="hide-for-large-up">{{$root.title}}</h1>
|
<h1 class="hide-for-large-up">{{$root.title}}</h1>
|
||||||
|
@ -65,5 +64,4 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
<div class="send" ng-controller="SendController" ng-init="loadTxs()">
|
<div class="send" ng-controller="SendController" ng-init="loadTxs()">
|
||||||
<div ng-show='$root.wallet.isReady()'>
|
|
||||||
|
|
||||||
<div class="row" ng-show="txps.length != 0">
|
<div class="row" ng-show="txps.length != 0">
|
||||||
<div class="large-12 columns">
|
<div class="large-12 columns">
|
||||||
<h2 translate>Pending Transactions Proposals</h2>
|
<h2 translate>Pending Transactions Proposals</h2>
|
||||||
|
@ -231,5 +229,4 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue