Merge pull request #5890 from cmgustavo/feat/improves-top-up

Feat/Enable SendMax
This commit is contained in:
Gabriel Edgardo Bazán 2017-04-17 19:34:56 +02:00 committed by GitHub
commit bfe12f7e32
5 changed files with 82 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;
});