Merge pull request #2901 from matiu/feat/send-all

Feature: send all and fee customization.
This commit is contained in:
Gustavo Maximiliano Cortez 2015-06-22 16:16:38 -03:00
commit 99e2953cc5
11 changed files with 149 additions and 16 deletions

View file

@ -17,7 +17,7 @@
"ng-lodash": "~0.2.0", "ng-lodash": "~0.2.0",
"angular-moment": "~0.10.1", "angular-moment": "~0.10.1",
"moment": "~2.10.3", "moment": "~2.10.3",
"angular-bitcore-wallet-client": "^0.0.24", "angular-bitcore-wallet-client": "^0.0.25",
"angular-ui-router": "~0.2.13", "angular-ui-router": "~0.2.13",
"qrcode-decoder-js": "*", "qrcode-decoder-js": "*",
"fastclick": "*", "fastclick": "*",

View file

@ -24,6 +24,10 @@
<span class="label gray radius">{{alternativeAmountStr}}</span> <span class="label gray radius">{{alternativeAmountStr}}</span>
</span> </span>
</li> </li>
<li class="line-b p10">
<span class="text-gray" translate>Fee</span>:
<span class="right">{{feeStr}}</span>
</li>
<li class="line-b p10"> <li class="line-b p10">
<span class="text-gray" translate>Time</span>: <span class="text-gray" translate>Time</span>:
<span class="right"> <span class="right">

View file

@ -77,6 +77,14 @@
{{preferences.selectedAlternative.name}} {{preferences.selectedAlternative.name}}
</span> </span>
</li> </li>
<li class="line-b p20" ng-click="$root.go('preferencesFee')">
<span translate>Bitcoin Network Fee Policy</span>
<span class="right text-gray">
<i class="icon-arrow-right3 size-24 right"></i>
{{preferences.feeName}}
</span>
</li>
<li class="line-b p20" ng-click="$root.go('preferencesBwsUrl')"> <li class="line-b p20" ng-click="$root.go('preferencesBwsUrl')">
<span>Bitcore Wallet Service</span> <span>Bitcore Wallet Service</span>

View file

@ -0,0 +1,14 @@
<div
class="topbar-container"
ng-include="'views/includes/topbar.html'"
ng-init="titleSection='Fee Policy'; goBackToState = 'preferences'; noColor = true">
</div>
<div class="content preferences" ng-controller="preferencesFeeController as prefFee">
<div ng-repeat="fee in prefFee.feeOpts" ng-click="prefFee.save(fee)" class="line-b p20 size-14">
<span>{{fee.name}} ({{fee.value}} bits per kB)</span>
<i class="fi-check size-16 right" ng-show="prefFee.feeName == fee.name"></i>
</div>
</div>
<div class="extra-margin-bottom"></div>

View file

@ -278,8 +278,14 @@
<div> <div>
<h4 class="title m0"> <h4 class="title m0">
<a class="right lh"
ng-if="index.feeToSendMaxStr && index.availableBalance > 0 && !home.blockUx && !home.lockAmount"
ng-click="home.sendAll(index.availableMaxBalance, index.feeToSendMaxStr)"
translate> Send All
</a>
<div ng-show="!index.lockedBalance && index.availableBalanceStr"> <div ng-show="!index.lockedBalance && index.availableBalanceStr">
<div class="size-12"> <div class="size-10">
<span class="db text-bold"> <span class="db text-bold">
<span translate>Available Balance</span>: <span translate>Available Balance</span>:
{{index.availableBalanceStr }} {{index.availableBalanceStr }}
@ -288,9 +294,9 @@
</div> </div>
<div ng-show="index.lockedBalance"> <div ng-show="index.lockedBalance">
<div class="left"> <div class="left">
<i class="fi-info size-36 m10r lh"></i> <i class="fi-info size-24 m10r"></i>
</div> </div>
<div class="size-12"> <div class="size-10">
<span class="db text-bold"> <span class="db text-bold">
<span translate>Available Balance</span>: <span translate>Available Balance</span>:
{{index.availableBalanceStr }} {{index.availableBalanceStr }}
@ -397,10 +403,10 @@
</div> </div>
<div class="row" ng-show="!home.onGoingProcess"> <div class="row" ng-show="!home.onGoingProcess">
<div class="large-6 medium-6 small-6 columns" ng-show="!home.blockUx && (home._paypro || home.lockAddress)"> <div class="large-6 medium-6 small-6 columns" ng-show="!home.blockUx && (home._paypro || home.lockAddress || home.lockAmount)">
<a ng-click="home.resetForm(sendForm)" class="button expand outline dark-gray round" translate>Cancel</a> <a ng-click="home.resetForm(sendForm)" class="button expand outline dark-gray round" translate>Cancel</a>
</div> </div>
<div class="columns" ng-class="{'small-6 medium-6 large-6':(home._paypro || home.lockAddress)}"> <div class="columns" ng-class="{'small-6 medium-6 large-6':(home._paypro || home.lockAddress || home.lockAmount)}">
<button type="submit" class="button black round expand" ng-disabled="sendForm.$invalid || home.blockUx || index.isOffline" <button type="submit" class="button black round expand" ng-disabled="sendForm.$invalid || home.blockUx || index.isOffline"
ng-style="{'background-color':index.backgroundColor}" translate> ng-style="{'background-color':index.backgroundColor}" translate>
Send Send

View file

@ -49,6 +49,13 @@ h4.title {
font-size: 0.7rem; font-size: 0.7rem;
} }
h4.title a {
text-transform: none;
font-weight: 400;
padding: 7px;
font-size: 12px;
}
body, html{ body, html{
height:100%; height:100%;
width:100%; width:100%;

View file

@ -57,9 +57,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
isoCode: 'pt', isoCode: 'pt',
}]; }];
self.setOngoingProcess = function(processName, isOn, quiet) { self.setOngoingProcess = function(processName, isOn) {
$log.debug('onGoingProcess', processName, isOn); $log.debug('onGoingProcess', processName, isOn);
if (quiet) return;
self[processName] = isOn; self[processName] = isOn;
self.onGoingProcess[processName] = isOn; self.onGoingProcess[processName] = isOn;
@ -179,13 +178,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.updateAll = function(opts, initStatusHash, tries) { self.updateAll = function(opts, initStatusHash, tries) {
tries = tries || 0; tries = tries || 0;
var quiet = (opts && opts.quiet) ? true : null; opts = opts || {};
if (opts && opts.untilItChanges && lodash.isUndefined(initStatusHash)) {
if (opts.untilItChanges && lodash.isUndefined(initStatusHash)) {
initStatusHash = _walletStatusHash(); initStatusHash = _walletStatusHash();
$log.debug('Updating status until it changes. initStatusHash:' + initStatusHash) $log.debug('Updating status until it changes. initStatusHash:' + initStatusHash)
} }
var get = function(cb) { var get = function(cb) {
if (opts && opts.walletStatus) if (opts.walletStatus)
return cb(null, opts.walletStatus); return cb(null, opts.walletStatus);
else { else {
self.updateError = false; self.updateError = false;
@ -193,7 +193,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (err) { if (err) {
self.updateError = true; self.updateError = true;
} else { } else {
self.setOngoingProcess('scanning', ret.wallet.scanning, quiet); if (!opts.quiet)
self.setOngoingProcess('scanning', ret.wallet.scanning);
} }
return cb(err, ret); return cb(err, ret);
}); });
@ -204,18 +205,23 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (!fc) return; if (!fc) return;
$timeout(function() { $timeout(function() {
self.setOngoingProcess('updatingStatus', true, quiet);
if (!opts.quiet)
self.setOngoingProcess('updatingStatus', true);
$log.debug('Updating Status:', fc, tries); $log.debug('Updating Status:', fc, tries);
get(function(err, walletStatus) { get(function(err, walletStatus) {
var currentStatusHash = _walletStatusHash(walletStatus); var currentStatusHash = _walletStatusHash(walletStatus);
$log.debug('Status update. hash:' + currentStatusHash + ' Try:'+ tries); $log.debug('Status update. hash:' + currentStatusHash + ' Try:'+ tries);
if (!err && (opts && opts.untilItChanges) && initStatusHash == currentStatusHash && tries < 7) { if (!err && opts.untilItChanges && initStatusHash == currentStatusHash && tries < 7) {
return $timeout(function() { return $timeout(function() {
$log.debug('Retrying update... Try:' + tries) $log.debug('Retrying update... Try:' + tries)
return self.updateAll({walletStatus: null, untilItChanges: true}, initStatusHash, ++tries); return self.updateAll({walletStatus: null, untilItChanges: true}, initStatusHash, ++tries);
}, 1400 * tries); }, 1400 * tries);
} }
self.setOngoingProcess('updatingStatus', false, quiet); if (!opts.quiet)
self.setOngoingProcess('updatingStatus', false);
if (err) { if (err) {
self.handleError(err); self.handleError(err);
return; return;
@ -343,6 +349,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
lodash.each(txps, function(tx) { lodash.each(txps, function(tx) {
var amount = tx.amount * self.satToUnit; var amount = tx.amount * self.satToUnit;
tx.amountStr = profileService.formatAmount(tx.amount) + ' ' + config.unitName; tx.amountStr = profileService.formatAmount(tx.amount) + ' ' + config.unitName;
tx.feeStr = profileService.formatAmount(tx.fee) + ' ' + config.unitName;
tx.alternativeAmount = rateService.toFiat(tx.amount, config.alternativeIsoCode) ? rateService.toFiat(tx.amount, config.alternativeIsoCode).toFixed(2) : 'N/A'; tx.alternativeAmount = rateService.toFiat(tx.amount, config.alternativeIsoCode) ? rateService.toFiat(tx.amount, config.alternativeIsoCode).toFixed(2) : 'N/A';
tx.alternativeAmountStr = tx.alternativeAmount + " " + config.alternativeIsoCode; tx.alternativeAmountStr = tx.alternativeAmount + " " + config.alternativeIsoCode;
tx.alternativeIsoCode = config.alternativeIsoCode; tx.alternativeIsoCode = config.alternativeIsoCode;
@ -436,6 +443,16 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.lockedBalanceBTC = strip(self.lockedBalanceSat / COIN); self.lockedBalanceBTC = strip(self.lockedBalanceSat / COIN);
self.availableBalanceBTC = strip(self.availableBalanceBTC / COIN); self.availableBalanceBTC = strip(self.availableBalanceBTC / COIN);
// KB to send max
self.feePerKbSat = config.feeValue || 10000;
if (balance.totalKbToSendMax) {
var feeToSendMaxSat = balance.totalKbToSendMax * self.feePerKbSat;
self.availableMaxBalance = strip((self.availableBalanceSat - feeToSendMaxSat) * self.satToUnit);
self.feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName;
} else {
self.feeToSendMaxStr = null;
}
//STR //STR
self.totalBalanceStr = profileService.formatAmount(self.totalBalanceSat) + ' ' + self.unitName; self.totalBalanceStr = profileService.formatAmount(self.totalBalanceSat) + ' ' + self.unitName;

View file

@ -4,6 +4,7 @@ angular.module('copayApp.controllers').controller('preferencesController',
function($scope, $rootScope, $filter, $timeout, $modal, $log, lodash, configService, profileService) { function($scope, $rootScope, $filter, $timeout, $modal, $log, lodash, configService, profileService) {
var config = configService.getSync(); var config = configService.getSync();
this.unitName = config.wallet.settings.unitName; this.unitName = config.wallet.settings.unitName;
this.feeName = config.wallet.settings.feeName || 'Priority';
this.bwsurl = config.bws.url; this.bwsurl = config.bws.url;
this.selectedAlternative = { this.selectedAlternative = {
name: config.wallet.settings.alternativeName, name: config.wallet.settings.alternativeName,

View file

@ -0,0 +1,35 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesFeeController',
function($rootScope, $scope, configService, go) {
var config = configService.getSync();
this.feeName = config.wallet.settings.feeName || 'Priority';
this.feeOpts = [{
name: 'Priority',
value: 100,
}, {
name: 'Normal',
value: 50,
}, {
name: 'Economy',
value: 10,
}];
this.save = function(newFee) {
var opts = {
wallet: {
settings: {
feeName: newFee.name,
feeValue: newFee.value * 100,
}
}
};
this.feeName = newFee.name;
configService.set(opts, function(err) {
if (err) console.log(err);
$scope.$emit('Local/UnitSettingUpdated');
});
};
});

View file

@ -132,6 +132,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$scope.error = null; $scope.error = null;
$scope.tx = tx; $scope.tx = tx;
$scope.amountStr = tx.amountStr; $scope.amountStr = tx.amountStr;
$scope.feeStr = tx.feeStr;
$scope.alternativeAmountStr = tx.alternativeAmountStr; $scope.alternativeAmountStr = tx.alternativeAmountStr;
$scope.copayers = copayers $scope.copayers = copayers
$scope.copayerId = fc.credentials.copayerId; $scope.copayerId = fc.credentials.copayerId;
@ -608,6 +609,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
amount: amount, amount: amount,
message: comment, message: comment,
payProUrl: paypro ? paypro.url : null, payProUrl: paypro ? paypro.url : null,
feePerKb: config.feeValue || 10000,
}, function(err, txp) { }, function(err, txp) {
if (err) { if (err) {
self.setOngoingProcess(); self.setOngoingProcess();
@ -917,6 +919,32 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
return actions.hasOwnProperty('create'); return actions.hasOwnProperty('create');
}; };
this._doSendAll = function(amount) {
this.setForm(null, amount);
};
this.sendAll = function(amount, feeStr) {
var self = this;
var msg = gettextCatalog.getString("{{fee}} will be discounted for bitcoin networking fees", {
fee: feeStr
});
if (isCordova) {
navigator.notification.confirm(
msg,
function(buttonIndex) {
if (buttonIndex == 1)
$timeout(function() {
self._doSendAll(amount);
}, 1);
}
);
} else {
if (confirm(msg))
this._doSendAll(amount);
}
}
this.bindTouchDown(); this.bindTouchDown();
this.setAddress(); this.setAddress();
this.setSendFormInputs(); this.setSendFormInputs();

View file

@ -58,7 +58,7 @@ angular
historicLog.add(level, args.join(' ')); historicLog.add(level, args.join(' '));
orig.apply(null, args); orig.apply(null, args);
} catch (e) { } catch (e) {
console.log('Error at log decorator:', e); console.log('ERROR (at log decorator):', e, args[0]);
} }
}; };
}); });
@ -245,6 +245,18 @@ angular
}, },
} }
}) })
.state('preferencesFee', {
url: '/preferencesFee',
templateUrl: 'views/preferencesFee.html',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/preferencesFee.html'
},
}
})
.state('preferencesAdvanced', { .state('preferencesAdvanced', {
url: '/preferencesAdvanced', url: '/preferencesAdvanced',
templateUrl: 'views/preferencesAdvanced.html', templateUrl: 'views/preferencesAdvanced.html',
@ -451,6 +463,7 @@ angular
delete: 13, delete: 13,
preferencesLanguage: 12, preferencesLanguage: 12,
preferencesUnit: 12, preferencesUnit: 12,
preferencesFee: 12,
preferencesAltCurrency: 12, preferencesAltCurrency: 12,
preferencesBwsUrl: 12, preferencesBwsUrl: 12,
preferencesAlias: 12, preferencesAlias: 12,