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

Integrate Send Chain Swap #47

Merged
merged 1 commit into from
Jul 12, 2024
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
33 changes: 33 additions & 0 deletions lib/routes/chainswap/send/fee/fee_breakdown/fee_breakdown.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';
import 'package:l_breez/routes/chainswap/send/fee/fee_breakdown/widgets/fee_breakdown_widgets/recipient_amount.dart';
import 'package:l_breez/routes/chainswap/send/fee/fee_breakdown/widgets/fee_breakdown_widgets/sender_amount.dart';
import 'package:l_breez/routes/chainswap/send/fee/fee_breakdown/widgets/fee_breakdown_widgets/transaction_fee.dart';

class FeeBreakdown extends StatelessWidget {
final PreparePayOnchainResponse feeOption;

const FeeBreakdown({required this.feeOption, super.key});

@override
Widget build(BuildContext context) {
final themeData = Theme.of(context);

return Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(5.0)),
border: Border.all(
color: themeData.colorScheme.onSurface.withOpacity(0.4),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SenderAmount(amountSat: (feeOption.receiverAmountSat + feeOption.feesSat).toInt()),
TransactionFee(txFeeSat: feeOption.feesSat.toInt()),
RecipientAmount(amountSat: feeOption.receiverAmountSat.toInt())
],
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:flutter/material.dart';
import 'package:l_breez/models/currency.dart';
import 'package:l_breez/utils/min_font_size.dart';

class BoltzServiceFee extends StatelessWidget {
final int boltzServiceFee;

const BoltzServiceFee({required this.boltzServiceFee, super.key});

@override
Widget build(BuildContext context) {
final texts = context.texts();
final themeData = Theme.of(context);
final minFont = MinFontSize(context);

return ListTile(
title: AutoSizeText(
texts.reverse_swap_confirmation_boltz_fee,
style: TextStyle(color: Colors.white.withOpacity(0.4)),
maxLines: 1,
minFontSize: minFont.minFontSize,
stepGranularity: 0.1,
),
trailing: AutoSizeText(
texts.reverse_swap_confirmation_boltz_fee_value(
BitcoinCurrency.SAT.format(boltzServiceFee),
),
style: TextStyle(color: themeData.colorScheme.error.withOpacity(0.4)),
maxLines: 1,
minFontSize: minFont.minFontSize,
stepGranularity: 0.1,
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:l_breez/bloc/currency/currency_bloc.dart';
import 'package:l_breez/bloc/currency/currency_state.dart';
import 'package:l_breez/models/currency.dart';
import 'package:l_breez/utils/min_font_size.dart';

class RecipientAmount extends StatelessWidget {
final int amountSat;

const RecipientAmount({required this.amountSat, super.key});

@override
Widget build(BuildContext context) {
final texts = context.texts();
final themeData = Theme.of(context);
final minFont = MinFontSize(context);

return ListTile(
title: AutoSizeText(
texts.sweep_all_coins_label_receive,
style: const TextStyle(color: Colors.white),
maxLines: 1,
minFontSize: minFont.minFontSize,
stepGranularity: 0.1,
),
trailing: BlocBuilder<CurrencyBloc, CurrencyState>(builder: (context, currency) {
final fiatConversion = currency.fiatConversion();

return AutoSizeText(
fiatConversion == null
? texts.sweep_all_coins_amount_no_fiat(
BitcoinCurrency.SAT.format(amountSat),
)
: texts.sweep_all_coins_amount_with_fiat(
BitcoinCurrency.SAT.format(amountSat),
fiatConversion.format(amountSat),
),
style: TextStyle(color: themeData.colorScheme.error),
maxLines: 1,
minFontSize: minFont.minFontSize,
stepGranularity: 0.1,
);
}),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:l_breez/bloc/currency/currency_bloc.dart';
import 'package:l_breez/bloc/currency/currency_state.dart';
import 'package:l_breez/models/currency.dart';
import 'package:l_breez/utils/min_font_size.dart';

class SenderAmount extends StatelessWidget {
final int amountSat;

const SenderAmount({required this.amountSat, super.key});

@override
Widget build(BuildContext context) {
final texts = context.texts();
final themeData = Theme.of(context);
final minFont = MinFontSize(context);

return ListTile(
title: AutoSizeText(
texts.sweep_all_coins_label_send,
maxLines: 1,
minFontSize: minFont.minFontSize,
stepGranularity: 0.1,
),
trailing: BlocBuilder<CurrencyBloc, CurrencyState>(
builder: (context, currency) {
final fiatConversion = currency.fiatConversion();

return AutoSizeText(
fiatConversion == null
? texts.sweep_all_coins_amount_no_fiat(
BitcoinCurrency.SAT.format(amountSat),
)
: texts.sweep_all_coins_amount_with_fiat(
BitcoinCurrency.SAT.format(amountSat),
fiatConversion.format(amountSat),
),
style: TextStyle(color: themeData.colorScheme.error),
maxLines: 1,
minFontSize: minFont.minFontSize,
stepGranularity: 0.1,
);
},
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:flutter/material.dart';
import 'package:l_breez/models/currency.dart';
import 'package:l_breez/utils/min_font_size.dart';

class TransactionFee extends StatelessWidget {
final int txFeeSat;

const TransactionFee({required this.txFeeSat, super.key});

@override
Widget build(BuildContext context) {
final texts = context.texts();
final themeData = Theme.of(context);
final minFont = MinFontSize(context);

return ListTile(
title: AutoSizeText(
texts.sweep_all_coins_label_transaction_fee,
style: TextStyle(color: Colors.white.withOpacity(0.4)),
maxLines: 1,
minFontSize: minFont.minFontSize,
stepGranularity: 0.1,
),
trailing: AutoSizeText(
texts.sweep_all_coins_fee(
BitcoinCurrency.SAT.format(txFeeSat),
),
style: TextStyle(color: themeData.colorScheme.error.withOpacity(0.4)),
maxLines: 1,
minFontSize: minFont.minFontSize,
stepGranularity: 0.1,
),
);
}
}
7 changes: 7 additions & 0 deletions lib/routes/chainswap/send/fee/fee_option.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';

extension PreparePayOnchainResponseAffordable on PreparePayOnchainResponse {
bool isAffordable({required int balance}) {
return balance >= (receiverAmountSat + feesSat).toInt();
}
}
56 changes: 56 additions & 0 deletions lib/routes/chainswap/send/send_chainswap_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';
import 'package:l_breez/bloc/chainswap/chainswap_bloc.dart';
import 'package:l_breez/utils/exceptions.dart';
import 'package:l_breez/widgets/error_dialog.dart';
import 'package:l_breez/widgets/loader.dart';
import 'package:l_breez/widgets/single_button_bottom_bar.dart';

class SendChainSwapButton extends StatelessWidget {
final String recipientAddress;
final PreparePayOnchainResponse preparePayOnchainResponse;

const SendChainSwapButton({
super.key,
required this.recipientAddress,
required this.preparePayOnchainResponse,
});

@override
Widget build(BuildContext context) {
final texts = context.texts();

return SingleButtonBottomBar(
text: texts.sweep_all_coins_action_confirm,
onPressed: () => _payOnchain(context),
);
}

Future _payOnchain(BuildContext context) async {
final texts = context.texts();
final themeData = Theme.of(context);
final chainSwapBloc = context.read<ChainSwapBloc>();

final navigator = Navigator.of(context);
var loaderRoute = createLoaderRoute(context);
navigator.push(loaderRoute);
try {
final req = PayOnchainRequest(address: recipientAddress, prepareRes: preparePayOnchainResponse);
await chainSwapBloc.payOnchain(req: req);
navigator.pushNamedAndRemoveUntil("/", (Route<dynamic> route) => false);
} catch (e) {
navigator.pop(loaderRoute);
if (!context.mounted) return;
promptError(
context,
null,
Text(
extractExceptionMessage(e, texts),
style: themeData.dialogTheme.contentTextStyle,
),
);
}
}
}
Loading