mirror of https://github.com/BTCPrivate/copay.git
commit
6af571547e
|
@ -120,7 +120,7 @@ angular.module('copayApp.controllers').controller('JoinController',
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
if (err || !w) {
|
if (err || !w) {
|
||||||
if (err === 'joinError')
|
if (err === 'joinError')
|
||||||
notification.error('Can\'t find peer.');
|
notification.error('Fatal error connecting to Insight server');
|
||||||
else if (err === 'walletFull')
|
else if (err === 'walletFull')
|
||||||
notification.error('The wallet is full');
|
notification.error('The wallet is full');
|
||||||
else if (err === 'badNetwork')
|
else if (err === 'badNetwork')
|
||||||
|
|
|
@ -207,7 +207,6 @@ WalletFactory.prototype.getWallets = function() {
|
||||||
|
|
||||||
WalletFactory.prototype.delete = function(walletId, cb) {
|
WalletFactory.prototype.delete = function(walletId, cb) {
|
||||||
var s = this.storage;
|
var s = this.storage;
|
||||||
this.log('## DELETING WALLET ID:' + walletId); //TODO
|
|
||||||
s.deleteWallet(walletId);
|
s.deleteWallet(walletId);
|
||||||
s.setLastOpened(undefined);
|
s.setLastOpened(undefined);
|
||||||
return cb();
|
return cb();
|
||||||
|
@ -257,7 +256,6 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras
|
||||||
|
|
||||||
self.network.start(opts, function() {
|
self.network.start(opts, function() {
|
||||||
self.network.greet(s.pubKey);
|
self.network.greet(s.pubKey);
|
||||||
|
|
||||||
self.network.on('data', function(sender, data) {
|
self.network.on('data', function(sender, data) {
|
||||||
if (data.type === 'walletId') {
|
if (data.type === 'walletId') {
|
||||||
if (data.networkName !== self.networkName) {
|
if (data.networkName !== self.networkName) {
|
||||||
|
|
|
@ -72,6 +72,7 @@ Network.prototype.connectedCopayers = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Network.prototype._sendHello = function(copayerId) {
|
Network.prototype._sendHello = function(copayerId) {
|
||||||
|
|
||||||
this.send(copayerId, {
|
this.send(copayerId, {
|
||||||
type: 'hello',
|
type: 'hello',
|
||||||
copayerId: this.copayerId,
|
copayerId: this.copayerId,
|
||||||
|
@ -211,13 +212,6 @@ Network.prototype._onMessage = function(enc) {
|
||||||
Network.prototype._setupConnectionHandlers = function(cb) {
|
Network.prototype._setupConnectionHandlers = function(cb) {
|
||||||
preconditions.checkState(this.socket);
|
preconditions.checkState(this.socket);
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.socket.on('connect', function() {
|
|
||||||
self.socket.on('disconnect', function() {
|
|
||||||
self.cleanUp();
|
|
||||||
});
|
|
||||||
if (typeof cb === 'function') cb();
|
|
||||||
});
|
|
||||||
self.socket.on('message', function(m) {
|
self.socket.on('message', function(m) {
|
||||||
// delay execution, to improve error handling
|
// delay execution, to improve error handling
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
@ -226,6 +220,14 @@ Network.prototype._setupConnectionHandlers = function(cb) {
|
||||||
});
|
});
|
||||||
self.socket.on('error', self._onError.bind(self));
|
self.socket.on('error', self._onError.bind(self));
|
||||||
|
|
||||||
|
self.socket.on('connect', function() {
|
||||||
|
|
||||||
|
self.socket.on('disconnect', function() {
|
||||||
|
self.cleanUp();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (typeof cb === 'function') cb();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Network.prototype._onError = function(err) {
|
Network.prototype._onError = function(err) {
|
||||||
|
@ -285,9 +287,23 @@ Network.prototype.start = function(opts, openCallback) {
|
||||||
this.socket = this.createSocket();
|
this.socket = this.createSocket();
|
||||||
this._setupConnectionHandlers(openCallback);
|
this._setupConnectionHandlers(openCallback);
|
||||||
this.socket.emit('subscribe', pubkey);
|
this.socket.emit('subscribe', pubkey);
|
||||||
this.socket.emit('sync', opts.lastTimestamp);
|
|
||||||
this.started = true;
|
|
||||||
|
|
||||||
|
var self = this,
|
||||||
|
tries = 0;
|
||||||
|
self.socket.on('insight-error', function(m) {
|
||||||
|
|
||||||
|
console.log('Retrying to sync...');
|
||||||
|
setTimeout(function() {
|
||||||
|
if (tries++ > 5) {
|
||||||
|
self.emit('serverError');
|
||||||
|
} else {
|
||||||
|
self.socket.emit('sync', opts.lastTimestamp);
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
});
|
||||||
|
|
||||||
|
self.socket.emit('sync', opts.lastTimestamp);
|
||||||
|
self.started = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
Network.prototype.createSocket = function() {
|
Network.prototype.createSocket = function() {
|
||||||
|
@ -329,7 +345,6 @@ Network.prototype.send = function(dest, payload, cb) {
|
||||||
dest = this.getCopayerIds();
|
dest = this.getCopayerIds();
|
||||||
payload.isBroadcast = 1;
|
payload.isBroadcast = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof dest === 'string')
|
if (typeof dest === 'string')
|
||||||
dest = [dest];
|
dest = [dest];
|
||||||
|
|
||||||
|
@ -339,6 +354,7 @@ Network.prototype.send = function(dest, payload, cb) {
|
||||||
dest.forEach(function(to) {
|
dest.forEach(function(to) {
|
||||||
//console.log('\t to ' + to);
|
//console.log('\t to ' + to);
|
||||||
var message = self.encode(to, payload);
|
var message = self.encode(to, payload);
|
||||||
|
|
||||||
self.socket.emit('message', message);
|
self.socket.emit('message', message);
|
||||||
});
|
});
|
||||||
if (typeof cb === 'function') cb();
|
if (typeof cb === 'function') cb();
|
||||||
|
|
Loading…
Reference in New Issue