-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: My Account access block (#6)
The purpose of this branch is to block access to MyAccountPage if the connected network does not contain information about default token or bech32 address prefix. List of changes: - created global_nav_controller.dart to enable navigation without passing an instance of BuildContext - added "leaveProtectedPage()" method from global_nav_controller.dart to "signOut()" method auth_cubit.dart to link those 2 actions - added methods in network_module_bloc.dart with reference to auth_cubit.dart to automatically log out and leave MyAccountPage if user changes to unhealthy network that does not contain TokenDefaultDenomModel - modified sign_in_drawer_page.dart to block connecting the wallet if network does not contain TokenDefaultDenomModel and created sign_in_drawer_warning_section.dart to display "Change network" button and refresh network timer in this case - added NetworkModuleState.refreshing() to provide information about network refreshing to SignInDrawerPage - added "lastRefreshDateTime" to all Network Models (except NetworkEmptyModel) to save info about time of last refresh of each network. This enabled creating a timer in SignInDrawerPage and optimizing network refreshing in network_module_bloc.dart and network_custom_section.cubit.dart. - renamed "timed_refresh_button_cubit.dart" -> "time_counter_cubit.dart" since it was used in sign_in_drawer_warning_section.dart, so it became a generic cubit instead of specific widget centered - removed redundant method from network_module_service.dart and changed nullable TokenDefaultDenomModel to bool variable "valuesFromNetworkExistBool" inside this model - unrelated with the branch's specific domain: added conditions in network_module_bloc.dart and network_custom_section_cubit.dart to prevent still refreshing networks from being refreshed again - unrelated with the branch's specific domain: added TODO about removing IdentityRegistrarCubit initialization in main.dart
- Loading branch information
Showing
52 changed files
with
854 additions
and
275 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
60 changes: 60 additions & 0 deletions
60
lib/blocs/pages/drawer/sign_in_drawer_page/sign_in_drawer_page_cubit.dart
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,60 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:miro/blocs/generic/network_module/events/network_module_refresh_event.dart'; | ||
import 'package:miro/blocs/generic/network_module/network_module_bloc.dart'; | ||
import 'package:miro/blocs/generic/network_module/network_module_state.dart'; | ||
import 'package:miro/blocs/pages/drawer/sign_in_drawer_page/sign_in_drawer_page_state.dart'; | ||
import 'package:miro/config/app_config.dart'; | ||
import 'package:miro/config/locator.dart'; | ||
import 'package:miro/shared/models/tokens/token_default_denom_model.dart'; | ||
|
||
class SignInDrawerPageCubit extends Cubit<SignInDrawerPageState> { | ||
final int refreshIntervalSeconds = globalLocator<AppConfig>().defaultRefreshIntervalSeconds; | ||
final NetworkModuleBloc _networkModuleBloc = globalLocator<NetworkModuleBloc>(); | ||
late final StreamSubscription<NetworkModuleState> _networkModuleStateSubscription; | ||
|
||
SignInDrawerPageCubit() : super(const SignInDrawerPageState(disabledBool: true)) { | ||
_refreshDrawer(); | ||
_networkModuleStateSubscription = _networkModuleBloc.stream.listen(_refreshDrawer); | ||
} | ||
|
||
void refreshNetwork() { | ||
_networkModuleBloc.add(NetworkModuleRefreshEvent()); | ||
emit(state.copyWith(refreshUnlockingDateTime: DateTime.now().add(Duration(seconds: refreshIntervalSeconds)))); | ||
} | ||
|
||
@override | ||
Future<void> close() { | ||
_networkModuleStateSubscription.cancel(); | ||
return super.close(); | ||
} | ||
|
||
void _refreshDrawer([NetworkModuleState? networkModuleState]) { | ||
TokenDefaultDenomModel tokenDefaultDenomModel = _networkModuleBloc.tokenDefaultDenomModel; | ||
bool disabledBool = tokenDefaultDenomModel.valuesFromNetworkExistBool == false; | ||
DateTime expirationDateTime = _calculateExpirationDateTime(); | ||
if (_networkModuleBloc.state.isRefreshing) { | ||
emit(state.copyWith(disabledBool: disabledBool, refreshingBool: true, refreshUnlockingDateTime: expirationDateTime)); | ||
} else { | ||
emit(state.copyWith(disabledBool: disabledBool, refreshingBool: false, refreshUnlockingDateTime: expirationDateTime)); | ||
} | ||
} | ||
|
||
DateTime _calculateExpirationDateTime() { | ||
DateTime calculationStartDateTime = DateTime.now(); | ||
|
||
// Last refresh of currently connected network from now, which refreshes only during NetworkModuleRefreshEvent | ||
// Can take bigger values than 60s because of long response time | ||
Duration lastRefreshFromNow = calculationStartDateTime.difference(_networkModuleBloc.state.networkStatusModel.lastRefreshDateTime!); | ||
|
||
// Last occurrence of NetworkModuleRefreshEvent from now | ||
// If lastRefreshFromNow is more than 60s (e.g. 78s), lastAutoRefreshEventFromNow will equal the remainder of dividing it by 60s (e.g. 18s) | ||
// Milliseconds were used to avoid inaccurate rounding by the Duration class (e.g. 59.9s -> 59.0s) | ||
Duration lastAutoRefreshEventFromNow = | ||
lastRefreshFromNow.inSeconds > 60 ? Duration(milliseconds: lastRefreshFromNow.inMilliseconds % 60000) : lastRefreshFromNow; | ||
|
||
Duration timeUntilNextRefresh = Duration(seconds: refreshIntervalSeconds) - lastAutoRefreshEventFromNow; | ||
return calculationStartDateTime.add(timeUntilNextRefresh); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
lib/blocs/pages/drawer/sign_in_drawer_page/sign_in_drawer_page_state.dart
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,28 @@ | ||
import 'package:equatable/equatable.dart'; | ||
|
||
class SignInDrawerPageState extends Equatable { | ||
final bool disabledBool; | ||
final bool refreshingBool; | ||
final DateTime? refreshUnlockingDateTime; | ||
|
||
const SignInDrawerPageState({ | ||
required this.disabledBool, | ||
this.refreshingBool = false, | ||
this.refreshUnlockingDateTime, | ||
}); | ||
|
||
SignInDrawerPageState copyWith({ | ||
bool? disabledBool, | ||
bool? refreshingBool, | ||
DateTime? refreshUnlockingDateTime, | ||
}) { | ||
return SignInDrawerPageState( | ||
disabledBool: disabledBool ?? this.disabledBool, | ||
refreshingBool: refreshingBool ?? this.refreshingBool, | ||
refreshUnlockingDateTime: refreshUnlockingDateTime ?? this.refreshUnlockingDateTime, | ||
); | ||
} | ||
|
||
@override | ||
List<Object?> get props => <Object?>[disabledBool, refreshingBool, refreshUnlockingDateTime]; | ||
} |
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
4 changes: 2 additions & 2 deletions
4
...sh_button/timed_refresh_button_state.dart → ...tons/time_counter/time_counter_state.dart
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
Oops, something went wrong.