-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove nodeID from valid input type list when pasted * Handle LNURL-Pay * Handle LNURL-Withdraw * Handle LNURL-Auth * Wait for input to be parsed * Fix title of destination pubkey * Move LnUrl API's to LnUrlBloc * Validate LnUrl payments against lightning limits * Rename isLnurlPayment to isLnUrlPayment for consistency of capitalization of LnUrl
- Loading branch information
1 parent
5ca0c5b
commit a79f575
Showing
20 changed files
with
1,291 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart'; | ||
import 'package:hydrated_bloc/hydrated_bloc.dart'; | ||
import 'package:l_breez/bloc/account/breez_sdk_liquid.dart'; | ||
import 'package:l_breez/bloc/lnurl/lnurl_state.dart'; | ||
import 'package:logging/logging.dart'; | ||
|
||
class LnUrlBloc extends Cubit<LnUrlState> { | ||
final _log = Logger("LnUrlBloc"); | ||
final BreezSDKLiquid _liquidSdk; | ||
|
||
LnUrlBloc(this._liquidSdk) : super(LnUrlState.initial()); | ||
|
||
Future<LightningPaymentLimitsResponse> fetchLightningLimits() async { | ||
try { | ||
final limits = await _liquidSdk.instance!.fetchLightningLimits(); | ||
emit(state.copyWith(limits: limits)); | ||
return limits; | ||
} catch (e) { | ||
_log.severe("fetchLightningLimits error", e); | ||
rethrow; | ||
} | ||
} | ||
|
||
Future<LnUrlWithdrawResult> lnurlWithdraw({ | ||
required LnUrlWithdrawRequest req, | ||
}) async { | ||
try { | ||
return await _liquidSdk.instance!.lnurlWithdraw(req: req); | ||
} catch (e) { | ||
_log.severe("lnurlWithdraw error", e); | ||
rethrow; | ||
} | ||
} | ||
|
||
Future<LnUrlPayResult> lnurlPay({ | ||
required LnUrlPayRequest req, | ||
}) async { | ||
try { | ||
return await _liquidSdk.instance!.lnurlPay(req: req); | ||
} catch (e) { | ||
_log.severe("lnurlPay error", e); | ||
rethrow; | ||
} | ||
} | ||
|
||
Future<LnUrlCallbackStatus> lnurlAuth({ | ||
required LnUrlAuthRequestData reqData, | ||
}) async { | ||
try { | ||
return await _liquidSdk.instance!.lnurlAuth(reqData: reqData); | ||
} catch (e) { | ||
_log.severe("lnurlAuth error", e); | ||
rethrow; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart'; | ||
|
||
class LnUrlState { | ||
final LightningPaymentLimitsResponse? limits; | ||
|
||
LnUrlState({this.limits}); | ||
|
||
LnUrlState.initial() : this(); | ||
|
||
LnUrlState copyWith({ | ||
LightningPaymentLimitsResponse? limits, | ||
}) { | ||
return LnUrlState( | ||
limits: limits ?? this.limits, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 9 additions & 15 deletions
24
lib/routes/home/widgets/payments_list/dialog/payment_details_dialog_destination_pubkey.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
import 'package:breez_translations/breez_translations_locales.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:l_breez/models/payment_minutiae.dart'; | ||
import 'package:l_breez/routes/home/widgets/payments_list/dialog/shareable_payment_row.dart'; | ||
|
||
class PaymentDetailsDestinationPubkey extends StatelessWidget { | ||
final PaymentMinutiae paymentMinutiae; | ||
|
||
const PaymentDetailsDestinationPubkey({ | ||
super.key, | ||
required this.paymentMinutiae, | ||
}); | ||
const PaymentDetailsDestinationPubkey({required this.paymentMinutiae, super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final texts = context.texts(); | ||
final destinationPubkey = paymentMinutiae.swapId; | ||
if (destinationPubkey.isNotEmpty) { | ||
return ShareablePaymentRow( | ||
title: texts.payment_details_dialog_single_info_node_id, | ||
sharedValue: destinationPubkey, | ||
); | ||
} else { | ||
return Container(); | ||
} | ||
return destinationPubkey.isNotEmpty | ||
? ShareablePaymentRow( | ||
// TODO: Move this message to Breez-Translations | ||
title: "Swap ID", | ||
sharedValue: destinationPubkey, | ||
) | ||
: const SizedBox.shrink(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
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/lnurl/lnurl_bloc.dart'; | ||
import 'package:l_breez/routes/lnurl/auth/login_text.dart'; | ||
import 'package:l_breez/routes/lnurl/widgets/lnurl_page_result.dart'; | ||
import 'package:l_breez/widgets/error_dialog.dart'; | ||
import 'package:l_breez/widgets/loader.dart'; | ||
import 'package:logging/logging.dart'; | ||
|
||
final _log = Logger("HandleLNURLAuthRequest"); | ||
|
||
Future<LNURLPageResult?> handleAuthRequest( | ||
BuildContext context, | ||
LnUrlAuthRequestData reqData, | ||
) async { | ||
return promptAreYouSure(context, null, LoginText(domain: reqData.domain)).then( | ||
(permitted) async { | ||
if (permitted == true) { | ||
final texts = context.texts(); | ||
final navigator = Navigator.of(context); | ||
final loaderRoute = createLoaderRoute(context); | ||
navigator.push(loaderRoute); | ||
try { | ||
final lnurlBloc = context.read<LnUrlBloc>(); | ||
final resp = await lnurlBloc.lnurlAuth(reqData: reqData); | ||
if (resp is LnUrlCallbackStatus_Ok) { | ||
_log.info("LNURL auth success"); | ||
return const LNURLPageResult(protocol: LnUrlProtocol.Auth); | ||
} else if (resp is LnUrlCallbackStatus_ErrorStatus) { | ||
_log.info("LNURL auth failed: ${resp.data.reason}"); | ||
return LNURLPageResult(protocol: LnUrlProtocol.Auth, error: resp.data.reason); | ||
} else { | ||
_log.warning("Unknown response from lnurlAuth: $resp"); | ||
return LNURLPageResult( | ||
protocol: LnUrlProtocol.Auth, | ||
error: texts.lnurl_payment_page_unknown_error, | ||
); | ||
} | ||
} catch (e) { | ||
_log.warning("Error authenticating LNURL auth", e); | ||
if (loaderRoute.isActive) { | ||
navigator.removeRoute(loaderRoute); | ||
} | ||
return LNURLPageResult(protocol: LnUrlProtocol.Auth, error: e); | ||
} finally { | ||
if (loaderRoute.isActive) { | ||
navigator.removeRoute(loaderRoute); | ||
} | ||
} | ||
} | ||
return Future.value(); | ||
}, | ||
); | ||
} | ||
|
||
void handleLNURLAuthPageResult(BuildContext context, LNURLPageResult result) { | ||
if (result.hasError) { | ||
_log.info("Handle LNURL auth page result with error '${result.error}'"); | ||
promptError( | ||
context, | ||
context.texts().lnurl_webview_error_title, | ||
Text(result.errorMessage), | ||
okFunc: () => Navigator.of(context).pop(), | ||
); | ||
throw result.error!; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:breez_translations/breez_translations_locales.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class LoginText extends StatelessWidget { | ||
final String domain; | ||
|
||
const LoginText({super.key, required this.domain}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final texts = context.texts(); | ||
final themeData = Theme.of(context); | ||
return RichText( | ||
text: TextSpan( | ||
style: themeData.dialogTheme.contentTextStyle, | ||
text: texts.handler_lnurl_login_anonymously, | ||
children: [ | ||
TextSpan( | ||
text: domain, | ||
style: themeData.dialogTheme.contentTextStyle!.copyWith(fontWeight: FontWeight.bold), | ||
), | ||
TextSpan( | ||
text: "?", | ||
style: themeData.dialogTheme.contentTextStyle, | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:l_breez/routes/lnurl/auth/lnurl_auth_handler.dart'; | ||
import 'package:l_breez/routes/lnurl/payment/lnurl_payment_handler.dart'; | ||
import 'package:l_breez/routes/lnurl/withdraw/lnurl_withdraw_handler.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:logging/logging.dart'; | ||
|
||
import 'widgets/lnurl_page_result.dart'; | ||
|
||
final _log = Logger("HandleLNURL"); | ||
|
||
void handleLNURLPageResult(BuildContext context, LNURLPageResult result) { | ||
_log.info("handle $result"); | ||
switch (result.protocol) { | ||
case LnUrlProtocol.Pay: | ||
handleLNURLPaymentPageResult(context, result); | ||
break; | ||
case LnUrlProtocol.Withdraw: | ||
handleLNURLWithdrawPageResult(context, result); | ||
break; | ||
case LnUrlProtocol.Auth: | ||
handleLNURLAuthPageResult(context, result); | ||
break; | ||
default: | ||
break; | ||
} | ||
} |
Oops, something went wrong.