2022-09-06 01:18:45 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2022-09-06 01:18:45 +00:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
import 'package:qr_flutter/qr_flutter.dart';
|
|
|
|
import 'package:stackwallet/notifications/show_flush_bar.dart';
|
|
|
|
import 'package:stackwallet/pages/receive_view/generate_receiving_uri_qr_code_view.dart';
|
2022-09-06 01:18:45 +00:00
|
|
|
import 'package:stackwallet/providers/providers.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/route_generator.dart';
|
|
|
|
import 'package:stackwallet/utilities/assets.dart';
|
|
|
|
import 'package:stackwallet/utilities/cfcolors.dart';
|
|
|
|
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
import 'package:stackwallet/utilities/enums/flush_bar_type.dart';
|
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
|
|
|
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
2022-09-06 01:18:45 +00:00
|
|
|
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
|
|
|
|
import 'package:stackwallet/widgets/custom_loading_overlay.dart';
|
|
|
|
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
|
2022-09-06 01:18:45 +00:00
|
|
|
class ReceiveView extends ConsumerStatefulWidget {
|
2022-08-26 08:11:35 +00:00
|
|
|
const ReceiveView({
|
|
|
|
Key? key,
|
|
|
|
required this.coin,
|
2022-09-06 01:18:45 +00:00
|
|
|
required this.walletId,
|
2022-08-26 08:11:35 +00:00
|
|
|
this.clipboard = const ClipboardWrapper(),
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
static const String routeName = "/receiveView";
|
|
|
|
|
|
|
|
final Coin coin;
|
2022-09-06 01:18:45 +00:00
|
|
|
final String walletId;
|
2022-08-26 08:11:35 +00:00
|
|
|
final ClipboardInterface clipboard;
|
|
|
|
|
2022-09-06 01:18:45 +00:00
|
|
|
@override
|
|
|
|
ConsumerState<ReceiveView> createState() => _ReceiveViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ReceiveViewState extends ConsumerState<ReceiveView> {
|
|
|
|
late final Coin coin;
|
|
|
|
late final String walletId;
|
|
|
|
late final ClipboardInterface clipboard;
|
|
|
|
|
|
|
|
Future<void> generateNewAddress() async {
|
|
|
|
bool shouldPop = false;
|
|
|
|
unawaited(
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (_) {
|
|
|
|
return WillPopScope(
|
|
|
|
onWillPop: () async => shouldPop,
|
|
|
|
child: const CustomLoadingOverlay(
|
|
|
|
message: "Generating address",
|
|
|
|
eventBus: null,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
await ref
|
|
|
|
.read(walletsChangeNotifierProvider)
|
|
|
|
.getManager(walletId)
|
|
|
|
.generateNewAddress();
|
|
|
|
|
|
|
|
shouldPop = true;
|
|
|
|
|
|
|
|
if (mounted) {
|
|
|
|
Navigator.of(context)
|
|
|
|
.popUntil(ModalRoute.withName(ReceiveView.routeName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String receivingAddress = "";
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
walletId = widget.walletId;
|
|
|
|
coin = widget.coin;
|
|
|
|
clipboard = widget.clipboard;
|
|
|
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
|
|
|
final address = await ref
|
|
|
|
.read(walletsChangeNotifierProvider)
|
|
|
|
.getManager(walletId)
|
|
|
|
.currentReceivingAddress;
|
|
|
|
setState(() {
|
|
|
|
receivingAddress = address;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
debugPrint("BUILD: $runtimeType");
|
2022-09-06 01:18:45 +00:00
|
|
|
|
|
|
|
ref.listen(
|
|
|
|
ref
|
|
|
|
.read(walletsChangeNotifierProvider)
|
|
|
|
.getManagerProvider(walletId)
|
|
|
|
.select((value) => value.currentReceivingAddress),
|
|
|
|
(previous, next) {
|
|
|
|
if (next is Future<String>) {
|
|
|
|
next.then((value) => setState(() => receivingAddress = value));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: CFColors.almostWhite,
|
|
|
|
appBar: AppBar(
|
|
|
|
leading: AppBarBackButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
"Receive ${coin.ticker}",
|
|
|
|
style: STextStyles.navBarTitle,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
body: Padding(
|
|
|
|
padding: const EdgeInsets.all(12),
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(4),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
2022-09-06 01:18:45 +00:00
|
|
|
GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
clipboard.setData(
|
|
|
|
ClipboardData(text: receivingAddress),
|
|
|
|
);
|
|
|
|
showFloatingFlushBar(
|
|
|
|
type: FlushBarType.info,
|
|
|
|
message: "Copied to clipboard",
|
|
|
|
iconAsset: Assets.svg.copy,
|
|
|
|
context: context,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: RoundedWhiteContainer(
|
2022-08-26 08:11:35 +00:00
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Your ${coin.ticker} address",
|
|
|
|
style: STextStyles.itemSubtitle,
|
|
|
|
),
|
|
|
|
const Spacer(),
|
2022-09-06 01:18:45 +00:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
SvgPicture.asset(
|
|
|
|
Assets.svg.copy,
|
|
|
|
width: 10,
|
|
|
|
height: 10,
|
|
|
|
color: CFColors.link2,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 4,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"Copy",
|
|
|
|
style: STextStyles.link2,
|
|
|
|
),
|
|
|
|
],
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 4,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
receivingAddress,
|
|
|
|
style: STextStyles.itemSubtitle12,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-09-06 01:18:45 +00:00
|
|
|
if (coin != Coin.epicCash)
|
|
|
|
const SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
if (coin != Coin.epicCash)
|
|
|
|
TextButton(
|
|
|
|
onPressed: generateNewAddress,
|
|
|
|
style: ButtonStyle(
|
|
|
|
backgroundColor: MaterialStateProperty.all<Color>(
|
|
|
|
CFColors.buttonGray,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
"Generate new address",
|
|
|
|
style: STextStyles.button.copyWith(
|
|
|
|
color: CFColors.stackAccent,
|
|
|
|
),
|
|
|
|
),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 30,
|
|
|
|
),
|
2022-09-06 01:18:45 +00:00
|
|
|
RoundedWhiteContainer(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Center(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
QrImage(
|
|
|
|
data: "${coin.uriScheme}:$receivingAddress",
|
|
|
|
size: MediaQuery.of(context).size.width / 2,
|
|
|
|
foregroundColor: CFColors.stackAccent,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
BlueTextButton(
|
|
|
|
text: "Create new QR code",
|
|
|
|
onTap: () async {
|
|
|
|
unawaited(Navigator.of(context).push(
|
|
|
|
RouteGenerator.getRoute(
|
|
|
|
shouldUseMaterialRoute:
|
|
|
|
RouteGenerator.useMaterialPageRoute,
|
|
|
|
builder: (_) => GenerateUriQrCodeView(
|
|
|
|
coin: coin,
|
|
|
|
receivingAddress: receivingAddress,
|
|
|
|
),
|
|
|
|
settings: const RouteSettings(
|
|
|
|
name: GenerateUriQrCodeView.routeName,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|