Skip to content

Commit

Permalink
feat: ✨ Display only tokens not present in the local list
Browse files Browse the repository at this point in the history
  • Loading branch information
redDwarf03 committed Dec 22, 2024
1 parent 2d3c17c commit 914df78
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ import 'package:aewallet/ui/views/add_custom_token/bloc/state.dart';
import 'package:aewallet/ui/views/add_custom_token/layouts/components/add_custom_token_info_token.dart';
import 'package:aewallet/ui/views/add_custom_token/layouts/components/add_custom_token_textfield_address.dart';
import 'package:aewallet/ui/widgets/components/app_button_tiny.dart';
import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart'
as aedappfm;
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';

class AddCustomTokenSheet extends ConsumerWidget {
const AddCustomTokenSheet({
this.myTokens,
super.key,
});
final List<aedappfm.AEToken>? myTokens;

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand Down Expand Up @@ -79,7 +83,9 @@ class AddCustomTokenSheet extends ConsumerWidget {
const SizedBox(
height: 30,
),
const AddCustomTokenTextFieldAddress(),
AddCustomTokenTextFieldAddress(
myTokens: myTokens,
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 20),
child: AddCustomTokenInfoToken(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';

class AddCustomTokenTextFieldAddress extends ConsumerStatefulWidget {
const AddCustomTokenTextFieldAddress({
this.myTokens,
super.key,
});

final List<aedappfm.AEToken>? myTokens;

@override
ConsumerState<AddCustomTokenTextFieldAddress> createState() =>
_AddCustomTokenTextFieldAddressState();
Expand Down Expand Up @@ -145,11 +148,12 @@ class _AddCustomTokenTextFieldAddressState
textAlign: TextAlign.center,
),
),
const TransferTokensList(
TransferTokensList(
withUCO: false,
withLPToken: true,
withNotVerified: true,
withCustomToken: false,
myTokens: widget.myTokens,
),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';

class CustomTokenAddBtn extends ConsumerWidget {
const CustomTokenAddBtn({
this.myTokens,
super.key,
});

final List<aedappfm.AEToken>? myTokens;

@override
Widget build(BuildContext context, WidgetRef ref) {
return Padding(
Expand All @@ -30,7 +33,9 @@ class CustomTokenAddBtn extends ConsumerWidget {
child: Scaffold(
backgroundColor: aedappfm.AppThemeBase.sheetBackground
.withOpacity(0.2),
body: const AddCustomTokenSheet(),
body: AddCustomTokenSheet(
myTokens: myTokens,
),
),
);
},
Expand Down
9 changes: 6 additions & 3 deletions lib/ui/views/tokens_list/layouts/tokens_list_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,14 @@ class TokensListState extends ConsumerState<TokensList>
Stack(
alignment: Alignment.centerLeft,
children: [
const Row(
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
if (FeatureFlags.tokenFungibleCreationFeature) TokenAddBtn(),
CustomTokenAddBtn(),
if (FeatureFlags.tokenFungibleCreationFeature)
const TokenAddBtn(),
CustomTokenAddBtn(
myTokens: tokens,
),
],
),
SizedBox(
Expand Down
21 changes: 18 additions & 3 deletions lib/ui/views/transfer/layouts/components/transfer_tokens_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'dart:ui';

import 'package:aewallet/application/tokens/tokens.dart';
import 'package:aewallet/ui/views/transfer/layouts/components/transfer_token_detail.dart';
import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart'
as aedappfm;
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

Expand All @@ -12,6 +14,7 @@ class TransferTokensList extends ConsumerStatefulWidget {
this.withNotVerified = false,
this.withLPToken = false,
this.withCustomToken = true,
this.myTokens,
super.key,
});

Expand All @@ -20,6 +23,7 @@ class TransferTokensList extends ConsumerStatefulWidget {
final bool withNotVerified;
final bool withLPToken;
final bool withCustomToken;
final List<aedappfm.AEToken>? myTokens;

@override
ConsumerState<TransferTokensList> createState() => TransferTokensListState();
Expand Down Expand Up @@ -50,7 +54,18 @@ class TransferTokensListState extends ConsumerState<TransferTokensList>
return const SizedBox.shrink();
}

tokensList.sort((a, b) {
final filteredTokensList = widget.myTokens != null
? tokensList.where((token) {
return widget.myTokens!
.every((myToken) => myToken.address != token.address);
}).toList()
: tokensList;

if (filteredTokensList.isEmpty) {
return const SizedBox.shrink();
}

filteredTokensList.sort((a, b) {
if (a.address == null && b.address != null) return -1;
if (a.address != null && b.address == null) return 1;

Expand Down Expand Up @@ -81,10 +96,10 @@ class TransferTokensListState extends ConsumerState<TransferTokensList>
top: MediaQuery.of(context).padding.top + 20,
bottom: MediaQuery.of(context).padding.bottom + 70,
),
itemCount: tokensList.length,
itemCount: filteredTokensList.length,
itemBuilder: (BuildContext context, int index) {
return TransferTokenDetail(
aeToken: tokensList[index],
aeToken: filteredTokensList[index],
);
},
),
Expand Down

0 comments on commit 914df78

Please sign in to comment.