Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase Crashlytics #1911

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

.vscode

.env*
secret_config.json
pubspec\.lock
Expand Down
3 changes: 2 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
22 changes: 7 additions & 15 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,12 @@
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:366914936426:android:7d2393ccb8b3bdda1a3413",
"mobilesdk_app_id": "1:366914936426:android:978896cb9d8996661a3413",
"android_client_info": {
"package_name": "com.joinseeds.seedswallet"
"package_name": "com.joinseeds.parq"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think this change is supposed to be here

Copy link
Collaborator Author

@RaulUrtecho RaulUrtecho Jun 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intresting these changes were performed by the FlutterFire ClI tool I only pick the seeds project in available options to config the Crashlytics.
Should I keep that name @n13 ?

Copy link
Collaborator Author

@RaulUrtecho RaulUrtecho Jun 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have 2 android projects?
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change that.

This is correct

package_name": "com.joinseeds.seedswallet

Why we have multiple firebase projects - Igor did this, we can delete them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RaulUrtecho is there's strange merge errors, I'd tend to just start over.

}
},
"oauth_client": [
{
"client_id": "366914936426-kn6vumn468dl6vc1rdp9ircp6v9ehufg.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.joinseeds.seedswallet",
"certificate_hash": "ada86e0a7e0067084ed872e08681b2104aaf5270"
}
},
{
"client_id": "366914936426-92ud91kd7hqj98to79aospg00m3f3to7.apps.googleusercontent.com",
"client_type": 3
Expand Down Expand Up @@ -53,18 +45,18 @@
},
{
"client_info": {
"mobilesdk_app_id": "1:366914936426:android:389b18d13a862a531a3413",
"mobilesdk_app_id": "1:366914936426:android:7d2393ccb8b3bdda1a3413",
"android_client_info": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever the package name is, don't change it?!

"package_name": "com.joinseeds.wallet"
"package_name": "com.joinseeds.seedswallet"
}
},
"oauth_client": [
{
"client_id": "366914936426-k4i8n24qb9eu1ug0cqs0rcfvc3pq1fh3.apps.googleusercontent.com",
"client_id": "366914936426-kn6vumn468dl6vc1rdp9ircp6v9ehufg.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.joinseeds.wallet",
"certificate_hash": "1d4a3d87c78e5d83f8b7c7fb5240f10fe072132f"
"package_name": "com.joinseeds.seedswallet",
"certificate_hash": "ada86e0a7e0067084ed872e08681b2104aaf5270"
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ buildscript {

dependencies {
classpath 'com.google.gms:google-services:4.3.3'

classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
classpath 'com.android.tools.build:gradle:4.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Expand Down
7 changes: 7 additions & 0 deletions ios/firebase_app_id_file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"file_generated_by": "FlutterFire CLI",
"purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory",
"GOOGLE_APP_ID": "1:366914936426:ios:75e7ba91678551811a3413",
"FIREBASE_PROJECT_ID": "seeds-77371",
"GCM_SENDER_ID": "366914936426"
}
7 changes: 2 additions & 5 deletions lib/datasource/remote/api/balance_repository.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:async/async.dart';
import 'package:http/http.dart' as http;
import 'package:seeds/datasource/remote/api/http_repo/http_repository.dart';
import 'package:seeds/datasource/remote/model/balance_model.dart';

Expand All @@ -19,10 +18,8 @@ class BalanceRepository extends HttpRepository {
final balanceURL = Uri.parse('$baseURL/v1/chain/get_currency_balance');

return http
.post(balanceURL, headers: headers, body: request)
.then((http.Response response) => mapHttpResponse<BalanceModel>(response, (dynamic body) {
return BalanceModel.fromJson(body);
}))
.post(balanceURL, body: request)
.then((response) => mapHttpResponse<BalanceModel>(response, (body) => BalanceModel.fromJson(body)))
.catchError((dynamic error) => mapHttpError(error));
}
}
7 changes: 6 additions & 1 deletion lib/datasource/remote/api/eos_repo/eos_repository.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:async';
import 'package:async/async.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart';
import 'package:seeds/crypto/eosdart/eosdart.dart';
import 'package:seeds/datasource/local/settings_storage.dart';
import 'package:seeds/datasource/remote/api/http_repo/seeds_scopes.dart';
Expand Down Expand Up @@ -71,7 +73,10 @@ abstract class EosRepository {
}

ErrorResult mapEosError(dynamic error) {
print('mapEosError: $error');
if (kDebugMode) {
print('mapEosError: $error');
}
FirebaseCrashlytics.instance.log('mapEosError: $error');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❀️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this removes EOS errors completely from the device log, then I don't agree with this change.

If crashlytics prints the errors to console as well, then OK.

EOS errors must be in the device logs, anyway.

return ErrorResult(error);
}
}
Expand Down
6 changes: 2 additions & 4 deletions lib/datasource/remote/api/esr_callback_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ class ESRCallbackRepository extends HttpRepository {
final postURI = Uri(scheme: uri.scheme, host: uri.host, path: uri.path);

return http
.post(postURI, headers: headers, body: params)
.then((http.Response response) => mapHttpResponse<bool>(response, (dynamic body) {
return true;
}))
.post(postURI, body: params)
.then((response) => mapHttpResponse<bool>(response, (body) => true))
.catchError((error) => mapHttpError(error));
}

Expand Down
17 changes: 6 additions & 11 deletions lib/datasource/remote/api/flag_repository.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';

import 'package:async/async.dart';
import 'package:http/http.dart' as http;
import 'package:seeds/crypto/eosdart/eosdart.dart';
import 'package:seeds/datasource/remote/api/eos_repo/eos_repository.dart';
import 'package:seeds/datasource/remote/api/eos_repo/seeds_eos_actions.dart';
Expand Down Expand Up @@ -35,9 +34,7 @@ class FlagRepository extends HttpRepository with EosRepository {

return buildEosClient()
.pushTransaction(transaction)
.then((dynamic response) => mapEosResponse<TransactionResponse>(response, (dynamic map) {
return TransactionResponse.fromJson(map);
}))
.then((response) => mapEosResponse<TransactionResponse>(response, (body) => TransactionResponse.fromJson(body)))
.catchError((error) => mapEosError(error));
}

Expand All @@ -64,9 +61,7 @@ class FlagRepository extends HttpRepository with EosRepository {

return buildEosClient()
.pushTransaction(transaction)
.then((dynamic response) => mapEosResponse<TransactionResponse>(response, (dynamic map) {
return TransactionResponse.fromJson(map);
}))
.then((response) => mapEosResponse<TransactionResponse>(response, (body) => TransactionResponse.fromJson(body)))
.catchError((error) => mapEosError(error));
}

Expand All @@ -88,8 +83,8 @@ class FlagRepository extends HttpRepository with EosRepository {
print("request $request");

return http
.post(url, headers: headers, body: request)
.then((http.Response response) => mapHttpResponse<List<FlagModel>>(response, (dynamic body) {
.post(url, body: request)
.then((response) => mapHttpResponse<List<FlagModel>>(response, (body) {
final List<dynamic> items = body['rows'].toList();
return items.map((item) => FlagModel.fromJson(item)).toList();
}))
Expand All @@ -112,8 +107,8 @@ class FlagRepository extends HttpRepository with EosRepository {
);

return http
.post(url, headers: headers, body: request)
.then((http.Response response) => mapHttpResponse<List<FlagModel>>(response, (dynamic body) {
.post(url, body: request)
.then((response) => mapHttpResponse<List<FlagModel>>(response, (body) {
final List<dynamic> items = body['rows'].toList();
return items.map((item) => FlagModel.fromJson(item)).toList();
}))
Expand Down
5 changes: 2 additions & 3 deletions lib/datasource/remote/api/google_places_repository.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:async/async.dart';
import 'package:http/http.dart' as http;
import 'package:seeds/datasource/remote/api/http_repo/http_repository.dart';
import 'package:seeds/datasource/remote/model/google_places_models/place_details_model.dart';
import 'package:seeds/datasource/remote/model/google_places_models/prediction_model.dart';
Expand Down Expand Up @@ -56,7 +55,7 @@ class GoogleMapsPlacesRepository extends HttpRepository {

return http
.get(Uri.https('maps.googleapis.com', '/maps/api/place/autocomplete/json', params))
.then((http.Response response) => mapHttpResponse<PlacesAutocompleteResponse>(response, (dynamic body) {
.then((response) => mapHttpResponse<PlacesAutocompleteResponse>(response, (body) {
return PlacesAutocompleteResponse.fromJson(body);
}))
.catchError((error) => mapHttpError(error));
Expand All @@ -67,7 +66,7 @@ class GoogleMapsPlacesRepository extends HttpRepository {

return http
.get(Uri.parse('https://maps.googleapis.com/maps/api/place/details/json?placeid=$placeId&key=$mapsApiKey'))
.then((http.Response response) => mapHttpResponse<PlacesDetailsResponse>(response, (dynamic body) {
.then((response) => mapHttpResponse<PlacesDetailsResponse>(response, (body) {
return PlacesDetailsResponse.fromJson(body);
}))
.catchError((error) => mapHttpError(error));
Expand Down
13 changes: 6 additions & 7 deletions lib/datasource/remote/api/guardians_repository.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:async/async.dart';
import 'package:http/http.dart' as http;
import 'package:seeds/crypto/dart_esr/dart_esr.dart' as esr;
import 'package:seeds/crypto/eosdart/eosdart.dart';
import 'package:seeds/datasource/local/settings_storage.dart';
Expand Down Expand Up @@ -204,8 +203,8 @@ class GuardiansRepository extends EosRepository with HttpRepository {
final body = '{ "account_name": "$accountName" }';

return http
.post(url, headers: headers, body: body)
.then((http.Response response) => mapHttpResponse(response, (dynamic body) {
.post(url, body: body)
.then((response) => mapHttpResponse(response, (body) {
final List<dynamic> allAccounts = body['permissions'].toList();
return allAccounts.map((item) => Permission.fromJson(item)).toList();
}))
Expand Down Expand Up @@ -263,8 +262,8 @@ class GuardiansRepository extends EosRepository with HttpRepository {
upperBound: accountName);

return http
.post(Uri.parse(requestURL), headers: headers, body: request)
.then((http.Response response) => mapHttpResponse(response, (dynamic body) {
.post(Uri.parse(requestURL), body: request)
.then((response) => mapHttpResponse(response, (body) {
final rows = body["rows"] as List<dynamic>;
return UserRecoversModel.fromTableRows(rows);
}))
Expand All @@ -285,8 +284,8 @@ class GuardiansRepository extends EosRepository with HttpRepository {
);

return http
.post(Uri.parse(requestURL), headers: headers, body: request)
.then((http.Response response) => mapHttpResponse(response, (dynamic body) {
.post(Uri.parse(requestURL), body: request)
.then((response) => mapHttpResponse(response, (body) {
final rows = body["rows"] as List<dynamic>;
return UserGuardiansModel.fromTableRows(rows);
}))
Expand Down
33 changes: 29 additions & 4 deletions lib/datasource/remote/api/http_repo/http_repository.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
import 'dart:async';

import 'package:async/async.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart';
import 'package:http/http.dart' as http;
import 'package:seeds/datasource/remote/api/http_repo/seeds_scopes.dart';
import 'package:seeds/datasource/remote/api/http_repo/seeds_tables.dart';
import 'package:seeds/datasource/remote/firebase/firebase_remote_config.dart';
import 'package:seeds/datasource/remote/util/response_extension.dart';

class _HttpClient extends http.BaseClient {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we should fire every request into crashalytics

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flutterfire docs says for log method:

To avoid slowing down your app, Crashlytics limits logs to 64kB and deletes older log entries when a session's logs go over that limit.

Copy link
Collaborator Author

@RaulUrtecho RaulUrtecho Jun 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

64 kB is quite a lot text I don't think be a problem also I did not notice any bottle neck in the app.
However this can be a big hindrance in issue diagnostic since many at times by the time we identify an issue and begin diagnostics, the logs are gone.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please let's not go overboard with Crashlytics.

It's useful but we do not want to depend on it (what if crashlytics is down, do these still work?)

We also don't want to send all http requests through crashlytics.

Only ones that have unexpected crashes.

We also need to filter out expected crashes - example, network error because user's internet was down.

final http.Client _httpClient = http.Client();
Map<String, String> headers = {'Content-type': 'application/json'};

// Intercept each call to log request info to Crashlytics.
@override
Future<http.StreamedResponse> send(http.BaseRequest request) {
if (kDebugMode) {
print('${request.method} ${request.url} ${request.contentLength}');
}
FirebaseCrashlytics.instance.log('${request.method} ${request.url} ${(request as Request).body}');
request.headers.addAll(headers);
return _httpClient.send(request);
}
}

abstract class HttpRepository {
String baseURL = remoteConfigurations.defaultEndPointUrl;
String v2historyURL = remoteConfigurations.defaultV2EndPointUrl;
String hyphaURL = remoteConfigurations.hyphaEndPoint;
String mapsApiKey = 'AIzaSyB3Ghs8i_Lw55vmSyh5mxLA9cGcWuc1A54';
String fxApiKey = "thesecretapikey989";
Map<String, String> headers = {'Content-type': 'application/json'};
_HttpClient http = _HttpClient();

FutureOr<Result<T>> mapHttpResponse<T>(http.Response response, Function modelMapper) {
FutureOr<Result<T>> mapHttpResponse<T>(Response response, Function modelMapper) {
switch (response.statusCode) {
case 200:
{
Expand All @@ -24,13 +43,19 @@ abstract class HttpRepository {
return ValueResult(modelMapper(body));
}
default:
print("network error: ${response.reasonPhrase}");
if (kDebugMode) {
print('http error: ${response.reasonPhrase}');
}
FirebaseCrashlytics.instance.log('http error: ${response.statusCode}, ${response.reasonPhrase}');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here - still going to device log?

return ErrorResult(NetworkError(response.statusCode));
}
}

ErrorResult mapHttpError(dynamic error) {
print('mapHttpError: $error');
if (kDebugMode) {
print('mapHttpError: $error');
}
FirebaseCrashlytics.instance.log('mapHttpError: $error');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

return ErrorResult(error);
}

Expand Down
21 changes: 8 additions & 13 deletions lib/datasource/remote/api/invite_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'dart:async';
import 'package:async/async.dart';

import 'package:seeds/crypto/eosdart/eosdart.dart';
import 'package:http/http.dart' as http;
import 'package:seeds/datasource/remote/api/eos_repo/eos_repository.dart';
import 'package:seeds/datasource/remote/api/eos_repo/seeds_eos_actions.dart';
import 'package:seeds/datasource/remote/api/http_repo/http_repository.dart';
Expand Down Expand Up @@ -61,9 +60,7 @@ class InviteRepository extends HttpRepository with EosRepository {

return buildEosClient()
.pushTransaction(transaction)
.then((dynamic response) => mapEosResponse<TransactionResponse>(response, (dynamic map) {
return TransactionResponse.fromJson(map);
}))
.then((response) => mapEosResponse<TransactionResponse>(response, (body) => TransactionResponse.fromJson(body)))
.catchError((error) => mapEosError(error));
}

Expand All @@ -79,8 +76,8 @@ class InviteRepository extends HttpRepository with EosRepository {
limit: 1000);

return http
.post(membersURL, headers: headers, body: request)
.then((http.Response response) => mapHttpResponse<ProfileModel>(response, (dynamic body) {
.post(membersURL, body: request)
.then((response) => mapHttpResponse<ProfileModel>(response, (body) {
final List<dynamic> allAccounts = body['rows'].toList();
return allAccounts.map((item) => ProfileModel.fromJson(item)).toList();
}))
Expand All @@ -103,8 +100,8 @@ class InviteRepository extends HttpRepository with EosRepository {
keyType: "sha256");

return http
.post(inviteURL, headers: headers, body: request)
.then((http.Response response) => mapHttpResponse<List<InviteModel>>(response, (dynamic body) {
.post(inviteURL, body: request)
.then((response) => mapHttpResponse<List<InviteModel>>(response, (body) {
final List<dynamic> invite = body['rows'].toList();
return invite.map((item) => InviteModel.fromJson(item)).toList();
}))
Expand All @@ -127,8 +124,8 @@ class InviteRepository extends HttpRepository with EosRepository {
);

return http
.post(inviteURL, headers: headers, body: request)
.then((http.Response response) => mapHttpResponse<List<InviteModel>>(response, toDomainInviteModel))
.post(inviteURL, body: request)
.then((response) => mapHttpResponse<List<InviteModel>>(response, toDomainInviteModel))
.catchError((e) => mapHttpError(e));
}

Expand All @@ -155,9 +152,7 @@ class InviteRepository extends HttpRepository with EosRepository {

return buildEosClient()
.pushTransaction(transaction)
.then((dynamic response) => mapEosResponse<TransactionResponse>(response, (dynamic map) {
return TransactionResponse.fromJson(map);
}))
.then((response) => mapEosResponse<TransactionResponse>(response, (body) => TransactionResponse.fromJson(body)))
.catchError((error) => mapEosError(error));
}
}
10 changes: 3 additions & 7 deletions lib/datasource/remote/api/key_accounts_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ class KeyAccountsRepository extends HttpRepository {
final body = '{ "public_key": "$publicKey" }';

return http
.post(url, headers: headers, body: body)
.then((http.Response response) => mapHttpResponse(response, (dynamic body) {
print('result: $body');

.post(url, body: body)
.then((response) => mapHttpResponse(response, (body) {
final result = List<String>.from(body['account_names']);

result.sort();

return result;
}))
.catchError((dynamic error) => mapHttpError(error));
.catchError((error) => mapHttpError(error));
}
}
Loading