Merge pull request #5108 from JDonadio/feat/send-max

Send max
This commit is contained in:
Gustavo Maximiliano Cortez 2016-12-01 15:14:19 -03:00 committed by GitHub
commit 1efad56261
13 changed files with 343 additions and 164 deletions

View file

@ -1,22 +1,21 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('amountController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, bitpayCardService, popupService, bwcError, payproService, amazonService, profileService) { angular.module('copayApp.controllers').controller('amountController', function($scope, $filter, $timeout, $ionicScrollDelegate, $ionicHistory, $ionicPopover, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, bitpayCardService, popupService, bwcError, payproService, profileService, bitcore, amazonService) {
var unitToSatoshi; var unitToSatoshi;
var satToUnit; var satToUnit;
var unitDecimals; var unitDecimals;
var satToBtc; var satToBtc;
var self = $scope.self;
var SMALL_FONT_SIZE_LIMIT = 10; var SMALL_FONT_SIZE_LIMIT = 10;
var LENGTH_EXPRESSION_LIMIT = 19; var LENGTH_EXPRESSION_LIMIT = 19;
var MENU_ITEM_HEIGHT = 55;
$scope.$on('$ionicView.leave', function() { $scope.$on('$ionicView.leave', function() {
angular.element($window).off('keydown'); angular.element($window).off('keydown');
}); });
$scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.isGiftCard = data.stateParams.isGiftCard; $scope.isGiftCard = data.stateParams.isGiftCard;
$scope.showMenu = $ionicHistory.backView().stateName == 'tabs.send';
$scope.isWallet = data.stateParams.isWallet; $scope.isWallet = data.stateParams.isWallet;
$scope.cardId = data.stateParams.cardId; $scope.cardId = data.stateParams.cardId;
$scope.toAddress = data.stateParams.toAddress; $scope.toAddress = data.stateParams.toAddress;
@ -52,8 +51,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
$timeout(function() { $timeout(function() {
$scope.$apply(); $scope.$apply();
}, 10); });
}); });
var config = configService.getSync().wallet.settings; var config = configService.getSync().wallet.settings;
@ -80,6 +78,35 @@ angular.module('copayApp.controllers').controller('amountController', function($
}, 10); }, 10);
}); });
$scope.showSendMaxMenu = function($event) {
var sendMaxObj = {
text: gettextCatalog.getString('Send max amount'),
action: setSendMax,
};
$scope.items = [sendMaxObj];
$scope.height = $scope.items.length * MENU_ITEM_HEIGHT;
$ionicPopover.fromTemplateUrl('views/includes/menu-popover.html', {
scope: $scope
}).then(function(popover) {
$scope.menu = popover;
$scope.menu.show($event);
});
};
function setSendMax() {
$scope.menu.hide();
$state.transitionTo('tabs.send.confirm', {
isWallet: $scope.isWallet,
toAmount: null,
toAddress: $scope.toAddress,
toName: $scope.toName,
toEmail: $scope.toEmail,
useSendMax: true,
});
};
$scope.toggleAlternative = function() { $scope.toggleAlternative = function() {
$scope.showAlternativeAmount = !$scope.showAlternativeAmount; $scope.showAlternativeAmount = !$scope.showAlternativeAmount;
@ -124,7 +151,6 @@ angular.module('copayApp.controllers').controller('amountController', function($
function isExpression(val) { function isExpression(val) {
var regex = /^\.?\d+(\.?\d+)?([\/\-\+\*x]\d?\.?\d+)+$/; var regex = /^\.?\d+(\.?\d+)?([\/\-\+\*x]\d?\.?\d+)+$/;
return regex.test(val); return regex.test(val);
}; };
@ -137,7 +163,6 @@ angular.module('copayApp.controllers').controller('amountController', function($
$scope.resetAmount = function() { $scope.resetAmount = function() {
$scope.amount = $scope.alternativeResult = $scope.amountResult = $scope.globalResult = ''; $scope.amount = $scope.alternativeResult = $scope.amountResult = $scope.globalResult = '';
$scope.allowSend = false; $scope.allowSend = false;
checkFontSize(); checkFontSize();
}; };
@ -251,7 +276,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
onlyComplete: true, onlyComplete: true,
network: 'livenet', network: 'livenet',
})[0].id; })[0].id;
} catch(err) { } catch (err) {
ongoingProcess.set('Preparing transaction...', false); ongoingProcess.set('Preparing transaction...', false);
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('No wallet found!')); popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('No wallet found!'));
return; return;

View file

@ -1,18 +1,19 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, gettext, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, amazonService) { angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, gettext, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, amazonService) {
var cachedTxp = {}; var cachedTxp = {};
var toAmount;
var isChromeApp = platformInfo.isChromeApp; var isChromeApp = platformInfo.isChromeApp;
var countDown = null; var countDown = null;
var giftCardAmountUSD; var giftCardAmountUSD;
var giftCardAccessKey; var giftCardAccessKey;
var giftCardInvoiceTime; var giftCardInvoiceTime;
var giftCardUUID; var giftCardUUID;
var cachedSendMax = {};
$scope.isCordova = platformInfo.isCordova; $scope.isCordova = platformInfo.isCordova;
$ionicConfig.views.swipeBackEnabled(false); $ionicConfig.views.swipeBackEnabled(false);
$scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.$on("$ionicView.beforeEnter", function(event, data) {
// Amazon.com Gift Card parameters // Amazon.com Gift Card parameters
$scope.isGiftCard = data.stateParams.isGiftCard; $scope.isGiftCard = data.stateParams.isGiftCard;
giftCardAmountUSD = data.stateParams.giftCardAmountUSD; giftCardAmountUSD = data.stateParams.giftCardAmountUSD;
@ -20,97 +21,201 @@ angular.module('copayApp.controllers').controller('confirmController', function(
giftCardInvoiceTime = data.stateParams.giftCardInvoiceTime; giftCardInvoiceTime = data.stateParams.giftCardInvoiceTime;
giftCardUUID = data.stateParams.giftCardUUID; giftCardUUID = data.stateParams.giftCardUUID;
toAmount = data.stateParams.toAmount;
cachedSendMax = {};
$scope.useSendMax = data.stateParams.useSendMax == 'true' ? true : false;
$scope.isWallet = data.stateParams.isWallet; $scope.isWallet = data.stateParams.isWallet;
$scope.cardId = data.stateParams.cardId; $scope.cardId = data.stateParams.cardId;
$scope.toAmount = data.stateParams.toAmount;
$scope.toAddress = data.stateParams.toAddress; $scope.toAddress = data.stateParams.toAddress;
$scope.toName = data.stateParams.toName; $scope.toName = data.stateParams.toName;
$scope.toEmail = data.stateParams.toEmail; $scope.toEmail = data.stateParams.toEmail;
$scope.description = data.stateParams.description; $scope.description = data.stateParams.description;
$scope.paypro = data.stateParams.paypro; $scope.paypro = data.stateParams.paypro;
$scope.insufficientFunds = false;
$scope.noMatchingWallet = false;
$scope.paymentExpired = { $scope.paymentExpired = {
value: false value: false
}; };
$scope.remainingTimeStr = { $scope.remainingTimeStr = {
value: null value: null
}; };
initConfirm();
});
var initConfirm = function() {
// TODO (URL , etc)
if (!$scope.toAddress || !$scope.toAmount) {
$log.error('Bad params at amount');
throw ('bad params');
}
var config = configService.getSync().wallet; var config = configService.getSync().wallet;
$scope.feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal'; $scope.feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal';
$scope.network = (new bitcore.Address($scope.toAddress)).network.name;
resetValues();
setwallets();
});
$scope.toAmount = parseInt($scope.toAmount); function setwallets() {
$scope.amountStr = txFormatService.formatAmountStr($scope.toAmount); $scope.wallets = profileService.getWallets({
$scope.displayAmount = getDisplayAmount($scope.amountStr);
$scope.displayUnit = getDisplayUnit($scope.amountStr);
var networkName = (new bitcore.Address($scope.toAddress)).network.name;
$scope.network = networkName;
$scope.insuffientFunds = false;
$scope.noMatchingWallet = false;
var wallets = profileService.getWallets({
onlyComplete: true, onlyComplete: true,
network: networkName, network: $scope.network,
n: $scope.isGiftCard ? true : false n: $scope.isGiftCard ? true : false
}); });
if (!wallets || !wallets.length) { if (!$scope.wallets || !$scope.wallets.length) {
$scope.noMatchingWallet = true; $scope.noMatchingWallet = true;
if ($scope.paypro) {
displayValues();
}
$timeout(function() {
$scope.$apply();
});
return;
} }
var filteredWallets = []; var filteredWallets = [];
var index = 0; var index = 0;
var enoughFunds = false; var enoughFunds = false;
lodash.each(wallets, function(w) { lodash.each($scope.wallets, function(w) {
walletService.getStatus(w, {}, function(err, status) { walletService.getStatus(w, {}, function(err, status) {
if (err || !status) { if (err || !status) {
$log.error(err); $log.error(err);
} else { } else {
w.status = status; w.status = status;
if (!status.availableBalanceSat) $log.debug('No balance available in: ' + w.name); if (!status.availableBalanceSat) $log.debug('No balance available in: ' + w.name);
if (status.availableBalanceSat > $scope.toAmount) { if (status.availableBalanceSat > toAmount) {
filteredWallets.push(w); filteredWallets.push(w);
enoughFunds = true; enoughFunds = true;
} }
} }
if (++index == wallets.length) { if (++index == $scope.wallets.length) {
if (!lodash.isEmpty(filteredWallets)) { if (!lodash.isEmpty(filteredWallets)) {
$scope.wallets = lodash.clone(filteredWallets); $scope.wallets = lodash.clone(filteredWallets);
setWallet($scope.wallets[0]); if ($scope.useSendMax) $scope.showWalletSelector();
else initConfirm();
} else { } else {
if (!enoughFunds) $scope.insufficientFunds = true;
if (!enoughFunds)
$scope.insuffientFunds = true;
$log.warn('No wallet available to make the payment'); $log.warn('No wallet available to make the payment');
$timeout(function() {
$scope.$apply();
});
} }
$timeout(function() {
$scope.$apply();
});
} }
}); });
}); });
};
txFormatService.formatAlternativeStr($scope.toAmount, function(v) { var initConfirm = function() {
if ($scope.paypro) _paymentTimeControl($scope.paypro.expires);
displayValues();
$scope.showWalletSelector();
$timeout(function() {
$scope.$apply();
});
};
function displayValues() {
toAmount = parseInt(toAmount);
$scope.amountStr = txFormatService.formatAmountStr(toAmount);
$scope.displayAmount = getDisplayAmount($scope.amountStr);
$scope.displayUnit = getDisplayUnit($scope.amountStr);
txFormatService.formatAlternativeStr(toAmount, function(v) {
$scope.alternativeAmountStr = v; $scope.alternativeAmountStr = v;
}); });
};
if($scope.paypro) { function resetValues() {
_paymentTimeControl($scope.paypro.expires); $scope.displayAmount = $scope.displayUnit = $scope.fee = $scope.alternativeAmountStr = $scope.insufficientFunds = $scope.noMatchingWallet = null;
} };
$scope.getSendMaxInfo = function() {
resetValues();
ongoingProcess.set('gettingFeeLevels', true);
feeService.getCurrentFeeValue($scope.network, function(err, feePerKb) {
ongoingProcess.set('gettingFeeLevels', false);
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err.message);
return;
}
var config = configService.getSync().wallet;
ongoingProcess.set('retrievingInputs', true);
walletService.getSendMaxInfo($scope.wallet, {
feePerKb: feePerKb,
excludeUnconfirmedUtxos: !config.spendUnconfirmed,
returnInputs: true,
}, function(err, resp) {
ongoingProcess.set('retrievingInputs', false);
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
return;
}
if (resp.amount == 0) {
$scope.insufficientFunds = true;
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee'));
return;
}
$scope.sendMaxInfo = {
sendMax: true,
amount: resp.amount,
inputs: resp.inputs,
fee: resp.fee,
feePerKb: feePerKb,
};
cachedSendMax[$scope.wallet.id] = $scope.sendMaxInfo;
var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees.", {
fee: txFormatService.formatAmountStr(resp.fee)
});
var warningMsg = verifyExcludedUtxos();
if (!lodash.isEmpty(warningMsg))
msg += '\n' + warningMsg;
popupService.showAlert(null, msg, function() {
setSendMaxValues(resp);
createTx($scope.wallet, true, function(err, txp) {
if (err) return;
cachedTxp[$scope.wallet.id] = txp;
apply(txp);
});
});
function verifyExcludedUtxos() {
var warningMsg = [];
if (resp.utxosBelowFee > 0) {
warningMsg.push(gettextCatalog.getString("A total of {{amountBelowFeeStr}} were excluded. These funds come from UTXOs smaller than the network fee provided.", {
amountBelowFeeStr: txFormatService.formatAmountStr(resp.amountBelowFee)
}));
}
if (resp.utxosAboveMaxSize > 0) {
warningMsg.push(gettextCatalog.getString("A total of {{amountAboveMaxSizeStr}} were excluded. The maximum size allowed for a transaction was exceeded.", {
amountAboveMaxSizeStr: txFormatService.formatAmountStr(resp.amountAboveMaxSize)
}));
}
return warningMsg.join('\n');
};
});
});
};
function setSendMaxValues(data) {
resetValues();
var config = configService.getSync().wallet;
var unitName = config.settings.unitName;
var unitToSatoshi = config.settings.unitToSatoshi;
var satToUnit = 1 / unitToSatoshi;
var unitDecimals = config.settings.unitDecimals;
$scope.displayAmount = txFormatService.formatAmount(data.amount, true);
$scope.displayUnit = unitName;
$scope.fee = txFormatService.formatAmountStr(data.fee);
toAmount = parseFloat((data.amount * satToUnit).toFixed(unitDecimals));
txFormatService.formatAlternativeStr(data.amount, function(v) {
$scope.alternativeAmountStr = v;
});
$timeout(function() { $timeout(function() {
$scope.$apply(); $scope.$apply();
}); });
@ -120,24 +225,24 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.approve(); $scope.approve();
}); });
$scope.$on('Wallet/Changed', function(event, wallet) {
if (lodash.isEmpty(wallet)) {
$log.debug('No wallet provided');
return;
}
$log.debug('Wallet changed: ' + wallet.name);
setWallet(wallet, true);
});
$scope.showWalletSelector = function() { $scope.showWalletSelector = function() {
if (!$scope.useSendMax && ($scope.insufficientFunds || $scope.noMatchingWallet)) return;
$scope.showWallets = true; $scope.showWallets = true;
}; };
$scope.onWalletSelect = function(wallet) { $scope.onWalletSelect = function(wallet) {
setWallet(wallet); if ($scope.useSendMax) {
$scope.wallet = wallet;
if (cachedSendMax[wallet.id]) {
$log.debug('Send max cached for wallet:', wallet.id);
setSendMaxValues(cachedSendMax[wallet.id]);
return;
}
$scope.getSendMaxInfo();
} else
setWallet(wallet);
}; };
$scope.showDescriptionPopup = function() { $scope.showDescriptionPopup = function() {
var message = gettextCatalog.getString('Add description'); var message = gettextCatalog.getString('Add description');
var opts = { var opts = {
@ -148,17 +253,17 @@ angular.module('copayApp.controllers').controller('confirmController', function(
if (typeof res != 'undefined') $scope.description = res; if (typeof res != 'undefined') $scope.description = res;
$timeout(function() { $timeout(function() {
$scope.$apply(); $scope.$apply();
}, 100); });
}); });
}; };
function getDisplayAmount(amountStr) { function getDisplayAmount(amountStr) {
return amountStr.split(' ')[0]; return $scope.amountStr.split(' ')[0];
} };
function getDisplayUnit(amountStr) { function getDisplayUnit(amountStr) {
return amountStr.split(' ')[1]; return $scope.amountStr.split(' ')[1];
} };
function _paymentTimeControl(expirationTime) { function _paymentTimeControl(expirationTime) {
$scope.paymentExpired.value = false; $scope.paymentExpired.value = false;
@ -180,7 +285,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
var m = Math.floor(totalSecs / 60); var m = Math.floor(totalSecs / 60);
var s = totalSecs % 60; var s = totalSecs % 60;
$scope.remainingTimeStr.value = ('0' + m).slice(-2) + ":" + ('0' + s).slice(-2); $scope.remainingTimeStr.value = ('0' + m).slice(-2) + ":" + ('0' + s).slice(-2);
} };
function setExpiredValues() { function setExpiredValues() {
$scope.paymentExpired.value = true; $scope.paymentExpired.value = true;
@ -189,19 +294,14 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$timeout(function() { $timeout(function() {
$scope.$apply(); $scope.$apply();
}); });
} };
} };
function setWallet(wallet, delayed) { function setWallet(wallet, delayed) {
var stop; var stop;
$scope.wallet = wallet; $scope.wallet = wallet;
$scope.fee = $scope.txp = null; $scope.fee = $scope.txp = null;
$timeout(function() {
$ionicScrollDelegate.resize();
$scope.$apply();
}, 10);
if (stop) { if (stop) {
$timeout.cancel(stop); $timeout.cancel(stop);
stop = null; stop = null;
@ -218,31 +318,37 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}); });
}, delayed ? 2000 : 1); }, delayed ? 2000 : 1);
} }
}
$timeout(function() {
$ionicScrollDelegate.resize();
$scope.$apply();
}, 10);
};
var setSendError = function(msg) { var setSendError = function(msg) {
$scope.sendStatus = ''; $scope.sendStatus = '';
$timeout(function() { $timeout(function() {
$scope.$apply(); $scope.$apply();
}); });
popupService.showAlert(gettextCatalog.getString('Error at confirm:'), msg); popupService.showAlert(gettextCatalog.getString('Error at confirm'), msg);
}; };
function apply(txp) { function apply(txp) {
$scope.fee = txFormatService.formatAmountStr(txp.fee); $scope.fee = txFormatService.formatAmountStr(txp.fee);
$scope.txp = txp; $scope.txp = txp;
$scope.$apply(); $timeout(function() {
} $scope.$apply();
});
};
var createTx = function(wallet, dryRun, cb) { var createTx = function(wallet, dryRun, cb) {
var config = configService.getSync().wallet; var config = configService.getSync().wallet;
var currentSpendUnconfirmed = config.spendUnconfirmed; var currentSpendUnconfirmed = config.spendUnconfirmed;
var outputs = [];
var paypro = $scope.paypro; var paypro = $scope.paypro;
var toAddress = $scope.toAddress; var toAddress = $scope.toAddress;
var toAmount = $scope.toAmount;
var description = $scope.description; var description = $scope.description;
var unitToSatoshi = config.settings.unitToSatoshi;
var unitDecimals = config.settings.unitDecimals;
// ToDo: use a credential's (or fc's) function for this // ToDo: use a credential's (or fc's) function for this
if (description && !wallet.credentials.sharedEncryptingKey) { if (description && !wallet.credentials.sharedEncryptingKey) {
@ -257,28 +363,30 @@ angular.module('copayApp.controllers').controller('confirmController', function(
return setSendError(msg); return setSendError(msg);
} }
outputs.push({
'toAddress': toAddress,
'amount': toAmount,
'message': description
});
var txp = {}; var txp = {};
var amount;
// TODO if ($scope.useSendMax) amount = parseFloat((toAmount * unitToSatoshi).toFixed(0));
if (!lodash.isEmpty($scope.sendMaxInfo)) { else amount = toAmount;
txp.sendMax = true;
txp.outputs = [{
'toAddress': toAddress,
'amount': amount,
'message': description
}];
if ($scope.sendMaxInfo) {
txp.inputs = $scope.sendMaxInfo.inputs; txp.inputs = $scope.sendMaxInfo.inputs;
txp.fee = $scope.sendMaxInfo.fee; txp.fee = $scope.sendMaxInfo.fee;
} } else
txp.feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal';
txp.outputs = outputs;
txp.message = description; txp.message = description;
if(paypro) {
if (paypro) {
txp.payProUrl = paypro.url; txp.payProUrl = paypro.url;
} }
txp.excludeUnconfirmedUtxos = config.spendUnconfirmed ? false : true; txp.excludeUnconfirmedUtxos = !currentSpendUnconfirmed;
txp.feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal';
txp.dryRun = dryRun; txp.dryRun = dryRun;
walletService.createTx(wallet, txp, function(err, ctxp) { walletService.createTx(wallet, txp, function(err, ctxp) {
@ -300,7 +408,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}; };
$scope.approve = function(onSendStatusChange) { $scope.approve = function(onSendStatusChange) {
if ($scope.paypro && $scope.paymentExpired.value) { if ($scope.paypro && $scope.paymentExpired.value) {
popupService.showAlert(null, gettextCatalog.getString('This bitcoin payment request has expired.')); popupService.showAlert(null, gettextCatalog.getString('This bitcoin payment request has expired.'));
$scope.sendStatus = ''; $scope.sendStatus = '';
@ -375,7 +482,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
} else if (showName) { } else if (showName) {
$scope.sendStatus = showName; $scope.sendStatus = showName;
} }
} };
$scope.statusChangeHandler = statusChangeHandler; $scope.statusChangeHandler = statusChangeHandler;

View file

@ -60,7 +60,7 @@ angular.module('copayApp.controllers').controller('paperWalletController',
$scope.wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, null, function(err, testTx) { $scope.wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, null, function(err, testTx) {
if (err) return cb(err); if (err) return cb(err);
var rawTxLength = testTx.serialize().length; var rawTxLength = testTx.serialize().length;
feeService.getCurrentFeeValue($scope.wallet, function(err, feePerKB) { feeService.getCurrentFeeValue('livenet', function(err, feePerKB) {
var opts = {}; var opts = {};
opts.fee = Math.round((feePerKB * rawTxLength) / 2000); opts.fee = Math.round((feePerKB * rawTxLength) / 2000);
$scope.wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, opts, function(err, tx) { $scope.wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, opts, function(err, tx) {

View file

@ -1,10 +1,14 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('preferencesFeeController', function($scope, $timeout, $ionicHistory, gettextCatalog, configService, feeService, ongoingProcess) { angular.module('copayApp.controllers').controller('preferencesFeeController', function($scope, $timeout, $ionicHistory, gettextCatalog, configService, feeService, ongoingProcess, popupService) {
ongoingProcess.set('gettingFeeLevels', true); ongoingProcess.set('gettingFeeLevels', true);
feeService.getFeeLevels(function(levels) { feeService.getFeeLevels(function(err, levels) {
ongoingProcess.set('gettingFeeLevels', false); ongoingProcess.set('gettingFeeLevels', false);
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
return;
}
$scope.feeLevels = levels; $scope.feeLevels = levels;
$scope.$apply(); $scope.$apply();
}); });

View file

@ -286,7 +286,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
} }
}) })
.state('tabs.send.confirm', { .state('tabs.send.confirm', {
url: '/confirm/:isWallet/:toAddress/:toName/:toAmount/:toEmail/:description', url: '/confirm/:isWallet/:toAddress/:toName/:toAmount/:toEmail/:description/:useSendMax',
views: { views: {
'tab-send@tabs': { 'tab-send@tabs': {
controller: 'confirmController', controller: 'confirmController',

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.services').factory('feeService', function($log, $stateParams, bwcService, walletService, configService, gettext, lodash, txFormatService) { angular.module('copayApp.services').factory('feeService', function($log, $stateParams, bwcService, walletService, configService, gettext, lodash, txFormatService, gettextCatalog) {
var root = {}; var root = {};
// Constant fee options to translate // Constant fee options to translate
@ -15,45 +15,48 @@ angular.module('copayApp.services').factory('feeService', function($log, $stateP
return configService.getSync().wallet.settings.feeLevel || 'normal'; return configService.getSync().wallet.settings.feeLevel || 'normal';
}; };
root.getCurrentFeeValue = function(wallet, cb) { root.getCurrentFeeValue = function(network, cb) {
network = network || 'livenet';
var feeLevel = root.getCurrentFeeLevel(); var feeLevel = root.getCurrentFeeLevel();
wallet.getFeeLevels(wallet.credentials.network, function(err, levels) { root.getFeeLevels(function(err, levels) {
if (err) if (err) return cb(err);
return cb({
message: 'Could not get dynamic fee'
});
var feeLevelValue = lodash.find(levels, { var feeLevelValue = lodash.find(levels[network], {
level: feeLevel level: feeLevel
}); });
if (!feeLevelValue || feeLevelValue.feePerKB == null)
if (!feeLevelValue || !feeLevelValue.feePerKB) {
return cb({ return cb({
message: 'Could not get dynamic fee for level: ' + feeLevel message: gettextCatalog.getString("Could not get dynamic fee for level: {{feeLevel}}", {
feeLevel: feeLevel
})
}); });
}
var fee = feeLevelValue.feePerKB; var fee = feeLevelValue.feePerKB;
$log.debug('Dynamic fee: ' + feeLevel + ' ' + fee + ' SAT'); $log.debug('Dynamic fee: ' + feeLevel + ' ' + fee + ' SAT');
return cb(null, fee); return cb(null, fee);
}); });
}; };
root.getFeeLevels = function(cb) { root.getFeeLevels = function(cb) {
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
var unitName = configService.getSync().wallet.settings.unitName; var unitName = configService.getSync().wallet.settings.unitName;
walletClient.getFeeLevels('livenet', function(errLivenet, levelsLivenet) { walletClient.getFeeLevels('livenet', function(errLivenet, levelsLivenet) {
walletClient.getFeeLevels('testnet', function(errTestnet, levelsTestnet) { walletClient.getFeeLevels('testnet', function(errTestnet, levelsTestnet) {
if (errLivenet || errTestnet) $log.debug('Could not get dynamic fee'); if (errLivenet || errTestnet) {
else { return cb(gettextCatalog.getString('Could not get dynamic fee'));
} else {
for (var i = 0; i < 4; i++) { for (var i = 0; i < 4; i++) {
levelsLivenet[i]['feePerKBUnit'] = txFormatService.formatAmount(levelsLivenet[i].feePerKB) + ' ' + unitName; levelsLivenet[i]['feePerKBUnit'] = txFormatService.formatAmount(levelsLivenet[i].feePerKB) + ' ' + unitName;
levelsTestnet[i]['feePerKBUnit'] = txFormatService.formatAmount(levelsTestnet[i].feePerKB) + ' ' + unitName; levelsTestnet[i]['feePerKBUnit'] = txFormatService.formatAmount(levelsTestnet[i].feePerKB) + ' ' + unitName;
} }
} }
return cb({ return cb(null, {
'livenet': levelsLivenet, 'livenet': levelsLivenet,
'testnet': levelsTestnet 'testnet': levelsTestnet
}); });

View file

@ -25,7 +25,7 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti
'recreating': gettext('Recreating Wallet...'), 'recreating': gettext('Recreating Wallet...'),
'rejectTx': gettext('Rejecting payment proposal'), 'rejectTx': gettext('Rejecting payment proposal'),
'removeTx': gettext('Deleting payment proposal'), 'removeTx': gettext('Deleting payment proposal'),
'retrivingInputs': gettext('Retrieving inputs information'), 'retrievingInputs': gettext('Retrieving inputs information'),
'scanning': gettext('Scanning Wallet funds...'), 'scanning': gettext('Scanning Wallet funds...'),
'sendingTx': gettext('Sending transaction'), 'sendingTx': gettext('Sending transaction'),
'signingTx': gettext('Signing transaction'), 'signingTx': gettext('Signing transaction'),

View file

@ -562,20 +562,13 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
if (lodash.isEmpty(txp) || lodash.isEmpty(wallet)) if (lodash.isEmpty(txp) || lodash.isEmpty(wallet))
return cb('MISSING_PARAMETER'); return cb('MISSING_PARAMETER');
if (txp.sendMax) { wallet.createTxProposal(txp, function(err, createdTxp) {
wallet.createTxProposal(txp, function(err, createdTxp) { if (err) return cb(err);
if (err) return cb(err); else {
else return cb(null, createdTxp); $log.debug('Transaction created');
}); return cb(null, createdTxp);
} else { }
wallet.createTxProposal(txp, function(err, createdTxp) { });
if (err) return cb(err);
else {
$log.debug('Transaction created');
return cb(null, createdTxp);
}
});
}
}; };
root.publishTx = function(wallet, txp, cb) { root.publishTx = function(wallet, txp, cb) {
@ -1083,6 +1076,12 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
return type; return type;
}; };
root.getSendMaxInfo = function(wallet, opts, cb) {
opts = opts || {};
wallet.getSendMaxInfo(opts, function(err, res) {
return cb(err, res);
});
};
return root; return root;
}); });

View file

@ -1,17 +1,32 @@
#tab-send { #tab-send {
@extend .deflash-blue; @extend .deflash-blue;
.qr-scan-icon a { .input {
z-index: 10; input {
display: block; width: 100%;
position: absolute; height: auto;
top: 55px; }
right: 0; &.item {
padding: 0 10px; height: 55px;
font-size: 24px; }
i {
&.left {
padding-left: 15px;
}
&.qr {
cursor: pointer;
cursor: hand;
padding-right: 5px;
}
}
}
.qr-scan-icon {
cursor: pointer; cursor: pointer;
cursor: hand;
border-left: 1px solid rgb(228, 228, 228);
padding-left: 10px;
} }
.qr-icon { .qr-icon {
line-height: 45px; line-height: 20px;
} }
.zero-state-cta { .zero-state-cta {
padding-bottom: 3vh; padding-bottom: 3vh;

24
www/img/scan-ico.svg Normal file
View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="25px" height="15px" viewBox="0 0 25 15" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 41 (35326) - http://www.bohemiancoding.com/sketch -->
<title>scan-ico</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" stroke-linecap="round" opacity="0.5">
<g id="Send---initial" transform="translate(-326.000000, -139.000000)" stroke-width="1.5" stroke="#4A4A4A">
<g id="Send-to-(Field)" transform="translate(0.000000, 70.000000)">
<g id="scan-ico" transform="translate(326.000000, 68.000000)">
<g id="Icons/Tabs/Scan" transform="translate(0.233333, 0.551724)">
<g id="Scan">
<path d="M8.01713862,1.23032704 L4.65481836,1.23032704 M4.40485821,1.23032704 L4.40485821,4.48620728" id="Line-Copy-2" stroke-linejoin="round"></path>
<path d="M16.3666389,1.23032704 L19.7289592,1.23032704 M19.9789194,1.23032704 L19.9789194,4.48620728" id="Line-Copy-3" stroke-linejoin="round"></path>
<path d="M8.01713862,14.3286527 L4.65481836,14.3286527 M4.40485821,14.3286527 L4.40485821,11.0727724" id="Line-Copy-5" stroke-linejoin="round"></path>
<path d="M16.3666389,14.3286527 L19.7289592,14.3286527 M19.9789194,14.3286527 L19.9789194,11.0727724" id="Line-Copy-4" stroke-linejoin="round"></path>
<path d="M0.559999983,7.67196401 L23.8933334,7.67196401" id="Line"></path>
</g>
</g>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

@ -5,6 +5,11 @@
</ion-nav-title> </ion-nav-title>
<ion-nav-back-button> <ion-nav-back-button>
</ion-nav-back-button> </ion-nav-back-button>
<ion-nav-buttons side="secondary">
<button class="button back-button" ng-click="showSendMaxMenu($event)" ng-if="showMenu">
<i class="icon ion-ios-more"></i>
</button>
</ion-nav-buttons>
</ion-nav-bar> </ion-nav-bar>
<ion-content scroll="false"> <ion-content scroll="false">

View file

@ -7,16 +7,17 @@
</ion-nav-back-button> </ion-nav-back-button>
</ion-nav-bar> </ion-nav-bar>
<ion-content ng-class="{'add-bottom-for-cta': !insuffientFunds && !noMatchingWallet}"> <ion-content ng-class="{'add-bottom-for-cta': !insufficientFunds && !noMatchingWallet}">
<div class="list"> <div class="list">
<div class="item head"> <div class="item head">
<div class="sending-label"> <div class="sending-label">
<img src="img/icon-tx-sent-outline.svg"> <img src="img/icon-tx-sent-outline.svg">
<span translate>Sending</span> <span translate ng-if="!useSendMax">Sending</span>
<span translate ng-if="useSendMax">Sending maximum amount</span>
</div> </div>
<div class="amount-label"> <div class="amount-label">
<div class="amount">{{displayAmount}} <span class="unit">{{displayUnit}}</span></div> <div class="amount">{{displayAmount || '...'}} <span class="unit">{{displayUnit}}</span></div>
<div class="alternative">{{alternativeAmountStr}}</div> <div class="alternative">{{alternativeAmountStr || '...'}}</div>
</div> </div>
</div> </div>
<div class="info"> <div class="info">
@ -49,13 +50,7 @@
<span ng-if="tx.hasMultiplesOutputs" translate>Multiple recipients</span> --> <span ng-if="tx.hasMultiplesOutputs" translate>Multiple recipients</span> -->
</span> </span>
</div> </div>
<div class="text-center" ng-show="noMatchingWallet"> <a class="item item-icon-right" ng-hide="!useSendMax && (insufficientFunds || noMatchingWallet)" ng-click="showWalletSelector()">
<span class="badge badge-energized" translate>No wallets available</span>
</div>
<div class="text-center" ng-show="insuffientFunds">
<span class="badge badge-energized" translate>Insufficient funds</span>
</div>
<a class="item item-icon-right" ng-hide="insuffientFunds || noMatchingWallet" ng-click="showWalletSelector()">
<span class="label" translate>From</span> <span class="label" translate>From</span>
<div class="wallet"> <div class="wallet">
<i class="icon big-icon-svg"> <i class="icon big-icon-svg">
@ -65,30 +60,36 @@
</div> </div>
<i class="icon bp-arrow-right"></i> <i class="icon bp-arrow-right"></i>
</a> </a>
<a class="item single-line item-icon-right" ng-hide="insuffientFunds || noMatchingWallet" ng-click="showDescriptionPopup()"> <a class="item single-line item-icon-right" ng-if="!insufficientFunds && !noMatchingWallet" ng-click="showDescriptionPopup()">
<span class="label" translate>Add Memo</span> <span class="label" translate>Add Memo</span>
<span class="item-note m10l"> <span class="item-note m10l">
{{description}} {{description}}
</span> </span>
<i class="icon bp-arrow-right"></i> <i class="icon bp-arrow-right"></i>
</a> </a>
<div class="item single-line" ng-hide="insuffientFunds || noMatchingWallet"> <div class="item single-line" ng-if="!insufficientFunds && !noMatchingWallet">
<span class="label" translate>Fee: {{feeLevel}}</span> <span class="label" translate>Fee: {{feeLevel}}</span>
<span class="item-note"> <span class="item-note">
{{fee || '...'}} {{fee || '...'}}
</span> </span>
</div> </div>
<div class="text-center" ng-show="noMatchingWallet">
<span class="badge badge-energized" translate>No wallets available</span>
</div>
<div class="text-center" ng-show="insufficientFunds">
<span class="badge badge-energized" translate>Insufficient funds</span>
</div>
</div> </div>
</div> </div>
</ion-content> </ion-content>
<click-to-accept <click-to-accept
ng-click="approve(statusChangeHandler)" ng-click="approve(statusChangeHandler)"
ng-if="!isCordova && wallets[0]" ng-if="!isCordova && wallets[0] && !insufficientFunds && !noMatchingWallet"
click-send-status="sendStatus"> click-send-status="sendStatus">
Click to pay Click to pay
</click-to-accept> </click-to-accept>
<slide-to-accept <slide-to-accept
ng-if="isCordova && wallets[0]" ng-if="isCordova && wallets[0] && !insufficientFunds && !noMatchingWallet"
slide-on-confirm="onConfirm()" slide-on-confirm="onConfirm()"
slide-send-status="sendStatus"> slide-send-status="sendStatus">
Slide to pay Slide to pay

View file

@ -18,19 +18,15 @@
</div> </div>
</div> </div>
</div> </div>
<div ng-if="hasFunds" class="has-funds"> <div ng-if="hasFunds">
<div class="item item-heading send-heading" translate>Recipient</div> <div class="item item-heading send-heading" translate>Recipient</div>
<div>
<label class="item item-input bitcoin-address"> <div class="item item-icon-left item-icon-right input">
<i class="icon icon-svg placeholder-icon"><img src="img/icon-bitcoin-symbol.svg"></i> <i class="icon icon-svg left"><img src="img/icon-bitcoin-symbol.svg"></i>
<input type="text" placeholder="{{'Search or enter bitcoin address' | translate}}" ng-model="formData.search" ng-change="findContact(formData.search)" ng-model-onblur> <input type="text" placeholder="{{'Search or enter bitcoin address' | translate}}" ng-model="formData.search" ng-change="findContact(formData.search)" ng-model-onblur>
</label> <i class="icon icon-svg qr" on-tap="openScanner()"><img src="img/scan-ico.svg"/></i>
<div class="qr-scan-icon">
<a on-tap="openScanner()" ng-style="{'top': '55px'}">
<i class="icon ion-qr-scanner"></i>
</a>
</div>
</div> </div>
<div class="card"> <div class="card">
<div class="item item-icon-right item-heading"> <div class="item item-icon-right item-heading">
<span translate>Contacts</span> <span translate>Contacts</span>