Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not display LSP cannot open channel message when account is disconnected #646

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration_test/breez_sdk_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:breez_sdk/breez_bridge.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

Expand Down
8 changes: 4 additions & 4 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ PODS:
- FirebaseCoreInternal (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/Logger (~> 7.8)
- FirebaseCoreInternal (10.15.0):
- FirebaseCoreInternal (10.16.0):
- "GoogleUtilities/NSData+zlib (~> 7.8)"
- FirebaseDynamicLinks (10.15.0):
- FirebaseCore (~> 10.0)
- FirebaseInstallations (10.15.0):
- FirebaseInstallations (10.16.0):
- FirebaseCore (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/UserDefaults (~> 7.8)
Expand Down Expand Up @@ -283,9 +283,9 @@ SPEC CHECKSUMS:
firebase_dynamic_links: 52f5d054c676061cf17f4390f3bad9cc964cfdeb
firebase_messaging: 91ec967913a5d144f951b3c3ac17a57796d38735
FirebaseCore: 2cec518b43635f96afe7ac3a9c513e47558abd2e
FirebaseCoreInternal: 2f4bee5ed00301b5e56da0849268797a2dd31fb4
FirebaseCoreInternal: 26233f705cc4531236818a07ac84d20c333e505a
FirebaseDynamicLinks: 206d4ed3efd2b722822598017f3980d9fda89815
FirebaseInstallations: cae95cab0f965ce05b805189de1d4c70b11c76fb
FirebaseInstallations: b822f91a61f7d1ba763e5ccc9d4f2e6f2ed3b3ee
FirebaseMessaging: 0c0ae1eb722ef0c07f7801e5ded8dccd1357d6d4
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_fgbg: 31c0d1140a131daea2d342121808f6aa0dcd879d
Expand Down
2 changes: 1 addition & 1 deletion lib/background/breez_service_initializer.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ignore_for_file: avoid_print
import 'package:bip39/bip39.dart' as bip39;
import 'package:breez_sdk/breez_bridge.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:c_breez/bloc/account/credentials_manager.dart';
import 'package:c_breez/config.dart';
import 'package:c_breez/services/injector.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/account/account_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:async';
import 'dart:io';

import 'package:bip39/bip39.dart' as bip39;
import 'package:breez_sdk/breez_bridge.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart' as sdk;
import 'package:c_breez/bloc/account/account_state.dart';
import 'package:c_breez/bloc/account/credentials_manager.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/backup/backup_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:breez_sdk/breez_bridge.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart' as sdk;
import 'package:c_breez/bloc/backup/backup_state.dart';
import 'package:fimber/fimber.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/buy_bitcoin/moonpay/moonpay_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:breez_sdk/breez_bridge.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart' as sdk;
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:c_breez/bloc/buy_bitcoin/moonpay/moonpay_state.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/currency/currency_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:breez_sdk/breez_bridge.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
import 'package:c_breez/bloc/currency/currency_state.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
Expand Down
11 changes: 5 additions & 6 deletions lib/bloc/fee_options/fee_options_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:breez_sdk/breez_bridge.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:c_breez/bloc/fee_options/fee_option.dart';
Expand All @@ -17,12 +17,11 @@ class FeeOptionsBloc extends Cubit<FeeOptionsState> {
FeeOptionsBloc(this._breezLib) : super(FeeOptionsState.initial());

/// Lookup the most recent reverse swap pair info using the Boltz API
Future<ReverseSwapPairInfo> fetchReverseSwapFees({int? amountSat}) async {
Future<ReverseSwapPairInfo> fetchReverseSwapFees({int? sendAmountSat}) async {
try {
_log.v("Estimate reverse swap fees for: $amountSat");
ReverseSwapPairInfo reverseSwapPairInfo = await _breezLib.fetchReverseSwapFees(
sendAmountSat: amountSat,
);
_log.v("Estimate reverse swap fees for: $sendAmountSat");
final req = ReverseSwapFeesRequest(sendAmountSat: sendAmountSat);
ReverseSwapPairInfo reverseSwapPairInfo = await _breezLib.fetchReverseSwapFees(req: req);
_log.v("Total estimated fees for reverse swap: ${reverseSwapPairInfo.totalEstimatedFees}");
emit(state.copyWith(reverseSwapPairInfo: reverseSwapPairInfo, error: ""));
return reverseSwapPairInfo;
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/input/input_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:breez_sdk/breez_bridge.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
import 'package:c_breez/bloc/input/input_state.dart';
import 'package:c_breez/models/invoice.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/lsp/lsp_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:breez_sdk/breez_bridge.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/lsp/lsp_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class LspState {
LspState({this.lspInfo, this.selectedLspId});

// this returns true if the current LSP supports opening new channels.
bool get isChannelOpeningAvailiable {
bool get isChannelOpeningAvailable {
return (lspInfo != null) ? lspInfo!.openingFeeParamsList.values.isNotEmpty : false;
}
}
2 changes: 1 addition & 1 deletion lib/bloc/refund/refund_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:breez_sdk/breez_bridge.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:c_breez/bloc/refund/refund_state.dart';
import 'package:fimber/fimber.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down
11 changes: 8 additions & 3 deletions lib/bloc/rev_swap_in_progress/rev_swap_in_progress_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:breez_sdk/breez_bridge.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:c_breez/bloc/rev_swap_in_progress/rev_swap_in_progress_state.dart';
import 'package:c_breez/utils/exceptions.dart';
Expand Down Expand Up @@ -29,10 +29,15 @@ class RevSwapsInProgressBloc extends Cubit<RevSwapsInProgressState> {
final texts = getSystemAppLocalizations();
try {
final reverseSwapsInProgress = await _breezLib.inProgressReverseSwaps();
emit(state.copyWith(reverseSwapsInProgress: reverseSwapsInProgress, isLoading: false, error: ""));
for (var revSwapInfo in reverseSwapsInProgress) {
_log.i(
"Reverse Swap ${revSwapInfo.id} to ${revSwapInfo.claimPubkey} for ${revSwapInfo.onchainAmountSat} sats status:${revSwapInfo.status.name}",
);
}
emit(RevSwapsInProgressState(reverseSwapsInProgress: reverseSwapsInProgress));
} catch (e) {
final errorMessage = extractExceptionMessage(e, texts);
emit(state.copyWith(isLoading: false, error: errorMessage));
emit(RevSwapsInProgressState(error: errorMessage));
timer.cancel();
_log.i("reverse swaps in progress polling finished due to error");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class RevSwapsInProgressState {
RevSwapsInProgressState({
this.reverseSwapsInProgress = const [],
this.isLoading = false,
this.error,
this.error = "",
});

RevSwapsInProgressState.initial() : this();
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/reverse_swap/reverse_swap_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:breez_sdk/breez_bridge.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:c_breez/bloc/reverse_swap/reverse_swap_state.dart';
Expand Down
3 changes: 2 additions & 1 deletion lib/bloc/swap_in_progress/swap_in_progress_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:breez_sdk/breez_bridge.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:c_breez/bloc/swap_in_progress/swap_in_progress_state.dart';
Expand Down Expand Up @@ -37,6 +37,7 @@ class SwapInProgressBloc extends Cubit<SwapInProgressState> {
} else {
swapUnused = (await _breezLib.receiveOnchain(reqData: const ReceiveOnchainRequest()));
}
_log.i("swapInProgress: $swapInProgress, swapUnused: $swapUnused");
emit(SwapInProgressState(swapInProgress, swapUnused));
} catch (e) {
final errorMessage = extractExceptionMessage(e, texts);
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/sweep/sweep_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:breez_sdk/breez_bridge.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:c_breez/bloc/sweep/sweep_state.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/config.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:breez_sdk/breez_bridge.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart' as sdk;
import 'package:c_breez/services/injector.dart';
import 'package:fimber/fimber.dart';
Expand Down
18 changes: 8 additions & 10 deletions lib/routes/create_invoice/create_invoice_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,21 @@ class CreateInvoicePageState extends State<CreateInvoicePage> {
builder: (context, accountState, currencyState, lspState) {
return ReceivableBTCBox(
onTap: () {
if (lspState != null &&
!lspState.isChannelOpeningAvailiable &&
accountState.maxInboundLiquidity > 0) {
final isChannelOpeningAvailable = lspState?.isChannelOpeningAvailable ?? false;
if (!isChannelOpeningAvailable && accountState.maxInboundLiquidity > 0) {
_amountController.text = currencyState.bitcoinCurrency.format(
accountState.maxInboundLiquidity,
includeDisplayName: false,
userInput: true,
);
} else if (lspState != null &&
!lspState.isChannelOpeningAvailiable &&
accountState.maxInboundLiquidity == 0) {
} else if (!isChannelOpeningAvailable && accountState.maxInboundLiquidity == 0) {
// do nothing
} else {
_amountController.text = currencyState.bitcoinCurrency.format(
accountState.maxAllowedToReceive,
includeDisplayName: false,
userInput: true);
accountState.maxAllowedToReceive,
includeDisplayName: false,
userInput: true,
);
}
},
);
Expand Down Expand Up @@ -255,7 +253,7 @@ class CreateInvoicePageState extends State<CreateInvoicePage> {
return PaymentValidator(
validatePayment: _validatePayment,
currency: context.read<CurrencyBloc>().state.bitcoinCurrency,
channelCreationPossible: context.read<LSPBloc>().state?.isChannelOpeningAvailiable ?? false,
channelCreationPossible: context.read<LSPBloc>().state?.isChannelOpeningAvailable ?? false,
channelMinimumFee: channelMinimumFee,
texts: context.texts(),
).validateIncoming(amount);
Expand Down
18 changes: 9 additions & 9 deletions lib/routes/home/account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class AccountPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocBuilder<AccountBloc, AccountState>(
builder: (context, account) {
builder: (context, accountState) {
return BlocBuilder<UserProfileBloc, UserProfileState>(
builder: (context, userModel) {
_log.v("AccountPage build with ${account.payments.length} payments");
_log.v("AccountPage build with ${accountState.payments.length} payments");
return Container(
color: Theme.of(context).customData.dashboardBgColor,
child: _build(
context,
account,
accountState,
userModel,
),
);
Expand All @@ -57,11 +57,11 @@ class AccountPage extends StatelessWidget {

Widget _build(
BuildContext context,
AccountState account,
AccountState accountState,
UserProfileState userModel,
) {
final nonFilteredPayments = account.payments;
final paymentFilters = account.paymentFilters;
final nonFilteredPayments = accountState.payments;
final paymentFilters = accountState.paymentFilters;
final filteredPayments = nonFilteredPayments.where((paymentMinutiae) {
final fromTimestamp = paymentFilters.fromTimestamp;
final toTimestamp = paymentFilters.toTimestamp;
Expand Down Expand Up @@ -126,14 +126,14 @@ class AccountPage extends StatelessWidget {
),
),
);
} else if (!account.initial && nonFilteredPayments.isEmpty) {
} else if (!accountState.initial && nonFilteredPayments.isEmpty) {
slivers.add(
SliverPersistentHeader(
delegate: FixedSliverDelegate(
250.0,
builder: (context, shrinkedHeight, overlapContent) {
return BlocBuilder<LSPBloc, LspState?>(builder: (context, lspState) {
var isConnecting = account.connectionStatus == ConnectionStatus.CONNECTING;
var isConnecting = accountState.connectionStatus == ConnectionStatus.CONNECTING;
if (!isConnecting && lspState != null && lspState.selectedLspId == null) {
return const Padding(
padding: EdgeInsets.only(top: 120.0),
Expand All @@ -142,7 +142,7 @@ class AccountPage extends StatelessWidget {
}
return Padding(
padding: const EdgeInsets.fromLTRB(40.0, 120.0, 40.0, 0.0),
child: StatusText(isConnecting: isConnecting),
child: StatusText(accountState: accountState, lspState: lspState),
);
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ AlertDialog createAnimatedLoaderDialog(
mainAxisSize: MainAxisSize.min,
children: [
LoadingAnimatedText(
text,
loadingMessage: text,
textStyle: themeData.dialogTheme.contentTextStyle,
textAlign: TextAlign.center,
),
Expand Down
51 changes: 24 additions & 27 deletions lib/routes/home/widgets/status_text.dart
Original file line number Diff line number Diff line change
@@ -1,48 +1,45 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:c_breez/bloc/account/account_bloc.dart';
import 'package:c_breez/bloc/account/account_state.dart';
import 'package:c_breez/bloc/ext/block_builder_extensions.dart';
import 'package:c_breez/bloc/lsp/lsp_bloc.dart';
import 'package:c_breez/bloc/lsp/lsp_state.dart';
import 'package:c_breez/theme/theme_provider.dart';
import 'package:c_breez/utils/min_font_size.dart';
import 'package:c_breez/widgets/loading_animated_text.dart';
import 'package:flutter/material.dart';

class StatusText extends StatelessWidget {
final String? message;
final bool isConnecting;
final AccountState accountState;
final LspState? lspState;

const StatusText({
Key? key,
this.message,
this.isConnecting = false,
required this.accountState,
required this.lspState,
}) : super(key: key);

@override
Widget build(BuildContext context) {
if (isConnecting || message != null) {
return LoadingAnimatedText(isConnecting ? "" : message!);
} else {
final texts = context.texts();
final themeData = Theme.of(context);
switch (accountState.connectionStatus) {
case ConnectionStatus.CONNECTING:
return const LoadingAnimatedText();
case ConnectionStatus.CONNECTED:
final texts = context.texts();
final themeData = Theme.of(context);

return BlocBuilder2<AccountBloc, AccountState, LSPBloc, LspState?>(
builder: (context, accountState, lspState) {
return AutoSizeText(
(lspState != null && lspState.isChannelOpeningAvailiable && accountState.maxInboundLiquidity <= 0)
? texts.status_text_ready
: texts.lsp_error_cannot_open_channel,
style: themeData.textTheme.bodyMedium?.copyWith(
color: themeData.isLightTheme ? BreezColors.grey[600] : themeData.colorScheme.onSecondary,
),
textAlign: TextAlign.center,
minFontSize: MinFontSize(context).minFontSize,
stepGranularity: 0.1,
);
},
);
final isChannelOpeningAvailable = lspState?.isChannelOpeningAvailable ?? false;
return AutoSizeText(
(isChannelOpeningAvailable && accountState.maxInboundLiquidity >= 0)
? texts.status_text_ready
: texts.lsp_error_cannot_open_channel,
style: themeData.textTheme.bodyMedium?.copyWith(
color: themeData.isLightTheme ? BreezColors.grey[600] : themeData.colorScheme.onSecondary,
),
textAlign: TextAlign.center,
minFontSize: MinFontSize(context).minFontSize,
stepGranularity: 0.1,
);
default:
return const SizedBox();
}
}
}
2 changes: 1 addition & 1 deletion lib/routes/lnurl/payment/lnurl_payment_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class LNURLPaymentPageState extends State<LNURLPaymentPage> {
return PaymentValidator(
validatePayment: accBloc.validatePayment,
currency: currencyState.bitcoinCurrency,
channelCreationPossible: lspState?.isChannelOpeningAvailiable ?? false,
channelCreationPossible: lspState?.isChannelOpeningAvailable ?? false,
channelMinimumFee: channelMinimumFee,
texts: context.texts(),
).validateIncoming(amount);
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/lnurl/withdraw/lnurl_withdraw_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class _LNURLWithdrawDialogState extends State<LNURLWithdrawDialog> with SingleTi
textAlign: TextAlign.center,
)
: LoadingAnimatedText(
texts.lnurl_withdraw_dialog_wait,
loadingMessage: texts.lnurl_withdraw_dialog_wait,
textStyle: themeData.dialogTheme.contentTextStyle,
textAlign: TextAlign.center,
),
Expand Down
Loading