complete evaluation of expressions
This commit is contained in:
parent
ff6348a233
commit
65766c6fe5
4 changed files with 134 additions and 68 deletions
|
|
@ -12,7 +12,8 @@
|
||||||
|
|
||||||
<ul class="no-bullet m0" ng-show="!index.noFocusedWallet">
|
<ul class="no-bullet m0" ng-show="!index.noFocusedWallet">
|
||||||
|
|
||||||
<li href ui-sref="preferencesAlias">
|
<!-- <li href ui-sref="preferencesAlias"> -->
|
||||||
|
<li href ui-sref="send2">
|
||||||
<div class="right text-gray">
|
<div class="right text-gray">
|
||||||
{{index.alias||index.walletName}}
|
{{index.alias||index.walletName}}
|
||||||
<i class="icon-arrow-right3 size-24 right"></i>
|
<i class="icon-arrow-right3 size-24 right"></i>
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,25 @@
|
||||||
<ion-content ng-controller="send2Controller">
|
<ion-content ng-controller="send2Controller" ng-init=init()>
|
||||||
<ion-header-bar align-title="center" class="tab-bar" ng-style="{'background-color':index.backgroundColor}">
|
<ion-header-bar align-title="center" class="tab-bar" ng-style="{'background-color':index.backgroundColor}">
|
||||||
<div class="left-small">
|
<div class="left-small">
|
||||||
<a class="p10" ng-click="close()"><span class="text-close" translate>Close</span></a>
|
<a class="p10" ng-click="close()"><span class="text-close" translate>Close</span></a>
|
||||||
</div>
|
</div>
|
||||||
<h1 class="title ellipsis" translate>Enter amount</h1>
|
<h1 class="title ellipsis" translate>Enter amount</h1>
|
||||||
<div class="right-small m5r">
|
<div class="right-small m5r" ng-click="toggleAlternative()">
|
||||||
<a class="postfix" ng-show="showAlternative" ng-click="toggleAlternative()">{{alternativeIsoCode}}</a>
|
<a class="postfix" ng-show="showAlternative">{{alternativeIsoCode}}</a>
|
||||||
<a class="postfix" ng-show="!showAlternative" ng-click="toggleAlternative()">{{unitName}}</a>
|
<a class="postfix" ng-show="!showAlternative">{{unitName}}</a>
|
||||||
</div>
|
</div>
|
||||||
</ion-header-bar>
|
</ion-header-bar>
|
||||||
|
|
||||||
<div class="send-amount row" ng-style="{'background-color':index.backgroundColor}">
|
<div class="send-amount row" ng-style="{'background-color':index.backgroundColor}">
|
||||||
<div class="size-48">${{amount}}</div>
|
<div class="size-48" ng-show="!showAlternative">{{amount}}</div>
|
||||||
<div class="size-21 text-light">= ${{result}}</div>
|
<div class="size-21 text-light" ng-show="!showAlternative">{{amountResult}} {{alternativeIsoCode}}</div>
|
||||||
|
<div class="size-48" ng-show="showAlternative">${{alternativeAmount}}</div>
|
||||||
|
<div class="size-21 text-light" ng-show="showAlternative">{{alternativeResult}} {{unitName}}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="button-content ext-center df">
|
||||||
|
<button class="button expand button-balanced" ng-click="">Request</button>
|
||||||
|
<button class="button expand button-balanced" ng-click="">Send</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="button-content ext-center df">
|
<div class="button-content ext-center df">
|
||||||
|
|
|
||||||
|
|
@ -1,80 +1,126 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('send2Controller',
|
angular.module('copayApp.controllers').controller('send2Controller', function($scope, lodash, configService, go, rateService) {
|
||||||
function($scope, lodash, configService, go) {
|
var unitToSatoshi;
|
||||||
|
var satToUnit;
|
||||||
|
var unitDecimals;
|
||||||
|
|
||||||
|
$scope.init = function() {
|
||||||
var config = configService.getSync().wallet.settings;
|
var config = configService.getSync().wallet.settings;
|
||||||
$scope.unitName = config.unitName;
|
$scope.unitName = config.unitName;
|
||||||
$scope.alternativeIsoCode = config.alternativeIsoCode;
|
$scope.alternativeIsoCode = config.alternativeIsoCode;
|
||||||
$scope.amount = $scope.result = 0;
|
unitToSatoshi = config.unitToSatoshi;
|
||||||
|
satToUnit = 1 / unitToSatoshi;
|
||||||
|
unitDecimals = config.unitDecimals;
|
||||||
$scope.showAlternative = false;
|
$scope.showAlternative = false;
|
||||||
|
resetAmount();
|
||||||
|
};
|
||||||
|
|
||||||
$scope.toggleAlternative = function() {
|
$scope.toggleAlternative = function() {
|
||||||
$scope.showAlternative = !$scope.showAlternative;
|
$scope.showAlternative = !$scope.showAlternative;
|
||||||
};
|
|
||||||
|
|
||||||
$scope.close = function() {
|
if ($scope.showAlternative) {
|
||||||
go.walletHome();
|
$scope.alternativeAmount = $scope.amountResult;
|
||||||
};
|
$scope.alternativeResult = isOperator(lodash.last($scope.amount)) ? evaluate($scope.amount.slice(0, -1)) : evaluate($scope.amount);
|
||||||
|
} else {
|
||||||
|
$scope.amount = $scope.alternativeResult;
|
||||||
|
$scope.amountResult = isOperator(lodash.last($scope.alternativeAmount)) ? evaluate($scope.alternativeAmount.slice(0, -1)) : evaluate($scope.alternativeAmount);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
$scope.pushDigit = function(digit) {
|
$scope.pushDigit = function(digit) {
|
||||||
if ($scope.amount.length >= 10) return;
|
var amount = $scope.showAlternative ? $scope.alternativeAmount : $scope.amount;
|
||||||
var amount;
|
|
||||||
if ($scope.amount == 0 && digit == 0) return;
|
|
||||||
amount = $scope.amount ? $scope.amount + digit : digit;
|
|
||||||
evaluate(amount);
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.pushOperator = function(operator) {
|
if (amount.toString().length >= 10) return;
|
||||||
|
if (amount == 0 && digit == 0) return;
|
||||||
|
|
||||||
|
var val = amount ? amount + digit : digit;
|
||||||
|
processAmount(val);
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.pushOperator = function(operator) {
|
||||||
|
if ($scope.showAlternative) {
|
||||||
|
if (!$scope.alternativeAmount || $scope.alternativeAmount.length == 0) return;
|
||||||
|
$scope.alternativeAmount = _pushOperator($scope.alternativeAmount);
|
||||||
|
} else {
|
||||||
if (!$scope.amount || $scope.amount.length == 0) return;
|
if (!$scope.amount || $scope.amount.length == 0) return;
|
||||||
if (!isOperator(lodash.last($scope.amount))) {
|
$scope.amount = _pushOperator($scope.amount);
|
||||||
$scope.amount = $scope.amount + operator;
|
}
|
||||||
} else
|
|
||||||
$scope.amount = $scope.amount.slice(0, -1) + operator;
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.removeDigit = function() {
|
function _pushOperator(val) {
|
||||||
if (!$scope.amount || $scope.amount.length == 0) {
|
if (!isOperator(lodash.last(val))) {
|
||||||
resetAmount();
|
return val + operator;
|
||||||
return;
|
} else {
|
||||||
|
return val.slice(0, -1) + operator;
|
||||||
}
|
}
|
||||||
|
|
||||||
var amount;
|
|
||||||
$scope.amount = amount = $scope.amount.slice(0, -1);
|
|
||||||
evaluate(amount);
|
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
function isOperator(val) {
|
function isOperator(val) {
|
||||||
var regex = /[\/\-\+\*]/;
|
var regex = /[\/\-\+\*]/;
|
||||||
var match = regex.exec(val);
|
var match = regex.exec(val);
|
||||||
if (match) return true;
|
if (match) return true;
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
function resetAmount() {
|
$scope.removeDigit = function() {
|
||||||
$scope.amount = $scope.result = 0;
|
var amount = $scope.showAlternative ? $scope.alternativeAmount.toString() : $scope.amount.toString();
|
||||||
};
|
|
||||||
|
|
||||||
function evaluate(val) {
|
if (amount && amount.length == 0) {
|
||||||
if (!val) {
|
resetAmount();
|
||||||
resetAmount();
|
return;
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
amount = amount.slice(0, -1);
|
||||||
|
|
||||||
|
if ($scope.showAlternative)
|
||||||
|
$scope.alternativeAmount = amount;
|
||||||
|
else
|
||||||
|
$scope.amount = amount;
|
||||||
|
|
||||||
|
processAmount(amount);
|
||||||
|
};
|
||||||
|
|
||||||
|
function resetAmount() {
|
||||||
|
$scope.amount = $scope.alternativeAmount = $scope.alternativeResult = $scope.amountResult = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
function processAmount(val) {
|
||||||
|
if (!val) {
|
||||||
|
resetAmount();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($scope.showAlternative) {
|
||||||
|
if ($scope.alternativeAmount == 0 && val == '.') {
|
||||||
|
$scope.alternativeAmount += val;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if ($scope.amount == 0 && val == '.') {
|
if ($scope.amount == 0 && val == '.') {
|
||||||
$scope.amount += val;
|
$scope.amount += val;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var result;
|
var result = evaluate(val);
|
||||||
try {
|
|
||||||
result = eval(val);
|
|
||||||
} catch (e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lodash.isNumber(result)) {
|
if (lodash.isNumber(result)) {
|
||||||
$scope.result = result;
|
$scope.amount = $scope.alternativeAmount = val;
|
||||||
$scope.amount = val;
|
$scope.alternativeResult = parseFloat((rateService.fromFiat(result, $scope.alternativeIsoCode) * satToUnit).toFixed(unitDecimals), 10);
|
||||||
}
|
$scope.amountResult = parseFloat((rateService.toFiat(result * unitToSatoshi, $scope.alternativeIsoCode)).toFixed(2), 10);
|
||||||
};
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
function evaluate(val) {
|
||||||
|
var result;
|
||||||
|
try {
|
||||||
|
result = eval(val);
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.close = function() {
|
||||||
|
go.walletHome();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -347,18 +347,30 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('preferencesAlias', {
|
.state('send2', {
|
||||||
url: '/preferencesAlias',
|
url: '/send2',
|
||||||
templateUrl: 'views/preferencesAlias.html',
|
templateUrl: 'views/send2.html',
|
||||||
walletShouldBeComplete: true,
|
walletShouldBeComplete: true,
|
||||||
needProfile: true,
|
needProfile: true,
|
||||||
views: {
|
views: {
|
||||||
'main': {
|
'main': {
|
||||||
templateUrl: 'views/preferencesAlias.html'
|
templateUrl: 'views/send2.html'
|
||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
// .state('preferencesAlias', {
|
||||||
|
// url: '/preferencesAlias',
|
||||||
|
// templateUrl: 'views/preferencesAlias.html',
|
||||||
|
// walletShouldBeComplete: true,
|
||||||
|
// needProfile: true,
|
||||||
|
// views: {
|
||||||
|
// 'main': {
|
||||||
|
// templateUrl: 'views/preferencesAlias.html'
|
||||||
|
// },
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// })
|
||||||
.state('preferencesEmail', {
|
.state('preferencesEmail', {
|
||||||
url: '/preferencesEmail',
|
url: '/preferencesEmail',
|
||||||
templateUrl: 'views/preferencesEmail.html',
|
templateUrl: 'views/preferencesEmail.html',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue