@@ -5,35 +5,45 @@ import '../../services/secure_storage_service.dart';
5
5
import '../../services/user_contract_service.dart' ;
6
6
7
7
part 'settings_event.dart' ;
8
-
9
8
part 'settings_state.dart' ;
10
9
11
10
class SettingsBloc extends Bloc <SettingsEvent , SettingsState > {
12
11
SettingsBloc () : super (Initial ()) {
13
12
on < LoadEvent > ((event, emit) async {
14
13
emit (Loading ());
15
- var privateKey = await SecureStorageService .get ("private-key" ) as String ;
16
- var contractAddress =
17
- await SecureStorageService .get ("contract-address" ) as String ;
18
14
19
- var service = UserContractService ();
20
- var userInfo = await service.getAll (contractAddress, privateKey);
21
- emit (Loaded (
22
- privateKey: privateKey,
23
- contractAddress: contractAddress,
24
- email: userInfo['Email' ] as String ,
25
- phone: userInfo['Phone' ] as String ));
15
+ try {
16
+ var privateKey =
17
+ await SecureStorageService .get ("private-key" ) as String ;
18
+ var contractAddress =
19
+ await SecureStorageService .get ("contract-address" ) as String ;
20
+
21
+ var service = UserContractService ();
22
+ var userInfo = await service.getAll (contractAddress, privateKey).timeout (const Duration (seconds: 10 ), onTimeout: (){
23
+ throw Exception ("Timeout" );
24
+ });
25
+ emit (Loaded (
26
+ privateKey: privateKey,
27
+ contractAddress: contractAddress,
28
+ email: userInfo['Email' ] as String ,
29
+ phone: userInfo['Phone' ] as String ));
30
+ } catch (e) {
31
+ emit (Failed (e.toString ()));
32
+ }
26
33
});
27
34
28
35
on < EditEvent > ((event, emit) async {
29
36
emit (Loading ());
30
- try {
37
+ try {
31
38
var service = UserContractService ();
32
- if (event.editedProperty == "email" ){
33
- await service.setEmail (event.email, contractAddress: event.contractAddress, privateKey: event.privateKey);
34
- }
35
- else if (event.editedProperty == "phone" ){
36
- await service.setMobile (event.phone, contractAddress: event.contractAddress, privateKey: event.privateKey);
39
+ if (event.editedProperty == "email" ) {
40
+ await service.setEmail (event.email,
41
+ contractAddress: event.contractAddress,
42
+ privateKey: event.privateKey);
43
+ } else if (event.editedProperty == "phone" ) {
44
+ await service.setMobile (event.phone,
45
+ contractAddress: event.contractAddress,
46
+ privateKey: event.privateKey);
37
47
}
38
48
else {
39
49
throw Exception ("Unexpected Error" );
0 commit comments