Address needed change to transaction resume, fix tests

This commit is contained in:
Esteban Ordano 2014-08-29 13:36:38 -03:00
commit 22b92aca61
3 changed files with 27 additions and 15 deletions

View file

@ -8,13 +8,19 @@ angular.module('copayApp.controllers').controller('SendController',
var satToUnit = 1 / config.unitToSatoshi; var satToUnit = 1 / config.unitToSatoshi;
$scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit; $scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit;
$scope.unitToBtc = config.unitToSatoshi / bitcore.util.COIN; $scope.unitToBtc = config.unitToSatoshi / bitcore.util.COIN;
$scope.unitToSatoshi = config.unitToSatoshi;
$scope.minAmount = config.limits.minAmountSatoshi * satToUnit; $scope.minAmount = config.limits.minAmountSatoshi * satToUnit;
this.alternativeName = config.alternativeName; $scope.alternativeName = config.alternativeName;
this.alternativeIsoCode = config.alternativeIsoCode; $scope.alternativeIsoCode = config.alternativeIsoCode;
this.rateService = rateService;
$scope.amount = 0; $scope.isRateAvailable = false;
$scope.rateService = rateService;
rateService.whenAvailable(function() {
$scope.isRateAvailable = true;
$scope.$digest();
});
/** /**
* Setting the two related amounts as properties prevents an infinite * Setting the two related amounts as properties prevents an infinite
@ -26,12 +32,13 @@ angular.module('copayApp.controllers').controller('SendController',
return this._alternative; return this._alternative;
}, },
set: function (newValue) { set: function (newValue) {
newValue = -(-newValue) || 0;
this._alternative = newValue; this._alternative = newValue;
if (typeof(newValue) === 'number') { if ($scope.isRateAvailable) {
this._amount = Number.parseFloat( this._amount = Number.parseFloat(
(rateService.fromFiat(newValue, config.alternativeIsoCode) * satToUnit (rateService.fromFiat(newValue, config.alternativeIsoCode) * satToUnit
).toFixed(config.unitDecimals), 10); ).toFixed(config.unitDecimals), 10);
} };
}, },
enumerable: true, enumerable: true,
configurable: true configurable: true
@ -42,12 +49,13 @@ angular.module('copayApp.controllers').controller('SendController',
return this._amount; return this._amount;
}, },
set: function (newValue) { set: function (newValue) {
newValue = -(-newValue) || 0;
this._amount = newValue; this._amount = newValue;
if (newValue) { if ($scope.isRateAvailable) {
this._alternative = Number.parseFloat( this._alternative = Number.parseFloat(
(rateService.toFiat(newValue * config.unitToSatoshi, config.alternativeIsoCode) (rateService.toFiat(newValue * config.unitToSatoshi, config.alternativeIsoCode)
).toFixed(2), 10); ).toFixed(2), 10);
} };
}, },
enumerable: true, enumerable: true,
configurable: true configurable: true

View file

@ -135,8 +135,9 @@ describe("Unit: Controllers", function() {
} }
}); });
})); }));
beforeEach(angular.mock.inject(function($compile, $rootScope, $controller) { beforeEach(angular.mock.inject(function($compile, $rootScope, $controller, rateService) {
scope = $rootScope.$new(); scope = $rootScope.$new();
scope.rateService = rateService;
$rootScope.wallet = new FakeWallet(walletConfig); $rootScope.wallet = new FakeWallet(walletConfig);
config.alternativeName = 'lol currency'; config.alternativeName = 'lol currency';
config.alternativeIsoCode = 'LOL'; config.alternativeIsoCode = 'LOL';
@ -254,7 +255,7 @@ describe("Unit: Controllers", function() {
}); });
it('should convert bits amount to fiat', function(done) { it('should convert bits amount to fiat', function(done) {
sendCtrl.rateService.whenAvailable(function() { scope.rateService.whenAvailable(function() {
sendForm.amount.$setViewValue(1e6); sendForm.amount.$setViewValue(1e6);
scope.$digest(); scope.$digest();
expect(scope.alternative).to.equal(2); expect(scope.alternative).to.equal(2);
@ -262,7 +263,7 @@ describe("Unit: Controllers", function() {
}); });
}); });
it('should convert fiat to bits amount', function(done) { it('should convert fiat to bits amount', function(done) {
sendCtrl.rateService.whenAvailable(function() { scope.rateService.whenAvailable(function() {
sendForm.alternative.$setViewValue(2); sendForm.alternative.$setViewValue(2);
scope.$digest(); scope.$digest();
expect(scope.amount).to.equal(1e6); expect(scope.amount).to.equal(1e6);

View file

@ -1,4 +1,4 @@
<div class="send" data-ng-controller="SendController as ctrl" data-ng-init="loadTxs()"> <div class="send" data-ng-controller="SendController" data-ng-init="loadTxs()">
<div ng-show='$root.wallet.isReady()'> <div ng-show='$root.wallet.isReady()'>
<h1 ng-show="txs.length != 0">Send Proposals</h1> <h1 ng-show="txs.length != 0">Send Proposals</h1>
@ -85,17 +85,17 @@
</div> </div>
<div class="large-6 medium-6 columns"> <div class="large-6 medium-6 columns">
<div class="row collapse"> <div class="row collapse">
<label for="alternative">Amount in {{ ctrl.alternativeName }} </label> <label for="alternative">Amount in {{ alternativeName }} </label>
<div class="small-9 columns"> <div class="small-9 columns">
<input type="number" id="alternative_amount" <input type="number" id="alternative_amount"
ng-disabled="loading || !ctrl.rateService.isAvailable " ng-disabled="loading || !isRateAvailable "
name="alternative" placeholder="Amount" ng-model="alternative" name="alternative" placeholder="Amount" ng-model="alternative"
enough-amount required enough-amount required
autocomplete="off" autocomplete="off"
> >
</div> </div>
<div class="small-3 columns"> <div class="small-3 columns">
<span class="postfix">{{ctrl.alternativeIsoCode}}</span> <span class="postfix">{{alternativeIsoCode}}</span>
</div> </div>
</div> </div>
</div> </div>
@ -135,6 +135,9 @@
<h6>Total amount for this transaction:</h6> <h6>Total amount for this transaction:</h6>
<p class="text-gray" ng-class="{'hidden': sendForm.amount.$invalid || !amount > 0}"> <p class="text-gray" ng-class="{'hidden': sendForm.amount.$invalid || !amount > 0}">
<b>{{amount + defaultFee |noFractionNumber}}</b> {{$root.unitName}} <b>{{amount + defaultFee |noFractionNumber}}</b> {{$root.unitName}}
<small ng-if="isRateAvailable">
{{ rateService.toFiat((amount + defaultFee) * unitToSatoshi, alternativeIsoCode) | noFractionNumber: 2 }} {{ alternativeIsoCode }}
</small>
<small> <small>
{{ ((amount + defaultFee) * unitToBtc)|noFractionNumber:8}} BTC <br/> {{ ((amount + defaultFee) * unitToBtc)|noFractionNumber:8}} BTC <br/>
Including fee of {{defaultFee|noFractionNumber}} {{$root.unitName}} Including fee of {{defaultFee|noFractionNumber}} {{$root.unitName}}