diff --git a/lib/screen/account/recovery_phrase_page.dart b/lib/screen/account/recovery_phrase_page.dart index 3fdd2387d..9b7f11c80 100644 --- a/lib/screen/account/recovery_phrase_page.dart +++ b/lib/screen/account/recovery_phrase_page.dart @@ -23,14 +23,14 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:feralfile_app_theme/feral_file_app_theme.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; +import 'package:libauk_dart/libauk_dart.dart'; import 'package:open_settings/open_settings.dart'; import 'package:permission_handler/permission_handler.dart'; class RecoveryPhrasePayload { - final List words; - final String passphrase; + final WalletStorage wallet; - RecoveryPhrasePayload({required this.words, required this.passphrase}); + RecoveryPhrasePayload({required this.wallet}); } class RecoveryPhrasePage extends StatefulWidget { @@ -44,6 +44,8 @@ class RecoveryPhrasePage extends StatefulWidget { class _RecoveryPhrasePageState extends State { bool _isShow = false; + List? _words; + String _passphrase = ''; bool? _isBackUpAvailable; @override @@ -52,6 +54,7 @@ class _RecoveryPhrasePageState extends State { SecureScreenChannel.setSecureFlag(true); WidgetsBinding.instance.addPostFrameCallback((context) { unawaited(_checkBackUpAvailable()); + unawaited(_loadRecoveryPhrase()); }); } @@ -74,133 +77,144 @@ class _RecoveryPhrasePageState extends State { setState(() {}); } + Future _loadRecoveryPhrase() async { + final words = await widget.payload.wallet.exportMnemonicWords(); + final passphrase = await widget.payload.wallet.exportMnemonicPassphrase(); + setState(() { + _words = words.split(' '); + _passphrase = passphrase; + }); + } + @override - Widget build(BuildContext context) { - final roundNumber = - widget.payload.words.length ~/ 2 + widget.payload.words.length % 2; - final theme = Theme.of(context); + Widget build(BuildContext context) => Scaffold( + appBar: getBackAppBar( + context, + title: 'your_recovery_phrase'.tr(), + onBack: () { + Navigator.of(context).pop(); + }, + ), + body: _body(context, _words, _passphrase), + ); - return Scaffold( - appBar: getBackAppBar( - context, - title: 'your_recovery_phrase'.tr(), - onBack: () { - Navigator.of(context).pop(); - }, - ), - body: Container( - margin: ResponsiveLayout.pageHorizontalEdgeInsetsWithSubmitButton, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - addTitleSpace(), - _getBackUpState(context), - Stack( - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Table( - children: List.generate( - roundNumber, - (index) => - _tableRow(context, index, roundNumber), - ), - border: TableBorder.all( - color: AppColor.auLightGrey, - borderRadius: BorderRadius.circular(10)), + Widget _body(BuildContext context, List? words, String passphrase) { + if (words == null) { + return const SizedBox(); + } + final theme = Theme.of(context); + final roundNumber = words.length ~/ 2 + words.length % 2; + return Container( + margin: ResponsiveLayout.pageHorizontalEdgeInsetsWithSubmitButton, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + addTitleSpace(), + _getBackUpState(context), + Stack( + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Table( + children: List.generate( + roundNumber, + (index) => + _tableRow(context, index, roundNumber, words), ), - if (widget.payload.passphrase.isNotEmpty) ...[ - const SizedBox(height: 20), - Container( - width: double.infinity, - padding: const EdgeInsets.all(10), - decoration: BoxDecoration( - border: - Border.all(color: AppColor.auLightGrey), - borderRadius: BorderRadius.circular(5), - ), - child: RichText( - text: TextSpan( - children: [ - TextSpan( - text: 'passphrase'.tr(), - style: theme - .textTheme.ppMori400FFQuickSilver14, - ), - const TextSpan(text: ' '), - TextSpan( - text: widget.payload.passphrase, - style: - theme.textTheme.ppMori400Black14), - ], - ), + border: TableBorder.all( + color: AppColor.auLightGrey, + borderRadius: BorderRadius.circular(10)), + ), + if (_passphrase.isNotEmpty) ...[ + const SizedBox(height: 20), + Container( + width: double.infinity, + padding: const EdgeInsets.all(10), + decoration: BoxDecoration( + border: Border.all(color: AppColor.auLightGrey), + borderRadius: BorderRadius.circular(5), + ), + child: RichText( + text: TextSpan( + children: [ + TextSpan( + text: 'passphrase'.tr(), + style: theme + .textTheme.ppMori400FFQuickSilver14, + ), + const TextSpan(text: ' '), + TextSpan( + text: passphrase, + style: + theme.textTheme.ppMori400Black14), + ], ), ), - ] - ], - ), - if (!_isShow) - Positioned.fill( - child: ClipRect( - child: BackdropFilter( - filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10), - child: Center( - child: ConstrainedBox( - constraints: const BoxConstraints.tightFor( - width: 168, height: 45), - child: PrimaryButton( - text: 'tap_to_reveal'.tr(), - onTap: () async { - final didAuthenticate = - await LocalAuthenticationService - .checkLocalAuth(); + ), + ] + ], + ), + if (!_isShow) + Positioned.fill( + child: ClipRect( + child: BackdropFilter( + filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10), + child: Center( + child: ConstrainedBox( + constraints: const BoxConstraints.tightFor( + width: 168, height: 45), + child: PrimaryButton( + text: 'tap_to_reveal'.tr(), + onTap: () async { + final didAuthenticate = + await LocalAuthenticationService + .checkLocalAuth(); - if (!didAuthenticate) { - return; - } - setState(() { - _isShow = !_isShow; - }); - Future.delayed( - const Duration(seconds: 60), - () { - if (mounted) { - setState(() { - _isShow = !_isShow; - }); - } - }, - ); - }, - ), - )), + if (!didAuthenticate) { + return; + } + setState(() { + _isShow = !_isShow; + }); + Future.delayed( + const Duration(seconds: 60), + () { + if (mounted) { + setState(() { + _isShow = !_isShow; + }); + } + }, + ); + }, + ), )), - ), - ], - ), - _recommend(context), - const SizedBox(height: 30), - ], - ), + )), + ), + ], + ), + _recommend(context), + const SizedBox(height: 30), + ], ), ), - _settingButton(context) - ], - ), + ), + _settingButton(context) + ], ), ); } - Widget _rowItem(BuildContext context, int index) { + Widget _rowItem(BuildContext context, int index, List words) { final theme = Theme.of(context); - final isNull = index >= widget.payload.words.length; - final word = isNull ? '' : widget.payload.words[index]; + final isNull = index >= words.length; + final word = isNull ? '' : words[index]; NumberFormat formatter = NumberFormat('00'); return Padding( @@ -381,9 +395,10 @@ class _RecoveryPhrasePageState extends State { ); } - TableRow _tableRow(BuildContext context, int index, int itemsEachCol) => + TableRow _tableRow(BuildContext context, int index, int itemsEachCol, + List words) => TableRow(children: [ - _rowItem(context, index), - _rowItem(context, index + itemsEachCol), + _rowItem(context, index, words), + _rowItem(context, index + itemsEachCol, words), ]); } diff --git a/lib/screen/settings/crypto/wallet_detail/wallet_detail_page.dart b/lib/screen/settings/crypto/wallet_detail/wallet_detail_page.dart index 7b6dd9860..727e63a94 100644 --- a/lib/screen/settings/crypto/wallet_detail/wallet_detail_page.dart +++ b/lib/screen/settings/crypto/wallet_detail/wallet_detail_page.dart @@ -592,19 +592,10 @@ class _WalletDetailPageState extends State with RouteAware { style: theme.textTheme.ppMori400Black14, ), onTap: () async { - final words = - await widget.payload.persona.wallet().exportMnemonicWords(); - final passphrase = - await widget.payload.persona.wallet().exportMnemonicPassphrase(); - if (!context.mounted) { - return; - } - unawaited( - Navigator.of(context).pushNamed( - AppRouter.recoveryPhrasePage, - arguments: RecoveryPhrasePayload( - words: words.split(' '), passphrase: passphrase), - ), + await Navigator.of(context).pushNamed( + AppRouter.recoveryPhrasePage, + arguments: + RecoveryPhrasePayload(wallet: widget.payload.persona.wallet()), ); }, ),