wallet-core: also return top-level fee gap estimate

This commit is contained in:
Florian Dold 2023-04-05 11:06:22 +02:00
parent 7090807fcb
commit d5c5c7463e
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 11 additions and 0 deletions

View File

@ -2263,6 +2263,12 @@ export interface PayPeerInsufficientBalanceDetails {
*/
balanceMaterial: AmountString;
/**
* If non-zero, the largest fee gap estimate of an exchange
* where we would otherwise have enough balance available.
*/
feeGapEstimate: AmountString;
perExchange: {
[url: string]: {
balanceAvailable: AmountString;

View File

@ -342,6 +342,8 @@ export async function selectPeerCoins(
const perExchange: PayPeerInsufficientBalanceDetails["perExchange"] = {};
let maxFeeGapEstimate = Amounts.zeroOfCurrency(currency);
for (const exch of exchanges) {
if (exch.detailsPointer?.currency !== currency) {
continue;
@ -361,12 +363,15 @@ export async function selectPeerCoins(
balanceMaterial: Amounts.stringify(infoExchange.balanceMaterial),
feeGapEstimate: Amounts.stringify(gap),
};
maxFeeGapEstimate = Amounts.max(maxFeeGapEstimate, gap);
}
const errDetails: PayPeerInsufficientBalanceDetails = {
amountRequested: Amounts.stringify(instructedAmount),
balanceAvailable: Amounts.stringify(infoGeneral.balanceAvailable),
balanceMaterial: Amounts.stringify(infoGeneral.balanceMaterial),
feeGapEstimate: Amounts.stringify(maxFeeGapEstimate),
perExchange,
};