Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #161 from MXCzkEVM/dapp_hooks
Browse files Browse the repository at this point in the history
feat: ignore already known error
  • Loading branch information
reasje authored Feb 15, 2024
2 parents de6c371 + 8779aa3 commit d2352d3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 17 deletions.
14 changes: 8 additions & 6 deletions lib/core/src/providers/providers_use_cases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ final Provider<BackgroundFetchConfigUseCase>

final Provider<DAppHooksUseCase> dAppHooksUseCaseProvider = Provider(
(ref) => DAppHooksUseCase(
ref.watch(datadashCacheProvider).dAppHooksRepository,
ref.watch(chainConfigurationUseCaseProvider),
ref.watch(tokenContractUseCaseProvider),
ref.watch(minerUseCaseProvider),
ref.watch(accountUseCaseProvider),
),
ref.watch(datadashCacheProvider).dAppHooksRepository,
ref.watch(chainConfigurationUseCaseProvider),
ref.watch(tokenContractUseCaseProvider),
ref.watch(minerUseCaseProvider),
ref.watch(
accountUseCaseProvider,
),
ref.watch(errorUseCaseProvider)),
);

final Provider<BalanceUseCase> balanceHistoryUseCaseProvider = Provider(
Expand Down
27 changes: 27 additions & 0 deletions lib/features/common/app/error_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,33 @@ class ErrorUseCase extends ReactiveUseCase {
}
}

bool handleBackgroundServiceError(
String notificationTitle,
dynamic e,
) {
if (e is RPCError && isRPCIgnoredError(e.message)) {
return true;
}

AXSNotification().showNotification(
notificationTitle,
e.toString(),
);
return true;
}
// already known

bool isRPCIgnoredError(String message) {
bool isIgnored = false;
for (String error in Config.ignoredErrors) {
if (message.contains(error)) {
isIgnored = true;
break;
}
}
return isIgnored;
}

bool handlerRPCError(
BuildContext context,
String message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class DAppHooksUseCase extends ReactiveUseCase {
this._tokenContractUseCase,
this._minerUseCase,
this._accountUseCase,
this._errorUseCase
) {
initialize();
}
Expand All @@ -29,6 +30,7 @@ class DAppHooksUseCase extends ReactiveUseCase {
final ChainConfigurationUseCase _chainConfigurationUseCase;
final AccountUseCase _accountUseCase;
final TokenContractUseCase _tokenContractUseCase;
final ErrorUseCase _errorUseCase;
final MinerUseCase _minerUseCase;

StreamSubscription<geo.Position>? positionStream;
Expand Down Expand Up @@ -156,11 +158,8 @@ class DAppHooksUseCase extends ReactiveUseCase {
);
print("tx : ${tx.hash}");
} catch (e) {
print(e);
AXSNotification().showNotification(
"Wi-Fi Transaction Update failed ",
e.toString(),
);
_errorUseCase.handleBackgroundServiceError(
"Wi-Fi Transaction Update failed ", e);
}
}
}
Expand Down Expand Up @@ -320,11 +319,8 @@ class DAppHooksUseCase extends ReactiveUseCase {
updatedAutoClaimTime = updatedAutoClaimTime.add(const Duration(days: 1));
return updatedAutoClaimTime;
} catch (e) {
print(e);
AXSNotification().showNotification(
"Miner auto-claim failed!",
e.toString(),
);
_errorUseCase.handleBackgroundServiceError(
"Wi-Fi Transaction Update failed ", e);
return minerAutoClaimTime;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/shared
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
super_tooltip:
dependency: transitive
description:
name: super_tooltip
sha256: "925bbc20d825922e415e9445b22a41987c10be5812f292b9f8b44c4b3ff16e21"
url: "https://pub.dev"
source: hosted
version: "2.0.7"
synchronized:
dependency: transitive
description:
Expand Down

0 comments on commit d2352d3

Please sign in to comment.