Skip to content

Commit

Permalink
eth: show dialog with error message on create account
Browse files Browse the repository at this point in the history
  • Loading branch information
torkelrogstad committed Nov 13, 2023
1 parent 7a86554 commit c01d12b
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions lib/pages/tabs/ethereum/ethereum_rpc_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:web3dart/web3dart.dart';
@RoutePage()
class EthereumRPCTabPage extends StatelessWidget {
AppRouter get router => GetIt.I.get<AppRouter>();
AppRouter get _router => GetIt.I.get<AppRouter>();

const EthereumRPCTabPage({super.key});

Expand All @@ -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)
Expand Down Expand Up @@ -64,7 +87,7 @@ class EthereumRPCTabPageViewModel extends BaseViewModel {

bool running = false;

void createAccount() async {
Future<void> createAccount() async {
if (account != null) {
throw Exception('you can only make one account using the GUI');
}
Expand Down

0 comments on commit c01d12b

Please sign in to comment.