Remove unnused variable. Added tests to check amount validation

This commit is contained in:
Gustavo Maximiliano Cortez 2015-01-30 11:09:07 -03:00
parent cf8670c64f
commit 6586a4b696
2 changed files with 23 additions and 6 deletions

View File

@ -5,8 +5,6 @@ var preconditions = require('preconditions').singleton();
angular.module('copayApp.controllers').controller('SendController',
function($scope, $rootScope, $window, $timeout, $modal, $filter, notification, isMobile, rateService, txStatus, isCordova) {
var satToUnit;
$scope.init = function() {
var w = $rootScope.wallet;
preconditions.checkState(w);
@ -23,8 +21,6 @@ angular.module('copayApp.controllers').controller('SendController',
$scope.loading = false;
$scope.error = $scope.success = null;
satToUnit = 1 / w.settings.unitToSatoshi;
$scope.alternativeName = w.settings.alternativeName;
$scope.alternativeIsoCode = w.settings.alternativeIsoCode;
@ -101,7 +97,7 @@ angular.module('copayApp.controllers').controller('SendController',
this.__alternative = newValue;
if (typeof(newValue) === 'number' && $scope.isRateAvailable) {
this._amount = parseFloat(
(rateService.fromFiat(newValue, $scope.alternativeIsoCode) * satToUnit).toFixed(w.settings.unitDecimals), 10);
(rateService.fromFiat(newValue, $scope.alternativeIsoCode) * 1 / w.settings.unitToSatoshi).toFixed(w.settings.unitDecimals), 10);
} else {
this._amount = 0;
}

View File

@ -273,7 +273,7 @@ describe("Unit: Controllers", function() {
var element2 = angular.element(
'<form name="form2">' +
'<input type="text" id="address" name="address" ng-model="_address" valid-address required>' +
'<input type="number" id="amount" name="amount" ng-model="_amount" min="1" max="10000000000" required>' +
'<input type="number" id="amount" name="amount" ng-model="_amount" min="0.00000001" max="10000000000" valid-amount required>' +
'<input type="number" id="alternative" name="alternative" ng-model="_alternative">' +
'<textarea id="comment" name="comment" ng-model="commentText" ng-maxlength="100"></textarea>' +
'</form>'
@ -390,6 +390,27 @@ describe("Unit: Controllers", function() {
done();
});
});
it('receive from uri using bits', inject(function() {
sendForm.address.$setViewValue('bitcoin:mxf5psDyA8EQVzb2MZ7MkDWiXuAuWWCRMB?amount=1.018085');
expect(sendForm.amount.$modelValue).to.equal(1018085);
sendForm.address.$setViewValue('bitcoin:mxf5psDyA8EQVzb2MZ7MkDWiXuAuWWCRMB?amount=1.01808500');
expect(sendForm.amount.$modelValue).to.equal(1018085);
sendForm.address.$setViewValue('bitcoin:mxf5psDyA8EQVzb2MZ7MkDWiXuAuWWCRMB?amount=0.29133585');
expect(sendForm.amount.$modelValue).to.equal(291335.85);
}));
it('receive from uri using BTC', inject(function($rootScope) {
var old = $rootScope.wallet.settings.unitToSatoshi;
$rootScope.wallet.settings.unitToSatoshi = 100000000;
sendForm.address.$setViewValue('bitcoin:mxf5psDyA8EQVzb2MZ7MkDWiXuAuWWCRMB?amount=1.018085');
expect(sendForm.amount.$modelValue).to.equal(1.018085);
sendForm.address.$setViewValue('bitcoin:mxf5psDyA8EQVzb2MZ7MkDWiXuAuWWCRMB?amount=1.01808500');
expect(sendForm.amount.$modelValue).to.equal(1.018085);
sendForm.address.$setViewValue('bitcoin:mxf5psDyA8EQVzb2MZ7MkDWiXuAuWWCRMB?amount=0.29133585');
expect(sendForm.amount.$modelValue).to.equal(0.29133585);
$rootScope.wallet.settings.unitToSatoshi = old;
}));
});
describe("Unit: Version Controller", function() {