From c01d12b07a89e2969d4372a6eda688b30c8499b3 Mon Sep 17 00:00:00 2001 From: Torkel Rogstad Date: Mon, 13 Nov 2023 08:58:19 +0100 Subject: [PATCH] eth: show dialog with error message on create account --- .../tabs/ethereum/ethereum_rpc_tab_page.dart | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/pages/tabs/ethereum/ethereum_rpc_tab_page.dart b/lib/pages/tabs/ethereum/ethereum_rpc_tab_page.dart index c01b448a..2907decc 100644 --- a/lib/pages/tabs/ethereum/ethereum_rpc_tab_page.dart +++ b/lib/pages/tabs/ethereum/ethereum_rpc_tab_page.dart @@ -12,6 +12,7 @@ import 'package:web3dart/web3dart.dart'; @RoutePage() class EthereumRPCTabPage extends StatelessWidget { AppRouter get router => GetIt.I.get(); + AppRouter get _router => GetIt.I.get(); const EthereumRPCTabPage({super.key}); @@ -30,7 +31,29 @@ class EthereumRPCTabPage extends StatelessWidget { if (viewModel.account == null) SailButton.primary( 'Create account', - onPressed: viewModel.createAccount, + onPressed: () async { + try { + await viewModel.createAccount(); + } catch (err) { + if (!context.mounted) { + return; + } + + await showDialog( + context: context, + builder: (context) => AlertDialog( + title: SailText.primary20('Could not create account'), + content: SailText.secondary13(err.toString()), + actions: [ + TextButton( + onPressed: () => _router.popUntilRoot(), + child: SailText.primary13('OK'), + ), + ], + ), + ); + } + }, size: ButtonSize.small, ), if (viewModel.account == null) @@ -64,7 +87,7 @@ class EthereumRPCTabPageViewModel extends BaseViewModel { bool running = false; - void createAccount() async { + Future createAccount() async { if (account != null) { throw Exception('you can only make one account using the GUI'); }