Add reconnecting notification, change subscribed list to dict, update balance after reconnect
This commit is contained in:
parent
0623c87727
commit
b97a332ae9
6 changed files with 49 additions and 26 deletions
|
|
@ -128,6 +128,19 @@ input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill, inpu
|
||||||
-webkit-box-shadow: 0 0 0px 1000px white inset;
|
-webkit-box-shadow: 0 0 0px 1000px white inset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.status {
|
||||||
|
border: 1px solid #f0c36d;
|
||||||
|
background-color: #f9edbe;
|
||||||
|
position: absolute;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
top: 10px;
|
||||||
|
width: 215px;
|
||||||
|
padding: 7px;
|
||||||
|
}
|
||||||
|
|
||||||
.join label,
|
.join label,
|
||||||
.open label,
|
.open label,
|
||||||
.setup label {
|
.setup label {
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<div class="off-canvas-wrap">
|
<div class="off-canvas-wrap">
|
||||||
<div class="inner-wrap">
|
<div class="inner-wrap">
|
||||||
|
<span class="status" ng-if="$root.reconnecting">Attempting to reconnect...</span>
|
||||||
<nav class="tab-bar" ng-class="{'hide-tab-bar' : !$root.wallet ||
|
<nav class="tab-bar" ng-class="{'hide-tab-bar' : !$root.wallet ||
|
||||||
!$root.wallet.isReady() || $root.wallet.isLocked}">
|
!$root.wallet.isReady() || $root.wallet.isLocked}">
|
||||||
<section class="left-small">
|
<section class="left-small">
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ var preconditions = require('preconditions').singleton();
|
||||||
|
|
||||||
var Insight = function (opts) {
|
var Insight = function (opts) {
|
||||||
this.status = this.STATUS.DISCONNECTED;
|
this.status = this.STATUS.DISCONNECTED;
|
||||||
this.subscribed = [];
|
this.subscribed = {};
|
||||||
this.listeningBlocks = false;
|
this.listeningBlocks = false;
|
||||||
|
|
||||||
preconditions.checkArgument(opts).shouldBeObject(opts)
|
preconditions.checkArgument(opts).shouldBeObject(opts)
|
||||||
|
|
@ -112,7 +112,7 @@ Insight.prototype.requestPost = function(path, data, cb) {
|
||||||
|
|
||||||
Insight.prototype.destroy = function() {
|
Insight.prototype.destroy = function() {
|
||||||
this.socket.destroy();
|
this.socket.destroy();
|
||||||
this.subscribed = [];
|
this.subscribed = {};
|
||||||
this.status = this.STATUS.DESTROYED;
|
this.status = this.STATUS.DESTROYED;
|
||||||
this.removeAllListeners();
|
this.removeAllListeners();
|
||||||
};
|
};
|
||||||
|
|
@ -124,7 +124,7 @@ Insight.prototype.subscribe = function(addresses) {
|
||||||
function handlerFor(self, address) {
|
function handlerFor(self, address) {
|
||||||
return function (txid) {
|
return function (txid) {
|
||||||
// verify the address is still subscribed
|
// verify the address is still subscribed
|
||||||
if (self.subscribed.indexOf(address) == -1) return;
|
if (!self.subscribed[address]) return;
|
||||||
self.emit('tx', {address: address, txid: txid});
|
self.emit('tx', {address: address, txid: txid});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -133,14 +133,18 @@ Insight.prototype.subscribe = function(addresses) {
|
||||||
preconditions.checkArgument(new bitcore.Address(address).isValid());
|
preconditions.checkArgument(new bitcore.Address(address).isValid());
|
||||||
|
|
||||||
// skip already subscibed
|
// skip already subscibed
|
||||||
if (self.subscribed.indexOf(address) == -1) {
|
if (!self.subscribed[address]) {
|
||||||
self.subscribed.push(address);
|
self.subscribed[address] = true;
|
||||||
self.socket.emit('subscribe', address);
|
self.socket.emit('subscribe', address);
|
||||||
self.socket.on(address, handlerFor(self, address));
|
self.socket.on(address, handlerFor(self, address));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Insight.prototype.getSubscriptions = function(addresses) {
|
||||||
|
return Object.keys(this.subscribed);
|
||||||
|
}
|
||||||
|
|
||||||
Insight.prototype.unsubscribe = function(addresses) {
|
Insight.prototype.unsubscribe = function(addresses) {
|
||||||
addresses = Array.isArray(addresses) ? addresses : [addresses];
|
addresses = Array.isArray(addresses) ? addresses : [addresses];
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
@ -148,15 +152,12 @@ Insight.prototype.unsubscribe = function(addresses) {
|
||||||
addresses.forEach(function(address) {
|
addresses.forEach(function(address) {
|
||||||
preconditions.checkArgument(new bitcore.Address(address).isValid());
|
preconditions.checkArgument(new bitcore.Address(address).isValid());
|
||||||
self.socket.removeEventListener(address);
|
self.socket.removeEventListener(address);
|
||||||
});
|
delete self.subscribed[address];
|
||||||
|
|
||||||
this.subscribed = this.subscribed.filter(function(a) {
|
|
||||||
return addresses.indexOf(a) == -1;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Insight.prototype.unsubscribeAll = function() {
|
Insight.prototype.unsubscribeAll = function() {
|
||||||
this.unsubscribe(this.subscribed);
|
this.unsubscribe(this.getSubscriptions());
|
||||||
};
|
};
|
||||||
|
|
||||||
Insight.prototype.broadcast = function(rawtx, cb) {
|
Insight.prototype.broadcast = function(rawtx, cb) {
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ angular.module('copayApp.services')
|
||||||
uriHandler.register();
|
uriHandler.register();
|
||||||
$rootScope.unitName = config.unitName;
|
$rootScope.unitName = config.unitName;
|
||||||
$rootScope.txAlertCount = 0;
|
$rootScope.txAlertCount = 0;
|
||||||
|
$rootScope.reconnecting = false;
|
||||||
$rootScope.isCollapsed = true;
|
$rootScope.isCollapsed = true;
|
||||||
$rootScope.$watch('txAlertCount', function(txAlertCount) {
|
$rootScope.$watch('txAlertCount', function(txAlertCount) {
|
||||||
if (txAlertCount && txAlertCount > 0) {
|
if (txAlertCount && txAlertCount > 0) {
|
||||||
|
|
@ -293,10 +294,16 @@ angular.module('copayApp.services')
|
||||||
wallet.blockchain.on('connect', function(attempts) {
|
wallet.blockchain.on('connect', function(attempts) {
|
||||||
if (attempts == 0) return;
|
if (attempts == 0) return;
|
||||||
notification.success('Networking restored', 'Connection to Insight re-established');
|
notification.success('Networking restored', 'Connection to Insight re-established');
|
||||||
|
$rootScope.reconnecting = false;
|
||||||
|
root.updateBalance(function() {
|
||||||
|
$rootScope.$digest();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
wallet.blockchain.on('disconnect', function() {
|
wallet.blockchain.on('disconnect', function() {
|
||||||
notification.error('Networking problem', 'Connection to Insight lost, trying to reconnect...');
|
notification.error('Networking problem', 'Connection to Insight lost, trying to reconnect...');
|
||||||
|
$rootScope.reconnecting = true;
|
||||||
|
$rootScope.$digest();
|
||||||
});
|
});
|
||||||
|
|
||||||
wallet.blockchain.on('tx', function(tx) {
|
wallet.blockchain.on('tx', function(tx) {
|
||||||
|
|
@ -319,18 +326,17 @@ angular.module('copayApp.services')
|
||||||
if (!$rootScope.wallet) return;
|
if (!$rootScope.wallet) return;
|
||||||
|
|
||||||
root.updateAddressList();
|
root.updateAddressList();
|
||||||
var currentAddrs = $rootScope.wallet.blockchain.subscribed;
|
var currentAddrs = $rootScope.wallet.blockchain.getSubscriptions();
|
||||||
var allAddrs = $rootScope.addrInfos;
|
var allAddrs = $rootScope.addrInfos;
|
||||||
|
|
||||||
var newAddrs = [];
|
var newAddrs = [];
|
||||||
for (var i in allAddrs) {
|
for (var i in allAddrs) {
|
||||||
var a = allAddrs[i];
|
var a = allAddrs[i];
|
||||||
if (!currentAddrs[a.addressStr] && !a.isChange)
|
if (!currentAddrs[a.addressStr] && !a.isChange)
|
||||||
newAddrs.push(a);
|
newAddrs.push(a.addressStr);
|
||||||
}
|
|
||||||
for (var i = 0; i < newAddrs.length; i++) {
|
|
||||||
$rootScope.wallet.blockchain.subscribe(newAddrs[i].addressStr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$rootScope.wallet.blockchain.subscribe(newAddrs);
|
||||||
};
|
};
|
||||||
return root;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,10 @@ var FakeWallet = function() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.blockchain = {subscribed: [], subscribe: function(){}};
|
this.blockchain = {
|
||||||
|
getSubscriptions: function(){ return []; },
|
||||||
|
subscribe: function(){}
|
||||||
|
};
|
||||||
|
|
||||||
this.privateKey = new FakePrivateKey();
|
this.privateKey = new FakePrivateKey();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -77,9 +77,9 @@ describe('Insight model', function() {
|
||||||
blockchain.status.should.be.equal('disconnected');
|
blockchain.status.should.be.equal('disconnected');
|
||||||
blockchain.on('connect', function() {
|
blockchain.on('connect', function() {
|
||||||
blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
||||||
blockchain.subscribed.length.should.equal(1);
|
blockchain.getSubscriptions().length.should.equal(1);
|
||||||
blockchain.destroy();
|
blockchain.destroy();
|
||||||
blockchain.subscribed.length.should.equal(0);
|
blockchain.getSubscriptions().length.should.equal(0);
|
||||||
blockchain.status.should.be.equal('destroyed');
|
blockchain.status.should.be.equal('destroyed');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
@ -90,7 +90,7 @@ describe('Insight model', function() {
|
||||||
var emitSpy = sinon.spy(blockchain.socket, 'emit');
|
var emitSpy = sinon.spy(blockchain.socket, 'emit');
|
||||||
|
|
||||||
blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
||||||
blockchain.subscribed.length.should.equal(1);
|
blockchain.getSubscriptions().length.should.equal(1);
|
||||||
emitSpy.calledWith('subscribe', 'mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
emitSpy.calledWith('subscribe', 'mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -99,7 +99,7 @@ describe('Insight model', function() {
|
||||||
|
|
||||||
blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
||||||
blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
||||||
blockchain.subscribed.length.should.equal(1);
|
blockchain.getSubscriptions().length.should.equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should subscribe to a list of addresses', function() {
|
it('should subscribe to a list of addresses', function() {
|
||||||
|
|
@ -110,7 +110,7 @@ describe('Insight model', function() {
|
||||||
'mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM',
|
'mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM',
|
||||||
'2NBBHBjB5sd7HFqKtout1L7d6dPhwJgP2j8'
|
'2NBBHBjB5sd7HFqKtout1L7d6dPhwJgP2j8'
|
||||||
]);
|
]);
|
||||||
blockchain.subscribed.length.should.equal(2);
|
blockchain.getSubscriptions().length.should.equal(2);
|
||||||
emitSpy.calledWith('subscribe', 'mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
emitSpy.calledWith('subscribe', 'mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
||||||
emitSpy.calledWith('subscribe', '2NBBHBjB5sd7HFqKtout1L7d6dPhwJgP2j8');
|
emitSpy.calledWith('subscribe', '2NBBHBjB5sd7HFqKtout1L7d6dPhwJgP2j8');
|
||||||
});
|
});
|
||||||
|
|
@ -118,19 +118,19 @@ describe('Insight model', function() {
|
||||||
it('should unsubscribe to an address', function() {
|
it('should unsubscribe to an address', function() {
|
||||||
var blockchain = new Insight(FAKE_OPTS);
|
var blockchain = new Insight(FAKE_OPTS);
|
||||||
blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
||||||
blockchain.subscribed.length.should.equal(1);
|
blockchain.getSubscriptions().length.should.equal(1);
|
||||||
blockchain.unsubscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
blockchain.unsubscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
||||||
blockchain.subscribed.length.should.equal(0);
|
blockchain.getSubscriptions().length.should.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should unsubscribe to all addresses', function() {
|
it('should unsubscribe to all addresses', function() {
|
||||||
var blockchain = new Insight(FAKE_OPTS);
|
var blockchain = new Insight(FAKE_OPTS);
|
||||||
blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
blockchain.subscribe('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
||||||
blockchain.subscribe('2NBBHBjB5sd7HFqKtout1L7d6dPhwJgP2j8');
|
blockchain.subscribe('2NBBHBjB5sd7HFqKtout1L7d6dPhwJgP2j8');
|
||||||
blockchain.subscribed.length.should.equal(2);
|
blockchain.getSubscriptions().length.should.equal(2);
|
||||||
|
|
||||||
blockchain.unsubscribeAll('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
blockchain.unsubscribeAll('mg7UbtKgMvWAixTNMbC8soyUnwFk1qxEuM');
|
||||||
blockchain.subscribed.length.should.equal(0);
|
blockchain.getSubscriptions().length.should.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should broadcast a raw transaction', function(done) {
|
it('should broadcast a raw transaction', function(done) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue