diff --git a/js/directives.js b/js/directives.js index f6816d863..897757e39 100644 --- a/js/directives.js +++ b/js/directives.js @@ -30,14 +30,14 @@ angular.module('copayApp.directives') // Bip21 uri if (/^bitcoin:/.test(value)) { var uri = new bitcore.BIP21(value); - var hasAddress = uri.address && uri.isValid() && uri.address.network().name === config.networkName; + var hasAddress = uri.address && uri.isValid() && uri.address.network().name === $rootScope.wallet.getNetworkName(); ctrl.$setValidity('validAddress', uri.data.merchant || hasAddress); return value; } // Regular Address var a = new Address(value); - ctrl.$setValidity('validAddress', a.isValid() && a.network().name === config.networkName); + ctrl.$setValidity('validAddress', a.isValid() && a.network().name === $rootScope.wallet.getNetworkName()); return value; }; diff --git a/test/mocks/FakeWallet.js b/test/mocks/FakeWallet.js index a206f70ce..4ca6d3e2c 100644 --- a/test/mocks/FakeWallet.js +++ b/test/mocks/FakeWallet.js @@ -122,5 +122,9 @@ FakeWallet.prototype.toEncryptedObj = function() { FakeWallet.prototype.close = function() {}; +FakeWallet.prototype.getNetworkName = function() { + return 'testnet'; +}; + // TODO a try catch was here module.exports = FakeWallet; diff --git a/test/unit/directives/directivesSpec.js b/test/unit/directives/directivesSpec.js index 87b8aab91..0e80db41b 100644 --- a/test/unit/directives/directivesSpec.js +++ b/test/unit/directives/directivesSpec.js @@ -42,16 +42,16 @@ describe("Unit: Testing Directives", function() { form = $scope.form; })); - it('should validate with network', function() { - config.networkName = 'testnet'; + it('should validate with network', inject(function($rootScope) { + $rootScope.wallet.getNetworkName = sinon.stub().returns('testnet'); form.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); expect(form.address.$invalid).to.equal(false); - }); - it('should not validate with other network', function() { - config.networkName = 'livenet'; + })); + it('should not validate with other network', inject(function($rootScope) { + $rootScope.wallet.getNetworkName = sinon.stub().returns('livenet'); form.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); expect(form.address.$invalid).to.equal(true); - }); + })); it('should not validate random', function() { form.address.$setViewValue('thisisaninvalidaddress'); expect(form.address.$invalid).to.equal(true); diff --git a/views/send.html b/views/send.html index 8a7592b32..a8f6b0499 100644 --- a/views/send.html +++ b/views/send.html @@ -14,14 +14,14 @@