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

Dapp hooks : wifi hooks + mining hooks (not yet complete) #157

Merged
merged 7 commits into from
Feb 12, 2024
Merged
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 assets/flutter_i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,5 @@
"unable_to_launch_service": "Unable to launch {0} service.",
"service_disabled_successfully": "{0} service disabled successfully.",
"location": "Location",
"location_service": "Location service",
"wifi_hooks_solutions": "Try re-enabling. \nRequirements :\n1. Location permission for always should be permitted \n2. Locations service should be running \n3. You should be connected to a Wi-Fi"
}
13 changes: 4 additions & 9 deletions lib/app/app_presenter.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import 'package:datadashwallet/core/core.dart';

final appContainer =
PresenterContainer<SettingsPresenter, void>(() => SettingsPresenter());



final appContainer = PresenterContainer<SettingsPresenter, void>(
() => SettingsPresenter());

class SettingsPresenter extends CompletePresenter
{
SettingsPresenter() : super(null);
class SettingsPresenter extends CompletePresenter {
SettingsPresenter() : super(null);

@override
void initState() {
super.initState();
AXSFireBase.initLocalNotificationsAndListeners();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export 'speed_up_bottom_sheet.dart';
export 'speed_up_cancel_bottom_sheet_info.dart';
export 'recent_transaction_item.dart';
export 'transaction_status_chip.dart';
export 'transaction_type_widget.dart';
export 'transaction_type_widget.dart';
2 changes: 1 addition & 1 deletion lib/common/dialogs/add_network/add_network.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export 'add_network_dialog.dart';
export 'add_network_item.dart';
export 'add_network_item.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ Future<bool?> showNetworkDetailsDialog(
children: [
Padding(
padding: const EdgeInsetsDirectional.only(
start: Sizes.spaceNormal,
end: Sizes.spaceNormal,
bottom: 0),
start: Sizes.spaceNormal, end: Sizes.spaceNormal, bottom: 0),
child: MxcAppBarEvenly.title(
titleText: network.label ?? network.web3RpcHttpUrl,
),
Expand Down
17 changes: 17 additions & 0 deletions lib/core/src/background_process/dapp_hooks_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:background_fetch/background_fetch.dart';
import 'package:datadashwallet/core/core.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:mxc_logic/mxc_logic.dart';

Expand Down Expand Up @@ -42,6 +43,9 @@ class DAppHooksService {
final account = accountUseCase.account.value;
final serviceEnabled = dappHooksData.enabled;
final wifiHooksEnabled = dappHooksData.wifiHooks.enabled;
final minerHooksEnabled = dappHooksData.minerHooks.enabled;
final minerHooksTime = dappHooksData.minerHooks.time;
final selectedMiners = dappHooksData.minerHooks.selectedMiners;

// Make sure user is logged in
if (isLoggedIn && Config.isMxcChains(chainId) && serviceEnabled) {
Expand All @@ -53,6 +57,19 @@ class DAppHooksService {
);
}

final now = DateTime.now();
final isPast = !(now.difference(minerHooksTime).isNegative);

if (minerHooksEnabled && isPast) {
final updatedAutoClaimTime = await dAppHooksUseCase.claimMiners(
account: account!,
selectedMinerListId: selectedMiners,
minerAutoClaimTime: minerHooksTime);
dappHooksData = dappHooksData.copyWith(
minerHooks: dappHooksData.minerHooks
.copyWith(time: updatedAutoClaimTime));
}

dAppHooksUseCase.updateItem(dappHooksData);
BackgroundFetch.finish(taskId);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/firebase/firebase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class AXSFireBase {
static void incrementBuildTap() async {
buildTap++;
if (buildTap == 10) {
// FlutterClipboard.copy('');
// FlutterClipboard.copy('');
buildTap = 0;
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/core/src/firebase/firebase_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:flutter/foundation.dart'
show defaultTargetPlatform, kIsWeb, TargetPlatform;


class DefaultFirebaseOptions {
static FirebaseOptions get currentPlatform {
if (kIsWeb) {
Expand Down
16 changes: 13 additions & 3 deletions lib/core/src/providers/providers_use_cases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:datadashwallet/common/components/recent_transactions/domain/mxc_
import 'package:datadashwallet/features/common/account/log_out_use_case.dart';
import 'package:datadashwallet/features/common/common.dart';
import 'package:datadashwallet/features/common/contract/chains_use_case.dart';
import 'package:datadashwallet/features/common/contract/miner_use_case.dart';
import 'package:datadashwallet/features/common/contract/nft_contract_use_case.dart';
import 'package:datadashwallet/features/common/contract/pricing_use_case.dart';
import 'package:datadashwallet/features/common/contract/transaction_controller.dart';
Expand Down Expand Up @@ -66,6 +67,12 @@ final Provider<TweetsUseCase> tweetsUseCaseProvider = Provider(
),
);

final Provider<MinerUseCase> minerUseCaseProvider = Provider(
(ref) => MinerUseCase(
ref.watch(web3RepositoryProvider),
),
);

final Provider<PricingUseCase> pricingUseCaseProvider = Provider(
(ref) => PricingUseCase(
ref.watch(web3RepositoryProvider),
Expand Down Expand Up @@ -116,9 +123,12 @@ final Provider<BackgroundFetchConfigUseCase>

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

final Provider<BalanceUseCase> balanceHistoryUseCaseProvider = Provider(
Expand Down
4 changes: 0 additions & 4 deletions lib/features/common/app/launcher_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ class LauncherUseCase extends ReactiveUseCase {
return await canLaunchUrl(url);
}

Future<void> launchMXCChatGPT() async {
await launchUrlInExternalAppWithString(Urls.mxcChatGPT);
}

Future<void> launchMXCZendesk() async {
await launchUrlInExternalAppWithString(Urls.mxcZendesk);
}
Expand Down
20 changes: 20 additions & 0 deletions lib/features/common/contract/miner_use_case.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'dart:async';

import 'package:datadashwallet/core/core.dart';
import 'package:mxc_logic/mxc_logic.dart';

class MinerUseCase extends ReactiveUseCase {
MinerUseCase(
this._repository,
);

final Web3Repository _repository;

Future<bool> claimMinersReward({
required List<String> selectedMinerListId,
required Account account,
}) async {
return await _repository.minerRepository.claimMinersReward(
selectedMinerListId: selectedMinerListId, account: account);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ class AllowMultipleDoubleTap extends DoubleTapGestureRecognizer {
void rejectGesture(int pointer) {
acceptGesture(pointer);
}


}


class AllowMultipleVerticalDrag extends VerticalDragGestureRecognizer {
@override
void rejectGesture(int pointer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// export
// export
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import 'settings_page_state.dart';
final settingsContainer = PresenterContainer<SettingsPresenter, SettingsState>(
() => SettingsPresenter());

class SettingsPresenter extends CompletePresenter<SettingsState>
{
SettingsPresenter() : super(SettingsState());
class SettingsPresenter extends CompletePresenter<SettingsState> {
SettingsPresenter() : super(SettingsState());
late final _webviewUseCase = WebviewUseCase();
late final _authUseCase = ref.read(authUseCaseProvider);
late final _accountUserCase = ref.read(accountUseCaseProvider);
Expand All @@ -22,7 +21,6 @@ class SettingsPresenter extends CompletePresenter<SettingsState>
super.initState();
getAppVersion();


listen(_accountUserCase.account, (value) {
if (value != null) {
notify(() => state.account = value);
Expand Down Expand Up @@ -104,5 +102,4 @@ class SettingsPresenter extends CompletePresenter<SettingsState>
void loadCache() {
_webviewUseCase.clearCache();
}

}
9 changes: 6 additions & 3 deletions lib/features/settings/presentation/settings_page_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ class SettingsState with EquatableMixin {
String? appVersion;
bool isLoading = false;


@override
List<Object?> get props =>
[account, accounts, appVersion, isLoading, ];
List<Object?> get props => [
account,
accounts,
appVersion,
isLoading,
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:mxc_logic/mxc_logic.dart';

import '../../../../../../../common/common.dart';


class AddNetworkUtils {
static List<Widget> generateMainnetList(List<Network> networkList) {
return networkList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ class CustomerSupportPage extends HookConsumerWidget {
),
],
const SizedBox(height: Sizes.space4XLarge),
CustomerSupportButton(
key: const ValueKey('jumpToTelegramButton'),
title: translate('contact_chatgpt_support'),
buttonLabel: translate('jump_to_telegram'),
buttonFunction: ref.watch(state).applist['telegram'] == true ||
ref.watch(state).applist['telegram_web'] == true
? () => ref.read(presenter).launchMXCChatGPT()
: null),
CustomerSupportButton(
key: const ValueKey('mxcSupport'),
title: translate('mxc_support_form'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ class CustomerSupportPresenter extends CompletePresenter<CustomerSupportState> {
notify(() => state.applist = applist);
}

Future<void> launchMXCChatGPT() {
return _launcherUseCase.launchMXCChatGPT();
}

Future<void> launchMXCZendesk() async {
return _launcherUseCase.launchMXCZendesk();
}
Expand Down
47 changes: 21 additions & 26 deletions lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class DAppHooksPage extends HookConsumerWidget {
final isSettingsChangeEnabled =
isMXCChains && dappHooksServiceServiceEnabled;

final minerAutoClaimDateTime =
dappHooksState.dAppHooksData!.minerHooks.time;
final autoClaimTime =
'${minerAutoClaimDateTime.hour.toString().padLeft(2, '0')} : ${minerAutoClaimDateTime.minute.toString().padLeft(2, '0')}';

String translate(String text) => FlutterI18n.translate(context, text);

return MxcPage(
Expand Down Expand Up @@ -101,32 +106,22 @@ class DAppHooksPage extends HookConsumerWidget {
),
]),
),
// const SizedBox(height: Sizes.spaceNormal),
// SwitchRowItem(
// key: const Key('locationServiceSwitch'),
// title: translate('location_service'),
// value: dappHooksState.locationServiceEnabled,
// onChanged: dappHooksPresenter.changeLocationServiceState,
// enabled: isSettingsChangeEnabled,
// paddings: const EdgeInsets.symmetric(horizontal: Sizes.spaceXSmall),
// switchActiveColor: ColorsTheme.of(context).btnBgBlue,
// ),
// const SizedBox(height: Sizes.spaceNormal),
// SwitchRowItem(
// key: const Key('minerHookSwitch'),
// title: translate('miner_hooks'),
// value: dappHooksState.dAppHooksData!.minerHooks.enabled,
// onChanged: dappHooksPresenter.enableMinerHooks,
// enabled: isSettingsChangeEnabled,
// ),
// const SizedBox(height: Sizes.spaceNormal),
// MXCDropDown(
// key: const Key('minerHooksTimingDropDown'),
// onTap: dappHooksPresenter.showTimePickerDialog,
// selectedItem:
// dappHooksState.dAppHooksData!.minerHooks.time.format(context),
// enabled: true,
// ),
const SizedBox(height: Sizes.spaceNormal),
SwitchRowItem(
key: const Key('minerHookSwitch'),
title: translate('miner_hooks'),
value: dappHooksState.dAppHooksData!.minerHooks.enabled,
onChanged: dappHooksPresenter.enableMinerHooks,
enabled: isSettingsChangeEnabled,
),
const SizedBox(height: Sizes.spaceNormal),
MXCDropDown(
key: const Key('minerHooksTimingDropDown'),
onTap: dappHooksPresenter.showTimePickerDialog,
selectedItem: autoClaimTime,
enabled: isSettingsChangeEnabled &&
dappHooksState.dAppHooksData!.minerHooks.enabled,
),
],
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class DAppHooksPresenter extends CompletePresenter<DAppHooksState>
void changeMinerHookTiming(TimeOfDay value) {
final newDAppHooksData = state.dAppHooksData!.copyWith(
minerHooks: state.dAppHooksData!.minerHooks.copyWith(
time: value,
time: state.dAppHooksData!.minerHooks.time
.copyWith(hour: value.hour, minute: value.minute, second: 0),
));
_dAppHooksUseCase.updateItem(newDAppHooksData);
}
Expand Down Expand Up @@ -241,9 +242,11 @@ class DAppHooksPresenter extends CompletePresenter<DAppHooksState>
}

void showTimePickerDialog() async {
final currentTimeOfDay = state.dAppHooksData!.minerHooks.time;
final newTimeOfDay = await showTimePicker(
context: context!,
initialTime: state.dAppHooksData!.minerHooks.time,
initialTime: TimeOfDay(
hour: currentTimeOfDay.hour, minute: currentTimeOfDay.minute),
initialEntryMode: TimePickerEntryMode.inputOnly,
);

Expand Down
Loading
Loading