fill in address from address book in exchange view

This commit is contained in:
julian 2022-09-30 10:34:25 -06:00
parent f02683581d
commit 8268aaa7fe
2 changed files with 87 additions and 12 deletions

View file

@ -5,6 +5,7 @@ import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/models/send_view_auto_fill_data.dart'; import 'package:stackwallet/models/send_view_auto_fill_data.dart';
import 'package:stackwallet/notifications/show_flush_bar.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/address_book_views/subviews/contact_details_view.dart';
import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_2_view.dart';
import 'package:stackwallet/pages/send_view/send_view.dart'; import 'package:stackwallet/pages/send_view/send_view.dart';
import 'package:stackwallet/providers/exchange/exchange_flow_is_active_state_provider.dart'; import 'package:stackwallet/providers/exchange/exchange_flow_is_active_state_provider.dart';
import 'package:stackwallet/providers/global/address_book_service_provider.dart'; import 'package:stackwallet/providers/global/address_book_service_provider.dart';
@ -19,6 +20,9 @@ import 'package:stackwallet/widgets/rounded_container.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
final exchangeFromAddressBookAddressStateProvider =
StateProvider<String>((ref) => "");
class ContactPopUp extends ConsumerWidget { class ContactPopUp extends ConsumerWidget {
const ContactPopUp({ const ContactPopUp({
Key? key, Key? key,
@ -280,6 +284,45 @@ class ContactPopUp extends ConsumerWidget {
), ),
], ],
), ),
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),
),
),
],
),
if (contact.id != "default" && if (contact.id != "default" &&
hasActiveWallet && hasActiveWallet &&
!isExchangeFlow) !isExchangeFlow)

View file

@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/models/exchange/incomplete_exchange.dart'; import 'package:stackwallet/models/exchange/incomplete_exchange.dart';
import 'package:stackwallet/pages/address_book_views/address_book_view.dart'; import 'package:stackwallet/pages/address_book_views/address_book_view.dart';
import 'package:stackwallet/pages/address_book_views/subviews/contact_popup.dart';
import 'package:stackwallet/pages/exchange_view/choose_from_stack_view.dart'; import 'package:stackwallet/pages/exchange_view/choose_from_stack_view.dart';
import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_3_view.dart'; import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_3_view.dart';
import 'package:stackwallet/pages/exchange_view/sub_widgets/step_row.dart'; import 'package:stackwallet/pages/exchange_view/sub_widgets/step_row.dart';
@ -303,11 +304,29 @@ class _Step2ViewState extends ConsumerState<Step2View> {
.pushNamed( .pushNamed(
AddressBookView.routeName, AddressBookView.routeName,
) )
.then((_) => ref .then((_) {
ref
.read( .read(
exchangeFlowIsActiveStateProvider exchangeFlowIsActiveStateProvider
.state) .state)
.state = false); .state = false;
final address = ref
.read(
exchangeFromAddressBookAddressStateProvider
.state)
.state;
if (address.isNotEmpty) {
_toController.text = address;
model.recipientAddress =
_toController.text;
ref
.read(
exchangeFromAddressBookAddressStateProvider
.state)
.state = "";
}
});
}, },
child: const AddressBookIcon(), child: const AddressBookIcon(),
), ),
@ -527,11 +546,24 @@ class _Step2ViewState extends ConsumerState<Step2View> {
.pushNamed( .pushNamed(
AddressBookView.routeName, AddressBookView.routeName,
) )
.then((_) => ref .then((_) {
ref
.read( .read(
exchangeFlowIsActiveStateProvider exchangeFlowIsActiveStateProvider
.state) .state)
.state = false); .state = false;
final address = ref
.read(
exchangeFromAddressBookAddressStateProvider
.state)
.state;
if (address.isNotEmpty) {
_refundController.text =
address;
model.refundAddress =
_refundController.text;
}
});
}, },
child: const AddressBookIcon(), child: const AddressBookIcon(),
), ),