105 lines
3.1 KiB
Dart
105 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'dart:convert';
|
|
import 'package:qr_flutter/qr_flutter.dart';
|
|
|
|
class ReceivePage extends StatefulWidget {
|
|
ReceivePage({Key? key, required this.uuid, required this.wallet})
|
|
: super(key: key);
|
|
|
|
final String uuid;
|
|
String wallet;
|
|
|
|
@override
|
|
_ReceivePageState createState() => _ReceivePageState();
|
|
}
|
|
|
|
class _ReceivePageState extends State<ReceivePage> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
fetchReceive();
|
|
}
|
|
|
|
String address = '';
|
|
|
|
Future<void> fetchReceive() async {
|
|
// Fetch domains from api
|
|
final response = await http.get(Uri.parse(
|
|
'https://api.firewallet.au/wallet/address?uuid=${widget.uuid}&name=${widget.wallet}'));
|
|
if (response.statusCode == 200) {
|
|
final data = jsonDecode(response.body);
|
|
if (data is Map && data.containsKey('error')) {
|
|
print('Error: ${data['error']}');
|
|
return;
|
|
}
|
|
// Return if empty
|
|
if (data.isEmpty) {
|
|
setState(() {
|
|
address = 'No address found';
|
|
});
|
|
|
|
return;
|
|
}
|
|
final addressData = data as Map;
|
|
setState(() {
|
|
address = addressData['address'];
|
|
});
|
|
} else {
|
|
// Handle error
|
|
print('Failed to load wallet names');
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('${widget.wallet} - Receive HNS or Domains'),
|
|
),
|
|
// Get wallet list from api and display here
|
|
body: Center(
|
|
child: LayoutBuilder(
|
|
builder: (BuildContext context, BoxConstraints constraints) {
|
|
return ListView(
|
|
children: <Widget>[
|
|
Center(child: Text(address, style: TextStyle(fontSize: 18.0))),
|
|
// QR Code
|
|
Center(
|
|
child: QrImageView(
|
|
data: address,
|
|
version: QrVersions.auto,
|
|
// Width = 90% of the screen width
|
|
size: constraints.maxWidth * 0.9,
|
|
eyeStyle: QrEyeStyle(
|
|
eyeShape: QrEyeShape.square,
|
|
color: Theme.of(context).brightness == Brightness.light
|
|
? Colors.black
|
|
: Colors.white,
|
|
),
|
|
dataModuleStyle: QrDataModuleStyle(
|
|
dataModuleShape: QrDataModuleShape.square,
|
|
color: Theme.of(context).brightness == Brightness.light
|
|
? Colors.black
|
|
: Colors.white,
|
|
),
|
|
),
|
|
),
|
|
|
|
TextButton(onPressed: copyAddress, child: Text('Copy Address')),
|
|
TextButton(onPressed: fetchReceive, child: Text('Refresh')),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> copyAddress() async {
|
|
// Copy the address to the clipboard
|
|
await Clipboard.setData(ClipboardData(text: address));
|
|
}
|
|
}
|