-
Notifications
You must be signed in to change notification settings - Fork 1
/
change_pin_usecase.dart
56 lines (51 loc) · 2.21 KB
/
change_pin_usecase.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright © 2022 Nevis Security AG. All rights reserved.
import 'package:flutter/foundation.dart';
import 'package:injectable/injectable.dart';
import 'package:nevis_mobile_authentication_sdk/nevis_mobile_authentication_sdk.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/blocs/domain_state/domain_bloc.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/blocs/domain_state/domain_event.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/client_provider/client_provider.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/error/error_handler.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/model/operation/operation_type.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/model/operation/pin_change_state.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/domain/repository/state_repository.dart';
abstract class ChangePinUseCase {
Future<void> execute({
required String username,
});
}
@Injectable(as: ChangePinUseCase)
class ChangePinUseCaseImpl implements ChangePinUseCase {
final ClientProvider _clientProvider;
final PinChanger _pinChanger;
final DomainBloc _domainBloc;
final StateRepository<OperationType> _operationTypeRepository;
final StateRepository<PinChangeState> _pinChangeStateRepository;
final ErrorHandler _errorHandler;
ChangePinUseCaseImpl(
this._clientProvider,
this._pinChanger,
this._domainBloc,
this._operationTypeRepository,
this._pinChangeStateRepository,
this._errorHandler,
);
@override
Future<void> execute({
required String username,
}) async {
_operationTypeRepository.save(OperationType.pinChange);
await _clientProvider.client.operations.pinChange //
.username(username)
.pinChanger(_pinChanger)
.onSuccess(() {
debugPrint('PIN change succeeded.');
_domainBloc.add(ResultEvent());
_pinChangeStateRepository.reset();
}).onError((error) {
debugPrint('PIN change failed: ${error.description}');
_errorHandler.handle(error);
_pinChangeStateRepository.reset();
}).execute();
}
}