Enable SendMax to top up debit card

This commit is contained in:
Gustavo Maximiliano Cortez 2017-04-16 22:23:20 -03:00
commit 28ef9a22dc
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
5 changed files with 81 additions and 15 deletions

View 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,
});
});
});
};
});

View file

@ -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;
});