stack_wallet/lib/pages/address_book_views/subviews/contact_popup.dart

429 lines
22 KiB
Dart
Raw Normal View History

2023-05-26 21:21:16 +00:00
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
import 'dart:io';
2022-08-26 08:11:35 +00:00
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/models/send_view_auto_fill_data.dart';
import 'package:stackwallet/notifications/show_flush_bar.dart';
import 'package:stackwallet/pages/address_book_views/subviews/contact_details_view.dart';
import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_2_view.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/pages/send_view/send_view.dart';
import 'package:stackwallet/providers/global/active_wallet_provider.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/providers/global/address_book_service_provider.dart';
import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/themes/coin_icon_provider.dart';
import 'package:stackwallet/themes/stack_colors.dart';
2023-04-25 22:07:28 +00:00
import 'package:stackwallet/themes/theme_providers.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/clipboard_interface.dart';
import 'package:stackwallet/utilities/text_styles.dart';
2024-05-07 17:49:49 +00:00
import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/widgets/rounded_container.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
import 'package:tuple/tuple.dart';
final exchangeFromAddressBookAddressStateProvider =
StateProvider<String>((ref) => "");
2022-08-26 08:11:35 +00:00
class ContactPopUp extends ConsumerWidget {
const ContactPopUp({
2024-05-07 17:49:49 +00:00
super.key,
2022-08-26 08:11:35 +00:00
required this.contactId,
this.clipboard = const ClipboardWrapper(),
2024-05-07 17:49:49 +00:00
});
2022-08-26 08:11:35 +00:00
final String contactId;
final ClipboardInterface clipboard;
@override
Widget build(BuildContext context, WidgetRef ref) {
final maxHeight = MediaQuery.of(context).size.height * 0.6;
final contact = ref.watch(addressBookServiceProvider
.select((value) => value.getContactById(contactId)));
final active = ref.read(currentWalletIdProvider);
2022-08-26 08:11:35 +00:00
2024-05-15 21:20:45 +00:00
final bool hasActiveWallet = active != null;
final bool isExchangeFlow =
2022-08-26 08:11:35 +00:00
ref.watch(exchangeFlowIsActiveStateProvider.state).state;
2023-07-04 23:40:06 +00:00
final addresses = contact.addressesSorted.where((e) {
2022-08-26 08:11:35 +00:00
if (hasActiveWallet && !isExchangeFlow) {
return e.coin == ref.watch(pWalletCoin(active));
2022-08-26 08:11:35 +00:00
} else {
return true;
}
}).toList(growable: false);
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: LimitedBox(
maxHeight: maxHeight,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Material(
borderRadius: BorderRadius.circular(
20,
),
child: Container(
decoration: BoxDecoration(
color:
Theme.of(context).extension<StackColors>()!.popupBG,
2022-08-26 08:11:35 +00:00
borderRadius: BorderRadius.circular(
20,
),
),
child: LimitedBox(
maxHeight: maxHeight,
child: ClipRRect(
borderRadius: BorderRadius.circular(
20,
),
child: SingleChildScrollView(
child: Column(
// spacing: 10,
children: [
const SizedBox(
height: 24,
),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 24),
child: Row(
children: [
Container(
width: 32,
height: 32,
decoration: BoxDecoration(
color: Theme.of(context)
.extension<StackColors>()!
.textFieldDefaultBG,
2022-08-26 08:11:35 +00:00
borderRadius: BorderRadius.circular(32),
),
2023-05-16 15:33:28 +00:00
child: contact.customId == "default"
2022-08-26 08:11:35 +00:00
? Center(
child: SvgPicture.file(
File(
ref.watch(
themeProvider.select(
(value) => value
.assets.stackIcon,
),
2023-04-25 22:07:28 +00:00
),
),
2022-08-26 08:11:35 +00:00
width: 20,
),
)
: contact.emojiChar != null
? Center(
child:
Text(contact.emojiChar!),
)
: Center(
child: SvgPicture.asset(
Assets.svg.user,
width: 18,
),
),
),
const SizedBox(
width: 12,
),
Expanded(
child: Text(
contact.name,
2022-09-22 22:17:21 +00:00
style:
STextStyles.itemSubtitle12(context),
2022-08-26 08:11:35 +00:00
),
),
2023-05-16 15:33:28 +00:00
if (contact.customId != "default")
2022-08-26 08:11:35 +00:00
TextButton(
onPressed: () {
Navigator.pop(context);
Navigator.of(context).pushNamed(
ContactDetailsView.routeName,
2023-05-16 15:33:28 +00:00
arguments: contact.customId,
2022-08-26 08:11:35 +00:00
);
},
style: Theme.of(context)
.extension<StackColors>()!
2023-01-24 19:29:12 +00:00
.getSecondaryEnabledButtonStyle(
2022-09-21 00:46:07 +00:00
context)!
.copyWith(
minimumSize:
MaterialStateProperty.all<
Size>(const Size(46, 32)),
),
2022-08-26 08:11:35 +00:00
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 18),
child: Text("Details",
2022-09-22 22:17:21 +00:00
style: STextStyles.buttonSmall(
context)),
2022-08-26 08:11:35 +00:00
),
),
],
),
),
SizedBox(
2023-05-16 15:33:28 +00:00
height: contact.customId == "default" ? 16 : 8,
2022-08-26 08:11:35 +00:00
),
Container(
height: 1,
color: Theme.of(context)
.extension<StackColors>()!
.background,
2022-08-26 08:11:35 +00:00
),
if (addresses.isEmpty)
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20),
child: RoundedWhiteContainer(
child: Center(
child: Text(
"No ${ref.watch(pWalletCoin(active!)).prettyName} addresses found",
2022-09-22 22:17:21 +00:00
style:
STextStyles.itemSubtitle(context),
2022-08-26 08:11:35 +00:00
),
),
),
),
...addresses.map(
(e) => Padding(
padding: const EdgeInsets.only(
top: 12,
bottom: 12,
left: 28,
right: 24,
),
child: Row(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Column(
children: [
const SizedBox(
height: 2,
),
SvgPicture.file(
File(
ref.watch(
coinIconProvider(e.coin),
),
),
2022-08-26 08:11:35 +00:00
height: 24,
),
],
),
const SizedBox(
width: 12,
),
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
2023-05-16 15:33:28 +00:00
if (contact.customId == "default")
Text(
e.other!,
style:
2022-09-22 22:17:21 +00:00
STextStyles.itemSubtitle12(
context),
),
2023-05-16 15:33:28 +00:00
if (contact.customId != "default")
Text(
"${e.label} (${e.coin.ticker})",
style:
2022-09-22 22:17:21 +00:00
STextStyles.itemSubtitle12(
context),
),
2022-08-26 08:11:35 +00:00
const SizedBox(
height: 2,
),
Text(
e.address,
2022-09-22 22:17:21 +00:00
style: STextStyles.itemSubtitle(
context)
2022-08-26 08:11:35 +00:00
.copyWith(
fontSize: 8,
),
),
],
),
),
const SizedBox(
width: 10,
),
Column(
children: [
const SizedBox(
height: 2,
),
GestureDetector(
onTap: () {
clipboard.setData(
ClipboardData(text: e.address),
);
showFloatingFlushBar(
type: FlushBarType.info,
message: "Copied to clipboard",
iconAsset: Assets.svg.copy,
context: context,
);
},
child: RoundedContainer(
color: Theme.of(context)
.extension<StackColors>()!
2022-09-21 00:46:07 +00:00
.textFieldDefaultBG,
2022-09-29 18:15:09 +00:00
padding: const EdgeInsets.all(6),
2022-08-26 08:11:35 +00:00
child: SvgPicture.asset(
Assets.svg.copy,
2022-09-29 18:15:09 +00:00
width: 16,
height: 16,
color: Theme.of(context)
.extension<StackColors>()!
.accentColorDark),
2022-08-26 08:11:35 +00:00
),
),
],
),
if (isExchangeFlow)
const SizedBox(
width: 6,
),
if (isExchangeFlow)
Column(
children: [
const SizedBox(
height: 2,
),
GestureDetector(
onTap: () {
ref
.read(
exchangeFromAddressBookAddressStateProvider
.state)
.state = e.address;
Navigator.of(context).popUntil(
ModalRoute.withName(
Step2View.routeName));
},
child: RoundedContainer(
color: Theme.of(context)
.extension<StackColors>()!
.textFieldDefaultBG,
padding:
const EdgeInsets.all(6),
child: SvgPicture.asset(
Assets.svg.chevronRight,
width: 16,
height: 16,
color: Theme.of(context)
.extension<
StackColors>()!
.accentColorDark),
),
),
],
),
2023-05-16 15:33:28 +00:00
if (contact.customId != "default" &&
2022-08-26 08:11:35 +00:00
hasActiveWallet &&
!isExchangeFlow)
const SizedBox(
width: 4,
),
2023-05-16 15:33:28 +00:00
if (contact.customId != "default" &&
2022-08-26 08:11:35 +00:00
hasActiveWallet &&
!isExchangeFlow)
Column(
children: [
const SizedBox(
height: 2,
),
GestureDetector(
onTap: () {
final String contactLabel =
"${contact.name} (${e.label})";
final String address =
e.address;
if (hasActiveWallet) {
Navigator.of(context)
.pushNamed(
SendView.routeName,
arguments: Tuple3(
active,
ref.read(
pWalletCoin(active)),
2022-08-26 08:11:35 +00:00
SendViewAutoFillData(
address: address,
contactLabel:
contactLabel,
),
),
);
}
},
child: RoundedContainer(
color: Theme.of(context)
.extension<StackColors>()!
2022-09-21 00:46:07 +00:00
.textFieldDefaultBG,
2024-05-07 17:49:49 +00:00
padding: EdgeInsets.all(
Util.isDesktop ? 4 : 6,
),
2022-08-26 08:11:35 +00:00
child: SvgPicture.asset(
Assets
.svg.circleArrowUpRight,
2024-05-07 17:49:49 +00:00
width: Util.isDesktop
? 12
: 16,
height: Util.isDesktop
? 12
: 16,
color: Theme.of(context)
.extension<
StackColors>()!
.accentColorDark),
2022-08-26 08:11:35 +00:00
),
),
],
),
],
),
),
),
const SizedBox(
height: 12,
),
],
),
),
),
),
),
),
],
),
),
),
],
);
}
}