fix UI - fix set form (alt amount)

This commit is contained in:
Javier 2016-07-19 17:10:40 -03:00
commit 9bf571bdd7
3 changed files with 62 additions and 30 deletions

View file

@ -50,16 +50,29 @@
<button class="button expand button-light" ng-click="removeDigit()"><</button>
</div>
</div>
<div class="row m20t">
<div class="columns">
<button class="round expand m0"
ng-style="{'background-color':index.backgroundColor}"
ng-disabled="alternativeResult == 0 && amountResult == 0"
ng-click="finish()"
ng-show="!specificAmount">
<span translate ng-show="!address">Ok</span>
<span translate ng-show="address">Generate QR Code</span>
</button>
</div>
</div>
</div>
<div class="modal-content m20b" ng-show="specificAmount">
<h4 class="title m10l" translate>QR Code</h4>
<ul class="no-bullet size-14 m0">
<li class="line-b p10 oh text-center">
<qrcode size="220" data="bitcoin:{{addr + '?amount=' + index.customizedAmountBtc}}"></qrcode>
<qrcode size="220" data="bitcoin:{{address + '?amount=' + specificAmountBtc}}"></qrcode>
<div class="m10t text-center" ng-show="isCordova">
<span class="button outline dark-gray tiny round"
ng-click="shareAddress('bitcoin:' + addr + '?amount=' + index.customizedAmountBtc)">
ng-click="shareAddress('bitcoin:' + address + '?amount=' + specificAmountBtc)">
<i class="fi-share"></i>
<span translate>Share address</span>
</span>
@ -83,25 +96,17 @@
</span>
</li>
</ul>
</div>
<div class="row p20t">
<div class="columns">
<button class="round expand m0"
ng-style="{'background-color':index.backgroundColor}"
ng-disabled="alternativeResult == 0 && amountResult == 0"
ng-click="finish()"
ng-show="!specificAmount">
<span translate ng-show="!address">Ok</span>
<span translate ng-show="address">Generate QR Code</span>
</button>
<button class="round expand m0"
ng-style="{'background-color':index.backgroundColor}"
ng-click="init()"
ng-show="specificAmount">
<span translate>Cancel</span>
</button>
<div class="row">
<div class="columns">
<button class="round expand m20t"
ng-style="{'background-color':index.backgroundColor}"
ng-click="init()">
<span translate>Cancel</span>
</button>
</div>
</div>
</div>
</ion-content>
</ion-modal-view>

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('inputAmountController', function($rootScope, $scope, lodash, configService, go, rateService) {
angular.module('copayApp.controllers').controller('inputAmountController', function($rootScope, $scope, platformInfo, lodash, configService, go, rateService) {
var unitToSatoshi;
var satToUnit;
var unitDecimals;
@ -11,12 +11,19 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
$scope.unitName = config.unitName;
$scope.alternativeIsoCode = config.alternativeIsoCode;
$scope.specificAmount = $scope.specificAlternativeAmount = null;
$scope.isCordova = platformInfo.isCordova;
unitToSatoshi = config.unitToSatoshi;
satToUnit = 1 / unitToSatoshi;
unitDecimals = config.unitDecimals;
resetAmount();
};
$scope.shareAddress = function(uri) {
if ($scope.isCordova) {
window.plugins.socialsharing.share(uri, null, null, null);
}
};
$scope.toggleAlternative = function() {
$scope.showAlternativeAmount = !$scope.showAlternativeAmount;
var amount;
@ -110,8 +117,8 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
if (lodash.isNumber(result)) {
$scope.amount = $scope.alternativeAmount = val;
$scope.alternativeResult = fromFiat(result);
$scope.amountResult = toFiat(result);
$scope.alternativeResult = fromFiat(result);
}
};
@ -138,20 +145,28 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
};
$scope.finish = function() {
var amount = toFiat($scope.alternativeResult);
var alternativeAmount = $scope.showAlternative ? fromFiat(amount) : toFiat(amount);
var amount;
var alternativeAmount;
if ($scope.showAlternativeAmount) {
amount = $scope.alternativeResult;
alternativeAmount = evaluate(format($scope.alternativeAmount));
} else {
amount = evaluate(format($scope.amount));
alternativeAmount = toFiat(amount);
}
if ($scope.address) {
var satToBtc = 1 / 100000000;
var amountSat = parseInt((amount * unitToSatoshi).toFixed(0));
if ($scope.unitName == 'bits') {
$scope.specificAmountBtc = (amountSat * satToBtc).toFixed(8);
}
$scope.specificAmount = amount;
$scope.specificAlternativeAmount = alternativeAmount;
} else {
if ($scope.showAlternativeAmount) {
self.showAlternative = true;
self.setForm(null, alternativeAmount, null);
} else {
self.showAlternative = false;
self.setForm(null, amount, null);
}
self.setAmount(amount, alternativeAmount, $scope.showAlternativeAmount);
$scope.cancel();
}
};

View file

@ -346,6 +346,18 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}, 1);
};
this.setAmount = function(amount, alternativeAmount, useAlternativeAmount) {
var amountResult;
if (useAlternativeAmount) {
amountResult = parseFloat((rateService.fromFiat(alternativeAmount, self.alternativeIsoCode) * self.satToUnit).toFixed(self.unitDecimals), 10);
$scope.showAlternative = true;
} else {
amountResult = amount;
$scope.showAlternative = false;
}
self.setForm(null, amountResult, null);
};
this.submitForm = function() {
if (!$scope._amount || !$scope._address) return;
var client = profileService.focusedClient;