diff --git a/config.js b/config.js index bb7389bb7..88fe27c82 100644 --- a/config.js +++ b/config.js @@ -103,6 +103,7 @@ var defaultConfig = { totalCopayers: 3, spendUnconfirmed: 1, verbose: 1, + reconnectDelay: 5000, }, // blockchain service API config diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index dab6a6303..7bdd86ec7 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -19,7 +19,8 @@ function Wallet(opts) { //required params ['storage', 'network', 'blockchain', 'requiredCopayers', 'totalCopayers', 'spendUnconfirmed', - 'publicKeyRing', 'txProposals', 'privateKey', 'version' + 'publicKeyRing', 'txProposals', 'privateKey', 'version', + 'reconnectDelay' ].forEach(function(k) { if (typeof opts[k] === 'undefined') throw new Error('missing required option for Wallet: ' + k); @@ -247,7 +248,7 @@ Wallet.prototype.netStart = function() { console.log('[EMIT publicKeyRingUpdated:]'); //TODO self.emit('publicKeyRingUpdated', true); console.log('[CONNECT:]'); //TODO - self.connectToAll(); + self.scheduleConnect(); console.log('[EMIT TxProposal]'); //TODO self.emit('txProposalsUpdated'); self.store(); @@ -255,6 +256,15 @@ Wallet.prototype.netStart = function() { }); }; +Wallet.prototype.scheduleConnect = function() { + var self = this; + self.connectToAll(); + setTimeout(function() { + self.scheduleConnect(); + }, + self.reconnectDelay); +} + Wallet.prototype.getOnlinePeerIDs = function() { return this.network.getOnlinePeerIDs(); }; diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index 1912b655d..dfdfe3b96 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -115,6 +115,7 @@ WalletFactory.prototype.create = function(opts) { opts.verbose = this.verbose; opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed; + opts.reconnectDelay = opts.reconnectDelay || this.walletDefaults.reconnectDelay; opts.requiredCopayers = requiredCopayers; opts.totalCopayers = totalCopayers; opts.version = opts.version || this.version; @@ -146,7 +147,6 @@ WalletFactory.prototype.open = function(walletId, opts) { this.storage._setPassphrase(opts.passphrase); var w = this.read(walletId); - if (w) { this._checkVersion(w.version); w.store();