Skip to content

Commit

Permalink
Merge pull request #78 from archethic-foundation/74-add-uco-in-search…
Browse files Browse the repository at this point in the history
…-tab-bar

Multi-updates
  • Loading branch information
redDwarf03 authored Feb 6, 2024
2 parents 443e10f + 9f6e568 commit 93d9441
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 49 deletions.
2 changes: 1 addition & 1 deletion lib/application/pool/dex_pool.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 18 additions & 7 deletions lib/application/pool/dex_pool_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,27 @@ Future<List<DexPool>> _getPoolListForSearch(
) async {
final dexPools = <DexPool>[];
final poolList = await ref.read(_getPoolListProvider.future);
final poolsListDatasource = await HivePoolsListDatasource.getInstance();

for (final pool in poolList) {
if (pool.poolAddress.toUpperCase() == searchText.toUpperCase() ||
pool.pair.token1.address!.toUpperCase() == searchText.toUpperCase() ||
pool.pair.token2.address!.toUpperCase() == searchText.toUpperCase()) {
final poolWithInfos = await ref.read(
DexPoolProviders.getPoolInfos(pool).future,
);
dexPools.add(poolWithInfos!);
if ((pool.poolAddress.toUpperCase() == searchText.toUpperCase() ||
pool.pair.token1.address!.toUpperCase() ==
searchText.toUpperCase() ||
pool.pair.token2.address!.toUpperCase() ==
searchText.toUpperCase()) ||
(searchText.toUpperCase() == 'UCO' &&
(pool.pair.token1.isUCO || pool.pair.token2.isUCO))) {
final poolHive = poolsListDatasource.getPool(pool.poolAddress);
if (poolHive == null) {
final poolWithInfos = await ref.read(
DexPoolProviders.getPoolInfos(pool).future,
);
dexPools.add(poolWithInfos!);
} else {
dexPools.add(poolHive.toDexPool());
}
}
}

return dexPools;
}
1 change: 1 addition & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"poolAddControlToken2AmountEmpty": "Please enter the amount of token 2",
"poolAddControlToken1AmountExceedBalance": "The amount entered for token 1 exceeds your balance.",
"poolAddControlToken2AmountExceedBalance": "The amount entered for token 2 exceeds your balance.",
"poolAddControlSameTokens": "You cannot create a pool with the same 2 tokens",
"poolAddConfirmToken1Lbl": "Token 1",
"poolAddConfirmToken2Lbl": "Token 2",
"addPoolProcessStep0": "Process not started",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class _ConnectionToWalletStatusState
);
}
},
icon: SelectableText(
icon: Text(
AppLocalizations.of(context)!.btn_connect_wallet,
style: TextStyle(
fontSize: 16,
Expand Down
9 changes: 9 additions & 0 deletions lib/ui/views/pool_add/bloc/provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ class PoolAddFormNotifier extends AutoDisposeNotifier<PoolAddFormState> {
return false;
}

if (state.token1!.address == state.token2!.address) {
setFailure(
Failure.other(
cause: AppLocalizations.of(context)!.poolAddControlSameTokens,
),
);
return false;
}

if (state.token1Amount <= 0) {
setFailure(
Failure.other(
Expand Down
3 changes: 1 addition & 2 deletions lib/ui/views/pool_add/bloc/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ class PoolAddFormState with _$PoolAddFormState {
token1Balance > 0 &&
token2Balance > 0 &&
token1Amount > 0 &&
token2Amount > 0 &&
token1!.address != token2!.address;
token2Amount > 0;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:aedex/application/pool/dex_pool.dart';
import 'package:aedex/ui/themes/dex_theme_base.dart';
import 'package:aedex/ui/views/util/iconsax.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

Expand Down Expand Up @@ -49,7 +50,7 @@ class PoolAddAddCacheIcon extends ConsumerWidget {
right: 10,
),
child: Icon(
Icons.add,
Iconsax.star,
size: 16,
color: ArchethicThemeBase.raspberry300,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import 'package:aedex/application/pool/dex_pool.dart';
import 'package:aedex/ui/themes/dex_theme_base.dart';
import 'package:aedex/ui/views/util/components/app_button.dart';
import 'package:aedex/ui/views/util/iconsax.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand Down Expand Up @@ -143,7 +144,7 @@ class PoolAddRemoveCacheIcon extends ConsumerWidget {
right: 10,
),
child: Icon(
Icons.remove,
Iconsax.star_slash,
size: 16,
color: ArchethicThemeBase.raspberry300,
),
Expand Down
14 changes: 2 additions & 12 deletions lib/ui/views/pool_list/components/pool_list_search_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,12 @@ class PoolListSearchBar extends ConsumerStatefulWidget {
}

class PoolListSearchBarState extends ConsumerState<PoolListSearchBar> {
late final TextEditingController searchController = TextEditingController();
late final FocusNode searchFocus;
// ignore: unused_field
String _searchText = '';

@override
void initState() {
super.initState();
searchFocus = FocusNode();
searchController.addListener(() {
setState(() {
_searchText = searchController.text;
});
});
}

@override
Expand Down Expand Up @@ -78,7 +70,6 @@ class PoolListSearchBarState extends ConsumerState<PoolListSearchBar> {
fontWeight: FontWeight.w400,
),
autocorrect: false,
controller: searchController,
onChanged: (text) {
ref
.read(
Expand All @@ -95,15 +86,15 @@ class PoolListSearchBarState extends ConsumerState<PoolListSearchBar> {
},
focusNode: searchFocus,
textAlign: TextAlign.left,
textInputAction: TextInputAction.next,
textInputAction: TextInputAction.none,
keyboardType: TextInputType.text,
inputFormatters: <TextInputFormatter>[
LengthLimitingTextInputFormatter(68),
UpperCaseTextFormatter(),
],
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Search by pool or token address',
hintText: 'Search by pool or token address or "UCO"',
contentPadding: const EdgeInsets.only(bottom: 15),
hintStyle: TextStyle(
fontFamily: DexThemeBase.mainFont,
Expand All @@ -121,7 +112,6 @@ class PoolListSearchBarState extends ConsumerState<PoolListSearchBar> {

@override
void dispose() {
searchController.dispose();
searchFocus.dispose();
super.dispose();
}
Expand Down
57 changes: 37 additions & 20 deletions lib/ui/views/pool_list/pool_list_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:ui';

import 'package:aedex/application/session/provider.dart';
import 'package:aedex/domain/models/dex_pool.dart';
import 'package:aedex/domain/models/failures.dart';
import 'package:aedex/ui/themes/dex_theme_base.dart';
Expand Down Expand Up @@ -36,6 +37,7 @@ class PoolListSheet extends ConsumerWidget {
),
);
final poolListForm = ref.watch(PoolListFormProvider.poolListForm);
final session = ref.watch(SessionProviders.session);
return Stack(
children: [
Center(
Expand Down Expand Up @@ -96,24 +98,39 @@ class PoolListSheet extends ConsumerWidget {
error: (error, stackTrace) =>
DexErrorMessage(failure: Failure.fromError(error)),
data: (pools) {
if (session.isConnected == false &&
poolListForm.tabIndexSelected == PoolsListTab.myPools) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SelectableText(
'Please, connect your wallet to list your pools with position.',
style: Theme.of(context).textTheme.bodyLarge,
),
],
);
}

if (pools.isEmpty &&
poolListForm.tabIndexSelected ==
PoolsListTab.favoritePools) {
return const Row(
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
SelectableText(
'To add your favorite pools to this tab, please click on the',
style: Theme.of(context).textTheme.bodyLarge,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 5),
const Padding(
padding: EdgeInsets.only(left: 2, right: 5),
child: Icon(
Icons.add,
Iconsax.star,
size: 14,
),
),
Text(
SelectableText(
'icon in the pool cards header.',
style: Theme.of(context).textTheme.bodyLarge,
),
],
);
Expand Down Expand Up @@ -217,6 +234,20 @@ class _PoolListItemState extends ConsumerState<PoolListItem> {
right: 20,
child: Row(
children: [
if (widget.pool.isFavorite)
Padding(
padding: const EdgeInsets.only(right: 5),
child: PoolAddRemoveCacheIcon(
poolAddress: widget.pool.poolAddress,
),
)
else
Padding(
padding: const EdgeInsets.only(right: 5),
child: PoolAddAddCacheIcon(
poolAddress: widget.pool.poolAddress,
),
),
SizedBox(
height: 40,
child: Card(
Expand Down Expand Up @@ -281,20 +312,6 @@ class _PoolListItemState extends ConsumerState<PoolListItem> {
),
),
),
if (widget.pool.isFavorite)
Padding(
padding: const EdgeInsets.only(left: 5),
child: PoolAddRemoveCacheIcon(
poolAddress: widget.pool.poolAddress,
),
)
else
Padding(
padding: const EdgeInsets.only(left: 5),
child: PoolAddAddCacheIcon(
poolAddress: widget.pool.poolAddress,
),
),
],
),
),
Expand Down
8 changes: 6 additions & 2 deletions lib/ui/views/util/components/liquidity_positions_icon.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:aedex/application/session/provider.dart';
import 'package:aedex/ui/themes/dex_theme_base.dart';
import 'package:aedex/ui/views/util/iconsax.dart';
import 'package:flutter/material.dart';
Expand All @@ -18,8 +19,11 @@ class LiquidityPositionsIcon extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
if (lpTokenInUserBalance == false) {
return const SizedBox.shrink();
final session = ref.watch(SessionProviders.session);
if (lpTokenInUserBalance == false || session.isConnected == false) {
return const SizedBox(
height: 16,
);
}
return Row(
children: [
Expand Down
4 changes: 3 additions & 1 deletion lib/ui/views/util/components/pool_favorite_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class LiquidityFavoriteIcon extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
if (isFavorite == false) {
return const SizedBox.shrink();
return const SizedBox(
height: 16,
);
}
return Row(
children: [
Expand Down
4 changes: 3 additions & 1 deletion lib/ui/views/util/components/verified_pool_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class VerifiedPoolIcon extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
if (isVerified == false) {
return const SizedBox.shrink();
return const SizedBox(
height: 16,
);
}
return Row(
children: [
Expand Down

0 comments on commit 93d9441

Please sign in to comment.