-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove declarative routes (#1288)
- Loading branch information
Showing
20 changed files
with
260 additions
and
443 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
75 changes: 75 additions & 0 deletions
75
packages/espressocash_app/lib/features/accounts/services/account_service.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,75 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | ||
import 'package:injectable/injectable.dart'; | ||
import 'package:sentry_flutter/sentry_flutter.dart'; | ||
|
||
import '../../../di.config.dart'; | ||
import '../../../di.dart'; | ||
import '../../analytics/analytics_manager.dart'; | ||
import '../../authenticated/auth_scope.dart'; | ||
import '../data/account_repository.dart'; | ||
import '../models/account.dart'; | ||
import '../models/mnemonic.dart'; | ||
|
||
@Singleton() | ||
class AccountService extends ChangeNotifier | ||
implements ValueListenable<MyAccount?> { | ||
AccountService( | ||
this._repository, | ||
this._analyticsManager, | ||
this._storage, | ||
); | ||
|
||
final AccountRepository _repository; | ||
final AnalyticsManager _analyticsManager; | ||
final FlutterSecureStorage _storage; | ||
|
||
MyAccount? _value; | ||
|
||
@override | ||
MyAccount? get value => _value; | ||
|
||
void _update(MyAccount? value) { | ||
if (value == _value) return; | ||
|
||
_value = value; | ||
notifyListeners(); | ||
} | ||
|
||
Future<void> initialize() async { | ||
final account = await _repository.loadAccount(); | ||
if (account != null) { | ||
await _processLogIn(account); | ||
} | ||
} | ||
|
||
Future<void> logIn({ | ||
required AccountSource source, | ||
required MyAccount account, | ||
}) async { | ||
await _repository.saveAccountSource(source); | ||
await _processLogIn(account); | ||
} | ||
|
||
Future<void> logOut() async { | ||
if (_value == null) return; | ||
|
||
_analyticsManager.setWalletAddress(null); | ||
Sentry.configureScope((scope) => scope.removeExtra('walletAddress')); | ||
|
||
await _storage.deleteAll(); | ||
await sl.dropScope(authScope); | ||
|
||
_update(null); | ||
} | ||
|
||
Future<void> _processLogIn(MyAccount account) async { | ||
Sentry.configureScope( | ||
(scope) => scope.setExtra('walletAddress', account.address), | ||
); | ||
_analyticsManager.setWalletAddress(account.address); | ||
await sl.initAuthScope(); | ||
|
||
_update(account); | ||
} | ||
} |
100 changes: 0 additions & 100 deletions
100
packages/espressocash_app/lib/features/accounts/services/accounts_bloc.dart
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.