Payment URI
This commit is contained in:
parent
0f2dc36fd7
commit
d7484f0f5b
|
@ -231,7 +231,7 @@ class QRAddressState extends State<QRAddressWidget> {
|
||||||
}
|
}
|
||||||
|
|
||||||
_onReceive() async {
|
_onReceive() async {
|
||||||
Navigator.of(context).pushNamed('/receive', arguments: _address());
|
Navigator.of(context).pushNamed('/receive');
|
||||||
}
|
}
|
||||||
|
|
||||||
_onSnapAddress() {
|
_onSnapAddress() {
|
||||||
|
|
|
@ -328,6 +328,10 @@ abstract class _ActiveAccount with Store {
|
||||||
return WarpApi.newDiversifiedAddress();
|
return WarpApi.newDiversifiedAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getAddress(bool t, bool s, bool o) {
|
||||||
|
return WarpApi.getAddress(coin, id, (t ? 1 : 0) | (s ? 2 : 0) | (o ? 4 : 0));
|
||||||
|
}
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
List<Note> get sortedNotes {
|
List<Note> get sortedNotes {
|
||||||
final _1 = syncStatus.syncedHeight;
|
final _1 = syncStatus.syncedHeight;
|
||||||
|
|
|
@ -243,7 +243,7 @@ void main() {
|
||||||
'/send': (context) =>
|
'/send': (context) =>
|
||||||
SendPage(routeSettings.arguments as SendPageArgs?),
|
SendPage(routeSettings.arguments as SendPageArgs?),
|
||||||
'/receive': (context) =>
|
'/receive': (context) =>
|
||||||
PaymentURIPage(routeSettings.arguments as String?),
|
PaymentURIPage(),
|
||||||
'/accounts': (context) => AccountManagerPage(),
|
'/accounts': (context) => AccountManagerPage(),
|
||||||
'/settings': (context) => SettingsPage(),
|
'/settings': (context) => SettingsPage(),
|
||||||
'/tx': (context) =>
|
'/tx': (context) =>
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import 'package:decimal/decimal.dart';
|
import 'package:decimal/decimal.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||||
import 'package:qr_flutter/qr_flutter.dart';
|
import 'package:qr_flutter/qr_flutter.dart';
|
||||||
import 'dualmoneyinput.dart';
|
import 'dualmoneyinput.dart';
|
||||||
import 'package:warp_api/warp_api.dart';
|
import 'package:warp_api/warp_api.dart';
|
||||||
|
@ -9,10 +11,6 @@ import 'generated/l10n.dart';
|
||||||
import 'settings.dart';
|
import 'settings.dart';
|
||||||
|
|
||||||
class PaymentURIPage extends StatefulWidget {
|
class PaymentURIPage extends StatefulWidget {
|
||||||
final String address;
|
|
||||||
|
|
||||||
PaymentURIPage(String? _address): address = _address ?? active.address;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
PaymentURIState createState() => PaymentURIState();
|
PaymentURIState createState() => PaymentURIState();
|
||||||
}
|
}
|
||||||
|
@ -20,13 +18,21 @@ class PaymentURIPage extends StatefulWidget {
|
||||||
class PaymentURIState extends State<PaymentURIPage> {
|
class PaymentURIState extends State<PaymentURIPage> {
|
||||||
var _memoController = TextEditingController(text: '');
|
var _memoController = TextEditingController(text: '');
|
||||||
var qrText = "";
|
var qrText = "";
|
||||||
|
var address = "";
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
final amountKey = GlobalKey<DualMoneyInputState>();
|
final amountKey = GlobalKey<DualMoneyInputState>();
|
||||||
|
final hasUA = active.coinDef.supportsUA;
|
||||||
|
var uaType = settings.uaType;
|
||||||
|
List<String> uaList = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
qrText = widget.address;
|
if (uaType & 1 != 0) uaList.add('T');
|
||||||
|
if (uaType & 2 != 0) uaList.add('S');
|
||||||
|
if (uaType & 4 != 0) uaList.add('O');
|
||||||
|
address = _decodeCheckboxes(uaList);
|
||||||
|
qrText = address;
|
||||||
Future.microtask(() {
|
Future.microtask(() {
|
||||||
priceStore.fetchCoinPrice(active.coin);
|
priceStore.fetchCoinPrice(active.coin);
|
||||||
});
|
});
|
||||||
|
@ -53,6 +59,22 @@ class PaymentURIState extends State<PaymentURIPage> {
|
||||||
size: qrSize,
|
size: qrSize,
|
||||||
backgroundColor: Colors.white)),
|
backgroundColor: Colors.white)),
|
||||||
Padding(padding: EdgeInsets.all(8)),
|
Padding(padding: EdgeInsets.all(8)),
|
||||||
|
Row(mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Expanded(child: FormBuilderCheckboxGroup<String>(
|
||||||
|
orientation: OptionsOrientation.horizontal,
|
||||||
|
name: 'ua',
|
||||||
|
decoration: InputDecoration(labelText: 'Main Address Type'),
|
||||||
|
initialValue: uaList,
|
||||||
|
onChanged: _onUAType,
|
||||||
|
options: [
|
||||||
|
FormBuilderFieldOption(value: 'T'),
|
||||||
|
FormBuilderFieldOption(value: 'S'),
|
||||||
|
FormBuilderFieldOption(value: 'O'),
|
||||||
|
])),
|
||||||
|
ElevatedButton.icon(onPressed: _onAddressCopy, icon: Icon(Icons.content_copy), label: Text(S.current.copy))
|
||||||
|
]),
|
||||||
|
Padding(padding: EdgeInsets.all(8)),
|
||||||
DualMoneyInputWidget(key: amountKey),
|
DualMoneyInputWidget(key: amountKey),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
decoration:
|
decoration:
|
||||||
|
@ -78,26 +100,49 @@ class PaymentURIState extends State<PaymentURIPage> {
|
||||||
]))))));
|
]))))));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _updateQR() {
|
String _getQR() {
|
||||||
final amount = amountKey.currentState!.amount;
|
final amount = amountKey.currentState!.amount;
|
||||||
final memo = _memoController.text;
|
final memo = _memoController.text;
|
||||||
|
|
||||||
final String _qrText;
|
final String _qrText;
|
||||||
if (amount > 0) {
|
if (amount > 0) {
|
||||||
_qrText = WarpApi.makePaymentURI(widget.address, amount, memo);
|
return WarpApi.makePaymentURI(address, amount, memo);
|
||||||
} else
|
}
|
||||||
_qrText = widget.address;
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
_onAddressCopy() {
|
||||||
|
Clipboard.setData(ClipboardData(text: qrText));
|
||||||
|
showSnackBar(S.of(context).addressCopiedToClipboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onUAType(List<String>? types) {
|
||||||
|
if (types == null) { return; }
|
||||||
setState(() {
|
setState(() {
|
||||||
qrText = _qrText;
|
if (types.isEmpty) {
|
||||||
|
address = active.getAddress(true, true, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
address = _decodeCheckboxes(types);
|
||||||
|
qrText = _getQR();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _decodeCheckboxes(List<String> types) {
|
||||||
|
var t = false;
|
||||||
|
var s = false;
|
||||||
|
var o = false;
|
||||||
|
if (types.contains("T")) t = true;
|
||||||
|
if (types.contains("S")) s = true;
|
||||||
|
if (types.contains("O")) o = true;
|
||||||
|
return active.getAddress(t, s, o);
|
||||||
|
}
|
||||||
|
|
||||||
void _reset() {
|
void _reset() {
|
||||||
_memoController.clear();
|
_memoController.clear();
|
||||||
amountKey.currentState?.clear();
|
amountKey.currentState?.clear();
|
||||||
setState(() {
|
setState(() {
|
||||||
qrText = widget.address;
|
qrText = address;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +150,9 @@ class PaymentURIState extends State<PaymentURIPage> {
|
||||||
final form = _formKey.currentState!;
|
final form = _formKey.currentState!;
|
||||||
if (form.validate()) {
|
if (form.validate()) {
|
||||||
form.save();
|
form.save();
|
||||||
_updateQR();
|
setState(() {
|
||||||
|
qrText = _getQR();
|
||||||
|
});
|
||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -449,9 +449,14 @@ Future<void> send(BuildContext context, List<Recipient> recipients) async {
|
||||||
|
|
||||||
if (recipients.length == 1)
|
if (recipients.length == 1)
|
||||||
active.setDraftRecipient(recipients[0]);
|
active.setDraftRecipient(recipients[0]);
|
||||||
final txPlan = await WarpApi.prepareTx(active.coin, active.id, recipients,
|
try {
|
||||||
settings.anchorOffset);
|
final txPlan = await WarpApi.prepareTx(active.coin, active.id, recipients,
|
||||||
Navigator.pushReplacementNamed(context, '/txplan', arguments: txPlan);
|
settings.anchorOffset);
|
||||||
|
Navigator.pushReplacementNamed(context, '/txplan', arguments: txPlan);
|
||||||
|
}
|
||||||
|
on String catch (message) {
|
||||||
|
showSnackBar(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class Suggestion {
|
abstract class Suggestion {
|
||||||
|
|
|
@ -255,16 +255,6 @@ class SettingsState extends State<SettingsPage>
|
||||||
settings.setTxView(_txView);
|
settings.setTxView(_txView);
|
||||||
})),
|
})),
|
||||||
]),
|
]),
|
||||||
// if (!simpleMode) FormBuilderCheckbox(
|
|
||||||
// name: 'note_table',
|
|
||||||
// title: Text(s.showNotesAsTable),
|
|
||||||
// initialValue: settings.noteTable,
|
|
||||||
// onSaved: _onNoteTable),
|
|
||||||
// if (!simpleMode) FormBuilderCheckbox(
|
|
||||||
// name: 'tx_table',
|
|
||||||
// title: Text(s.showTransactionsAsTable),
|
|
||||||
// initialValue: settings.txTable,
|
|
||||||
// onSaved: _onTxTable),
|
|
||||||
if (!simpleMode)
|
if (!simpleMode)
|
||||||
TextFormField(
|
TextFormField(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
|
|
Loading…
Reference in New Issue