commit
1efad56261
13 changed files with 343 additions and 164 deletions
|
|
@ -1,22 +1,21 @@
|
|||
'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 satToUnit;
|
||||
var unitDecimals;
|
||||
var satToBtc;
|
||||
var self = $scope.self;
|
||||
var SMALL_FONT_SIZE_LIMIT = 10;
|
||||
var LENGTH_EXPRESSION_LIMIT = 19;
|
||||
var MENU_ITEM_HEIGHT = 55;
|
||||
|
||||
$scope.$on('$ionicView.leave', function() {
|
||||
angular.element($window).off('keydown');
|
||||
});
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
|
||||
$scope.isGiftCard = data.stateParams.isGiftCard;
|
||||
$scope.showMenu = $ionicHistory.backView().stateName == 'tabs.send';
|
||||
$scope.isWallet = data.stateParams.isWallet;
|
||||
$scope.cardId = data.stateParams.cardId;
|
||||
$scope.toAddress = data.stateParams.toAddress;
|
||||
|
|
@ -52,8 +51,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 10);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
var config = configService.getSync().wallet.settings;
|
||||
|
|
@ -80,6 +78,35 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
}, 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.showAlternativeAmount = !$scope.showAlternativeAmount;
|
||||
|
||||
|
|
@ -124,7 +151,6 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
|
||||
function isExpression(val) {
|
||||
var regex = /^\.?\d+(\.?\d+)?([\/\-\+\*x]\d?\.?\d+)+$/;
|
||||
|
||||
return regex.test(val);
|
||||
};
|
||||
|
||||
|
|
@ -137,7 +163,6 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
$scope.resetAmount = function() {
|
||||
$scope.amount = $scope.alternativeResult = $scope.amountResult = $scope.globalResult = '';
|
||||
$scope.allowSend = false;
|
||||
|
||||
checkFontSize();
|
||||
};
|
||||
|
||||
|
|
@ -251,7 +276,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
onlyComplete: true,
|
||||
network: 'livenet',
|
||||
})[0].id;
|
||||
} catch(err) {
|
||||
} catch (err) {
|
||||
ongoingProcess.set('Preparing transaction...', false);
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('No wallet found!'));
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
'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 toAmount;
|
||||
var isChromeApp = platformInfo.isChromeApp;
|
||||
var countDown = null;
|
||||
var giftCardAmountUSD;
|
||||
var giftCardAccessKey;
|
||||
var giftCardInvoiceTime;
|
||||
var giftCardUUID;
|
||||
var cachedSendMax = {};
|
||||
$scope.isCordova = platformInfo.isCordova;
|
||||
$ionicConfig.views.swipeBackEnabled(false);
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
|
||||
// Amazon.com Gift Card parameters
|
||||
$scope.isGiftCard = data.stateParams.isGiftCard;
|
||||
giftCardAmountUSD = data.stateParams.giftCardAmountUSD;
|
||||
|
|
@ -20,97 +21,201 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
giftCardInvoiceTime = data.stateParams.giftCardInvoiceTime;
|
||||
giftCardUUID = data.stateParams.giftCardUUID;
|
||||
|
||||
toAmount = data.stateParams.toAmount;
|
||||
cachedSendMax = {};
|
||||
$scope.useSendMax = data.stateParams.useSendMax == 'true' ? true : false;
|
||||
$scope.isWallet = data.stateParams.isWallet;
|
||||
$scope.cardId = data.stateParams.cardId;
|
||||
$scope.toAmount = data.stateParams.toAmount;
|
||||
$scope.toAddress = data.stateParams.toAddress;
|
||||
$scope.toName = data.stateParams.toName;
|
||||
$scope.toEmail = data.stateParams.toEmail;
|
||||
$scope.description = data.stateParams.description;
|
||||
$scope.paypro = data.stateParams.paypro;
|
||||
$scope.insufficientFunds = false;
|
||||
$scope.noMatchingWallet = false;
|
||||
$scope.paymentExpired = {
|
||||
value: false
|
||||
};
|
||||
$scope.remainingTimeStr = {
|
||||
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;
|
||||
$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);
|
||||
$scope.amountStr = txFormatService.formatAmountStr($scope.toAmount);
|
||||
$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({
|
||||
function setwallets() {
|
||||
$scope.wallets = profileService.getWallets({
|
||||
onlyComplete: true,
|
||||
network: networkName,
|
||||
network: $scope.network,
|
||||
n: $scope.isGiftCard ? true : false
|
||||
});
|
||||
|
||||
if (!wallets || !wallets.length) {
|
||||
if (!$scope.wallets || !$scope.wallets.length) {
|
||||
$scope.noMatchingWallet = true;
|
||||
if ($scope.paypro) {
|
||||
displayValues();
|
||||
}
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var filteredWallets = [];
|
||||
var index = 0;
|
||||
var enoughFunds = false;
|
||||
|
||||
lodash.each(wallets, function(w) {
|
||||
lodash.each($scope.wallets, function(w) {
|
||||
walletService.getStatus(w, {}, function(err, status) {
|
||||
if (err || !status) {
|
||||
$log.error(err);
|
||||
} else {
|
||||
w.status = status;
|
||||
if (!status.availableBalanceSat) $log.debug('No balance available in: ' + w.name);
|
||||
if (status.availableBalanceSat > $scope.toAmount) {
|
||||
if (status.availableBalanceSat > toAmount) {
|
||||
filteredWallets.push(w);
|
||||
enoughFunds = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (++index == wallets.length) {
|
||||
if (++index == $scope.wallets.length) {
|
||||
if (!lodash.isEmpty(filteredWallets)) {
|
||||
$scope.wallets = lodash.clone(filteredWallets);
|
||||
setWallet($scope.wallets[0]);
|
||||
if ($scope.useSendMax) $scope.showWalletSelector();
|
||||
else initConfirm();
|
||||
} else {
|
||||
|
||||
if (!enoughFunds)
|
||||
$scope.insuffientFunds = true;
|
||||
|
||||
if (!enoughFunds) $scope.insufficientFunds = true;
|
||||
$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;
|
||||
});
|
||||
};
|
||||
|
||||
if($scope.paypro) {
|
||||
_paymentTimeControl($scope.paypro.expires);
|
||||
}
|
||||
function resetValues() {
|
||||
$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() {
|
||||
$scope.$apply();
|
||||
});
|
||||
|
|
@ -120,24 +225,24 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
$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() {
|
||||
if (!$scope.useSendMax && ($scope.insufficientFunds || $scope.noMatchingWallet)) return;
|
||||
$scope.showWallets = true;
|
||||
};
|
||||
|
||||
$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() {
|
||||
var message = gettextCatalog.getString('Add description');
|
||||
var opts = {
|
||||
|
|
@ -148,17 +253,17 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
if (typeof res != 'undefined') $scope.description = res;
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function getDisplayAmount(amountStr) {
|
||||
return amountStr.split(' ')[0];
|
||||
}
|
||||
return $scope.amountStr.split(' ')[0];
|
||||
};
|
||||
|
||||
function getDisplayUnit(amountStr) {
|
||||
return amountStr.split(' ')[1];
|
||||
}
|
||||
return $scope.amountStr.split(' ')[1];
|
||||
};
|
||||
|
||||
function _paymentTimeControl(expirationTime) {
|
||||
$scope.paymentExpired.value = false;
|
||||
|
|
@ -180,7 +285,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
var m = Math.floor(totalSecs / 60);
|
||||
var s = totalSecs % 60;
|
||||
$scope.remainingTimeStr.value = ('0' + m).slice(-2) + ":" + ('0' + s).slice(-2);
|
||||
}
|
||||
};
|
||||
|
||||
function setExpiredValues() {
|
||||
$scope.paymentExpired.value = true;
|
||||
|
|
@ -189,19 +294,14 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
function setWallet(wallet, delayed) {
|
||||
var stop;
|
||||
$scope.wallet = wallet;
|
||||
$scope.fee = $scope.txp = null;
|
||||
|
||||
$timeout(function() {
|
||||
$ionicScrollDelegate.resize();
|
||||
$scope.$apply();
|
||||
}, 10);
|
||||
|
||||
if (stop) {
|
||||
$timeout.cancel(stop);
|
||||
stop = null;
|
||||
|
|
@ -218,31 +318,37 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
});
|
||||
}, delayed ? 2000 : 1);
|
||||
}
|
||||
}
|
||||
|
||||
$timeout(function() {
|
||||
$ionicScrollDelegate.resize();
|
||||
$scope.$apply();
|
||||
}, 10);
|
||||
};
|
||||
|
||||
var setSendError = function(msg) {
|
||||
$scope.sendStatus = '';
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
popupService.showAlert(gettextCatalog.getString('Error at confirm:'), msg);
|
||||
popupService.showAlert(gettextCatalog.getString('Error at confirm'), msg);
|
||||
};
|
||||
|
||||
function apply(txp) {
|
||||
$scope.fee = txFormatService.formatAmountStr(txp.fee);
|
||||
$scope.txp = txp;
|
||||
$scope.$apply();
|
||||
}
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
var createTx = function(wallet, dryRun, cb) {
|
||||
var config = configService.getSync().wallet;
|
||||
var currentSpendUnconfirmed = config.spendUnconfirmed;
|
||||
var outputs = [];
|
||||
|
||||
var paypro = $scope.paypro;
|
||||
var toAddress = $scope.toAddress;
|
||||
var toAmount = $scope.toAmount;
|
||||
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
|
||||
if (description && !wallet.credentials.sharedEncryptingKey) {
|
||||
|
|
@ -257,28 +363,30 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
return setSendError(msg);
|
||||
}
|
||||
|
||||
outputs.push({
|
||||
'toAddress': toAddress,
|
||||
'amount': toAmount,
|
||||
'message': description
|
||||
});
|
||||
|
||||
var txp = {};
|
||||
var amount;
|
||||
|
||||
// TODO
|
||||
if (!lodash.isEmpty($scope.sendMaxInfo)) {
|
||||
txp.sendMax = true;
|
||||
if ($scope.useSendMax) amount = parseFloat((toAmount * unitToSatoshi).toFixed(0));
|
||||
else amount = toAmount;
|
||||
|
||||
txp.outputs = [{
|
||||
'toAddress': toAddress,
|
||||
'amount': amount,
|
||||
'message': description
|
||||
}];
|
||||
|
||||
if ($scope.sendMaxInfo) {
|
||||
txp.inputs = $scope.sendMaxInfo.inputs;
|
||||
txp.fee = $scope.sendMaxInfo.fee;
|
||||
}
|
||||
} else
|
||||
txp.feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal';
|
||||
|
||||
txp.outputs = outputs;
|
||||
txp.message = description;
|
||||
if(paypro) {
|
||||
|
||||
if (paypro) {
|
||||
txp.payProUrl = paypro.url;
|
||||
}
|
||||
txp.excludeUnconfirmedUtxos = config.spendUnconfirmed ? false : true;
|
||||
txp.feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal';
|
||||
txp.excludeUnconfirmedUtxos = !currentSpendUnconfirmed;
|
||||
txp.dryRun = dryRun;
|
||||
|
||||
walletService.createTx(wallet, txp, function(err, ctxp) {
|
||||
|
|
@ -300,7 +408,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
};
|
||||
|
||||
$scope.approve = function(onSendStatusChange) {
|
||||
|
||||
if ($scope.paypro && $scope.paymentExpired.value) {
|
||||
popupService.showAlert(null, gettextCatalog.getString('This bitcoin payment request has expired.'));
|
||||
$scope.sendStatus = '';
|
||||
|
|
@ -375,7 +482,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
} else if (showName) {
|
||||
$scope.sendStatus = showName;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.statusChangeHandler = statusChangeHandler;
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ angular.module('copayApp.controllers').controller('paperWalletController',
|
|||
$scope.wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, null, function(err, testTx) {
|
||||
if (err) return cb(err);
|
||||
var rawTxLength = testTx.serialize().length;
|
||||
feeService.getCurrentFeeValue($scope.wallet, function(err, feePerKB) {
|
||||
feeService.getCurrentFeeValue('livenet', function(err, feePerKB) {
|
||||
var opts = {};
|
||||
opts.fee = Math.round((feePerKB * rawTxLength) / 2000);
|
||||
$scope.wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, opts, function(err, tx) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
'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);
|
||||
feeService.getFeeLevels(function(levels) {
|
||||
feeService.getFeeLevels(function(err, levels) {
|
||||
ongoingProcess.set('gettingFeeLevels', false);
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
return;
|
||||
}
|
||||
$scope.feeLevels = levels;
|
||||
$scope.$apply();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
}
|
||||
})
|
||||
.state('tabs.send.confirm', {
|
||||
url: '/confirm/:isWallet/:toAddress/:toName/:toAmount/:toEmail/:description',
|
||||
url: '/confirm/:isWallet/:toAddress/:toName/:toAmount/:toEmail/:description/:useSendMax',
|
||||
views: {
|
||||
'tab-send@tabs': {
|
||||
controller: 'confirmController',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'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 = {};
|
||||
|
||||
// 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';
|
||||
};
|
||||
|
||||
root.getCurrentFeeValue = function(wallet, cb) {
|
||||
root.getCurrentFeeValue = function(network, cb) {
|
||||
network = network || 'livenet';
|
||||
var feeLevel = root.getCurrentFeeLevel();
|
||||
|
||||
wallet.getFeeLevels(wallet.credentials.network, function(err, levels) {
|
||||
if (err)
|
||||
return cb({
|
||||
message: 'Could not get dynamic fee'
|
||||
});
|
||||
root.getFeeLevels(function(err, levels) {
|
||||
if (err) return cb(err);
|
||||
|
||||
var feeLevelValue = lodash.find(levels, {
|
||||
var feeLevelValue = lodash.find(levels[network], {
|
||||
level: feeLevel
|
||||
});
|
||||
if (!feeLevelValue || feeLevelValue.feePerKB == null)
|
||||
|
||||
if (!feeLevelValue || !feeLevelValue.feePerKB) {
|
||||
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;
|
||||
$log.debug('Dynamic fee: ' + feeLevel + ' ' + fee + ' SAT');
|
||||
|
||||
return cb(null, fee);
|
||||
});
|
||||
};
|
||||
|
||||
root.getFeeLevels = function(cb) {
|
||||
var walletClient = bwcService.getClient();
|
||||
|
||||
var unitName = configService.getSync().wallet.settings.unitName;
|
||||
|
||||
walletClient.getFeeLevels('livenet', function(errLivenet, levelsLivenet) {
|
||||
walletClient.getFeeLevels('testnet', function(errTestnet, levelsTestnet) {
|
||||
if (errLivenet || errTestnet) $log.debug('Could not get dynamic fee');
|
||||
else {
|
||||
if (errLivenet || errTestnet) {
|
||||
return cb(gettextCatalog.getString('Could not get dynamic fee'));
|
||||
} else {
|
||||
for (var i = 0; i < 4; i++) {
|
||||
levelsLivenet[i]['feePerKBUnit'] = txFormatService.formatAmount(levelsLivenet[i].feePerKB) + ' ' + unitName;
|
||||
levelsTestnet[i]['feePerKBUnit'] = txFormatService.formatAmount(levelsTestnet[i].feePerKB) + ' ' + unitName;
|
||||
}
|
||||
}
|
||||
|
||||
return cb({
|
||||
return cb(null, {
|
||||
'livenet': levelsLivenet,
|
||||
'testnet': levelsTestnet
|
||||
});
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti
|
|||
'recreating': gettext('Recreating Wallet...'),
|
||||
'rejectTx': gettext('Rejecting payment proposal'),
|
||||
'removeTx': gettext('Deleting payment proposal'),
|
||||
'retrivingInputs': gettext('Retrieving inputs information'),
|
||||
'retrievingInputs': gettext('Retrieving inputs information'),
|
||||
'scanning': gettext('Scanning Wallet funds...'),
|
||||
'sendingTx': gettext('Sending transaction'),
|
||||
'signingTx': gettext('Signing transaction'),
|
||||
|
|
|
|||
|
|
@ -562,20 +562,13 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
if (lodash.isEmpty(txp) || lodash.isEmpty(wallet))
|
||||
return cb('MISSING_PARAMETER');
|
||||
|
||||
if (txp.sendMax) {
|
||||
wallet.createTxProposal(txp, function(err, createdTxp) {
|
||||
if (err) return cb(err);
|
||||
else 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
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) {
|
||||
|
|
@ -1083,6 +1076,12 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
return type;
|
||||
};
|
||||
|
||||
root.getSendMaxInfo = function(wallet, opts, cb) {
|
||||
opts = opts || {};
|
||||
wallet.getSendMaxInfo(opts, function(err, res) {
|
||||
return cb(err, res);
|
||||
});
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,17 +1,32 @@
|
|||
#tab-send {
|
||||
@extend .deflash-blue;
|
||||
.qr-scan-icon a {
|
||||
z-index: 10;
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 55px;
|
||||
right: 0;
|
||||
padding: 0 10px;
|
||||
font-size: 24px;
|
||||
.input {
|
||||
input {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
&.item {
|
||||
height: 55px;
|
||||
}
|
||||
i {
|
||||
&.left {
|
||||
padding-left: 15px;
|
||||
}
|
||||
&.qr {
|
||||
cursor: pointer;
|
||||
cursor: hand;
|
||||
padding-right: 5px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.qr-scan-icon {
|
||||
cursor: pointer;
|
||||
cursor: hand;
|
||||
border-left: 1px solid rgb(228, 228, 228);
|
||||
padding-left: 10px;
|
||||
}
|
||||
.qr-icon {
|
||||
line-height: 45px;
|
||||
line-height: 20px;
|
||||
}
|
||||
.zero-state-cta {
|
||||
padding-bottom: 3vh;
|
||||
|
|
|
|||
24
www/img/scan-ico.svg
Normal file
24
www/img/scan-ico.svg
Normal 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 |
|
|
@ -5,6 +5,11 @@
|
|||
</ion-nav-title>
|
||||
<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-content scroll="false">
|
||||
|
|
|
|||
|
|
@ -7,16 +7,17 @@
|
|||
</ion-nav-back-button>
|
||||
</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="item head">
|
||||
<div class="sending-label">
|
||||
<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 class="amount-label">
|
||||
<div class="amount">{{displayAmount}} <span class="unit">{{displayUnit}}</span></div>
|
||||
<div class="alternative">{{alternativeAmountStr}}</div>
|
||||
<div class="amount">{{displayAmount || '...'}} <span class="unit">{{displayUnit}}</span></div>
|
||||
<div class="alternative">{{alternativeAmountStr || '...'}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="info">
|
||||
|
|
@ -49,13 +50,7 @@
|
|||
<span ng-if="tx.hasMultiplesOutputs" translate>Multiple recipients</span> -->
|
||||
</span>
|
||||
</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="insuffientFunds">
|
||||
<span class="badge badge-energized" translate>Insufficient funds</span>
|
||||
</div>
|
||||
<a class="item item-icon-right" ng-hide="insuffientFunds || noMatchingWallet" ng-click="showWalletSelector()">
|
||||
<a class="item item-icon-right" ng-hide="!useSendMax && (insufficientFunds || noMatchingWallet)" ng-click="showWalletSelector()">
|
||||
<span class="label" translate>From</span>
|
||||
<div class="wallet">
|
||||
<i class="icon big-icon-svg">
|
||||
|
|
@ -65,30 +60,36 @@
|
|||
</div>
|
||||
<i class="icon bp-arrow-right"></i>
|
||||
</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="item-note m10l">
|
||||
{{description}}
|
||||
</span>
|
||||
<i class="icon bp-arrow-right"></i>
|
||||
</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="item-note">
|
||||
{{fee || '...'}}
|
||||
</span>
|
||||
</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>
|
||||
</ion-content>
|
||||
<click-to-accept
|
||||
ng-click="approve(statusChangeHandler)"
|
||||
ng-if="!isCordova && wallets[0]"
|
||||
ng-if="!isCordova && wallets[0] && !insufficientFunds && !noMatchingWallet"
|
||||
click-send-status="sendStatus">
|
||||
Click to pay
|
||||
</click-to-accept>
|
||||
<slide-to-accept
|
||||
ng-if="isCordova && wallets[0]"
|
||||
ng-if="isCordova && wallets[0] && !insufficientFunds && !noMatchingWallet"
|
||||
slide-on-confirm="onConfirm()"
|
||||
slide-send-status="sendStatus">
|
||||
Slide to pay
|
||||
|
|
|
|||
|
|
@ -18,19 +18,15 @@
|
|||
</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>
|
||||
<label class="item item-input bitcoin-address">
|
||||
<i class="icon icon-svg placeholder-icon"><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>
|
||||
</label>
|
||||
<div class="qr-scan-icon">
|
||||
<a on-tap="openScanner()" ng-style="{'top': '55px'}">
|
||||
<i class="icon ion-qr-scanner"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="item item-icon-left item-icon-right input">
|
||||
<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>
|
||||
<i class="icon icon-svg qr" on-tap="openScanner()"><img src="img/scan-ico.svg"/></i>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="item item-icon-right item-heading">
|
||||
<span translate>Contacts</span>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue