From ac1ed44551b39aa165473f4f128217b741c57234 Mon Sep 17 00:00:00 2001 From: Chiziaruhoma Date: Thu, 19 May 2022 11:45:31 +0100 Subject: [PATCH 1/5] create Error screen --- .../lib/pages/create_account_page.dart | 4 +- starport_template/lib/starport_app.dart | 47 ++++++++++++++- .../lib/stores/accounts_store.dart | 59 +++++++++++++------ 3 files changed, 89 insertions(+), 21 deletions(-) diff --git a/starport_template/lib/pages/create_account_page.dart b/starport_template/lib/pages/create_account_page.dart index ccc22804..63a4bc08 100644 --- a/starport_template/lib/pages/create_account_page.dart +++ b/starport_template/lib/pages/create_account_page.dart @@ -122,9 +122,7 @@ class _CreateAccountPageState extends State { } Widget _errorUI() { - return const Center( - child: Text('Error!'), - ); + return ErrorWidget.withDetails(); } Future _authenticateUser() async { diff --git a/starport_template/lib/starport_app.dart b/starport_template/lib/starport_app.dart index 66b0d61e..a6c510ca 100644 --- a/starport_template/lib/starport_app.dart +++ b/starport_template/lib/starport_app.dart @@ -1,6 +1,6 @@ import 'package:alan/alan.dart'; import 'package:cosmos_auth/auth/cosmos_auth.dart'; -import 'package:cosmos_ui_components/cosmos_theme.dart'; +import 'package:cosmos_ui_components/cosmos_ui_components.dart'; import 'package:cosmos_utils/cosmos_utils.dart'; import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; @@ -34,6 +34,7 @@ class StarportApp extends StatelessWidget { brightness: themeStore.isDarkTheme ? Brightness.dark : Brightness.light, child: Builder( builder: (context) { + setErrorBuilder(context); return MaterialApp( title: 'Starport template', theme: CosmosTheme.of(context).buildFlutterTheme(), @@ -44,4 +45,48 @@ class StarportApp extends StatelessWidget { ), ); } + + void setErrorBuilder(BuildContext context) { + ErrorWidget.builder = (errorDetails) { + return Material( + color: Colors.white, + child: Center( + child: Padding( + padding: const EdgeInsets.all(24), + child: ListView( + children: [ + const Text( + 'Error!', + style: TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + ), + ), + Text( + errorDetails.toString(), + style: const TextStyle( + color: Colors.white, + fontWeight: FontWeight.w400, + ), + ), + Row( + children: [ + CosmosElevatedButton( + text: 'Take me back', + onTap: () => Navigator.pop(context), + textColor: Colors.black, + ), + CosmosTextButton( + text: 'Back', + onTap: () => Navigator.of(context).pop(), + ), + ], + ), + ], + ), + ), + ), + ); + }; + } } diff --git a/starport_template/lib/stores/accounts_store.dart b/starport_template/lib/stores/accounts_store.dart index 270732fb..ab536dd2 100644 --- a/starport_template/lib/stores/accounts_store.dart +++ b/starport_template/lib/stores/accounts_store.dart @@ -32,10 +32,13 @@ class AccountsStore { final Observable _isBalancesLoadingError = Observable(false); final Observable _isRenamingAccount = Observable(false); final Observable _isSendingMoney = Observable(false); + final Observable _errorDetails = Observable(''); final ObservableList balancesList = ObservableList(); - final Observable loadAccountsFailure = Observable(null); - final Observable _renameAccountFailure = Observable(null); + final Observable loadAccountsFailure = + Observable(null); + final Observable _renameAccountFailure = + Observable(null); final ObservableList accounts = ObservableList(); int? get selectedAccountIndex => _selectetAccountIndex.value; @@ -44,7 +47,8 @@ class AccountsStore { bool get areAccountsLoading => _areAccountsLoading.value; - set areAccountsLoading(bool val) => Action(() => _areAccountsLoading.value = val)(); + set areAccountsLoading(bool val) => + Action(() => _areAccountsLoading.value = val)(); bool get isSendingMoney => _isSendingMoney.value; @@ -52,43 +56,58 @@ class AccountsStore { bool get isRenamingAccount => _isRenamingAccount.value; - set isRenamingAccount(bool val) => Action(() => _isRenamingAccount.value = val)(); + set isRenamingAccount(bool val) => + Action(() => _isRenamingAccount.value = val)(); bool get isSendMoneyError => _isSendMoneyError.value; - set isSendMoneyError(bool val) => Action(() => _isSendMoneyError.value = val)(); + set isSendMoneyError(bool val) => + Action(() => _isSendMoneyError.value = val)(); bool get isSendMoneyLoading => _isSendMoneyLoading.value; - set isSendMoneyLoading(bool val) => Action(() => _isSendMoneyLoading.value = val)(); + set isSendMoneyLoading(bool val) => + Action(() => _isSendMoneyLoading.value = val)(); bool get isBalancesLoadingError => _isBalancesLoadingError.value; - set isBalancesLoadingError(bool val) => Action(() => _isBalancesLoadingError.value = val)(); + set isBalancesLoadingError(bool val) => + Action(() => _isBalancesLoadingError.value = val)(); bool get isBalancesLoading => _isBalancesLoading.value; - set isBalancesLoading(bool val) => Action(() => _isBalancesLoading.value = val)(); + set isBalancesLoading(bool val) => + Action(() => _isBalancesLoading.value = val)(); bool get isAccountImportingError => _isAccountImportingError.value; - set isAccountImportingError(bool val) => Action(() => _isAccountImportingError.value = val)(); + set isAccountImportingError(bool val) => + Action(() => _isAccountImportingError.value = val)(); bool get isMnemonicCreatingError => _isMnemonicCreatingError.value; - set isMnemonicCreatingError(bool val) => Action(() => _isMnemonicCreatingError.value = val)(); + set isMnemonicCreatingError(bool val) => + Action(() => _isMnemonicCreatingError.value = val)(); + + String get errorDetails => _errorDetails.value; + + set errorDetails(String val) => Action(() => _errorDetails.value = val)(); bool get isMnemonicCreating => _isMnemonicCreating.value; - set isMnemonicCreating(bool val) => Action(() => _isMnemonicCreating.value = val)(); + set isMnemonicCreating(bool val) => + Action(() => _isMnemonicCreating.value = val)(); bool get isAccountImporting => _isAccountImporting.value; - set isAccountImporting(bool val) => Action(() => _isAccountImporting.value = val)(); + set isAccountImporting(bool val) => + Action(() => _isAccountImporting.value = val)(); - CredentialsStorageFailure? get renameAccountFailure => _renameAccountFailure.value; + CredentialsStorageFailure? get renameAccountFailure => + _renameAccountFailure.value; - set renameAccountFailure(CredentialsStorageFailure? val) => Action(() => _renameAccountFailure.value = val)(); + set renameAccountFailure(CredentialsStorageFailure? val) => + Action(() => _renameAccountFailure.value = val)(); AccountPublicInfo get selectedAccount { final index = _selectetAccountIndex.value; @@ -138,7 +157,8 @@ class AccountsStore { .fold( (fail) => Action(() => renameAccountFailure = fail)(), (success) { - final index = accounts.indexWhere((it) => it.accountId == newInfo.accountId); + final index = + accounts.indexWhere((it) => it.accountId == newInfo.accountId); accounts[index] = newInfo; }, ); @@ -149,7 +169,8 @@ class AccountsStore { isBalancesLoadingError = false; isBalancesLoading = true; try { - final newBalances = await CosmosBalances(appConfig).getBalances(accountAddress); + final newBalances = + await CosmosBalances(appConfig).getBalances(accountAddress); balancesList ..clear() ..addAll(newBalances); @@ -202,6 +223,7 @@ class AccountsStore { return result.fold( (fail) { logError(fail); + errorDetails = fail.toString(); isAccountImportingError = true; return null; }, @@ -234,6 +256,7 @@ class AccountsStore { await getBalances(selectedAccount.publicAddress); } catch (ex, stack) { logError(ex, stack); + errorDetails = '$ex\n\nStackTrace:\n\n$stack'; isSendMoneyError = true; } isSendMoneyLoading = false; @@ -271,6 +294,7 @@ class AccountsStore { mnemonic = await generateMnemonic(); } catch (ex, stack) { logError(ex, stack); + errorDetails = '$ex\n\nStackTrace:\n\n$stack'; isMnemonicCreatingError = true; } isMnemonicCreating = false; @@ -279,7 +303,8 @@ class AccountsStore { void selectAccount(AccountPublicInfo account) { try { - selectedAccountIndex = accounts.indexWhere((element) => element.accountId == account.accountId); + selectedAccountIndex = accounts + .indexWhere((element) => element.accountId == account.accountId); } catch (ex, stack) { logError(ex, stack); } From a51e290e502931e752ca33e6cf4331d1d2b29535 Mon Sep 17 00:00:00 2001 From: Chiziaruhoma Date: Thu, 19 May 2022 11:47:49 +0100 Subject: [PATCH 2/5] pass error to erro widget --- .../lib/pages/create_account_page.dart | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/starport_template/lib/pages/create_account_page.dart b/starport_template/lib/pages/create_account_page.dart index 63a4bc08..0b0699cb 100644 --- a/starport_template/lib/pages/create_account_page.dart +++ b/starport_template/lib/pages/create_account_page.dart @@ -40,9 +40,13 @@ class _CreateAccountPageState extends State { bool get isAccountImporting => StarportApp.accountsStore.isAccountImporting; - bool get isMnemonicCreatingError => StarportApp.accountsStore.isMnemonicCreatingError; + bool get isMnemonicCreatingError => + StarportApp.accountsStore.isMnemonicCreatingError; - bool get isAccountImportingError => StarportApp.accountsStore.isAccountImportingError; + bool get isAccountImportingError => + StarportApp.accountsStore.isAccountImportingError; + + String get errorDetails => StarportApp.accountsStore.errorDetails; @override void initState() { @@ -60,7 +64,9 @@ class _CreateAccountPageState extends State { loadingChild: LoadingSplash( text: isAuthenticating ? 'Authenticating..' - : (isMnemonicCreating ? 'Creating a recovery phrase..' : 'Creating account..'), + : (isMnemonicCreating + ? 'Creating a recovery phrase..' + : 'Creating account..'), ), contentChild: Scaffold( backgroundColor: CosmosTheme.of(context).colors.background, @@ -102,12 +108,16 @@ class _CreateAccountPageState extends State { style: CosmosTextTheme.copy0Normal, ), SizedBox(height: theme.spacingXL), - const InfoCard(text: 'We will never ask you to share your recovery phrase.'), + const InfoCard( + text: 'We will never ask you to share your recovery phrase.'), SizedBox(height: theme.spacingL), - const InfoCard(text: 'Never share your recovery phrase with anyone, store it securely.'), + const InfoCard( + text: + 'Never share your recovery phrase with anyone, store it securely.'), SizedBox(height: theme.spacingL), const InfoCard( - text: 'If you don’t backup your account or lose your recovery phrase, ' + text: + 'If you don’t backup your account or lose your recovery phrase, ' 'you will not able to recover your account', ), const Spacer(), @@ -122,7 +132,9 @@ class _CreateAccountPageState extends State { } Widget _errorUI() { - return ErrorWidget.withDetails(); + return ErrorWidget.withDetails( + error: FlutterError(errorDetails), + ); } Future _authenticateUser() async { @@ -145,7 +157,8 @@ class _CreateAccountPageState extends State { } if (mounted) { await Navigator.of(context).pushReplacement( - MaterialPageRoute(builder: (context) => BackUpAccountPage(mnemonic: mnemonic)), + MaterialPageRoute( + builder: (context) => BackUpAccountPage(mnemonic: mnemonic)), ); } } @@ -169,7 +182,8 @@ class _CreateAccountPageState extends State { password: password, isBackedUp: isBackedUp, onMnemonicGenerationStarted: () => setState(() {}), - onAccountCreationStarted: () => setState(() {}), //this will cause the loading message to update + onAccountCreationStarted: () => + setState(() {}), //this will cause the loading message to update ); if (mounted) { await Navigator.of(context).pushAndRemoveUntil( @@ -185,12 +199,14 @@ class _CreateAccountPageState extends State { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties - ..add(DiagnosticsProperty('isMnemonicCreatingError', isMnemonicCreatingError)) + ..add(DiagnosticsProperty( + 'isMnemonicCreatingError', isMnemonicCreatingError)) ..add(DiagnosticsProperty('isMnemonicCreating', isMnemonicCreating)) ..add(DiagnosticsProperty('isAccountImporting', isAccountImporting)) ..add(DiagnosticsProperty('isLoading', isLoading)) ..add(DiagnosticsProperty('isAuthenticating', isAuthenticating)) - ..add(DiagnosticsProperty('isAccountImportingError', isAccountImportingError)) + ..add(DiagnosticsProperty( + 'isAccountImportingError', isAccountImportingError)) ..add(DiagnosticsProperty('isError', isError)); } } From 91bd60b6edb521c5cf422ccbe9391bc5ed4ef818 Mon Sep 17 00:00:00 2001 From: Chiziaruhoma Date: Thu, 19 May 2022 11:48:08 +0100 Subject: [PATCH 3/5] pass error to widget --- .../lib/pages/create_account_page.dart | 32 ++++-------- .../lib/stores/accounts_store.dart | 51 +++++++------------ 2 files changed, 27 insertions(+), 56 deletions(-) diff --git a/starport_template/lib/pages/create_account_page.dart b/starport_template/lib/pages/create_account_page.dart index 0b0699cb..564642e5 100644 --- a/starport_template/lib/pages/create_account_page.dart +++ b/starport_template/lib/pages/create_account_page.dart @@ -40,11 +40,9 @@ class _CreateAccountPageState extends State { bool get isAccountImporting => StarportApp.accountsStore.isAccountImporting; - bool get isMnemonicCreatingError => - StarportApp.accountsStore.isMnemonicCreatingError; + bool get isMnemonicCreatingError => StarportApp.accountsStore.isMnemonicCreatingError; - bool get isAccountImportingError => - StarportApp.accountsStore.isAccountImportingError; + bool get isAccountImportingError => StarportApp.accountsStore.isAccountImportingError; String get errorDetails => StarportApp.accountsStore.errorDetails; @@ -64,9 +62,7 @@ class _CreateAccountPageState extends State { loadingChild: LoadingSplash( text: isAuthenticating ? 'Authenticating..' - : (isMnemonicCreating - ? 'Creating a recovery phrase..' - : 'Creating account..'), + : (isMnemonicCreating ? 'Creating a recovery phrase..' : 'Creating account..'), ), contentChild: Scaffold( backgroundColor: CosmosTheme.of(context).colors.background, @@ -108,16 +104,12 @@ class _CreateAccountPageState extends State { style: CosmosTextTheme.copy0Normal, ), SizedBox(height: theme.spacingXL), - const InfoCard( - text: 'We will never ask you to share your recovery phrase.'), + const InfoCard(text: 'We will never ask you to share your recovery phrase.'), SizedBox(height: theme.spacingL), - const InfoCard( - text: - 'Never share your recovery phrase with anyone, store it securely.'), + const InfoCard(text: 'Never share your recovery phrase with anyone, store it securely.'), SizedBox(height: theme.spacingL), const InfoCard( - text: - 'If you don’t backup your account or lose your recovery phrase, ' + text: 'If you don’t backup your account or lose your recovery phrase, ' 'you will not able to recover your account', ), const Spacer(), @@ -157,8 +149,7 @@ class _CreateAccountPageState extends State { } if (mounted) { await Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (context) => BackUpAccountPage(mnemonic: mnemonic)), + MaterialPageRoute(builder: (context) => BackUpAccountPage(mnemonic: mnemonic)), ); } } @@ -182,8 +173,7 @@ class _CreateAccountPageState extends State { password: password, isBackedUp: isBackedUp, onMnemonicGenerationStarted: () => setState(() {}), - onAccountCreationStarted: () => - setState(() {}), //this will cause the loading message to update + onAccountCreationStarted: () => setState(() {}), //this will cause the loading message to update ); if (mounted) { await Navigator.of(context).pushAndRemoveUntil( @@ -199,14 +189,12 @@ class _CreateAccountPageState extends State { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties - ..add(DiagnosticsProperty( - 'isMnemonicCreatingError', isMnemonicCreatingError)) + ..add(DiagnosticsProperty('isMnemonicCreatingError', isMnemonicCreatingError)) ..add(DiagnosticsProperty('isMnemonicCreating', isMnemonicCreating)) ..add(DiagnosticsProperty('isAccountImporting', isAccountImporting)) ..add(DiagnosticsProperty('isLoading', isLoading)) ..add(DiagnosticsProperty('isAuthenticating', isAuthenticating)) - ..add(DiagnosticsProperty( - 'isAccountImportingError', isAccountImportingError)) + ..add(DiagnosticsProperty('isAccountImportingError', isAccountImportingError)) ..add(DiagnosticsProperty('isError', isError)); } } diff --git a/starport_template/lib/stores/accounts_store.dart b/starport_template/lib/stores/accounts_store.dart index ab536dd2..4c7150cc 100644 --- a/starport_template/lib/stores/accounts_store.dart +++ b/starport_template/lib/stores/accounts_store.dart @@ -35,10 +35,8 @@ class AccountsStore { final Observable _errorDetails = Observable(''); final ObservableList balancesList = ObservableList(); - final Observable loadAccountsFailure = - Observable(null); - final Observable _renameAccountFailure = - Observable(null); + final Observable loadAccountsFailure = Observable(null); + final Observable _renameAccountFailure = Observable(null); final ObservableList accounts = ObservableList(); int? get selectedAccountIndex => _selectetAccountIndex.value; @@ -47,8 +45,7 @@ class AccountsStore { bool get areAccountsLoading => _areAccountsLoading.value; - set areAccountsLoading(bool val) => - Action(() => _areAccountsLoading.value = val)(); + set areAccountsLoading(bool val) => Action(() => _areAccountsLoading.value = val)(); bool get isSendingMoney => _isSendingMoney.value; @@ -56,38 +53,31 @@ class AccountsStore { bool get isRenamingAccount => _isRenamingAccount.value; - set isRenamingAccount(bool val) => - Action(() => _isRenamingAccount.value = val)(); + set isRenamingAccount(bool val) => Action(() => _isRenamingAccount.value = val)(); bool get isSendMoneyError => _isSendMoneyError.value; - set isSendMoneyError(bool val) => - Action(() => _isSendMoneyError.value = val)(); + set isSendMoneyError(bool val) => Action(() => _isSendMoneyError.value = val)(); bool get isSendMoneyLoading => _isSendMoneyLoading.value; - set isSendMoneyLoading(bool val) => - Action(() => _isSendMoneyLoading.value = val)(); + set isSendMoneyLoading(bool val) => Action(() => _isSendMoneyLoading.value = val)(); bool get isBalancesLoadingError => _isBalancesLoadingError.value; - set isBalancesLoadingError(bool val) => - Action(() => _isBalancesLoadingError.value = val)(); + set isBalancesLoadingError(bool val) => Action(() => _isBalancesLoadingError.value = val)(); bool get isBalancesLoading => _isBalancesLoading.value; - set isBalancesLoading(bool val) => - Action(() => _isBalancesLoading.value = val)(); + set isBalancesLoading(bool val) => Action(() => _isBalancesLoading.value = val)(); bool get isAccountImportingError => _isAccountImportingError.value; - set isAccountImportingError(bool val) => - Action(() => _isAccountImportingError.value = val)(); + set isAccountImportingError(bool val) => Action(() => _isAccountImportingError.value = val)(); bool get isMnemonicCreatingError => _isMnemonicCreatingError.value; - set isMnemonicCreatingError(bool val) => - Action(() => _isMnemonicCreatingError.value = val)(); + set isMnemonicCreatingError(bool val) => Action(() => _isMnemonicCreatingError.value = val)(); String get errorDetails => _errorDetails.value; @@ -95,19 +85,15 @@ class AccountsStore { bool get isMnemonicCreating => _isMnemonicCreating.value; - set isMnemonicCreating(bool val) => - Action(() => _isMnemonicCreating.value = val)(); + set isMnemonicCreating(bool val) => Action(() => _isMnemonicCreating.value = val)(); bool get isAccountImporting => _isAccountImporting.value; - set isAccountImporting(bool val) => - Action(() => _isAccountImporting.value = val)(); + set isAccountImporting(bool val) => Action(() => _isAccountImporting.value = val)(); - CredentialsStorageFailure? get renameAccountFailure => - _renameAccountFailure.value; + CredentialsStorageFailure? get renameAccountFailure => _renameAccountFailure.value; - set renameAccountFailure(CredentialsStorageFailure? val) => - Action(() => _renameAccountFailure.value = val)(); + set renameAccountFailure(CredentialsStorageFailure? val) => Action(() => _renameAccountFailure.value = val)(); AccountPublicInfo get selectedAccount { final index = _selectetAccountIndex.value; @@ -157,8 +143,7 @@ class AccountsStore { .fold( (fail) => Action(() => renameAccountFailure = fail)(), (success) { - final index = - accounts.indexWhere((it) => it.accountId == newInfo.accountId); + final index = accounts.indexWhere((it) => it.accountId == newInfo.accountId); accounts[index] = newInfo; }, ); @@ -169,8 +154,7 @@ class AccountsStore { isBalancesLoadingError = false; isBalancesLoading = true; try { - final newBalances = - await CosmosBalances(appConfig).getBalances(accountAddress); + final newBalances = await CosmosBalances(appConfig).getBalances(accountAddress); balancesList ..clear() ..addAll(newBalances); @@ -303,8 +287,7 @@ class AccountsStore { void selectAccount(AccountPublicInfo account) { try { - selectedAccountIndex = accounts - .indexWhere((element) => element.accountId == account.accountId); + selectedAccountIndex = accounts.indexWhere((element) => element.accountId == account.accountId); } catch (ex, stack) { logError(ex, stack); } From 331bfea4ad58a32be37dee94905e28eaf5dd1fc1 Mon Sep 17 00:00:00 2001 From: Chiziaruhoma Date: Mon, 23 May 2022 07:33:24 +0100 Subject: [PATCH 4/5] fix minor lint bug --- starport_template/lib/pages/create_account_page.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/starport_template/lib/pages/create_account_page.dart b/starport_template/lib/pages/create_account_page.dart index 564642e5..693e8ea4 100644 --- a/starport_template/lib/pages/create_account_page.dart +++ b/starport_template/lib/pages/create_account_page.dart @@ -195,6 +195,7 @@ class _CreateAccountPageState extends State { ..add(DiagnosticsProperty('isLoading', isLoading)) ..add(DiagnosticsProperty('isAuthenticating', isAuthenticating)) ..add(DiagnosticsProperty('isAccountImportingError', isAccountImportingError)) - ..add(DiagnosticsProperty('isError', isError)); + ..add(DiagnosticsProperty('isError', isError)) + ..add(DiagnosticsProperty('errorDetails', errorDetails)); } } From ecf42f43d54bb18437f0bbe7655ae1f19d0bda4c Mon Sep 17 00:00:00 2001 From: Chiziaruhoma Date: Sun, 29 May 2022 09:28:19 +0100 Subject: [PATCH 5/5] create CosmosErrorDetails entity --- .../lib/entities/error_details.dart | 26 +++++++++++++++++++ .../lib/pages/create_account_page.dart | 7 ++--- .../lib/stores/accounts_store.dart | 13 +++++----- 3 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 starport_template/lib/entities/error_details.dart diff --git a/starport_template/lib/entities/error_details.dart b/starport_template/lib/entities/error_details.dart new file mode 100644 index 00000000..478db966 --- /dev/null +++ b/starport_template/lib/entities/error_details.dart @@ -0,0 +1,26 @@ +import 'package:equatable/equatable.dart'; + +class CosmosErrorDetails extends Equatable { + const CosmosErrorDetails({ + required this.error, + this.stackTrace, + }); + + factory CosmosErrorDetails.empty() => const CosmosErrorDetails(error: ''); + + final dynamic error; + final StackTrace? stackTrace; + + @override + List get props => [ + error, + stackTrace ?? '', + ]; + + @override + String toString() => ''' + Error[ + error: $error, + stackTrace: $stackTrace + ]'''; +} diff --git a/starport_template/lib/pages/create_account_page.dart b/starport_template/lib/pages/create_account_page.dart index 693e8ea4..62c8c9cc 100644 --- a/starport_template/lib/pages/create_account_page.dart +++ b/starport_template/lib/pages/create_account_page.dart @@ -5,6 +5,7 @@ import 'package:cosmos_utils/cosmos_utils.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; +import 'package:starport_template/entities/error_details.dart'; import 'package:starport_template/pages/assets_portfolio_page.dart'; import 'package:starport_template/pages/back_up_account_page.dart'; import 'package:starport_template/pages/backup_later_bottom_sheet.dart'; @@ -44,7 +45,7 @@ class _CreateAccountPageState extends State { bool get isAccountImportingError => StarportApp.accountsStore.isAccountImportingError; - String get errorDetails => StarportApp.accountsStore.errorDetails; + CosmosErrorDetails get errorDetails => StarportApp.accountsStore.errorDetails; @override void initState() { @@ -125,7 +126,7 @@ class _CreateAccountPageState extends State { Widget _errorUI() { return ErrorWidget.withDetails( - error: FlutterError(errorDetails), + error: FlutterError(errorDetails.toString()), ); } @@ -196,6 +197,6 @@ class _CreateAccountPageState extends State { ..add(DiagnosticsProperty('isAuthenticating', isAuthenticating)) ..add(DiagnosticsProperty('isAccountImportingError', isAccountImportingError)) ..add(DiagnosticsProperty('isError', isError)) - ..add(DiagnosticsProperty('errorDetails', errorDetails)); + ..add(DiagnosticsProperty('errorDetails', errorDetails)); } } diff --git a/starport_template/lib/stores/accounts_store.dart b/starport_template/lib/stores/accounts_store.dart index 4c7150cc..9b488a89 100644 --- a/starport_template/lib/stores/accounts_store.dart +++ b/starport_template/lib/stores/accounts_store.dart @@ -4,6 +4,7 @@ import 'package:mobx/mobx.dart'; import 'package:starport_template/app_config.dart'; import 'package:starport_template/entities/account_additional_data.dart'; import 'package:starport_template/entities/balance.dart'; +import 'package:starport_template/entities/error_details.dart'; import 'package:starport_template/entities/import_account_form_data.dart'; import 'package:starport_template/utils/cosmos_balances.dart'; import 'package:starport_template/utils/token_sender.dart'; @@ -32,7 +33,7 @@ class AccountsStore { final Observable _isBalancesLoadingError = Observable(false); final Observable _isRenamingAccount = Observable(false); final Observable _isSendingMoney = Observable(false); - final Observable _errorDetails = Observable(''); + final Observable _errorDetails = Observable(CosmosErrorDetails.empty()); final ObservableList balancesList = ObservableList(); final Observable loadAccountsFailure = Observable(null); @@ -79,9 +80,9 @@ class AccountsStore { set isMnemonicCreatingError(bool val) => Action(() => _isMnemonicCreatingError.value = val)(); - String get errorDetails => _errorDetails.value; + CosmosErrorDetails get errorDetails => _errorDetails.value; - set errorDetails(String val) => Action(() => _errorDetails.value = val)(); + set errorDetails(CosmosErrorDetails val) => Action(() => _errorDetails.value = val)(); bool get isMnemonicCreating => _isMnemonicCreating.value; @@ -207,7 +208,7 @@ class AccountsStore { return result.fold( (fail) { logError(fail); - errorDetails = fail.toString(); + errorDetails = CosmosErrorDetails(error: fail); isAccountImportingError = true; return null; }, @@ -240,7 +241,7 @@ class AccountsStore { await getBalances(selectedAccount.publicAddress); } catch (ex, stack) { logError(ex, stack); - errorDetails = '$ex\n\nStackTrace:\n\n$stack'; + errorDetails = CosmosErrorDetails(error: ex, stackTrace: stack); isSendMoneyError = true; } isSendMoneyLoading = false; @@ -278,7 +279,7 @@ class AccountsStore { mnemonic = await generateMnemonic(); } catch (ex, stack) { logError(ex, stack); - errorDetails = '$ex\n\nStackTrace:\n\n$stack'; + errorDetails = CosmosErrorDetails(error: ex, stackTrace: stack); isMnemonicCreatingError = true; } isMnemonicCreating = false;