Skip to content

Commit

Permalink
Allow payments below max inbound liquidity when LSP does not support …
Browse files Browse the repository at this point in the history
…channel openings
  • Loading branch information
erdemyerebasmaz committed Aug 9, 2023
1 parent dd6c4ef commit beba3f7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/bloc/account/account_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
(amount > accState.maxInboundLiquidity && amount <= channelMinimumFee)) {
throw PaymentBelowSetupFeesError(channelMinimumFee);
}
if (amount > accState.maxInboundLiquidity) {
throw PaymentExceedLiquidityError(accState.maxInboundLiquidity);
}
if (amount > accState.maxAllowedToReceive) {
throw PaymentExceededLimitError(accState.maxAllowedToReceive);
}
Expand Down
8 changes: 8 additions & 0 deletions lib/bloc/account/payment_error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ class PaymentBelowSetupFeesError implements Exception {
this.setupFees,
);
}

class PaymentExceedLiquidityError implements Exception {
final int limitSat;

const PaymentExceedLiquidityError(
this.limitSat,
);
}
2 changes: 1 addition & 1 deletion lib/routes/create_invoice/create_invoice_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class CreateInvoicePageState extends State<CreateInvoicePage> {
String? validatePayment(BuildContext context, int amount) {
final lspInfo = context.read<LSPBloc>().state?.lspInfo;
int? channelMinimumFee =
lspInfo != null ? lspInfo.openingFeeParamsList.values.first.minMsat ~/ 1000 : null;
lspInfo != null && lspInfo.openingFeeParamsList.values.isNotEmpty ? lspInfo.openingFeeParamsList.values.first.minMsat ~/ 1000 : null;

return PaymentValidator(
validatePayment: _validatePayment,
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/payment_validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class PaymentValidator {
return texts.invoice_payment_validator_error_payment_below_limit(
currency.format(e.reserveAmount),
);
} on PaymentExceedLiquidityError catch (e) {
// TODO: Add translation
return "Insufficient inbound liquidity (${currency.format(e.limitSat)})";
} on InsufficientLocalBalanceError {
return texts.invoice_payment_validator_error_insufficient_local_balance;
} on PaymentBelowSetupFeesError catch (e) {
Expand Down

0 comments on commit beba3f7

Please sign in to comment.