add balance warning

This commit is contained in:
Matias Alejo Garcia 2017-06-22 17:00:20 -03:00
parent b83c0590dc
commit 44cd3cd495
No known key found for this signature in database
GPG Key ID: 02470DB551277AB3
3 changed files with 72 additions and 14 deletions

View File

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('addressesController', function($scope, $log, $stateParams, $state, $timeout, $ionicHistory, $ionicScrollDelegate, configService, popupService, gettextCatalog, ongoingProcess, lodash, profileService, walletService, bwcError, platformInfo, appConfigService) {
angular.module('copayApp.controllers').controller('addressesController', function($scope, $log, $stateParams, $state, $timeout, $ionicHistory, $ionicScrollDelegate, configService, popupService, gettextCatalog, ongoingProcess, lodash, profileService, walletService, bwcError, platformInfo, appConfigService, txFormatService, feeService) {
var UNUSED_ADDRESS_LIMIT = 5;
var BALANCE_ADDRESS_LIMIT = 5;
var config = configService.getSync().wallet.settings;
@ -55,7 +55,7 @@ angular.module('copayApp.controllers').controller('addressesController', functio
$scope.latestWithBalance = lodash.slice(withBalance, 0, BALANCE_ADDRESS_LIMIT);
lodash.each(withBalance, function(a) {
a.balanceStr = (a.amount * satToUnit).toFixed(unitDecimals) + ' ' + unitName;
a.balanceStr = txFormatService.formatAmount(a.amount);
});
$scope.viewAll = {
@ -72,6 +72,31 @@ angular.module('copayApp.controllers').controller('addressesController', functio
});
});
});
feeService.getFeeLevels(function(err, levels){
walletService.getLowUtxos($scope.wallet, levels, function(err, resp) {
if (err) return;
if (resp.allUtxos && resp.allUtxos.length) {
var allSum = lodash.sum(resp.allUtxos || 0, 'satoshis');
var per = (resp.minFee / allSum) * 100;
$scope.lowWarning = resp.warning;
$scope.lowUtxosNb = resp.lowUtxos.length;
$scope.allUtxosNb = resp.allUtxos.length;
$scope.lowUtxosSum = txFormatService.formatAmountStr(lodash.sum(resp.lowUtxos || 0, 'satoshis'));
$scope.allUtxosSum = txFormatService.formatAmountStr(allSum);
$scope.minFee = txFormatService.formatAmountStr(resp.minFee || 0);
$scope.minFeePer = per.toFixed(2) + '%';
}
});
});
};
function processPaths(list) {

View File

@ -1,10 +1,12 @@
'use strict';
angular.module('copayApp.services').factory('walletService', function($log, $timeout, lodash, trezor, ledger, intelTEE, storageService, configService, rateService, uxLanguage, $filter, gettextCatalog, bwcError, $ionicPopup, fingerprintService, ongoingProcess, gettext, $rootScope, txFormatService, $ionicModal, $state, bwcService, bitcore, popupService) {
// `wallet` is a decorated version of client.
var LOW_AMOUNT_RATIO = 0.15; //Ratio low amount warning (econ fee/amount)
var TOTAL_LOW_WARNING_RATIO = .15;
// Ratio low amount warning (fee/amount) in incoming TX
var LOW_AMOUNT_RATIO = 0.15;
// Ratio of "many utxos" warning in total balance (fee/amount)
var TOTAL_LOW_WARNING_RATIO = .3;
var root = {};
@ -921,15 +923,20 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
// Approx utxo amount, from which the uxto is economically redeemable
root.getLowAmount = function(wallet, feeLevels, nbOutputs) {
root.getMinFee = function(wallet, feeLevels, nbOutputs) {
var lowLevelRate = (lodash.find(feeLevels[wallet.network], {
level: 'normal',
}).feePerKB / 1000).toFixed(0);
var size = root.getEstimatedTxSize(wallet, nbOutputs);
var minFee = size * lowLevelRate;
return size * lowLevelRate;
};
return parseInt(minFee / (LOW_AMOUNT_RATIO));
// Approx utxo amount, from which the uxto is economically redeemable
root.getLowAmount = function(wallet, feeLevels, nbOutputs) {
var minFee = root.getMinFee(wallet,feeLevels, nbOutputs);
return parseInt( minFee / LOW_AMOUNT_RATIO);
};
@ -939,14 +946,10 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
wallet.getUtxos({}, function(err, resp) {
if (err || !resp || !resp.length) return cb();
var lowAmountN = root.getLowAmount(wallet, levels, resp.length + 1);
console.log('[walletService.js.946:lowAmountN:]',lowAmountN); //TODO
var total = lodash.sum(resp, 'satoshis');
console.log('[walletService.js.948:total:]',total); //TODO
var lowAmount1 = root.getLowAmount(wallet, levels);
console.log('[walletService.js.950:lowAmount1:]',lowAmount1); //TODO
var lowUtxos = lodash.filter(resp, function(x) {
return x.satoshis < lowAmount1;
});
@ -954,8 +957,10 @@ console.log('[walletService.js.950:lowAmount1:]',lowAmount1); //TODO
var totalLow = lodash.sum(lowUtxos, 'satoshis');
return cb(err, {
lowUtxos: lowUtxos,
allUtxos: resp || [],
lowUtxos: lowUtxos || [],
warning: lowAmountN / total > TOTAL_LOW_WARNING_RATIO,
minFee: root.getMinFee(wallet, levels, resp.length),
});
});
};

View File

@ -35,7 +35,7 @@
<i class="icon ion-ios-arrow-thin-right"></i>
</div>
<div class="item item-divider item-icon-right" ng-click="newAddress()">
<div class="item item-divider item-icon-right" ng-click="newAddress()">
<span translate>Unused Addresses</span>
<i class="icon ion-ios-plus-empty"></i>
</div>
@ -70,6 +70,34 @@
<div class="addr-balance">{{w.balanceStr}}</div>
</div>
</div>
<div ng-if="allUtxosNb">
<div class="item item-divider" translate>
Wallet Inputs
</div>
<div class="item" >
<span translate> Total wallet inputs </span>
<div class="addr-path">
{{allUtxosNb}} [{{allUtxosSum}}]
</div>
</div>
<div class="item" >
<span translate> Low amount inputs </span>
<div class="addr-path">
{{lowUtxosNb}} [{{ lowUtxosSum }}]
</div>
</div>
<div class="item" >
<span translate> Approximate fee to move all wallet's balance (with normal priority) </span>
<div class="addr-path">
{{minFeePer}} [{{minFee}}]
</div>
</div>
</div>
</div>
</div>
</ion-content>