diff --git a/lib/pages/add_wallet_views/add_token_view/add_custom_token_view.dart b/lib/pages/add_wallet_views/add_token_view/add_custom_token_view.dart index 395e8fa52..760efb00f 100644 --- a/lib/pages/add_wallet_views/add_token_view/add_custom_token_view.dart +++ b/lib/pages/add_wallet_views/add_token_view/add_custom_token_view.dart @@ -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 { 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 = ""; diff --git a/lib/pages/add_wallet_views/add_token_view/sub_widgets/add_custom_token_selector.dart b/lib/pages/add_wallet_views/add_token_view/sub_widgets/add_custom_token_selector.dart new file mode 100644 index 000000000..6c12107b0 --- /dev/null +++ b/lib/pages/add_wallet_views/add_token_view/sub_widgets/add_custom_token_selector.dart @@ -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()!.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()!.textDark, + width: 26, + height: 26, + ), + const SizedBox( + width: 12, + ), + Text( + "Add custom token", + style: Util.isDesktop + ? STextStyles.desktopTextMedium(context) + : STextStyles.w600_14(context), + ), + ], + ), + ), + ), + ), + ); + } +} diff --git a/lib/pages/add_wallet_views/add_token_view/sub_widgets/add_token_list.dart b/lib/pages/add_wallet_views/add_token_view/sub_widgets/add_token_list.dart index 5b532536e..b472f1f63 100644 --- a/lib/pages/add_wallet_views/add_token_view/sub_widgets/add_token_list.dart +++ b/lib/pages/add_wallet_views/add_token_view/sub_widgets/add_token_list.dart @@ -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()!.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()! - .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()!.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()! + // .textDark, + // width: 24, + // height: 24, + // ), + // const SizedBox( + // width: 12, + // ), + // Text( + // "Add custom token", + // style: STextStyles.w600_14(context), + // ), + // ], + // ), + // ), + // ), + // ), ], ), child: Padding( diff --git a/lib/pages/add_wallet_views/add_wallet_view/add_wallet_view.dart b/lib/pages/add_wallet_views/add_wallet_view/add_wallet_view.dart index a3ca0aef8..6e74f9e81 100644 --- a/lib/pages/add_wallet_views/add_wallet_view/add_wallet_view.dart +++ b/lib/pages/add_wallet_views/add_wallet_view/add_wallet_view.dart @@ -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 { ...Coin.values.sublist(0, Coin.values.length - kTestNetCoinCount - 1) ]; final List coinEntities = []; - final List tokenEntities = []; + final List tokenEntities = []; final bool isDesktop = Util.isDesktop; @@ -77,6 +79,26 @@ class _AddWalletViewState extends ConsumerState { return _entities; } + Future _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 { title: "Tokens", entities: filter(_searchTerm, tokenEntities), initialState: ExpandableState.collapsed, + trailing: AddCustomTokenSelector( + addFunction: _addToken, + ), ), ], ), diff --git a/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/add_wallet_entity_list.dart b/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/add_wallet_entity_list.dart index 590a8c8ce..c503daa88 100644 --- a/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/add_wallet_entity_list.dart +++ b/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/add_wallet_entity_list.dart @@ -6,23 +6,32 @@ class AddWalletEntityList extends StatelessWidget { const AddWalletEntityList({ Key? key, required this.entities, + this.trailing, }) : super(key: key); final List 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], + ), + ); + } }, ); } diff --git a/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/expanding_sub_list_item.dart b/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/expanding_sub_list_item.dart index d3a4b543a..67c748b99 100644 --- a/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/expanding_sub_list_item.dart +++ b/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/expanding_sub_list_item.dart @@ -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 entities; + final Widget? trailing; final ExpandableState initialState; final double animationDurationMultiplier; final Curve curve; @@ -113,6 +115,7 @@ class _ExpandingSubListItemState extends State { primary: false, child: AddWalletEntityList( entities: widget.entities, + trailing: widget.trailing, ), ), ); diff --git a/lib/route_generator.dart b/lib/route_generator.dart index 81426cec5..75a5dc429 100644 --- a/lib/route_generator.dart +++ b/lib/route_generator.dart @@ -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(