mirror of https://github.com/BTCPrivate/copay.git
Enable SendMax to top up debit card
This commit is contained in:
parent
c9bad23b20
commit
28ef9a22dc
|
@ -22,7 +22,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
$scope.currency = data.stateParams.currency;
|
||||
$scope.forceCurrency = data.stateParams.forceCurrency;
|
||||
|
||||
$scope.showMenu = $ionicHistory.backView() && $ionicHistory.backView().stateName == 'tabs.send';
|
||||
$scope.showMenu = $ionicHistory.backView() && ($ionicHistory.backView().stateName == 'tabs.send' ||
|
||||
$ionicHistory.backView().stateName == 'tabs.bitpayCard');
|
||||
$scope.recipientType = data.stateParams.recipientType || null;
|
||||
$scope.toAddress = data.stateParams.toAddress;
|
||||
$scope.toName = data.stateParams.toName;
|
||||
|
@ -111,15 +112,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
|
||||
$scope.sendMax = function() {
|
||||
$scope.showSendMax = false;
|
||||
$state.transitionTo('tabs.send.confirm', {
|
||||
recipientType: $scope.recipientType,
|
||||
toAmount: null,
|
||||
toAddress: $scope.toAddress,
|
||||
toName: $scope.toName,
|
||||
toEmail: $scope.toEmail,
|
||||
toColor: $scope.toColor,
|
||||
useSendMax: true,
|
||||
});
|
||||
$scope.useSendMax = true;
|
||||
$scope.finish();
|
||||
};
|
||||
|
||||
$scope.toggleAlternative = function() {
|
||||
|
@ -234,8 +228,9 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
if ($scope.nextStep) {
|
||||
$state.transitionTo($scope.nextStep, {
|
||||
id: _cardId,
|
||||
amount: _amount,
|
||||
currency: $scope.showAlternativeAmount ? $scope.alternativeIsoCode : $scope.unitName
|
||||
amount: $scope.useSendMax ? null : _amount,
|
||||
currency: $scope.showAlternativeAmount ? $scope.alternativeIsoCode : $scope.unitName,
|
||||
useSendMax: $scope.useSendMax
|
||||
});
|
||||
} else {
|
||||
var amount = $scope.showAlternativeAmount ? fromFiat(_amount) : _amount;
|
||||
|
@ -247,11 +242,12 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
|||
} else {
|
||||
$state.transitionTo('tabs.send.confirm', {
|
||||
recipientType: $scope.recipientType,
|
||||
toAmount: (amount * unitToSatoshi).toFixed(0),
|
||||
toAmount: $scope.useSendMax ? null : (amount * unitToSatoshi).toFixed(0),
|
||||
toAddress: $scope.toAddress,
|
||||
toName: $scope.toName,
|
||||
toEmail: $scope.toEmail,
|
||||
toColor: $scope.toColor,
|
||||
useSendMax: $scope.useSendMax
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('topUpController', function($scope, $log, $state, $timeout, $ionicHistory, lodash, popupService, profileService, ongoingProcess, walletService, configService, platformInfo, bitpayService, bitpayCardService, payproService, bwcError, txFormatService) {
|
||||
angular.module('copayApp.controllers').controller('topUpController', function($scope, $log, $state, $timeout, $ionicHistory, lodash, popupService, profileService, ongoingProcess, walletService, configService, platformInfo, bitpayService, bitpayCardService, payproService, bwcError, txFormatService, sendMaxService) {
|
||||
|
||||
var amount;
|
||||
var currency;
|
||||
var cardId;
|
||||
var sendMax;
|
||||
|
||||
$scope.isCordova = platformInfo.isCordova;
|
||||
|
||||
|
@ -51,6 +52,7 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
|||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
cardId = data.stateParams.id;
|
||||
sendMax = data.stateParams.useSendMax;
|
||||
|
||||
if (!cardId) {
|
||||
showErrorAndBack('No card selected');
|
||||
|
@ -188,6 +190,29 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
|||
|
||||
$scope.onWalletSelect = function(wallet) {
|
||||
$scope.wallet = wallet;
|
||||
if (sendMax) {
|
||||
ongoingProcess.set('retrievingInputs', true);
|
||||
sendMaxService.getInfo($scope.wallet, function(err, values) {
|
||||
ongoingProcess.set('retrievingInputs', false);
|
||||
if (err) {
|
||||
showErrorAndBack(err);
|
||||
return;
|
||||
}
|
||||
var config = configService.getSync().wallet.settings;
|
||||
var unitName = config.unitName;
|
||||
var amountUnit = txFormatService.satToUnit(values.amount);
|
||||
var parsedAmount = txFormatService.parseAmount(
|
||||
amountUnit,
|
||||
unitName);
|
||||
|
||||
amount = parsedAmount.amount;
|
||||
currency = parsedAmount.currency;
|
||||
$scope.amountUnitStr = parsedAmount.amountUnitStr;
|
||||
$timeout(function() {
|
||||
$scope.$digest();
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.goBackHome = function() {
|
||||
|
|
|
@ -1103,7 +1103,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
},
|
||||
params: {
|
||||
id: null,
|
||||
currency: 'USD'
|
||||
currency: 'USD',
|
||||
useSendMax: null
|
||||
}
|
||||
})
|
||||
.state('tabs.bitpayCard.amount', {
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').service('sendMaxService', function(feeService, configService, walletService) {
|
||||
|
||||
/**
|
||||
* Get sendMaxInfo
|
||||
*
|
||||
* @param {Obj} Wallet
|
||||
* @param {Callback} Function (optional)
|
||||
*
|
||||
*/
|
||||
this.getInfo = function(wallet, cb) {
|
||||
feeService.getCurrentFeeValue(wallet.credentials.network, function(err, feePerKb) {
|
||||
if (err) return cb(err);
|
||||
|
||||
var config = configService.getSync().wallet;
|
||||
|
||||
walletService.getSendMaxInfo(wallet, {
|
||||
feePerKb: feePerKb,
|
||||
excludeUnconfirmedUtxos: !config.spendUnconfirmed,
|
||||
returnInputs: true,
|
||||
}, function(err, resp) {
|
||||
if (err) return cb(err);
|
||||
|
||||
return cb(null, {
|
||||
sendMax: true,
|
||||
amount: resp.amount,
|
||||
inputs: resp.inputs,
|
||||
fee: resp.fee,
|
||||
feePerKb: feePerKb,
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
});
|
|
@ -184,5 +184,13 @@ angular.module('copayApp.services').factory('txFormatService', function($filter,
|
|||
};
|
||||
};
|
||||
|
||||
root.satToUnit = function(amount) {
|
||||
var config = configService.getSync().wallet.settings;
|
||||
var unitToSatoshi = config.unitToSatoshi;
|
||||
var satToUnit = 1 / unitToSatoshi;
|
||||
var unitDecimals = config.unitDecimals;
|
||||
return parseFloat((amount * satToUnit).toFixed(unitDecimals));
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue