add custom token dialog modified for desktop

This commit is contained in:
julian 2023-04-07 15:40:00 -06:00
parent f744fd10de
commit 1ff19194e7
2 changed files with 101 additions and 58 deletions

View file

@ -12,7 +12,6 @@ import 'package:stackwallet/pages/add_wallet_views/add_token_view/sub_widgets/ad
import 'package:stackwallet/pages/add_wallet_views/add_token_view/sub_widgets/add_token_list_element.dart'; import 'package:stackwallet/pages/add_wallet_views/add_token_view/sub_widgets/add_token_list_element.dart';
import 'package:stackwallet/pages/add_wallet_views/add_token_view/sub_widgets/add_token_text.dart'; import 'package:stackwallet/pages/add_wallet_views/add_token_view/sub_widgets/add_token_text.dart';
import 'package:stackwallet/pages_desktop_specific/desktop_home_view.dart'; import 'package:stackwallet/pages_desktop_specific/desktop_home_view.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/exit_to_my_stack_button.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/services/coins/ethereum/ethereum_wallet.dart'; import 'package:stackwallet/services/coins/ethereum/ethereum_wallet.dart';
import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/assets.dart';
@ -113,18 +112,32 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
} }
Future<void> _addToken() async { Future<void> _addToken() async {
final token = await Navigator.of(context).pushNamed( EthContract? contract;
AddCustomTokenView.routeName,
arguments: widget.walletId, if (isDesktop) {
); contract = await showDialog(
if (token is EthContract) { context: context,
await MainDB.instance.putEthContract(token); builder: (context) => const DesktopDialog(
maxWidth: 580,
maxHeight: 500,
child: AddCustomTokenView(),
),
);
} else {
contract = await Navigator.of(context).pushNamed(
AddCustomTokenView.routeName,
);
}
if (contract != null) {
await MainDB.instance.putEthContract(contract);
if (mounted) { if (mounted) {
setState(() { setState(() {
if (tokenEntities if (tokenEntities
.where((e) => e.token.address == token.address) .where((e) => e.token.address == contract!.address)
.isEmpty) { .isEmpty) {
tokenEntities.add(AddTokenListElementData(token)..selected = true); tokenEntities
.add(AddTokenListElementData(contract!)..selected = true);
tokenEntities.sort((a, b) => a.token.name.compareTo(b.token.name)); tokenEntities.sort((a, b) => a.token.name.compareTo(b.token.name));
} }
}); });
@ -184,51 +197,79 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
builder: (child) => DesktopScaffold( builder: (child) => DesktopScaffold(
appBar: DesktopAppBar( appBar: DesktopAppBar(
isCompactHeight: false, isCompactHeight: false,
useSpacers: false,
leading: const AppBarBackButton(), leading: const AppBarBackButton(),
overlayCenter: Text(
walletName,
style: STextStyles.desktopSubtitleH2(context),
),
trailing: widget.contractsToMarkSelected == null trailing: widget.contractsToMarkSelected == null
? const ExitToMyStackButton() ? Padding(
padding: const EdgeInsets.only(
right: 24,
),
child: SizedBox(
height: 56,
child: TextButton(
style: Theme.of(context)
.extension<StackColors>()!
.getSmallSecondaryEnabledButtonStyle(context),
onPressed: _addToken,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 30,
),
child: Text(
"Add custom token",
style:
STextStyles.desktopButtonSmallSecondaryEnabled(
context),
),
),
),
),
)
: null, : null,
), ),
body: SizedBox( body: SizedBox(
width: 480, width: 480,
child: RoundedWhiteContainer( child: Column(
radiusMultiplier: 2, children: [
padding: const EdgeInsets.only( const AddTokenText(
left: 20, isDesktop: true,
top: 20, ),
right: 20, const SizedBox(
bottom: 0, height: 16,
), ),
child: Column( Expanded(
children: [ child: RoundedWhiteContainer(
AddTokenText( radiusMultiplier: 2,
isDesktop: true, padding: const EdgeInsets.only(
walletName: walletName, left: 20,
), top: 20,
const SizedBox( right: 20,
height: 16, bottom: 0,
), ),
Expanded(
child: child, child: child,
), ),
const SizedBox( ),
height: 26, const SizedBox(
height: 26,
),
SizedBox(
height: 70,
width: 480,
child: PrimaryButton(
label: widget.contractsToMarkSelected != null
? "Save"
: "Next",
onPressed: onNextPressed,
), ),
SizedBox( ),
height: 70, const SizedBox(
width: 480, height: 32,
child: PrimaryButton( ),
label: widget.contractsToMarkSelected != null ],
? "Save"
: "Next",
onPressed: onNextPressed,
),
),
const SizedBox(
height: 32,
),
],
),
), ),
), ),
), ),
@ -369,7 +410,7 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
child: AddTokenList( child: AddTokenList(
walletId: widget.walletId, walletId: widget.walletId,
items: filter(_searchTerm, tokenEntities), items: filter(_searchTerm, tokenEntities),
addFunction: widget.isDesktopPopup ? null : _addToken, addFunction: isDesktop ? null : _addToken,
), ),
), ),
const SizedBox( const SizedBox(

View file

@ -5,10 +5,10 @@ class AddTokenText extends StatelessWidget {
const AddTokenText({ const AddTokenText({
Key? key, Key? key,
required this.isDesktop, required this.isDesktop,
required this.walletName, this.walletName,
}) : super(key: key); }) : super(key: key);
final String walletName; final String? walletName;
final bool isDesktop; final bool isDesktop;
@override @override
@ -16,16 +16,18 @@ class AddTokenText extends StatelessWidget {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
Text( if (walletName != null)
walletName, Text(
textAlign: TextAlign.center, walletName!,
style: isDesktop textAlign: TextAlign.center,
? STextStyles.sectionLabelMedium12(context) // todo: fixme style: isDesktop
: STextStyles.sectionLabelMedium12(context), ? STextStyles.sectionLabelMedium12(context) // todo: fixme
), : STextStyles.sectionLabelMedium12(context),
const SizedBox( ),
height: 4, if (walletName != null)
), const SizedBox(
height: 4,
),
Text( Text(
"Edit Tokens", "Edit Tokens",
textAlign: TextAlign.center, textAlign: TextAlign.center,