-
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.
- Loading branch information
1 parent
3e82107
commit f20b322
Showing
5 changed files
with
115 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import 'package:breez_translations/breez_translations_locales.dart'; | ||
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart'; | ||
import 'package:l_breez/bloc/account/account_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:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.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 resp = await context.read<AccountBloc>().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