diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 202cdff91..454295368 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -20,7 +20,7 @@ function Wallet(opts) { ['storage', 'network', 'blockchain', 'requiredCopayers', 'totalCopayers', 'spendUnconfirmed', 'publicKeyRing', 'txProposals', 'privateKey', 'version', - 'reconnectDelay' + 'reconnectDelay', 'networkName' ].forEach(function(k) { if (typeof opts[k] === 'undefined') throw new Error('missing required option for Wallet: ' + k); @@ -181,6 +181,7 @@ Wallet.prototype._optsToObj = function() { requiredCopayers: this.requiredCopayers, totalCopayers: this.totalCopayers, reconnectDelay: this.reconnectDelay, + networkName: this.networkName, name: this.name, netKey: this.netKey, version: this.version, diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index 58054502b..5a2edd19b 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -23,10 +23,10 @@ function WalletFactory(config, version) { this.network = new Network(config.network); this.blockchain = new Blockchain(config.blockchain); - this.networkName = config.networkName; - this.verbose = config.verbose; + this.networkName = config.networkName; + this.verbose = config.verbose; this.walletDefaults = config.wallet; - this.version = version; + this.version = version; } WalletFactory.prototype.log = function(){ @@ -115,6 +115,7 @@ WalletFactory.prototype.create = function(opts) { opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed; opts.reconnectDelay = opts.reconnectDelay || this.walletDefaults.reconnectDelay; + opts.networkName = opts.networkName || this.networkName; opts.requiredCopayers = requiredCopayers; opts.totalCopayers = totalCopayers; opts.version = opts.version || this.version; @@ -139,6 +140,20 @@ WalletFactory.prototype._checkVersion = function(inVersion) { } }; + +WalletFactory.prototype._checkNetwork = function(inNetworkName) { + if( this.networkName !== inNetworkName ) { + throw new Error('This Wallet is configured for ' + + inNetworkName + + ' while currently Copay is configured for: ' + + this.networkName + + '. Check your settings.' + ); + } +}; + + + WalletFactory.prototype.open = function(walletId, opts) { opts = opts || {}; opts.id = walletId; @@ -148,6 +163,7 @@ WalletFactory.prototype.open = function(walletId, opts) { var w = this.read(walletId); if (w) { this._checkVersion(w.version); + this._checkNetwork(w.networkName); w.store(); } return w;