Enable SendMax to top up debit card
This commit is contained in:
parent
c9bad23b20
commit
28ef9a22dc
5 changed files with 81 additions and 15 deletions
|
|
@ -22,7 +22,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
$scope.currency = data.stateParams.currency;
|
$scope.currency = data.stateParams.currency;
|
||||||
$scope.forceCurrency = data.stateParams.forceCurrency;
|
$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.recipientType = data.stateParams.recipientType || null;
|
||||||
$scope.toAddress = data.stateParams.toAddress;
|
$scope.toAddress = data.stateParams.toAddress;
|
||||||
$scope.toName = data.stateParams.toName;
|
$scope.toName = data.stateParams.toName;
|
||||||
|
|
@ -111,15 +112,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
|
|
||||||
$scope.sendMax = function() {
|
$scope.sendMax = function() {
|
||||||
$scope.showSendMax = false;
|
$scope.showSendMax = false;
|
||||||
$state.transitionTo('tabs.send.confirm', {
|
$scope.useSendMax = true;
|
||||||
recipientType: $scope.recipientType,
|
$scope.finish();
|
||||||
toAmount: null,
|
|
||||||
toAddress: $scope.toAddress,
|
|
||||||
toName: $scope.toName,
|
|
||||||
toEmail: $scope.toEmail,
|
|
||||||
toColor: $scope.toColor,
|
|
||||||
useSendMax: true,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.toggleAlternative = function() {
|
$scope.toggleAlternative = function() {
|
||||||
|
|
@ -234,8 +228,9 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
if ($scope.nextStep) {
|
if ($scope.nextStep) {
|
||||||
$state.transitionTo($scope.nextStep, {
|
$state.transitionTo($scope.nextStep, {
|
||||||
id: _cardId,
|
id: _cardId,
|
||||||
amount: _amount,
|
amount: $scope.useSendMax ? null : _amount,
|
||||||
currency: $scope.showAlternativeAmount ? $scope.alternativeIsoCode : $scope.unitName
|
currency: $scope.showAlternativeAmount ? $scope.alternativeIsoCode : $scope.unitName,
|
||||||
|
useSendMax: $scope.useSendMax
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var amount = $scope.showAlternativeAmount ? fromFiat(_amount) : _amount;
|
var amount = $scope.showAlternativeAmount ? fromFiat(_amount) : _amount;
|
||||||
|
|
@ -247,11 +242,12 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
} else {
|
} else {
|
||||||
$state.transitionTo('tabs.send.confirm', {
|
$state.transitionTo('tabs.send.confirm', {
|
||||||
recipientType: $scope.recipientType,
|
recipientType: $scope.recipientType,
|
||||||
toAmount: (amount * unitToSatoshi).toFixed(0),
|
toAmount: $scope.useSendMax ? null : (amount * unitToSatoshi).toFixed(0),
|
||||||
toAddress: $scope.toAddress,
|
toAddress: $scope.toAddress,
|
||||||
toName: $scope.toName,
|
toName: $scope.toName,
|
||||||
toEmail: $scope.toEmail,
|
toEmail: $scope.toEmail,
|
||||||
toColor: $scope.toColor,
|
toColor: $scope.toColor,
|
||||||
|
useSendMax: $scope.useSendMax
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
'use strict';
|
'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 amount;
|
||||||
var currency;
|
var currency;
|
||||||
var cardId;
|
var cardId;
|
||||||
|
var sendMax;
|
||||||
|
|
||||||
$scope.isCordova = platformInfo.isCordova;
|
$scope.isCordova = platformInfo.isCordova;
|
||||||
|
|
||||||
|
|
@ -51,6 +52,7 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
||||||
|
|
||||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||||
cardId = data.stateParams.id;
|
cardId = data.stateParams.id;
|
||||||
|
sendMax = data.stateParams.useSendMax;
|
||||||
|
|
||||||
if (!cardId) {
|
if (!cardId) {
|
||||||
showErrorAndBack('No card selected');
|
showErrorAndBack('No card selected');
|
||||||
|
|
@ -188,6 +190,29 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
||||||
|
|
||||||
$scope.onWalletSelect = function(wallet) {
|
$scope.onWalletSelect = function(wallet) {
|
||||||
$scope.wallet = 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() {
|
$scope.goBackHome = function() {
|
||||||
|
|
|
||||||
|
|
@ -1103,7 +1103,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
id: null,
|
id: null,
|
||||||
currency: 'USD'
|
currency: 'USD',
|
||||||
|
useSendMax: null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('tabs.bitpayCard.amount', {
|
.state('tabs.bitpayCard.amount', {
|
||||||
|
|
|
||||||
36
src/js/services/sendMax.js
Normal file
36
src/js/services/sendMax.js
Normal file
|
|
@ -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;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue