Remove unnused variable. Added tests to check amount validation
This commit is contained in:
parent
cf8670c64f
commit
6586a4b696
2 changed files with 23 additions and 6 deletions
|
|
@ -5,8 +5,6 @@ var preconditions = require('preconditions').singleton();
|
||||||
angular.module('copayApp.controllers').controller('SendController',
|
angular.module('copayApp.controllers').controller('SendController',
|
||||||
function($scope, $rootScope, $window, $timeout, $modal, $filter, notification, isMobile, rateService, txStatus, isCordova) {
|
function($scope, $rootScope, $window, $timeout, $modal, $filter, notification, isMobile, rateService, txStatus, isCordova) {
|
||||||
|
|
||||||
var satToUnit;
|
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
preconditions.checkState(w);
|
preconditions.checkState(w);
|
||||||
|
|
@ -23,8 +21,6 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
$scope.error = $scope.success = null;
|
$scope.error = $scope.success = null;
|
||||||
|
|
||||||
satToUnit = 1 / w.settings.unitToSatoshi;
|
|
||||||
|
|
||||||
$scope.alternativeName = w.settings.alternativeName;
|
$scope.alternativeName = w.settings.alternativeName;
|
||||||
$scope.alternativeIsoCode = w.settings.alternativeIsoCode;
|
$scope.alternativeIsoCode = w.settings.alternativeIsoCode;
|
||||||
|
|
||||||
|
|
@ -101,7 +97,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
this.__alternative = newValue;
|
this.__alternative = newValue;
|
||||||
if (typeof(newValue) === 'number' && $scope.isRateAvailable) {
|
if (typeof(newValue) === 'number' && $scope.isRateAvailable) {
|
||||||
this._amount = parseFloat(
|
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 {
|
} else {
|
||||||
this._amount = 0;
|
this._amount = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -273,7 +273,7 @@ describe("Unit: Controllers", function() {
|
||||||
var element2 = angular.element(
|
var element2 = angular.element(
|
||||||
'<form name="form2">' +
|
'<form name="form2">' +
|
||||||
'<input type="text" id="address" name="address" ng-model="_address" valid-address required>' +
|
'<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">' +
|
'<input type="number" id="alternative" name="alternative" ng-model="_alternative">' +
|
||||||
'<textarea id="comment" name="comment" ng-model="commentText" ng-maxlength="100"></textarea>' +
|
'<textarea id="comment" name="comment" ng-model="commentText" ng-maxlength="100"></textarea>' +
|
||||||
'</form>'
|
'</form>'
|
||||||
|
|
@ -390,6 +390,27 @@ describe("Unit: Controllers", function() {
|
||||||
done();
|
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() {
|
describe("Unit: Version Controller", function() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue