settings: fix send in livenet

This commit is contained in:
Manuel Araoz 2014-09-11 11:19:19 -07:00
parent dcb78847d2
commit c47318c728
4 changed files with 14 additions and 10 deletions

View File

@ -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;
};

View File

@ -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;

View File

@ -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);

View File

@ -14,14 +14,14 @@
<div class="row collapse">
<div class="large-12 columns">
<div class="row collapse">
<label for="address"><span translate>To address</span>
<label for="address"><span translate>To:</span>
<small translate ng-hide="!sendForm.address.$pristine || address">required</small>
<small translate class="is-valid" ng-show="!sendForm.address.$invalid && address">valid!</small>
<small translate class="has-error" ng-show="sendForm.address.$invalid && address">not valid</small>
</label>
<div class="small-10 columns">
<input type="text" id="address" name="address" ng-disabled="loading || !!$root.merchant"
placeholder="{{'Send to'|translate}}" ng-model="address" ng-change="onChanged()" valid-address required>
placeholder="{{'Bitcoin address'|translate}}" ng-model="address" ng-change="onChanged()" valid-address required>
<small class="icon-input" ng-show="!sendForm.address.$invalid && address"><i class="fi-check"></i></small>
<small class="icon-input" ng-show="sendForm.address.$invalid && address"><i class="fi-x"></i></small>
</div>