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 #168 from MXCzkEVM/dapp_hooks
Browse files Browse the repository at this point in the history
Auto claim UX improvement & bug fixes & log url address bug fix
  • Loading branch information
reasje authored Mar 12, 2024
2 parents 72f2efd + 0f4bfc1 commit e825671
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 67 deletions.
3 changes: 2 additions & 1 deletion assets/flutter_i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,5 +346,6 @@
"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",
"auto_claim_execution_dialog_title": "Time Already Passed!",
"auto_claim_execution_dialog_text": "The time for auto claim has elapsed. Would you like to execute auto claim now?",
"execute": "Execute"
"execute": "Execute",
"auto_claim_scheduling_text": "Auto-claim will execute at {0} tomorrow"
}
114 changes: 65 additions & 49 deletions lib/features/dapps/subfeatures/open_dapp/widgets/drag_down_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DragDownPanel extends HookConsumerWidget {

final logo = state.network!.logo;
final name = state.network!.label ?? state.network!.web3RpcHttpUrl;
final url = state.currentUrl;
final url = state.currentUrl?.host ?? '';
final isSecure = state.isSecure;

state.animationController = useAnimationController();
Expand Down Expand Up @@ -63,62 +63,78 @@ class DragDownPanel extends HookConsumerWidget {
ColorsTheme.of(context).screenBackground,
)),
child: Stack(
fit: StackFit.passthrough,
children: [
Row(
children: [
IconButton(
key: const Key('closedAppButton'),
onPressed: () {
presenter.closedApp();
},
icon: const Icon(
Icons.close_rounded,
size: 24,
)),
InkWell(
onTap: presenter
.showNetworkDetailsBottomSheet,
child: ChainLogoWidget(logo: logo)),
],
),
Center(
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(
width: Sizes.space2XSmall,
Row(
children: [
IconButton(
key: const Key('closedAppButton'),
onPressed: () {
presenter.closedApp();
},
icon: const Icon(
Icons.close_rounded,
size: 24,
)),
InkWell(
onTap: presenter
.showNetworkDetailsBottomSheet,
child:
ChainLogoWidget(logo: logo)),
],
),
isSecure
? Icon(
Icons.lock_rounded,
color: ColorsTheme.of(context)
.textPrimary,
size: 16,
)
: Icon(
Icons.warning,
color: ColorsTheme.of(context)
.mainRed,
size: 16,
Expanded(
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
const SizedBox(
width: Sizes.space2XSmall,
),
const SizedBox(
width: Sizes.space2XSmall,
),
InkWell(
onTap: () => presenter.copyUrl(),
child: Text(
url?.host ?? '',
style: FontTheme.of(context)
.body1
.primary()
.copyWith(
fontWeight: FontWeight.w500),
overflow: TextOverflow.ellipsis,
isSecure
? Icon(
Icons.lock_rounded,
color:
ColorsTheme.of(context)
.textPrimary,
size: 16,
)
: Icon(
Icons.warning,
color:
ColorsTheme.of(context)
.mainRed,
size: 16,
),
const SizedBox(
width: Sizes.space2XSmall,
),
Expanded(
child: InkWell(
onTap: () =>
presenter.copyUrl(),
child: Text(
url,
style: FontTheme.of(context)
.body1
.primary()
.copyWith(
fontWeight:
FontWeight.w500),
overflow:
TextOverflow.ellipsis,
),
),
)
],
),
)
),
],
),
),
)
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import 'package:datadashwallet/features/common/common.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 '../dapp_hooks_state.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';
Expand Down Expand Up @@ -35,20 +34,28 @@ class MinerHooksHelper {
final success = await dAppHooksUseCase.scheduleAutoClaimTransaction(time);
final reached = dAppHooksUseCase.isTimeReached(time);

bool shouldShowScheduleSnackBar = false;

if (success) {
// Time past, need to run the auto claim
if (reached) {
await showAutoClaimExecutionAlertDialog(
context: context!,
executeAutoClaim: () {
dAppHooksUseCase.claimMiners(
account: accountUseCase.account.value!,
minerAutoClaimTime: time,
selectedMinerListId: dAppHooksUseCase
.dappHooksData.value.minerHooks.selectedMiners);
});
shouldShowScheduleSnackBar = !(await showAutoClaimExecutionAlertDialog(
context: context!,
executeAutoClaim: () {
dAppHooksUseCase.claimMiners(
account: accountUseCase.account.value!,
minerAutoClaimTime: time,
selectedMinerListId: dAppHooksUseCase
.dappHooksData.value.minerHooks.selectedMiners);
}) ??
false);
}
if (shouldShowScheduleSnackBar) {
dappHooksSnackBarUtils
.showScheduleSnackBar(DateFormat('HH:mm').format(time));
} else {
dappHooksSnackBarUtils.showMinerHooksServiceSuccessSnackBar();
}
dappHooksSnackBarUtils.showMinerHooksServiceSuccessSnackBar();
return true;
} else {
dappHooksSnackBarUtils.showMinerHooksServiceFailureSnackBar();
Expand All @@ -70,7 +77,9 @@ class MinerHooksHelper {
return true;
}

Future<void> changeMinerHooksEnabled(bool value) {
Future<void> changeMinerHooksEnabled(
bool value,
) {
return DAppHooksHelper.shouldUpdateWrapper(() async {
late bool update;
if (value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class DappHooksSnackBarUtils {
.replaceAll('{0}', translate('miner_hooks')!));
}

void showScheduleSnackBar(String time) {
showSnackBar(
context: context!,
content:
translate('auto_claim_scheduling_text')!.replaceAll('{0}', time));
}

void showMinerHooksServiceDisableSuccessSnackBar() {
showSnackBar(
context: context!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ Future<bool?> showAutoClaimExecutionAlertDialog(
MxcButton.secondary(
key: const ValueKey('cancelButton'),
title: translate('cancel'),
onTap: () {
Navigator.of(context).pop(true);
},
onTap: () => Navigator.of(context).pop(false),
size: AxsButtonSize.xl,
),
const SizedBox(
Expand Down
2 changes: 1 addition & 1 deletion packages/shared

0 comments on commit e825671

Please sign in to comment.