diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 522bae41..f0ae7ec7 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -29,6 +29,8 @@
+
+
diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist
index 3a2c1b3f..606a22f7 100644
--- a/ios/Runner/Info.plist
+++ b/ios/Runner/Info.plist
@@ -5,8 +5,8 @@
BGTaskSchedulerPermittedIdentifiers
com.transistorsoft.fetch
- com.mxc.axswallet.periodicalTasks
- com.mxc.axswallet.dappHooksTasks
+ com.mxc.axswallet.notificationsTask
+ com.mxc.axswallet.wifiHooksTask
com.mxc.axswallet.minerAutoClaimTask
CADisableMinimumFrameDurationOnPhone
@@ -103,13 +103,10 @@
AXS Wallet needs access to your Biometric data when the app is in use for authentication only. Your Biometric data is not saved or shared with any third parties.
NSLocationAlwaysAndWhenInUseUsageDescription
AXS Wallet needs access to your location for features such as Wi-Fi hooks while the app is in use or running in the background. Your location data is not saved or shared with any third parties.
-
NSLocationAlwaysUsageDescription
AXS Wallet requires access to your location at all times for services such as Wi-Fi hooks. Your location data is not saved or shared with any third parties.
-
NSLocationUsageDescription
AXS Wallet needs access to your location to provide services such as Wi-Fi hooks. Your location data is not saved or shared with any third parties.
-
NSLocationWhenInUseUsageDescription
AXS Wallet needs access to your location when the app is in use for services such as Wi-Fi hooks. Your location data is not saved or shared with any third parties.
NSMotionUsageDescription
@@ -124,7 +121,6 @@
Would you allow AXS Wallet to use the Notification?
NSBluetoothAlwaysUsageDescription
AXS Wallet needs access to your Bluetooth when the app is in use or running in the background for services such as BluberryRing. Blutooth data is not saved or shared with any third parties.
-
UIApplicationSupportsIndirectInputEvents
UIBackgroundModes
diff --git a/lib/core/src/background_process/axs_background_fetch.dart b/lib/core/src/background_process/axs_background_fetch.dart
index f0adb4ff..b4edb33c 100644
--- a/lib/core/src/background_process/axs_background_fetch.dart
+++ b/lib/core/src/background_process/axs_background_fetch.dart
@@ -22,9 +22,9 @@ class AXSBackgroundFetch {
}
static void handleCallBackDispatcher(String taskId) async {
- if (taskId == BackgroundExecutionConfig.axsPeriodicalTask) {
+ if (taskId == BackgroundExecutionConfig.notificationsTask) {
NotificationsService.notificationsCallbackDispatcher(taskId);
- } else if (taskId == BackgroundExecutionConfig.dappHookTasks) {
+ } else if (taskId == BackgroundExecutionConfig.wifiHooksTask) {
DAppHooksService.dappHooksServiceCallBackDispatcherForeground(taskId);
} else if (taskId == BackgroundExecutionConfig.minerAutoClaimTask) {
DAppHooksService.autoClaimServiceCallBackDispatcherForeground(taskId);
@@ -40,7 +40,7 @@ class AXSBackgroundFetch {
static bool turnOffAll(
DAppHooksModel dAppHooksData, PeriodicalCallData periodicalCallData) {
- return !dAppHooksData.enabled &&
+ return !dAppHooksData.wifiHooks.enabled &&
!periodicalCallData.serviceEnabled &&
!dAppHooksData.minerHooks.enabled;
}
diff --git a/lib/core/src/background_process/dapp_hooks_service.dart b/lib/core/src/background_process/dapp_hooks_service.dart
index eb335b97..674b892c 100644
--- a/lib/core/src/background_process/dapp_hooks_service.dart
+++ b/lib/core/src/background_process/dapp_hooks_service.dart
@@ -26,20 +26,18 @@ class DAppHooksService {
final isLoggedIn = authUseCase.loggedIn;
final account = accountUseCase.account.value;
- final serviceEnabled = dappHooksData.enabled;
final wifiHooksEnabled = dappHooksData.wifiHooks.enabled;
// Make sure user is logged in
- if (isLoggedIn && MXCChains.isMXCChains(chainId) && serviceEnabled) {
+ if (isLoggedIn && MXCChains.isMXCChains(chainId) && wifiHooksEnabled) {
await AXSNotification()
.setupFlutterNotifications(shouldInitFirebase: false);
await contextLessTranslationUseCase.setupTranslator();
- if (wifiHooksEnabled) {
- await dAppHooksUseCase.sendWifiInfo(
- account!,
- );
- }
+ await dAppHooksUseCase.sendWifiInfo(
+ account!,
+ );
+
BackgroundFetch.finish(taskId);
} else {
// terminate background fetch
diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart
index 599bd0b6..da1e5439 100644
--- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart
+++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart
@@ -884,8 +884,9 @@ class OpenDAppPresenter extends CompletePresenter {
final uInt8List = Uint8List.fromList(value);
- collectLog('characteristicValueStreamSubscription:value $value');
- collectLog('characteristicValueStreamSubscription:uInt8List ${uInt8List.toString()}');
+ collectLog('characteristicValueStreamSubscription:value $value');
+ collectLog(
+ 'characteristicValueStreamSubscription:uInt8List ${uInt8List.toString()}');
return uInt8List;
}
@@ -906,7 +907,8 @@ class OpenDAppPresenter extends CompletePresenter {
final uInt8List = Uint8List.fromList(event);
print(uInt8List);
collectLog('characteristicValueStreamSubscription:event $event');
- collectLog('characteristicValueStreamSubscription:uInt8List ${uInt8List.toString()}');
+ collectLog(
+ 'characteristicValueStreamSubscription:uInt8List ${uInt8List.toString()}');
final script = '''
navigator.bluetooth.updateCharacteristicValue('${characteristic.uuid.str}', ${uInt8List.toString()},);
''';
@@ -932,7 +934,7 @@ class OpenDAppPresenter extends CompletePresenter {
await state.webviewController!.injectJavascriptFileFromAsset(
assetFilePath: 'assets/js/bluetooth/bluetooth.js');
- // There is a gap for detecting the axs object in webview, It's intermittent after adding function structure to the scripts
+ // There is a gap for detecting the axs object in webview, It's intermittent after adding function structure to the scripts
Future.delayed(
const Duration(milliseconds: 500),
() async {
diff --git a/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_page.dart b/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_page.dart
index 316bd07a..cb5352ce 100644
--- a/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_page.dart
+++ b/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_page.dart
@@ -25,14 +25,9 @@ class DAppHooksPage extends HookConsumerWidget {
final dappHooksPresenter = ref.read(presenter);
final frequency = getPeriodicalCallDurationFromInt(
- dappHooksState.dAppHooksData!.duration);
+ dappHooksState.dAppHooksData!.wifiHooks.duration);
final isMXCChains = MXCChains.isMXCChains(dappHooksState.network!.chainId);
- final dappHooksServiceServiceEnabled =
- dappHooksState.dAppHooksData!.enabled;
-
- final isSettingsChangeEnabled =
- isMXCChains && dappHooksServiceServiceEnabled;
final minerAutoClaimDateTime =
dappHooksState.dAppHooksData!.minerHooks.time;
@@ -52,9 +47,10 @@ class DAppHooksPage extends HookConsumerWidget {
),
children: [
MXCSwitchRowItem(
- title: translate('dapp_hooks'),
- value: dappHooksState.dAppHooksData!.enabled,
- onChanged: dappHooksPresenter.changeDAppHooksEnabled,
+ key: const Key('wifiHookSwitch'),
+ title: translate('wifi_hexagon_location_hooks'),
+ value: dappHooksState.dAppHooksData!.wifiHooks.enabled,
+ onChanged: dappHooksPresenter.changeWiFiHooksEnabled,
enabled: true,
textTrailingWidget: MXCInformationButton(texts: [
TextSpan(
@@ -94,6 +90,13 @@ class DAppHooksPage extends HookConsumerWidget {
.copyWith(color: ColorsTheme.of(context).textPrimary),
),
const TextSpan(text: '\n\n'),
+ TextSpan(
+ text: FlutterI18n.translate(context, 'wifi_hooks_solutions'),
+ style: FontTheme.of(context)
+ .subtitle1()
+ .copyWith(color: ColorsTheme.of(context).textPrimary),
+ ),
+ const TextSpan(text: '\n\n'),
TextSpan(
text: FlutterI18n.translate(context, 'need_further_assistant'),
style: FontTheme.of(context)
@@ -105,80 +108,10 @@ class DAppHooksPage extends HookConsumerWidget {
),
const SizedBox(height: Sizes.spaceNormal),
MXCDropDown(
- key: const Key('dappHooksFrequencyDropDown'),
- onTap: dappHooksPresenter.showDAppHooksFrequency,
+ key: const Key('wifiHooksFrequencyDropDown'),
+ onTap: dappHooksPresenter.showWiFiHooksFrequency,
selectedItem: frequency.toStringFormatted(),
- enabled:
- isSettingsChangeEnabled && dappHooksState.dAppHooksData!.enabled,
- ),
- const SizedBox(height: Sizes.spaceXLarge),
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: Sizes.spaceLarge),
- child: Column(
- children: [
- MXCSwitchRowItem(
- key: const Key('wifiHookSwitch'),
- title: translate('wifi_hexagon_location_hooks'),
- value: dappHooksState.dAppHooksData!.wifiHooks.enabled,
- onChanged: dappHooksPresenter.changeWifiHooksEnabled,
- enabled: isSettingsChangeEnabled,
- textTrailingWidget: MXCInformationButton(texts: [
- TextSpan(
- text: FlutterI18n.translate(context, 'experiencing_issues'),
- style: FontTheme.of(context)
- .subtitle2()
- .copyWith(color: ColorsTheme.of(context).textPrimary),
- ),
- const TextSpan(text: '\n\n'),
- TextSpan(
- text: FlutterI18n.translate(
- context, 'background_service_solution_1_title'),
- style: FontTheme.of(context)
- .subtitle2()
- .copyWith(color: ColorsTheme.of(context).textPrimary),
- ),
- TextSpan(
- text: FlutterI18n.translate(
- context, 'background_service_solution_1_text'),
- style: FontTheme.of(context)
- .subtitle1()
- .copyWith(color: ColorsTheme.of(context).textPrimary),
- ),
- const TextSpan(text: '\n\n'),
- TextSpan(
- text: FlutterI18n.translate(
- context, 'background_service_solution_2_title'),
- style: FontTheme.of(context)
- .subtitle2()
- .copyWith(color: ColorsTheme.of(context).textPrimary),
- ),
- TextSpan(
- text: FlutterI18n.translate(
- context, 'background_service_solution_2_text'),
- style: FontTheme.of(context)
- .subtitle1()
- .copyWith(color: ColorsTheme.of(context).textPrimary),
- ),
- const TextSpan(text: '\n\n'),
- TextSpan(
- text:
- FlutterI18n.translate(context, 'wifi_hooks_solutions'),
- style: FontTheme.of(context)
- .subtitle1()
- .copyWith(color: ColorsTheme.of(context).textPrimary),
- ),
- const TextSpan(text: '\n\n'),
- TextSpan(
- text: FlutterI18n.translate(
- context, 'need_further_assistant'),
- style: FontTheme.of(context)
- .subtitle1()
- .copyWith(color: ColorsTheme.of(context).textPrimary),
- ),
- ]),
- ),
- ],
- ),
+ enabled: isMXCChains,
),
const SizedBox(height: Sizes.spaceLarge),
MXCSwitchRowItem(
diff --git a/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_presenter.dart b/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_presenter.dart
index 9e6a9b7e..5e7ad2cd 100644
--- a/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_presenter.dart
+++ b/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_presenter.dart
@@ -7,7 +7,7 @@ import 'package:geolocator/geolocator.dart' as geo;
import 'package:mxc_logic/mxc_logic.dart';
import 'dapp_hooks_state.dart';
-import 'widgets/dapp_hooks_frequency_dialog.dart';
+import 'widgets/wifi_hooks_frequency_bottom_sheet.dart';
final notificationsContainer =
PresenterContainer(
@@ -39,18 +39,19 @@ class DAppHooksPresenter extends CompletePresenter
backgroundFetchConfigUseCase: _backgroundFetchConfigUseCase);
WiFiHooksHelper get wifiHooksHelper => WiFiHooksHelper(
- translate: translate,
- context: context,
- dAppHooksUseCase: _dAppHooksUseCase,
- state: state,
- geoLocatorPlatform: _geoLocatorPlatform);
+ translate: translate,
+ context: context,
+ dAppHooksUseCase: _dAppHooksUseCase,
+ state: state,
+ geoLocatorPlatform: _geoLocatorPlatform,
+ backgroundFetchConfigUseCase: _backgroundFetchConfigUseCase,
+ );
DAppHooksHelper get dappHooksHelper => DAppHooksHelper(
- translate: translate,
- context: context,
- dAppHooksUseCase: _dAppHooksUseCase,
- state: state,
- backgroundFetchConfigUseCase: _backgroundFetchConfigUseCase);
+ translate: translate,
+ context: context,
+ state: state,
+ );
@override
void initState() {
@@ -75,20 +76,17 @@ class DAppHooksPresenter extends CompletePresenter
);
}
- void changeDAppHooksEnabled(bool value) =>
- dappHooksHelper.changeDAppHooksEnabled(value);
-
- void changeWifiHooksEnabled(bool value) =>
- wifiHooksHelper.changeWifiHooksEnabled(value);
+ void changeWiFiHooksEnabled(bool value) =>
+ wifiHooksHelper.changeWiFiHooksEnabled(value);
void changeMinerHooksEnabled(bool value) =>
minerHooksHelper.changeMinerHooksEnabled(value);
- void showDAppHooksFrequency() {
- showDAppHooksFrequencyDialog(context!,
- onTap: dappHooksHelper.handleFrequencyChange,
- selectedFrequency:
- getPeriodicalCallDurationFromInt(state.dAppHooksData!.duration));
+ void showWiFiHooksFrequency() {
+ showWiFiHooksFrequencyBottomSheet(context!,
+ onTap: wifiHooksHelper.handleFrequencyChange,
+ selectedFrequency: getPeriodicalCallDurationFromInt(
+ state.dAppHooksData!.wifiHooks.duration));
}
void showTimePickerDialog() async {
diff --git a/lib/features/settings/subfeatures/dapp_hooks/domain/dapp_hooks_use_case.dart b/lib/features/settings/subfeatures/dapp_hooks/domain/dapp_hooks_use_case.dart
index 1d78aa0c..291208a8 100644
--- a/lib/features/settings/subfeatures/dapp_hooks/domain/dapp_hooks_use_case.dart
+++ b/lib/features/settings/subfeatures/dapp_hooks/domain/dapp_hooks_use_case.dart
@@ -55,7 +55,7 @@ class DAppHooksUseCase extends ReactiveUseCase {
update(dappHooksData, _repository.item);
}
- String get dappHookTasksTaskId => BackgroundExecutionConfig.dappHookTasks;
+ String get wifiHookTasksTaskId => BackgroundExecutionConfig.wifiHooksTask;
String get minerAutoClaimTaskTaskId =>
BackgroundExecutionConfig.minerAutoClaimTask;
@@ -65,21 +65,23 @@ class DAppHooksUseCase extends ReactiveUseCase {
network != null && !MXCChains.isMXCChains(network.chainId);
final dappHooksData = _repository.item;
if (!isMXCChains) {
- bgFetch.BackgroundFetch.stop(BackgroundExecutionConfig.dappHookTasks);
- } else if (isMXCChains && dappHooksData.enabled) {
- startDAppHooksService(dappHooksData.duration);
+ bgFetch.BackgroundFetch.stop(BackgroundExecutionConfig.wifiHooksTask);
+ bgFetch.BackgroundFetch.stop(
+ BackgroundExecutionConfig.minerAutoClaimTask);
+ } else if (isMXCChains && dappHooksData.wifiHooks.enabled) {
+ startWifiHooksService(dappHooksData.wifiHooks.duration);
+ } else if (isMXCChains && dappHooksData.minerHooks.enabled) {
+ // TODO:
+ // startAutoClaimService(dappHooksData)
}
});
}
- void updateDAppHooksEnabled(bool value) {
- final newDAppHooksData = dappHooksData.value.copyWith(enabled: value);
- updateItem(newDAppHooksData);
- }
-
- void updateDAppHooksDuration(PeriodicalCallDuration duration) {
- final newDAppHooksData =
- dappHooksData.value.copyWith(duration: duration.toMinutes());
+ void updateWifiHooksDuration(PeriodicalCallDuration duration) {
+ final newDAppHooksData = dappHooksData.value.copyWith(
+ wifiHooks: dappHooksData.value.wifiHooks
+ .copyWith(duration: duration.toMinutes()),
+ );
updateItem(newDAppHooksData);
}
@@ -223,23 +225,25 @@ class DAppHooksUseCase extends ReactiveUseCase {
if (Platform.isAndroid) {
locationSettings = geo.AndroidSettings(
- accuracy: geo.LocationAccuracy.high,
- distanceFilter: 100,
+ accuracy: geo.LocationAccuracy.best,
+ distanceFilter: 10,
forceLocationManager: true,
- intervalDuration: const Duration(minutes: 15),
+ intervalDuration: const Duration(seconds: 5),
//(Optional) Set foreground notification config to keep the app alive
//when going to the background
foregroundNotificationConfig: geo.ForegroundNotificationConfig(
- notificationText: FlutterI18n.translate(
- appNavigatorKey.currentContext!,
- 'axs_background_location_service_text'),
- notificationTitle: FlutterI18n.translate(
- appNavigatorKey.currentContext!,
- 'axs_background_location_service_title'),
- enableWakeLock: true,
- notificationIcon: const geo.AndroidResource(
- name: 'axs_logo',
- )),
+ notificationText: FlutterI18n.translate(
+ appNavigatorKey.currentContext!,
+ 'axs_background_location_service_text'),
+ notificationTitle: FlutterI18n.translate(
+ appNavigatorKey.currentContext!,
+ 'axs_background_location_service_title'),
+ enableWakeLock: true,
+ notificationIcon: const geo.AndroidResource(
+ name: 'axs_logo',
+ ),
+ setOngoing: true,
+ ),
);
} else if (Platform.isIOS) {
locationSettings = geo.AppleSettings(
@@ -291,16 +295,16 @@ class DAppHooksUseCase extends ReactiveUseCase {
}
// delay is in minutes
- Future startDAppHooksService(int delay) async {
+ Future startWifiHooksService(int delay) async {
try {
final result = await AXSBackgroundFetch.startBackgroundProcess(
- taskId: dappHookTasksTaskId);
+ taskId: wifiHookTasksTaskId);
if (!result) return result;
final scheduleState =
await bgFetch.BackgroundFetch.scheduleTask(bgFetch.TaskConfig(
- taskId: BackgroundExecutionConfig.dappHookTasks,
+ taskId: BackgroundExecutionConfig.wifiHooksTask,
delay: delay * 60 * 1000,
periodic: true,
requiresNetworkConnectivity: true,
@@ -376,9 +380,9 @@ class DAppHooksUseCase extends ReactiveUseCase {
taskId: minerAutoClaimTaskTaskId, turnOffAll: turnOffAll);
}
- Future stopDAppHooksService({required bool turnOffAll}) async {
+ Future stopWifiHooksService({required bool turnOffAll}) async {
return await AXSBackgroundFetch.stopServices(
- taskId: dappHookTasksTaskId, turnOffAll: turnOffAll);
+ taskId: wifiHookTasksTaskId, turnOffAll: turnOffAll);
}
List getWifiModels(List wifiList) {
diff --git a/lib/features/settings/subfeatures/dapp_hooks/utils/dapp_hooks_helper.dart b/lib/features/settings/subfeatures/dapp_hooks/utils/dapp_hooks_helper.dart
index 3a1d1fdc..74439cb1 100644
--- a/lib/features/settings/subfeatures/dapp_hooks/utils/dapp_hooks_helper.dart
+++ b/lib/features/settings/subfeatures/dapp_hooks/utils/dapp_hooks_helper.dart
@@ -1,23 +1,13 @@
-import 'package:datadashwallet/core/core.dart';
import 'package:datadashwallet/features/settings/subfeatures/dapp_hooks/utils/utils.dart';
-import 'package:datadashwallet/features/settings/subfeatures/notifications/domain/background_fetch_config_use_case.dart';
import 'package:flutter/material.dart';
-import 'package:mxc_logic/mxc_logic.dart';
import '../dapp_hooks_state.dart';
-import '../domain/dapp_hooks_use_case.dart';
-import '../widgets/background_fetch_dialog.dart';
-
class DAppHooksHelper {
DAppHooksHelper(
{required this.state,
- required this.dAppHooksUseCase,
- required this.backgroundFetchConfigUseCase,
required this.context,
required this.translate});
- DAppHooksUseCase dAppHooksUseCase;
- BackgroundFetchConfigUseCase backgroundFetchConfigUseCase;
DAppHooksState state;
DappHooksSnackBarUtils get dappHooksSnackBarUtils =>
DappHooksSnackBarUtils(translate: translate, context: context);
@@ -31,62 +21,4 @@ class DAppHooksHelper {
update();
}
}
-
- void changeDAppHooksEnabled(bool value) async {
- shouldUpdateWrapper(() async {
- late bool update;
- if (value) {
- update = await startDAppHooksService(
- delay: state.dAppHooksData!.duration, showBGFetchAlert: true);
- } else {
- update = await stopDAppHooksService(showSnackbar: true);
- }
- return update;
- }, () {
- return dAppHooksUseCase.updateDAppHooksEnabled(value);
- });
- }
-
- // delay is in minutes, returns true if success
- Future startDAppHooksService(
- {required int delay, required bool showBGFetchAlert}) async {
- if (showBGFetchAlert) {
- final res =
- await showDAppHooksBackgroundFetchAlertDialog(context: context!);
- if (res == null || !res) {
- return false;
- }
- }
- final success = await dAppHooksUseCase.startDAppHooksService(delay);
- if (success) {
- dappHooksSnackBarUtils.showDAppHooksServiceSuccessSnackBar();
- } else {
- dappHooksSnackBarUtils.showDAppHooksServiceFailureSnackBar();
- }
- return success;
- }
-
- Future stopDAppHooksService({required bool showSnackbar}) async {
- final dappHooksData = dAppHooksUseCase.dappHooksData.value;
- final periodicalCallData =
- backgroundFetchConfigUseCase.periodicalCallData.value;
- final turnOffAll =
- AXSBackgroundFetch.turnOffAll(dappHooksData, periodicalCallData);
- await dAppHooksUseCase.stopDAppHooksService(turnOffAll: turnOffAll);
- if (showSnackbar) {
- dappHooksSnackBarUtils.showDAppHooksServiceDisableSuccessSnackBar();
- }
- return true;
- }
-
- void handleFrequencyChange(PeriodicalCallDuration duration) {
- shouldUpdateWrapper(() async {
- late bool update;
- update = await startDAppHooksService(
- delay: duration.toMinutes(), showBGFetchAlert: false);
- return update;
- }, () {
- return dAppHooksUseCase.updateDAppHooksDuration(duration);
- });
- }
}
diff --git a/lib/features/settings/subfeatures/dapp_hooks/utils/miner_hooks_helper.dart b/lib/features/settings/subfeatures/dapp_hooks/utils/miner_hooks_helper.dart
index 0c6bb5f4..907ed553 100644
--- a/lib/features/settings/subfeatures/dapp_hooks/utils/miner_hooks_helper.dart
+++ b/lib/features/settings/subfeatures/dapp_hooks/utils/miner_hooks_helper.dart
@@ -7,7 +7,6 @@ import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import '../domain/dapp_hooks_use_case.dart';
import '../widgets/auto_claim_dialog.dart';
-import '../widgets/background_fetch_dialog.dart';
class MinerHooksHelper {
MinerHooksHelper(
diff --git a/lib/features/settings/subfeatures/dapp_hooks/utils/snack_bar_utils.dart b/lib/features/settings/subfeatures/dapp_hooks/utils/snack_bar_utils.dart
index baa5e3c4..c6118eef 100644
--- a/lib/features/settings/subfeatures/dapp_hooks/utils/snack_bar_utils.dart
+++ b/lib/features/settings/subfeatures/dapp_hooks/utils/snack_bar_utils.dart
@@ -7,7 +7,7 @@ class DappHooksSnackBarUtils {
BuildContext? context;
String? Function(String) translate;
- void showDAppHooksServiceFailureSnackBar() {
+ void showWiFiHooksServiceFailureSnackBar() {
showSnackBar(
context: context!,
content: translate('unable_to_launch_service')!
@@ -23,14 +23,14 @@ class DappHooksSnackBarUtils {
type: SnackBarType.fail);
}
- void showDAppHooksServiceSuccessSnackBar() {
+ void showWiFiHooksServiceSuccessSnackBar() {
showSnackBar(
context: context!,
content: translate('service_launched_successfully')!
.replaceAll('{0}', translate('dapp_hooks')!));
}
- void showDAppHooksServiceDisableSuccessSnackBar() {
+ void showWiFiHooksServiceDisableSuccessSnackBar() {
showSnackBar(
context: context!,
content: translate('service_disabled_successfully')!
diff --git a/lib/features/settings/subfeatures/dapp_hooks/utils/wifi_hooks_helper.dart b/lib/features/settings/subfeatures/dapp_hooks/utils/wifi_hooks_helper.dart
index 9301f828..3f0244ea 100644
--- a/lib/features/settings/subfeatures/dapp_hooks/utils/wifi_hooks_helper.dart
+++ b/lib/features/settings/subfeatures/dapp_hooks/utils/wifi_hooks_helper.dart
@@ -2,13 +2,17 @@ import 'dart:async';
import 'dart:io';
import 'package:app_settings/app_settings.dart';
+import 'package:datadashwallet/core/core.dart';
import 'package:datadashwallet/features/settings/subfeatures/dapp_hooks/utils/utils.dart';
+import 'package:datadashwallet/features/settings/subfeatures/notifications/domain/background_fetch_config_use_case.dart';
import 'package:flutter/material.dart';
+import 'package:mxc_logic/mxc_logic.dart';
import 'package:permission_handler/permission_handler.dart';
import '../dapp_hooks_state.dart';
import '../domain/dapp_hooks_use_case.dart';
import 'package:datadashwallet/common/common.dart';
import 'package:geolocator/geolocator.dart' as geo;
+import '../widgets/wifi_hooks_background_fetch_alert_bottom_sheet.dart';
import '../widgets/location_permission_bottom_sheet.dart';
class WiFiHooksHelper {
@@ -16,6 +20,7 @@ class WiFiHooksHelper {
{required this.state,
required this.dAppHooksUseCase,
required this.geoLocatorPlatform,
+ required this.backgroundFetchConfigUseCase,
required this.context,
required this.translate});
DAppHooksUseCase dAppHooksUseCase;
@@ -23,6 +28,7 @@ class WiFiHooksHelper {
geo.GeolocatorPlatform geoLocatorPlatform;
DappHooksSnackBarUtils get dappHooksSnackBarUtils =>
DappHooksSnackBarUtils(translate: translate, context: context);
+ BackgroundFetchConfigUseCase backgroundFetchConfigUseCase;
BuildContext? context;
String? Function(String) translate;
StreamSubscription? locationServiceStateStreamSubscription;
@@ -39,15 +45,7 @@ class WiFiHooksHelper {
checkWifiHookEnabled();
}
- void changeWifiHooksEnabled(bool value) {
- if (value) {
- checkWifiHooksRequirements();
- } else {
- dAppHooksUseCase.updatedWifiHooksEnabled(value);
- }
- }
-
- Future checkWifiHooksRequirements() async {
+ Future checkWifiHooksRequirements() async {
final isGranted = await PermissionUtils.initLocationPermission();
if (isGranted) {
@@ -55,23 +53,85 @@ class WiFiHooksHelper {
if (isServiceEnabled) {
dAppHooksUseCase.setLocationSettings();
}
- dAppHooksUseCase.updatedWifiHooksEnabled(isServiceEnabled);
+ return isServiceEnabled;
} else {
- dAppHooksUseCase.updatedWifiHooksEnabled(false);
// Looks like the notification is blocked permanently
showLocationPermissionBottomSheet(
context: context!, openLocationSettings: openLocationSettings);
+ return false;
}
}
// Checks if wifi hooks enabled, If enabled starts location service
void checkWifiHookEnabled() {
- if (state.dAppHooksData!.wifiHooks.enabled &&
- state.dAppHooksData!.enabled) {
+ if (state.dAppHooksData!.wifiHooks.enabled) {
checkWifiHooksRequirements();
}
}
+ void changeWiFiHooksEnabled(bool value) async {
+ DAppHooksHelper.shouldUpdateWrapper(() async {
+ late bool update;
+ if (value) {
+ update = await checkWifiHooksRequirements();
+ if (!update) {
+ return update;
+ }
+ update = await startWifiHooksService(
+ delay: state.dAppHooksData!.wifiHooks.duration,
+ showBGFetchAlert: true);
+ } else {
+ update = await stopWiFiHooksService(showSnackbar: true);
+ }
+ return update;
+ }, () {
+ return dAppHooksUseCase.updatedWifiHooksEnabled(value);
+ });
+ }
+
+ // delay is in minutes, returns true if success
+ Future startWifiHooksService(
+ {required int delay, required bool showBGFetchAlert}) async {
+ if (showBGFetchAlert) {
+ final res =
+ await showWiFiHooksBackgroundFetchAlertBottomSheet(context: context!);
+ if (res == null || !res) {
+ return false;
+ }
+ }
+ final success = await dAppHooksUseCase.startWifiHooksService(delay);
+ if (success) {
+ dappHooksSnackBarUtils.showWiFiHooksServiceSuccessSnackBar();
+ } else {
+ dappHooksSnackBarUtils.showWiFiHooksServiceFailureSnackBar();
+ }
+ return success;
+ }
+
+ Future stopWiFiHooksService({required bool showSnackbar}) async {
+ final dappHooksData = dAppHooksUseCase.dappHooksData.value;
+ final periodicalCallData =
+ backgroundFetchConfigUseCase.periodicalCallData.value;
+ final turnOffAll =
+ AXSBackgroundFetch.turnOffAll(dappHooksData, periodicalCallData);
+ await dAppHooksUseCase.stopWifiHooksService(turnOffAll: turnOffAll);
+ if (showSnackbar) {
+ dappHooksSnackBarUtils.showWiFiHooksServiceDisableSuccessSnackBar();
+ }
+ return true;
+ }
+
+ void handleFrequencyChange(PeriodicalCallDuration duration) {
+ DAppHooksHelper.shouldUpdateWrapper(() async {
+ late bool update;
+ update = await startWifiHooksService(
+ delay: duration.toMinutes(), showBGFetchAlert: false);
+ return update;
+ }, () {
+ return dAppHooksUseCase.updateWifiHooksDuration(duration);
+ });
+ }
+
Future enableLocationService() async {
ServiceStatus locationServiceStatus =
await Permission.location.serviceStatus;
diff --git a/lib/features/settings/subfeatures/dapp_hooks/widgets/widget.dart b/lib/features/settings/subfeatures/dapp_hooks/widgets/widget.dart
new file mode 100644
index 00000000..0eb516c9
--- /dev/null
+++ b/lib/features/settings/subfeatures/dapp_hooks/widgets/widget.dart
@@ -0,0 +1,4 @@
+export 'location_permission_bottom_sheet.dart';
+export 'auto_claim_dialog.dart';
+export 'wifi_hooks_background_fetch_alert_bottom_sheet.dart';
+export 'wifi_hooks_frequency_bottom_sheet.dart';
diff --git a/lib/features/settings/subfeatures/dapp_hooks/widgets/background_fetch_dialog.dart b/lib/features/settings/subfeatures/dapp_hooks/widgets/wifi_hooks_background_fetch_alert_bottom_sheet.dart
similarity index 97%
rename from lib/features/settings/subfeatures/dapp_hooks/widgets/background_fetch_dialog.dart
rename to lib/features/settings/subfeatures/dapp_hooks/widgets/wifi_hooks_background_fetch_alert_bottom_sheet.dart
index c862c10f..0ee9a5b9 100644
--- a/lib/features/settings/subfeatures/dapp_hooks/widgets/background_fetch_dialog.dart
+++ b/lib/features/settings/subfeatures/dapp_hooks/widgets/wifi_hooks_background_fetch_alert_bottom_sheet.dart
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:mxc_ui/mxc_ui.dart';
-Future showDAppHooksBackgroundFetchAlertDialog({
+Future showWiFiHooksBackgroundFetchAlertBottomSheet({
required BuildContext context,
}) async {
String translate(String text) => FlutterI18n.translate(context, text);
diff --git a/lib/features/settings/subfeatures/dapp_hooks/widgets/dapp_hooks_frequency_dialog.dart b/lib/features/settings/subfeatures/dapp_hooks/widgets/wifi_hooks_frequency_bottom_sheet.dart
similarity index 98%
rename from lib/features/settings/subfeatures/dapp_hooks/widgets/dapp_hooks_frequency_dialog.dart
rename to lib/features/settings/subfeatures/dapp_hooks/widgets/wifi_hooks_frequency_bottom_sheet.dart
index 283f7538..b4efa98c 100644
--- a/lib/features/settings/subfeatures/dapp_hooks/widgets/dapp_hooks_frequency_dialog.dart
+++ b/lib/features/settings/subfeatures/dapp_hooks/widgets/wifi_hooks_frequency_bottom_sheet.dart
@@ -3,7 +3,7 @@ import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:mxc_logic/mxc_logic.dart';
import 'package:mxc_ui/mxc_ui.dart';
-Future showDAppHooksFrequencyDialog(BuildContext context,
+Future showWiFiHooksFrequencyBottomSheet(BuildContext context,
{required void Function(PeriodicalCallDuration duration) onTap,
required PeriodicalCallDuration selectedFrequency}) {
String translate(String text) => FlutterI18n.translate(context, text);
diff --git a/lib/features/settings/subfeatures/notifications/domain/background_fetch_config_use_case.dart b/lib/features/settings/subfeatures/notifications/domain/background_fetch_config_use_case.dart
index e3af34fb..7fb1fe2f 100644
--- a/lib/features/settings/subfeatures/notifications/domain/background_fetch_config_use_case.dart
+++ b/lib/features/settings/subfeatures/notifications/domain/background_fetch_config_use_case.dart
@@ -17,7 +17,7 @@ class BackgroundFetchConfigUseCase extends ReactiveUseCase {
initialize();
}
- String get taskId => BackgroundExecutionConfig.axsPeriodicalTask;
+ String get taskId => BackgroundExecutionConfig.notificationsTask;
final BackgroundFetchConfigRepository _repository;
final ChainConfigurationUseCase _chainConfigurationUseCase;
@@ -48,7 +48,7 @@ class BackgroundFetchConfigUseCase extends ReactiveUseCase {
final periodicalCallData = _repository.item;
if (!isMXCChains) {
bgFetch.BackgroundFetch.stop(
- BackgroundExecutionConfig.axsPeriodicalTask);
+ BackgroundExecutionConfig.notificationsTask);
} else if (isMXCChains && periodicalCallData.serviceEnabled) {
startNotificationsService(periodicalCallData.duration);
}
diff --git a/packages/shared b/packages/shared
index 9147cfdf..09469264 160000
--- a/packages/shared
+++ b/packages/shared
@@ -1 +1 @@
-Subproject commit 9147cfdfaec7dc9d8452f7ec8a7d7790c21d551d
+Subproject commit 094692644e4b254006b7757eece9253739e6cc18