Merge pull request #4597 from JDonadio/feat/send-view-01

New amount view on send tab and request specific amounts - Mobile
This commit is contained in:
Gustavo Maximiliano Cortez 2016-08-09 18:10:58 -03:00 committed by GitHub
commit 8de466e49d
8 changed files with 452 additions and 50 deletions

View File

@ -0,0 +1,114 @@
<ion-modal-view ng-controller="inputAmountController" ng-style="{'background-color':'#F6F7F9'}" ng-init=init()>
<ion-header-bar align-title="center" class="tab-bar" ng-style="{'background-color':color}">
<div class="left-small">
<a ng-click="cancel()" class="p10">
<span class="text-close" translate>Close</span>
</a>
</div>
<h1 class="title ellipsis" translate>Enter amount</h1>
<div class="buttons m5r m3t" ng-if="!specificAmount" ng-click="toggleAlternative()">
<button class="button black" ng-show="showAlternativeAmount">{{alternativeIsoCode}}</button>
<button class="button" ng-style="{'background-color':color}" ng-show="!showAlternativeAmount">{{unitName}}</button>
</div>
<div class="right-small m10r" ng-if="specificAmount">
<a ng-click="init()">
<span class="text-close" translate>Cancel</span>
</a>
</div>
</ion-header-bar>
<ion-pane>
<ion-content class="calculator" scroll="false" ng-show="!specificAmount">
<div class="header-calc">
<div class="text-light text-black" ng-class="{'size-28': smallFont, 'size-36': !smallFont}">{{amount || '-'}}</div>
<div class="text-light text-black" ng-class="{'size-16': smallFont, 'size-17': !smallFont}" ng-show="!showAlternativeAmount">
{{globalResult}} <span class="label gray radius">{{amountResult || '0.00'}} {{alternativeIsoCode}}</span>
</div>
<div class="text-light text-black size-17" ng-show="showAlternativeAmount">
{{globalResult}} <span class="label gray radius">{{alternativeResult || '0.00'}} {{unitName}}</span>
</div>
</div>
<div class="button-calc">
<div class="oh">
<div class="left large-3 medium-3 small-3">
<button class="button expand text-center m0 operator"
ng-click="resetAmount()">
AC
</button>
</div>
<div class="left large-9 medium-9 small-9">
<button class="button expand text-center m0"
ng-style="{'background-color':index.backgroundColor}"
ng-disabled="alternativeResult <= 0 && amountResult <= 0" ng-click="finish()" ng-show="!specificAmount">
OK
</button>
</div>
</div>
<div class="row collapse">
<div class="columns large-3 medium-3 small-3" ng-click="pushDigit('7')">7</div>
<div class="columns large-3 medium-3 small-3" ng-click="pushDigit('8')">8</div>
<div class="columns large-3 medium-3 small-3" ng-click="pushDigit('9')">9</div>
<div class="columns large-3 medium-3 small-3 operator" ng-click="pushOperator('/')">/</div>
</div>
<div class="row collapse">
<div class="columns large-3 medium-3 small-3" ng-click="pushDigit('4')">4</div>
<div class="columns large-3 medium-3 small-3" ng-click="pushDigit('5')">5</div>
<div class="columns large-3 medium-3 small-3" ng-click="pushDigit('6')">6</div>
<div class="columns large-3 medium-3 small-3 operator" ng-click="pushOperator('x')">x</div>
</div>
<div class="row collapse">
<div class="columns large-3 medium-3 small-3" ng-click="pushDigit('1')">1</div>
<div class="columns large-3 medium-3 small-3" ng-click="pushDigit('2')">2</div>
<div class="columns large-3 medium-3 small-3" ng-click="pushDigit('3')">3</div>
<div class="columns large-3 medium-3 small-3 operator" ng-click="pushOperator('+')">+</div>
</div>
<div class="row collapse">
<div class="columns large-3 medium-3 small-3 operator" ng-click="pushDigit('.')">.</div>
<div class="columns large-3 medium-3 small-3" ng-click="pushDigit('0')">0</div>
<div class="columns large-3 medium-3 small-3 operator icon ion-arrow-left-a" ng-click="removeDigit()"></div>
<div class="columns large-3 medium-3 small-3 operator" ng-click="pushOperator('-')">-</div>
</div>
</div>
</ion-content>
<ion-content ng-show="specificAmount" ng-style="{'background-color':'#f6f7f9'}">
<section class="modal-content m20b">
<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=' + customizedAmountBtc}}"></qrcode>
<div class="m10t text-center" ng-show="isCordova">
<span class="button outline dark-gray tiny round"
ng-click="shareAddress('bitcoin:' + addr + '?amount=' + customizedAmountBtc)">
<i class="fi-share"></i>
<span translate>Share address</span>
</span>
</div>
</li>
</ul>
<h4 class="title m10l" translate>Details</h4>
<ul class="no-bullet size-14 m0">
<li class="line-b p10 oh">
<span class="text-gray" translate>Address</span>:
<span class="right">
<span class="text-gray enable_text_select">{{addr}}</span>
</span>
</li>
<li class="line-b p10 oh">
<span class="text-gray" translate>Amount</span>:
<span class="right">
{{specificAmount}} {{unitName}}
<span class="label gray radius">{{specificAlternativeAmount}} {{alternativeIsoCode}}</span>
</span>
</li>
</ul>
<div class="extra-margin-bottom"></div>
</section>
</ion-content>
</ion-pane>
</ion-modal-view>

View File

@ -302,9 +302,9 @@
</button>
</div>
<div class="small-12 columns" ng-show="home.addr">
<button class="button expand small round m10b" ng-click="home.openCustomizedAmountModal(home.addr)"
ng-style="{'background-color':index.backgroundColor}"
ng-disabled="home.generatingAddress">
<button class="button expand small round m10b" ng-click="openAmountModal(home.addr)"
ng-style="{'background-color':index.backgroundColor}"
ng-disabled="home.generatingAddress">
<span translate>Request a specific amount</span>
</button>
</div>
@ -403,34 +403,32 @@
</div>
</div>
<div class="row" ng-init="home.hideAlternative()">
<div class="row">
<div class="large-12 medium-12 columns">
<div class="right" ng-hide="sendForm.amount.$pristine && !sendForm.amount.$modelValue ">
<span class="has-error right size-12" ng-if="sendForm.amount.$invalid">
<span class="has-error right size-12" ng-show="sendForm.amount.$invalid">
<i class="icon-close-circle size-14"></i>
<span clas="vm" translate>Not valid</span>
</span>
<small class="text-primary right" ng-if="!sendForm.amount.$invalid && !sendForm.alternative.$invalid">
<small class="text-primary right" ng-show="!sendForm.amount.$invalid && !sendForm.alternative.$invalid">
<i class="icon-checkmark-circle size-14"></i>
</small>
</div>
<div ng-show="!home.canShowAlternative()">
<div>
<label for="amount">
<span translate>Amount</span>
<span translate>Amount</span><span ng-show="showAlternative"> [{{home.alternativeIsoCode}}]</span>
</label>
<div class="input">
<input type="number" id="amount" ng-disabled=" home.lockAmount" name="amount" ng-attr-placeholder="{{'Amount in'|translate}} {{home.unitName}}" ng-model="_amount" valid-amount required autocomplete="off" ng-focus="home.formFocus('amount')" ng-blur="home.formFocus(false)" ignore-mouse-wheel>
<input type="number" id="alternative" name="alternative" ng-model="_alternative" style="display:none">
<a class="postfix button" ng-style="{'background-color':index.backgroundColor}" ng-click="home.showAlternative()">{{home.unitName}}</a>
</div>
</div>
<div ng-show="home.canShowAlternative()">
<label for="alternative"><span translate>Amount</span> [{{ home.alternativeIsoCode }}]
</label>
<div class="input">
<input type="number" id="alternative" ng-disabled="!home.isRateAvailable || home.lockAmount" name="alternative" ng-attr-placeholder="{{'Amount in'|translate}} {{ home.alternativeName }}" ng-model="_alternative" required autocomplete="off" ng-focus="home.formFocus('amount')" ng-blur="home.formFocus(false)" ignore-mouse-wheel>
<input type="number" id="amount" name="amount" ng-model="_amount" style="display:none">
<a class="postfix button black" ng-click="home.hideAlternative()"> {{ home.alternativeIsoCode }}</a>
<div ng-if="index.isCordova">
<input type="amount" readonly="true" ng-show="!showAlternative" id="amount" ng-disabled="home.lockAmount" name="amount" ng-attr-placeholder="{{'Amount in'|translate}} {{home.unitName}}" ng-model="_amount" valid-amount required autocomplete="off" ng-focus="openInputAmountModal()" ignore-mouse-wheel>
<input type="amount" readonly="true" ng-show="showAlternative" id="alternative" ng-disabled="!home.isRateAvailable || home.lockAmount" name="alternative" ng-attr-placeholder="{{'Amount in'|translate}} {{ home.alternativeName }}" ng-model="_alternative" required autocomplete="off" ng-focus="openInputAmountModal()" ignore-mouse-wheel>
</div>
<div ng-if="!index.isCordova">
<input type="number" ng-show="!showAlternative" id="amount" ng-disabled="home.lockAmount" name="amount" ng-attr-placeholder="{{'Amount in'|translate}} {{home.unitName}}" ng-model="_amount" valid-amount required autocomplete="off" ignore-mouse-wheel>
<input type="number" ng-show="showAlternative" id="alternative" ng-disabled="!home.isRateAvailable || home.lockAmount" name="alternative" ng-attr-placeholder="{{'Amount in'|translate}} {{ home.alternativeName }}" ng-model="_alternative" required autocomplete="off" ignore-mouse-wheel>
</div>
<a class="postfix button" ng-show="!showAlternative" ng-style="{'background-color':index.backgroundColor}" ng-click="showAlternative = !showAlternative">{{home.unitName}}</a>
<a class="postfix button black" ng-show="showAlternative" ng-click="showAlternative = !showAlternative">{{home.alternativeIsoCode}}</a>
</div>
</div>
</div>

View File

@ -88,6 +88,30 @@
font-size: 14px;
}
.button.button-light:hover {
background-color: #fff;
border: 1px solid #E9E9EC;
}
.button.button-light:active {
background-color: #ababab;
border: 1px solid #E9E9EC;
}
.button.button-stable:hover {
background-color: transparent;
border: 1px solid #E9E9EC;
}
.button.button-stable:active {
background-color: #ababab;
border: 1px solid #E9E9EC;
}
.button-amount {
text-transform: none;
}
button, .button {
min-width: inherit;
min-height: inherit;

View File

@ -0,0 +1,170 @@
'use strict';
angular.module('copayApp.controllers').controller('inputAmountController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, profileService, platformInfo, lodash, configService, go, rateService) {
var unitToSatoshi;
var satToUnit;
var unitDecimals;
var satToBtc;
var self = $scope.self;
var SMALL_FONT_SIZE_LIMIT = 13;
var LENGTH_EXPRESSION_LIMIT = 19;
$scope.init = function() {
var config = configService.getSync().wallet.settings;
$scope.unitName = config.unitName;
$scope.alternativeIsoCode = config.alternativeIsoCode;
$scope.specificAmount = $scope.specificAlternativeAmount = '';
$scope.isCordova = platformInfo.isCordova;
unitToSatoshi = config.unitToSatoshi;
satToUnit = 1 / unitToSatoshi;
satToBtc = 1 / 100000000;
unitDecimals = config.unitDecimals;
$scope.resetAmount();
$timeout(function() {
$ionicScrollDelegate.resize();
}, 100);
};
$scope.shareAddress = function(uri) {
if ($scope.isCordova) {
window.plugins.socialsharing.share(uri, null, null, null);
}
};
$scope.toggleAlternative = function() {
$scope.showAlternativeAmount = !$scope.showAlternativeAmount;
if ($scope.amount && isExpression($scope.amount)) {
var amount = evaluate(format($scope.amount));
$scope.globalResult = '= ' + processResult(amount);
}
};
function checkFontSize() {
if ($scope.amount && $scope.amount.length >= SMALL_FONT_SIZE_LIMIT) $scope.smallFont = true;
else $scope.smallFont = false;
};
$scope.pushDigit = function(digit) {
if ($scope.amount && $scope.amount.length >= LENGTH_EXPRESSION_LIMIT) return;
$scope.amount = ($scope.amount + digit).replace('..', '.');
checkFontSize();
processAmount($scope.amount);
};
$scope.pushOperator = function(operator) {
if (!$scope.amount || $scope.amount.length == 0) return;
$scope.amount = _pushOperator($scope.amount);
function _pushOperator(val) {
if (!isOperator(lodash.last(val))) {
return val + operator;
} else {
return val.slice(0, -1) + operator;
}
};
};
function isOperator(val) {
var regex = /[\/\-\+\x\*]/;
return regex.test(val);
};
function isExpression(val) {
var regex = /^\.?\d+(\.?\d+)?([\/\-\+\*x]\d?\.?\d+)+$/;
return regex.test(val);
};
$scope.removeDigit = function() {
$scope.amount = $scope.amount.slice(0, -1);
processAmount($scope.amount);
checkFontSize();
};
$scope.resetAmount = function() {
$scope.amount = $scope.alternativeResult = $scope.amountResult = $scope.globalResult = '';
checkFontSize();
};
function processAmount(val) {
if (!val) {
$scope.resetAmount();
return;
}
var formatedValue = format(val);
var result = evaluate(formatedValue);
if (lodash.isNumber(result)) {
$scope.globalResult = isExpression(val) ? '= ' + processResult(result) : '';
$scope.amountResult = $filter('formatFiatAmount')(toFiat(result));
$scope.alternativeResult = profileService.formatAmount(fromFiat(result) * unitToSatoshi, true);
}
};
function processResult(val) {
if ($scope.showAlternativeAmount)
return $filter('formatFiatAmount')(val);
else
return profileService.formatAmount(val.toFixed(unitDecimals) * unitToSatoshi, true);
};
function fromFiat(val) {
return parseFloat((rateService.fromFiat(val, $scope.alternativeIsoCode) * satToUnit).toFixed(unitDecimals), 10);
};
function toFiat(val) {
return parseFloat((rateService.toFiat(val * unitToSatoshi, $scope.alternativeIsoCode)).toFixed(2), 10);
};
function evaluate(val) {
var result;
try {
result = $scope.$eval(val);
} catch (e) {
return 0;
}
if (!lodash.isFinite(result)) return 0;
return result;
};
function format(val) {
var result = val.toString();
if (isOperator(lodash.last(val)))
result = result.slice(0, -1);
return result.replace('x', '*');
};
$scope.finish = function() {
var amount = $scope.showAlternativeAmount ? fromFiat(evaluate(format($scope.amount))).toFixed(unitDecimals) : evaluate(format($scope.amount));
var alternativeAmount = $scope.showAlternativeAmount ? evaluate(format($scope.amount)) : toFiat(evaluate(format($scope.amount)));
if (amount % 1 == 0) amount = parseInt(amount);
if ($scope.addr) {
$scope.specificAmount = profileService.formatAmount(amount * unitToSatoshi, true);
$scope.specificAlternativeAmount = $filter('formatFiatAmount')(alternativeAmount);
if ($scope.unitName == 'bits') {
var amountSat = parseInt((amount * unitToSatoshi).toFixed(0));
amount = (amountSat * satToBtc).toFixed(8);
}
$scope.customizedAmountBtc = amount;
$timeout(function() {
$ionicScrollDelegate.resize();
}, 100);
} else {
self.setAmount(amount, $scope.showAlternativeAmount);
$scope.cancel();
}
};
$scope.cancel = function() {
$scope.inputAmountModal.hide();
};
});

View File

@ -29,6 +29,8 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
ret.isWindowsPhoneApp = platformInfo.isWP;
ret.countDown = null;
ret.sendMaxInfo = {};
ret.showAlternative = false;
ret.fromInputAmount = null;
var vanillaScope = ret;
var disableScannerListener = $rootScope.$on('dataScanned', function(event, data) {
@ -239,35 +241,8 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}
};
this.openCustomizedAmountModal = function(addr) {
var fc = profileService.focusedClient;
$scope.color = fc.backgroundColor;
$scope.self = self;
$scope.addr = addr;
$ionicModal.fromTemplateUrl('views/modals/customized-amount.html', {
scope: $scope
}).then(function(modal) {
$scope.customAmountModal = modal;
$scope.customAmountModal.show();
});
};
// Send
this.canShowAlternative = function() {
return $scope.showAlternative;
};
this.showAlternative = function() {
$scope.showAlternative = true;
};
this.hideAlternative = function() {
$scope.showAlternative = false;
};
this.resetError = function() {
this.error = this.success = null;
};
@ -336,7 +311,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
},
set: function(newValue) {
$scope.__alternative = newValue;
if (typeof(newValue) === 'number' && self.isRateAvailable) {
if (self.isRateAvailable) {
$scope._amount = parseFloat((rateService.fromFiat(newValue, self.alternativeIsoCode) * satToUnit).toFixed(self.unitDecimals), 10);
} else {
$scope.__amount = null;
@ -352,7 +327,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
},
set: function(newValue) {
$scope.__amount = newValue;
if (typeof(newValue) === 'number' && self.isRateAvailable) {
if (self.isRateAvailable) {
$scope.__alternative = parseFloat((rateService.toFiat(newValue * self.unitToSatoshi, self.alternativeIsoCode)).toFixed(2), 10);
} else {
$scope.__alternative = null;
@ -396,6 +371,13 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}, 1);
};
this.setAmount = function(amount, useAlternativeAmount) {
$scope.showAlternative = useAlternativeAmount;
self.fromInputAmount = true;
self.setForm(null, amount, null);
};
this.submitForm = function() {
if (!$scope._amount || !$scope._address) return;
var client = profileService.focusedClient;
@ -579,6 +561,42 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
});
};
$scope.openCustomInputAmountModal = function(addr) {
var fc = profileService.focusedClient;
$scope.color = fc.backgroundColor;
$scope.self = self;
$scope.addr = addr;
$ionicModal.fromTemplateUrl('views/modals/customAmount.html', {
scope: $scope
}).then(function(modal) {
$scope.customAmountModal = modal;
$scope.customAmountModal.show();
});
};
$scope.openAmountModal = function(addr) {
if (isCordova)
$scope.openInputAmountModal(addr);
else
$scope.openCustomInputAmountModal(addr);
};
$scope.openInputAmountModal = function(addr) {
var fc = profileService.focusedClient;
$scope.color = fc.backgroundColor;
$scope.showAlternativeAmount = $scope.showAlternative || null;
$scope.self = self;
$scope.addr = addr;
$ionicModal.fromTemplateUrl('views/modals/inputAmount.html', {
scope: $scope
}).then(function(modal) {
$scope.inputAmountModal = modal;
$scope.inputAmountModal.show();
});
};
this.setForm = function(to, amount, comment) {
var form = $scope.sendForm;
if (to) {
@ -592,7 +610,9 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
form.amount.$setViewValue("" + amount);
form.amount.$isValid = true;
form.amount.$render();
this.lockAmount = true;
if (!this.fromInputAmount)
this.lockAmount = true;
this.fromInputAmount = false;
}
if (comment) {

View File

@ -44,6 +44,28 @@ textarea:focus {
background: transparent;
}
input[type="amount"] {
&[readonly] {
width: 100%;
opacity: 1;
color: #B7C2CD;
margin-bottom: 1.5rem;
height: 35px;
background: transparent;
border: none;
padding-left: 0.1rem;
font-size: 13px;
border-bottom: 1px solid #E9EDF0;
cursor: text;
},
&[disabled] {
background-color: #E4E8EC;
color: #2C3E50;
padding-left: 0.5rem;
opacity: 1;
}
}
input[type="text"] {
&[disabled], &[readonly] {
background-color: #E4E8EC;

View File

@ -588,6 +588,10 @@ ul.manage li {
margin-bottom: 10px;
}
.m3t {
margin-top: 3px;
}
.m10t {
margin-top: 10px;
}
@ -2123,3 +2127,53 @@ body.modal-open {
color: #2C3E50;
}
}
.calculator .header-calc {
position: absolute;
width: 100%;
text-align: center;
}
.calculator .button-calc {
position: absolute;
width: 100%;
bottom: 0;
}
.calculator .button-calc .row {
padding: 0 !important;
}
.calculator .button-calc .columns {
cursor: pointer;
text-align: center;
}
.calculator .button-calc .operator {
color: #2C3E50;
background-color: #eee;
}
.calculator .button-calc .columns:active {
background-color: #eee;
}
.calculator .button-calc .operator:active {
background-color: #f8f8f8;
}
@media all and (max-height: 480px) {
.calculator .button-calc .columns { padding: 10px; }
.calculator .header-calc { top: 11%; }
}
@media (min-height: 481px) and (max-height: 670px) {
.calculator .button-calc .columns { padding: 15px; }
.calculator .header-calc { top: 15%; }
}
@media all and (min-height: 671px) {
.calculator .button-calc .columns { padding: 20px; }
.calculator .header-calc { top: 18%; }
}