many bugs fix in peer connections, and ux
This commit is contained in:
parent
ac784ad9ae
commit
7693f0a7ff
5 changed files with 58 additions and 41 deletions
|
|
@ -74,11 +74,11 @@
|
||||||
<div class="large-6 columns">
|
<div class="large-6 columns">
|
||||||
<h3>Open a Existing Wallet</h3>
|
<h3>Open a Existing Wallet</h3>
|
||||||
<select class="form-control" >
|
<select class="form-control" >
|
||||||
<option data-ng-repeat="walletId in listWalletIds()" value="walletId">{{walletId}}</option>
|
<option ng-repeat="walletId in listWalletIds()" ng-model="sel" value="walletId">{{walletId}}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="large-3 columns">
|
<div class="large-3 columns">
|
||||||
<button class="button primary expand round" type="button" ng-click="open(walletId)">Open</button>
|
<button class="button primary expand round" type="button" ng-click="open(sel || $scope.sel)">Open</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,12 @@ angular.module('copay.header').controller('HeaderController',
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.signout = function() {
|
$scope.signout = function() {
|
||||||
|
console.log('[header.js.37:signout:]'); //TODO
|
||||||
|
|
||||||
Network.disconnect(function() {
|
Network.disconnect(function() {
|
||||||
|
console.log('[header.js.41] disconnect CB'); //TODO
|
||||||
$location.path('signin');
|
$location.path('signin');
|
||||||
|
$rootScope.$digest();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@ CopayPeer.prototype._showConnectedPeers = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
CopayPeer.prototype._onClose = function(peerId) {
|
CopayPeer.prototype._onClose = function(peerId) {
|
||||||
|
console.log('[CopayPeer.js.70] _onClose'); //TODO
|
||||||
this.connectedPeers = CopayPeer._arrayRemove(peerId, this.connectedPeers);
|
this.connectedPeers = CopayPeer._arrayRemove(peerId, this.connectedPeers);
|
||||||
this._notify();
|
this._notify();
|
||||||
};
|
};
|
||||||
|
|
@ -92,7 +93,7 @@ CopayPeer.prototype._onData = function(data, isInbound) {
|
||||||
console.log('### ERROR ON DATA: "%s" ', data, isInbound, e);
|
console.log('### ERROR ON DATA: "%s" ', data, isInbound, e);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
console.log('### RECEIVED TYPE: %s FROM %s', obj.data.type, obj.sender);
|
console.log('### RECEIVED TYPE: %s FROM %s', obj.data.type, obj.sender, obj.data);
|
||||||
|
|
||||||
switch(obj.data.type) {
|
switch(obj.data.type) {
|
||||||
case 'peerList':
|
case 'peerList':
|
||||||
|
|
@ -156,13 +157,16 @@ CopayPeer.prototype._setupConnectionHandlers = function(
|
||||||
});
|
});
|
||||||
|
|
||||||
dataConn.on('close', function() {
|
dataConn.on('close', function() {
|
||||||
console.log('### CLOSE RECV FROM:', dataConn.peer); //TODO
|
if (self.closing) return;
|
||||||
|
console.log('### CLOSE RECV FROM:', dataConn.peer);
|
||||||
|
|
||||||
self._onClose(dataConn.peer);
|
self._onClose(dataConn.peer);
|
||||||
if (typeof closeCallback === 'function') closeCallback();
|
if (typeof closeCallback === 'function') closeCallback();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
CopayPeer.prototype._notify = function(newPeer) {
|
CopayPeer.prototype._notify = function(newPeer) {
|
||||||
|
console.log('[CopayPeer.js.168:_notify:]'); //TODO
|
||||||
this._showConnectedPeers();
|
this._showConnectedPeers();
|
||||||
this.emit('networkChange', newPeer);
|
this.emit('networkChange', newPeer);
|
||||||
};
|
};
|
||||||
|
|
@ -182,6 +186,10 @@ CopayPeer.prototype._setupPeerHandlers = function(openCallback) {
|
||||||
|
|
||||||
p.on('error', function(err) {
|
p.on('error', function(err) {
|
||||||
console.log('### PEER ERROR:', err);
|
console.log('### PEER ERROR:', err);
|
||||||
|
self.peer.disconnect();
|
||||||
|
self.peer.destroy();
|
||||||
|
self.peer = null;
|
||||||
|
this.emit('abort');
|
||||||
});
|
});
|
||||||
|
|
||||||
p.on('connection', function(dataConn) {
|
p.on('connection', function(dataConn) {
|
||||||
|
|
@ -266,9 +274,13 @@ CopayPeer.prototype.connectTo = function(peerId, openCallback, closeCallback ) {
|
||||||
};
|
};
|
||||||
|
|
||||||
CopayPeer.prototype.disconnect = function(peerId, cb) {
|
CopayPeer.prototype.disconnect = function(peerId, cb) {
|
||||||
|
console.log('[CopayPeer.js.268:disconnect:]'); //TODO
|
||||||
var self = this;
|
var self = this;
|
||||||
|
self.closing = 1;
|
||||||
|
|
||||||
this.send(null, { type: 'disconnect' }, function() {
|
this.send(null, { type: 'disconnect' }, function() {
|
||||||
|
|
||||||
|
console.log('[CopayPeer.js.273] disconnect CB'); //TODO
|
||||||
self.connectedPeers = [];
|
self.connectedPeers = [];
|
||||||
self.peerId = null;
|
self.peerId = null;
|
||||||
if (self.peer) {
|
if (self.peer) {
|
||||||
|
|
@ -276,6 +288,7 @@ CopayPeer.prototype.disconnect = function(peerId, cb) {
|
||||||
self.peer.destroy();
|
self.peer.destroy();
|
||||||
self.peer = null;
|
self.peer = null;
|
||||||
}
|
}
|
||||||
|
self.closing = 0;
|
||||||
if (typeof cb === 'function') cb();
|
if (typeof cb === 'function') cb();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ PublicKeyRing.fromObj = function (data) {
|
||||||
|
|
||||||
var w = new PublicKeyRing(config);
|
var w = new PublicKeyRing(config);
|
||||||
|
|
||||||
|
w.id = data.id;
|
||||||
w.requiredCopayers = data.requiredCopayers;
|
w.requiredCopayers = data.requiredCopayers;
|
||||||
w.totalCopayers = data.totalCopayers;
|
w.totalCopayers = data.totalCopayers;
|
||||||
w.addressIndex = data.addressIndex;
|
w.addressIndex = data.addressIndex;
|
||||||
|
|
|
||||||
|
|
@ -110,13 +110,13 @@ console.log('[network.js.97:priv:]',priv); //TODO
|
||||||
$rootScope.txProposals = new copay.TxProposals.fromObj(txp);
|
$rootScope.txProposals = new copay.TxProposals.fromObj(txp);
|
||||||
$rootScope.PrivateKey = new copay.PrivateKey.fromObj(priv); //TODO secure
|
$rootScope.PrivateKey = new copay.PrivateKey.fromObj(priv); //TODO secure
|
||||||
|
|
||||||
// Add our key JIC
|
// JIC: Add our key
|
||||||
try {
|
try {
|
||||||
$rootScope.publicKeyRing.addCopayer(
|
$rootScope.publicKeyRing.addCopayer(
|
||||||
$rootScope.PrivateKey.getBIP32().extendedPublicKeyString()
|
$rootScope.PrivateKey.getBIP32().extendedPublicKeyString()
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('[network.js.103]', e); //TODO
|
console.log('NOT NECCESARY AN ERROR:', e); //TODO
|
||||||
};
|
};
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
@ -127,7 +127,8 @@ console.log('[network.js.103]', e); //TODO
|
||||||
console.log('### CLOSING WALLET');
|
console.log('### CLOSING WALLET');
|
||||||
$rootScope.walletId = null;
|
$rootScope.walletId = null;
|
||||||
$rootScope.publicKeyRing = null;
|
$rootScope.publicKeyRing = null;
|
||||||
//TODO
|
$rootScope.privateKey = null;
|
||||||
|
$rootScope.txProposals = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
var _checkWallet = function(walletId, allowChange) {
|
var _checkWallet = function(walletId, allowChange) {
|
||||||
|
|
@ -137,9 +138,6 @@ console.log('[network.js.103]', e); //TODO
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ($rootScope.walletId && $rootScope.walletId !== walletId) {
|
if ($rootScope.walletId && $rootScope.walletId !== walletId) {
|
||||||
if (allowChange)
|
|
||||||
closeWallet();
|
|
||||||
else
|
|
||||||
throw new Error('message to wrong walletID');
|
throw new Error('message to wrong walletID');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,37 +148,9 @@ console.log('[network.js.103]', e); //TODO
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var _handlePublicKeyRing = function(senderId, data, isInbound) {
|
|
||||||
var cp = $rootScope.cp;
|
|
||||||
_checkWallet(data.publicKeyRing.id, true);
|
|
||||||
var shouldSend = false;
|
|
||||||
|
|
||||||
var recipients, pkr = $rootScope.publicKeyRing;
|
|
||||||
var inPKR = copay.PublicKeyRing.fromObj(data.publicKeyRing);
|
|
||||||
if (pkr.merge(inPKR, true) && !data.isBroadcast) {
|
|
||||||
console.log('### BROADCASTING PKR');
|
|
||||||
recipients = null;
|
|
||||||
shouldSend = true;
|
|
||||||
}
|
|
||||||
else if (isInbound && !data.isBroadcast) {
|
|
||||||
// always replying to connecting peer
|
|
||||||
console.log('### REPLYING PKR TO:', senderId);
|
|
||||||
recipients = senderId;
|
|
||||||
shouldSend = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldSend) {
|
|
||||||
console.log('### SENDING PKR TO:', recipients);
|
|
||||||
cp.send( recipients, {
|
|
||||||
type: 'publicKeyRing',
|
|
||||||
publicKeyRing: $rootScope.publicKeyRing.toObj(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var sendTxProposals = function(recipients) {
|
var sendTxProposals = function(recipients) {
|
||||||
var cp = $rootScope.cp;
|
var cp = $rootScope.cp;
|
||||||
console.log('### SENDING txProposals TO:', recipients||'All');
|
console.log('### SENDING txProposals TO:', recipients||'All', $rootScope.txProposals);
|
||||||
cp.send( recipients, {
|
cp.send( recipients, {
|
||||||
type: 'txProposals',
|
type: 'txProposals',
|
||||||
txProposals: $rootScope.txProposals.toObj(),
|
txProposals: $rootScope.txProposals.toObj(),
|
||||||
|
|
@ -197,9 +167,36 @@ console.log('[network.js.103]', e); //TODO
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var _handlePublicKeyRing = function(senderId, data, isInbound) {
|
||||||
|
var cp = $rootScope.cp;
|
||||||
|
_checkWallet(data.publicKeyRing.id);
|
||||||
|
var shouldSend = false;
|
||||||
|
|
||||||
|
var recipients, pkr = $rootScope.publicKeyRing;
|
||||||
|
var inPKR = copay.PublicKeyRing.fromObj(data.publicKeyRing);
|
||||||
|
console.log('[network.js.176:inPKR:]',inPKR); //TODO
|
||||||
|
console.log('[network.js.178:pkr:]',pkr); //TODO
|
||||||
|
if (pkr.merge(inPKR, true) && !data.isBroadcast) {
|
||||||
|
console.log('### BROADCASTING PKR');
|
||||||
|
recipients = null;
|
||||||
|
shouldSend = true;
|
||||||
|
}
|
||||||
|
else if (isInbound && !data.isBroadcast) {
|
||||||
|
// always replying to connecting peer
|
||||||
|
console.log('### REPLYING PKR TO:', senderId);
|
||||||
|
recipients = senderId;
|
||||||
|
shouldSend = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[network.js.189:shouldSend:]',shouldSend); //TODO
|
||||||
|
if (shouldSend) {
|
||||||
|
sendPublicKeyRing(recipients);
|
||||||
|
}
|
||||||
|
_refreshUx();
|
||||||
|
};
|
||||||
var _handleTxProposals = function(senderId, data, isInbound) {
|
var _handleTxProposals = function(senderId, data, isInbound) {
|
||||||
var cp = $rootScope.cp;
|
var cp = $rootScope.cp;
|
||||||
_checkWallet(data.txProposals.walletId, false);
|
_checkWallet(data.txProposals.walletId);
|
||||||
|
|
||||||
var shouldSend = false;
|
var shouldSend = false;
|
||||||
console.log('RECV TXPROPOSAL:',data); //TODO
|
console.log('RECV TXPROPOSAL:',data); //TODO
|
||||||
|
|
@ -220,7 +217,7 @@ console.log('[network.js.103]', e); //TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldSend) {
|
if (shouldSend) {
|
||||||
this.sendTxProposals(recipients);
|
sendTxProposals(recipients);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -233,9 +230,11 @@ console.log('[network.js.103]', e); //TODO
|
||||||
case 'txProposals':
|
case 'txProposals':
|
||||||
_handleTxProposals(senderId, data, isInbound);
|
_handleTxProposals(senderId, data, isInbound);
|
||||||
break;
|
break;
|
||||||
|
case 'abort':
|
||||||
|
disconnect();
|
||||||
|
_refreshUx();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
_refreshUx();
|
|
||||||
};
|
};
|
||||||
var _setupHandlers = function () {
|
var _setupHandlers = function () {
|
||||||
var cp = $rootScope.cp;
|
var cp = $rootScope.cp;
|
||||||
|
|
@ -261,9 +260,9 @@ console.log('[network.js.103]', e); //TODO
|
||||||
if ($rootScope.cp) {
|
if ($rootScope.cp) {
|
||||||
$rootScope.cp.disconnect();
|
$rootScope.cp.disconnect();
|
||||||
}
|
}
|
||||||
|
closeWallet();
|
||||||
Storage.remove('peerData');
|
Storage.remove('peerData');
|
||||||
$rootScope.isLogged = false;
|
$rootScope.isLogged = false;
|
||||||
_refreshUx();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var connect = function(peerId, openCallback, failCallback) {
|
var connect = function(peerId, openCallback, failCallback) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue