mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #460 from yemel/feature/reconnect-session
Feature/reconnect session
This commit is contained in:
commit
d02bd2c11a
|
@ -730,7 +730,7 @@ on supported browsers please check <a href="http://www.webrtc.org/">http://www.w
|
||||||
<script src="lib/angular-route/angular-route.min.js"></script>
|
<script src="lib/angular-route/angular-route.min.js"></script>
|
||||||
<script src="lib/angular-foundation/mm-foundation.min.js"></script>
|
<script src="lib/angular-foundation/mm-foundation.min.js"></script>
|
||||||
<script src="lib/angular-foundation/mm-foundation-tpls.min.js"></script>
|
<script src="lib/angular-foundation/mm-foundation-tpls.min.js"></script>
|
||||||
<script src="lib/peerjs/peer.js"></script>
|
<script src="lib/peer.js"></script> <!-- TODO Change this on new PeerJS version -->
|
||||||
<script src="lib/bitcore/browser/bundle.js"></script>
|
<script src="lib/bitcore/browser/bundle.js"></script>
|
||||||
<script src="lib/crypto-js/rollups/sha256.js"></script>
|
<script src="lib/crypto-js/rollups/sha256.js"></script>
|
||||||
<script src="lib/crypto-js/rollups/pbkdf2.js"></script>
|
<script src="lib/crypto-js/rollups/pbkdf2.js"></script>
|
||||||
|
|
|
@ -83,7 +83,7 @@ angular.module('copay.signin').controller('SigninController',
|
||||||
};
|
};
|
||||||
|
|
||||||
function installStartupHandlers(wallet) {
|
function installStartupHandlers(wallet) {
|
||||||
wallet.network.on('error', function(err) {
|
wallet.on('connectionError', function(err) {
|
||||||
$scope.failure = true;
|
$scope.failure = true;
|
||||||
});
|
});
|
||||||
wallet.on('ready', function() {
|
wallet.on('ready', function() {
|
||||||
|
|
|
@ -32,6 +32,12 @@ function Wallet(opts) {
|
||||||
this.name = opts.name;
|
this.name = opts.name;
|
||||||
this.netKey = opts.netKey || SecureRandom.getRandomBuffer(8).toString('base64');
|
this.netKey = opts.netKey || SecureRandom.getRandomBuffer(8).toString('base64');
|
||||||
|
|
||||||
|
// Renew token every 24hs
|
||||||
|
if (opts.tokenTime && new Date().getTime() - opts.tokenTime < 86400000) {
|
||||||
|
this.token = opts.token;
|
||||||
|
this.tokenTime = opts.tokenTime;
|
||||||
|
}
|
||||||
|
|
||||||
this.verbose = opts.verbose;
|
this.verbose = opts.verbose;
|
||||||
this.publicKeyRing.walletId = this.id;
|
this.publicKeyRing.walletId = this.id;
|
||||||
this.txProposals.walletId = this.id;
|
this.txProposals.walletId = this.id;
|
||||||
|
@ -166,6 +172,11 @@ Wallet.prototype._optsToObj = function() {
|
||||||
version: this.version,
|
version: this.version,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (this.token){
|
||||||
|
obj.token = this.token;
|
||||||
|
obj.tokenTime = new Date().getTime();
|
||||||
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -214,6 +225,9 @@ Wallet.prototype.netStart = function() {
|
||||||
self.log('[Wallet.js.132:openError:] GOT openError'); //TODO
|
self.log('[Wallet.js.132:openError:] GOT openError'); //TODO
|
||||||
self.emit('openError');
|
self.emit('openError');
|
||||||
});
|
});
|
||||||
|
net.on('error', function(){
|
||||||
|
self.emit('connectionError'); // Bubble the error
|
||||||
|
});
|
||||||
net.on('close', function() {
|
net.on('close', function() {
|
||||||
self.emit('close');
|
self.emit('close');
|
||||||
});
|
});
|
||||||
|
@ -221,6 +235,7 @@ Wallet.prototype.netStart = function() {
|
||||||
var myId = self.getMyCopayerId();
|
var myId = self.getMyCopayerId();
|
||||||
var startOpts = {
|
var startOpts = {
|
||||||
copayerId: myId,
|
copayerId: myId,
|
||||||
|
token: self.token,
|
||||||
maxPeers: self.totalCopayers,
|
maxPeers: self.totalCopayers,
|
||||||
netKey: this.netKey,
|
netKey: this.netKey,
|
||||||
};
|
};
|
||||||
|
@ -230,6 +245,7 @@ Wallet.prototype.netStart = function() {
|
||||||
}
|
}
|
||||||
net.start(startOpts, function() {
|
net.start(startOpts, function() {
|
||||||
self.emit('ready', net.getPeer());
|
self.emit('ready', net.getPeer());
|
||||||
|
self.token = net.peer.options.token;
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
console.log('[EMIT publicKeyRingUpdated:]'); //TODO
|
console.log('[EMIT publicKeyRingUpdated:]'); //TODO
|
||||||
self.emit('publicKeyRingUpdated', true);
|
self.emit('publicKeyRingUpdated', true);
|
||||||
|
@ -237,6 +253,7 @@ Wallet.prototype.netStart = function() {
|
||||||
self.connectToAll();
|
self.connectToAll();
|
||||||
console.log('[EMIT TxProposal]'); //TODO
|
console.log('[EMIT TxProposal]'); //TODO
|
||||||
self.emit('txProposalsUpdated');
|
self.emit('txProposalsUpdated');
|
||||||
|
self.store();
|
||||||
},10);
|
},10);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -305,6 +322,8 @@ Wallet.fromObj = function(o, storage, network, blockchain) {
|
||||||
|
|
||||||
Wallet.prototype.toEncryptedObj = function() {
|
Wallet.prototype.toEncryptedObj = function() {
|
||||||
var walletObj = this.toObj();
|
var walletObj = this.toObj();
|
||||||
|
delete walletObj.opts.token;
|
||||||
|
delete walletObj.opts.tokenTime;
|
||||||
return this.storage.export(walletObj);
|
return this.storage.export(walletObj);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ var imports = require('soop').imports();
|
||||||
var EventEmitter= imports.EventEmitter || require('events').EventEmitter;
|
var EventEmitter= imports.EventEmitter || require('events').EventEmitter;
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
var util = bitcore.util;
|
var util = bitcore.util;
|
||||||
|
var extend = require('util')._extend;
|
||||||
/*
|
/*
|
||||||
* Emits
|
* Emits
|
||||||
* 'connect'
|
* 'connect'
|
||||||
|
@ -327,6 +328,9 @@ Network.prototype.start = function(opts, openCallback) {
|
||||||
this.netKey = opts.netKey;
|
this.netKey = opts.netKey;
|
||||||
this.maxPeers = opts.maxPeers || this.maxPeers;
|
this.maxPeers = opts.maxPeers || this.maxPeers;
|
||||||
|
|
||||||
|
if (opts.token)
|
||||||
|
this.opts.token = opts.token;
|
||||||
|
|
||||||
if (!this.copayerId)
|
if (!this.copayerId)
|
||||||
this.setCopayerId(opts.copayerId);
|
this.setCopayerId(opts.copayerId);
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue