Skip to content

Commit

Permalink
fix: 🚧 Fix accounts dialog usage
Browse files Browse the repository at this point in the history
  • Loading branch information
redDwarf03 committed Jan 13, 2025
1 parent aa7fdde commit 396227a
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 351 deletions.
25 changes: 11 additions & 14 deletions lib/ui/util/accounts_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import 'dart:async';
import 'dart:ui';

import 'package:aewallet/application/account/accounts_notifier.dart';
import 'package:aewallet/model/data/account.dart';
import 'package:aewallet/ui/themes/archethic_theme.dart';
import 'package:aewallet/ui/themes/styles.dart';
Expand All @@ -16,31 +15,27 @@ import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutte
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';

class AccountsDialog {
static Future<Account?> selectSingleAccount({
required BuildContext context,
required WidgetRef ref,
required List<Account> accounts,
String? dialogTitle,
Widget? header,
bool? isModal = false,
double? heightFactor = 1,
}) async {
final selection = await _showAccountsDialog(
return await _showAccountsDialog(
context: context,
accounts: accounts,
multipleSelectionsAllowed: false,
dialogTitle: dialogTitle,
header: header,
isModal: isModal,
heightFactor: heightFactor,
) as Account?;
if (selection != null) {
await ref
.read(accountsNotifierProvider.notifier)
.selectAccount(selection);
}
return selection;
}

static Future<List<Account>?> selectMultipleAccounts({
Expand All @@ -50,6 +45,7 @@ class AccountsDialog {
String? dialogTitle,
Widget? header,
bool? isModal = false,
double? heightFactor = 1,
}) async {
return await _showAccountsDialog(
context: context,
Expand All @@ -59,6 +55,7 @@ class AccountsDialog {
dialogTitle: dialogTitle,
header: header,
isModal: isModal,
heightFactor: heightFactor,
) as List<Account>?;
}

Expand All @@ -70,6 +67,7 @@ class AccountsDialog {
String? dialogTitle,
Widget? header,
bool? isModal = false,
double? heightFactor = 1,
}) async {
final pickerItemsList = <PickerItem<Account>>[];

Expand Down Expand Up @@ -116,7 +114,7 @@ class AccountsDialog {
context: context,
builder: (BuildContext context) {
return FractionallySizedBox(
heightFactor: 1,
heightFactor: heightFactor,
child: Scaffold(
backgroundColor:
aedappfm.AppThemeBase.sheetBackground.withOpacity(0.2),
Expand Down Expand Up @@ -204,7 +202,7 @@ class AccountsDialogContentState extends ConsumerState<AccountsDialogContent> {
scrollable: true,
onSelected: (pickerItem) {
if (!widget.multipleSelectionsAllowed) {
Navigator.of(context).pop(pickerItem.value);
context.pop(pickerItem.value);
}
},
onUnselected: (selectedIndexes) {
Expand Down Expand Up @@ -255,8 +253,7 @@ class AccountsDialogContentState extends ConsumerState<AccountsDialogContent> {
final _accountsList = pickerItemsListSelected
.map((item) => item.value)
.toList();

Navigator.of(context).pop(_accountsList);
context.pop(_accountsList);
},
disabled: pickerItemsListSelected.isEmpty,
),
Expand All @@ -268,7 +265,7 @@ class AccountsDialogContentState extends ConsumerState<AccountsDialogContent> {
localizations.cancel,
Dimens.buttonBottomDimens,
onPressed: () {
Navigator.of(context).pop();
context.pop();
},
),
],
Expand Down
58 changes: 0 additions & 58 deletions lib/ui/util/formatters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,6 @@ import 'dart:math';

import 'package:flutter/services.dart';

/// Input formatter that ensures text starts with @
class ContactInputFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue,
TextEditingValue newValue,
) {
if (newValue.selection.baseOffset == 0) {
return newValue;
}

var workingText = newValue.text;
if (!workingText.startsWith('@')) {
workingText = '@$workingText';
}

final splitStr = workingText.split('@');
// If this string contains more than 1 @, remove all but the first one
if (splitStr.length > 2) {
workingText = '@${workingText.replaceAll('@', '')}';
}

// If nothing changed, return original
if (workingText == newValue.text) {
return newValue;
}

return newValue.copyWith(
text: workingText,
selection: TextSelection.collapsed(offset: workingText.length),
);
}
}

/// Input formatter that ensures only one space between words
class SingleSpaceInputFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue,
TextEditingValue newValue,
) {
if (newValue.selection.baseOffset == 0) {
return newValue;
}

// Don't allow first character to be a space
if (newValue.text.length < oldValue.text.length) {
return newValue;
} else if (oldValue.text.isEmpty && newValue.text == ' ') {
return oldValue;
} else if (oldValue.text.endsWith(' ') && newValue.text.endsWith(' ')) {
return oldValue;
}

return newValue;
}
}

/// Ensures input is always uppercase
class UpperCaseTextFormatter extends TextInputFormatter {
@override
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/util/transfer_recipient_formatters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ extension TransferRecipientFormatters on TransferRecipient {
? localizations.burnAddressLbl
: AddressFormatters(address.address!).getShortString(),
account: (account) => account.format,
unknownContact: (name) => name.replaceFirst('@', ''),
unknownContact: (name) => name,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class _AccountListItemState extends ConsumerState<AccountListItem>

if (widget.selectedAccount?.nameDisplayed ==
widget.account.nameDisplayed) {
Navigator.of(context).pop();
context.pop();
return;
}
context.loadingOverlay.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class _AddAccountConfirmState extends ConsumerState<AddAccountConfirmSheet>
icon: Symbols.info,
);
context.loadingOverlay.hide();
Navigator.of(context).pop();
context.pop();
}

Future<void> _showSendSucceed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';

class LiquiditySettingsSlippageTolerance extends ConsumerStatefulWidget {
const LiquiditySettingsSlippageTolerance({
Expand Down Expand Up @@ -155,7 +156,7 @@ class LiquiditySettingsSlippageToleranceState
double.tryParse(slippageToleranceController.text) ?? 0,
);
if (!context.mounted) return;
Navigator.of(context).pop();
context.pop();
},
isConnected: true,
displayWalletConnectOnPressed: () {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';

class SwapSettingsSlippageTolerance extends ConsumerStatefulWidget {
const SwapSettingsSlippageTolerance({
Expand Down Expand Up @@ -155,7 +156,7 @@ class SwapSettingsSlippageToleranceState
);

if (!context.mounted) return;
Navigator.of(context).pop();
context.pop();
},
isConnected: true,
displayWalletConnectOnPressed: () {},
Expand Down
50 changes: 36 additions & 14 deletions lib/ui/views/nft_search/layouts/nft_search_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,10 @@ class _NFTSearchBarState extends ConsumerState<NFTSearchBar> {
@override
Widget build(BuildContext context) {
final hasQRCode = ref.watch(DeviceAbilities.hasQRCodeProvider);
final session = ref.watch(sessionNotifierProvider).loggedIn!;
final localizations = AppLocalizations.of(context)!;
final nftSearchBar = ref.watch(
NftSearchBarFormProvider.nftSearchBar,
);
final nftSearchBarNotifier = ref.watch(
NftSearchBarFormProvider.nftSearchBar.notifier,
);
final connectivityStatusProvider = ref.watch(connectivityStatusProviders);
ref.listen<NftSearchBarFormState>(
NftSearchBarFormProvider.nftSearchBar,
Expand All @@ -83,7 +79,11 @@ class _NFTSearchBarState extends ConsumerState<NFTSearchBar> {
},
);

nftSearchBarNotifier.reset();
ref
.read(
NftSearchBarFormProvider.nftSearchBar.notifier,
)
.reset();
return;
}

Expand All @@ -98,7 +98,11 @@ class _NFTSearchBarState extends ConsumerState<NFTSearchBar> {
duration: const Duration(seconds: 5),
);

nftSearchBarNotifier.setError('');
ref
.read(
NftSearchBarFormProvider.nftSearchBar.notifier,
)
.setError('');
},
);

Expand Down Expand Up @@ -151,7 +155,11 @@ class _NFTSearchBarState extends ConsumerState<NFTSearchBar> {
return;
} else {
final address = Address(address: scanResult);
nftSearchBarNotifier
ref
.read(
NftSearchBarFormProvider
.nftSearchBar.notifier,
)
.setSearchCriteria(address.address!);
_updateAdressTextController();
}
Expand All @@ -167,7 +175,11 @@ class _NFTSearchBarState extends ConsumerState<NFTSearchBar> {
),
suffixIcon: PasteIcon(
onPaste: (String value) {
nftSearchBarNotifier.setSearchCriteria(value);
ref
.read(
NftSearchBarFormProvider.nftSearchBar.notifier,
)
.setSearchCriteria(value);
_updateAdressTextController();
},
),
Expand Down Expand Up @@ -205,15 +217,25 @@ class _NFTSearchBarState extends ConsumerState<NFTSearchBar> {
ConnectivityStatus.isConnected
? null
: () async {
final session =
ref.read(sessionNotifierProvider).loggedIn!;
final selectedAccount = await session
.wallet.appKeychain
.getAccountSelected();
await nftSearchBarNotifier.searchNFT(
searchController.text,
context,
session.wallet.keychainSecuredInfos
.services[selectedAccount!.name]!.keyPair!,
);
await ref
.read(
NftSearchBarFormProvider
.nftSearchBar.notifier,
)
.searchNFT(
searchController.text,
context,
session
.wallet
.keychainSecuredInfos
.services[selectedAccount!.name]!
.keyPair!,
);
},
child: Container(
height: 30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:go_router/go_router.dart';
import 'package:gradient_borders/gradient_borders.dart';

class TokenSelectionCommonBases extends ConsumerWidget {
Expand Down Expand Up @@ -76,7 +77,7 @@ class _TokenSelector extends StatelessWidget {
),
child: InkWell(
onTap: () {
Navigator.pop(context, token);
context.pop(token);
},
child: Row(
children: [
Expand Down
Loading

0 comments on commit 396227a

Please sign in to comment.