Skip to content

Commit

Permalink
Merge pull request #250 from hypha-dao/bugfix/update_account_import
Browse files Browse the repository at this point in the history
Update account import
  • Loading branch information
n13 authored Sep 7, 2023
2 parents 7a4a655 + 30abed2 commit 572f9b2
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
13 changes: 8 additions & 5 deletions lib/core/crypto/eosdart/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,15 @@ class EOSClient extends NetworkingManager {
});
}

/// Get Key Accounts
Future<Result<AccountNames>> getKeyAccounts(String pubKey) async {
/// Get accounts by key - uses /chain/get_accounts_by_authorizers
Future<Result<AccountNames>> getAccountsByKey(String pubKey) async {
try {
return Result.capture(
_post('/history/get_key_accounts', {'public_key': pubKey}).then((dio.Response accountNames) {
return AccountNames.fromJson(accountNames.data as Map<String, dynamic>);
return Result.capture(_post('/chain/get_accounts_by_authorizers', {
'accounts': [],
'keys': [pubKey]
}).then((dio.Response response) {
final List<String> accountNames = List.from(response.data['accounts'].map((e) => e['account_name']));
return AccountNames(accountNames.toSet().toList());
}));
} catch (e) {
LogHelper.e(e.toString());
Expand Down
5 changes: 3 additions & 2 deletions lib/core/logging/log_helper.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:fimber/fimber.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart';

const kLogQuietMode = false;
const kIsDebugNetworking = true;
Expand Down Expand Up @@ -36,6 +35,8 @@ class LogHelper {
static void e(String message, {dynamic error, StackTrace? stacktrace}) {
Fimber.e(message, ex: error, stacktrace: stacktrace);
FirebaseCrashlytics.instance.log('Error message $message \nStackTrace: $stacktrace');
if (error != null && kDebugMode) throw error;
// Nik: I commented out below. A log should never throw an error!
// It should log things. Not throw errors.
// if (error != null && kDebugMode) throw error;
}
}
5 changes: 3 additions & 2 deletions lib/core/network/api/services/remote_config_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ class RemoteConfigService {
},
"eosTestnet": {
"name": "Jungle4 Testnet",
"endpoint": "https://jungle4.dfuse.eosnation.io",
"fastEndpoint": "https://jungle4.dfuse.eosnation.io",
"endpoint": "http://jungle.eosusa.io/",
"fastEndpoint": "http://jungle.eosusa.io/",
"loginContract": "logintohypha",
"loginAction": "loginuser",
"logoutAction": "logoutuser",
Expand Down Expand Up @@ -207,6 +207,7 @@ class RemoteConfigService {
'walletEnabled': false,
});
FirebaseRemoteConfig.instance.onConfigUpdated.listen((event) async {
// Side note: This does not seem to work reliably on simulator but it works in the app.
await FirebaseRemoteConfig.instance.activate();
});
}
Expand Down
5 changes: 3 additions & 2 deletions lib/core/network/repository/profile_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ class ProfileService {
final map = Map<String, dynamic>.from(response.data);
return Result.value(ProfileData.fromJson(map, user.network, []));
} else {
LogHelper.e('get profile status error', stacktrace: StackTrace.current);
LogHelper.i('get profile error status code: ${response.statusMessage}');
return Result.error(HyphaError(type: HyphaErrorType.api, message: 'server error ${response.statusMessage}'));
}
} catch (error, stackTrace) {
// note: 500 status on get throws an error
LogHelper.e('get profile error', stacktrace: stackTrace, error: error);
// this happens when the profile doesn't exist, which is valid
LogHelper.i('get profile error', stacktrace: stackTrace, error: error);
return Result.error(HyphaError(type: HyphaErrorType.api, message: 'server error $error'));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:hypha_wallet/core/error_handler/model/hypha_error.dart';
import 'package:hypha_wallet/core/logging/log_helper.dart';
import 'package:hypha_wallet/core/network/api/services/transaction_history_service.dart';
import 'package:hypha_wallet/core/network/dio_exception.dart';
import 'package:hypha_wallet/core/network/models/network.dart';
import 'package:hypha_wallet/core/network/models/transaction_model.dart';
import 'package:hypha_wallet/core/network/models/user_profile_data.dart';
import 'package:hypha_wallet/ui/architecture/result/result.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/home_page/components/scanner_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class _ScannerWidgetState extends State<ScannerWidget> {
),
);
} else {
final String code = barcodes.first!.rawValue!;
final String code = barcodes.first.rawValue!;
LogHelper.d('Barcode found! $code');
hideScanner();
context.read<HomeBloc>().add(HomeEvent.onQRCodeScanned(code));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class FindAccountsUseCase extends InputUseCase<Result<Iterable<UserProfileData>,
);

final results = await Future.wait([
eosClient.getKeyAccounts(input),
telosClient.getKeyAccounts(input),
telosTestnetClient.getKeyAccounts(input),
eosTestnetClient.getKeyAccounts(input)
eosClient.getAccountsByKey(input),
telosClient.getAccountsByKey(input),
telosTestnetClient.getAccountsByKey(input),
eosTestnetClient.getAccountsByKey(input)
]);
final eosResult = results[0];
final telosResult = results[1];
Expand Down

0 comments on commit 572f9b2

Please sign in to comment.