add custom token selector to global list for desktop

This commit is contained in:
julian-CStack 2023-03-05 13:59:44 -06:00
parent e3bd3d3bf3
commit 99a9414851
7 changed files with 160 additions and 57 deletions

View file

@ -20,7 +20,7 @@ class AddCustomTokenView extends ConsumerStatefulWidget {
required this.walletId,
}) : super(key: key);
final String walletId;
final String? walletId;
static const routeName = "/addCustomToken";
@ -96,7 +96,10 @@ class _AddCustomTokenViewState extends ConsumerState<AddCustomTokenView> {
nameController.text = currentToken!.name;
symbolController.text = currentToken!.symbol;
decimalsController.text = currentToken!.decimals.toString();
currentToken!.walletIds.add(widget.walletId);
if (widget.walletId != null) {
// TODO: this needs to be changed?
currentToken!.walletIds.add(widget.walletId!);
}
} else {
nameController.text = "";
symbolController.text = "";

View file

@ -0,0 +1,66 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/utilities/util.dart';
class AddCustomTokenSelector extends StatelessWidget {
const AddCustomTokenSelector({
Key? key,
required this.addFunction,
}) : super(key: key);
final VoidCallback addFunction;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: RawMaterialButton(
fillColor: Theme.of(context).extension<StackColors>()!.popupBG,
elevation: 0,
focusElevation: 0,
hoverElevation: 0,
highlightElevation: 0,
constraints: const BoxConstraints(),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
onPressed: addFunction,
child: Padding(
padding: Util.isDesktop
? const EdgeInsets.only(left: 24)
: const EdgeInsets.all(12),
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: Util.isDesktop ? 70 : 0,
),
child: Row(
children: [
SvgPicture.asset(
Assets.svg.circlePlusFilled,
color: Theme.of(context).extension<StackColors>()!.textDark,
width: 26,
height: 26,
),
const SizedBox(
width: 12,
),
Text(
"Add custom token",
style: Util.isDesktop
? STextStyles.desktopTextMedium(context)
: STextStyles.w600_14(context),
),
],
),
),
),
),
);
}
}

View file

@ -1,11 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:stackwallet/pages/add_wallet_views/add_token_view/add_custom_token_view.dart';
import 'package:stackwallet/pages/add_wallet_views/add_token_view/sub_widgets/add_custom_token_selector.dart';
import 'package:stackwallet/pages/add_wallet_views/add_token_view/sub_widgets/add_token_list_element.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/conditional_parent.dart';
class AddTokenList extends StatelessWidget {
@ -33,46 +28,49 @@ class AddTokenList extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
children: [
child,
Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: RawMaterialButton(
fillColor:
Theme.of(context).extension<StackColors>()!.popupBG,
elevation: 0,
focusElevation: 0,
hoverElevation: 0,
highlightElevation: 0,
constraints: const BoxConstraints(),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
onPressed: addFunction,
child: Padding(
padding: const EdgeInsets.all(12),
child: Row(
children: [
SvgPicture.asset(
Assets.svg.circlePlusFilled,
color: Theme.of(context)
.extension<StackColors>()!
.textDark,
width: 24,
height: 24,
),
const SizedBox(
width: 12,
),
Text(
"Add custom token",
style: STextStyles.w600_14(context),
),
],
),
),
),
AddCustomTokenSelector(
addFunction: addFunction,
),
// Padding(
// padding: const EdgeInsets.symmetric(vertical: 4),
// child: RawMaterialButton(
// fillColor:
// Theme.of(context).extension<StackColors>()!.popupBG,
// elevation: 0,
// focusElevation: 0,
// hoverElevation: 0,
// highlightElevation: 0,
// constraints: const BoxConstraints(),
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(
// Constants.size.circularBorderRadius,
// ),
// ),
// onPressed: addFunction,
// child: Padding(
// padding: const EdgeInsets.all(12),
// child: Row(
// children: [
// SvgPicture.asset(
// Assets.svg.circlePlusFilled,
// color: Theme.of(context)
// .extension<StackColors>()!
// .textDark,
// width: 24,
// height: 24,
// ),
// const SizedBox(
// width: 12,
// ),
// Text(
// "Add custom token",
// style: STextStyles.w600_14(context),
// ),
// ],
// ),
// ),
// ),
// ),
],
),
child: Padding(

View file

@ -9,6 +9,8 @@ import 'package:stackwallet/models/add_wallet_list_entity/add_wallet_list_entity
import 'package:stackwallet/models/add_wallet_list_entity/sub_classes/coin_entity.dart';
import 'package:stackwallet/models/add_wallet_list_entity/sub_classes/eth_token_entity.dart';
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
import 'package:stackwallet/pages/add_wallet_views/add_token_view/add_custom_token_view.dart';
import 'package:stackwallet/pages/add_wallet_views/add_token_view/sub_widgets/add_custom_token_selector.dart';
import 'package:stackwallet/pages/add_wallet_views/add_wallet_view/sub_widgets/add_wallet_text.dart';
import 'package:stackwallet/pages/add_wallet_views/add_wallet_view/sub_widgets/expanding_sub_list_item.dart';
import 'package:stackwallet/pages/add_wallet_views/add_wallet_view/sub_widgets/next_button.dart';
@ -53,7 +55,7 @@ class _AddWalletViewState extends ConsumerState<AddWalletView> {
...Coin.values.sublist(0, Coin.values.length - kTestNetCoinCount - 1)
];
final List<AddWalletListEntity> coinEntities = [];
final List<AddWalletListEntity> tokenEntities = [];
final List<EthTokenEntity> tokenEntities = [];
final bool isDesktop = Util.isDesktop;
@ -77,6 +79,26 @@ class _AddWalletViewState extends ConsumerState<AddWalletView> {
return _entities;
}
Future<void> _addToken() async {
final token = await Navigator.of(context).pushNamed(
AddCustomTokenView.routeName,
arguments: null, // no walletId as no wallet has been selected/created yet
);
if (token is EthContract) {
await MainDB.instance.putEthContract(token);
if (mounted) {
setState(() {
if (tokenEntities
.where((e) => e.token.address == token.address)
.isEmpty) {
tokenEntities.add(EthTokenEntity(token));
tokenEntities.sort((a, b) => a.token.name.compareTo(b.token.name));
}
});
}
}
}
@override
void initState() {
_searchFieldController = TextEditingController();
@ -233,6 +255,9 @@ class _AddWalletViewState extends ConsumerState<AddWalletView> {
title: "Tokens",
entities: filter(_searchTerm, tokenEntities),
initialState: ExpandableState.collapsed,
trailing: AddCustomTokenSelector(
addFunction: _addToken,
),
),
],
),

View file

@ -6,23 +6,32 @@ class AddWalletEntityList extends StatelessWidget {
const AddWalletEntityList({
Key? key,
required this.entities,
this.trailing,
}) : super(key: key);
final List<AddWalletListEntity> entities;
final Widget? trailing;
@override
Widget build(BuildContext context) {
return ListView.builder(
shrinkWrap: true,
primary: false,
itemCount: entities.length,
itemCount: trailing != null ? entities.length + 1 : entities.length,
itemBuilder: (ctx, index) {
return Padding(
padding: const EdgeInsets.all(4),
child: CoinSelectItem(
entity: entities[index],
),
);
if (trailing != null && index == entities.length) {
return Padding(
padding: const EdgeInsets.all(4),
child: trailing,
);
} else {
return Padding(
padding: const EdgeInsets.all(4),
child: CoinSelectItem(
entity: entities[index],
),
);
}
},
);
}

View file

@ -14,6 +14,7 @@ class ExpandingSubListItem extends StatefulWidget {
Key? key,
required this.title,
required this.entities,
this.trailing,
required this.initialState,
double? animationDurationMultiplier,
this.curve = Curves.easeInOutCubicEmphasized,
@ -23,6 +24,7 @@ class ExpandingSubListItem extends StatefulWidget {
final String title;
final List<AddWalletListEntity> entities;
final Widget? trailing;
final ExpandableState initialState;
final double animationDurationMultiplier;
final Curve curve;
@ -113,6 +115,7 @@ class _ExpandingSubListItemState extends State<ExpandingSubListItem> {
primary: false,
child: AddWalletEntityList(
entities: widget.entities,
trailing: widget.trailing,
),
),
);

View file

@ -7,7 +7,6 @@ import 'package:stackwallet/models/buy/response_objects/quote.dart';
import 'package:stackwallet/models/contact_address_entry.dart';
import 'package:stackwallet/models/exchange/incomplete_exchange.dart';
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart';
import 'package:stackwallet/models/isar/models/isar_models.dart';
import 'package:stackwallet/models/paynym/paynym_account_lite.dart';
import 'package:stackwallet/models/send_view_auto_fill_data.dart';
@ -219,7 +218,7 @@ class RouteGenerator {
return _routeError("${settings.name} invalid args: ${args.toString()}");
case AddCustomTokenView.routeName:
if (args is String) {
if (args is String?) {
return getRoute(
shouldUseMaterialRoute: useMaterialPageRoute,
builder: (_) => AddCustomTokenView(