Payment URI
This commit is contained in:
parent
0f2dc36fd7
commit
d7484f0f5b
|
@ -231,7 +231,7 @@ class QRAddressState extends State<QRAddressWidget> {
|
|||
}
|
||||
|
||||
_onReceive() async {
|
||||
Navigator.of(context).pushNamed('/receive', arguments: _address());
|
||||
Navigator.of(context).pushNamed('/receive');
|
||||
}
|
||||
|
||||
_onSnapAddress() {
|
||||
|
|
|
@ -328,6 +328,10 @@ abstract class _ActiveAccount with Store {
|
|||
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
|
||||
List<Note> get sortedNotes {
|
||||
final _1 = syncStatus.syncedHeight;
|
||||
|
|
|
@ -243,7 +243,7 @@ void main() {
|
|||
'/send': (context) =>
|
||||
SendPage(routeSettings.arguments as SendPageArgs?),
|
||||
'/receive': (context) =>
|
||||
PaymentURIPage(routeSettings.arguments as String?),
|
||||
PaymentURIPage(),
|
||||
'/accounts': (context) => AccountManagerPage(),
|
||||
'/settings': (context) => SettingsPage(),
|
||||
'/tx': (context) =>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import 'package:decimal/decimal.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 'dualmoneyinput.dart';
|
||||
import 'package:warp_api/warp_api.dart';
|
||||
|
@ -9,10 +11,6 @@ import 'generated/l10n.dart';
|
|||
import 'settings.dart';
|
||||
|
||||
class PaymentURIPage extends StatefulWidget {
|
||||
final String address;
|
||||
|
||||
PaymentURIPage(String? _address): address = _address ?? active.address;
|
||||
|
||||
@override
|
||||
PaymentURIState createState() => PaymentURIState();
|
||||
}
|
||||
|
@ -20,13 +18,21 @@ class PaymentURIPage extends StatefulWidget {
|
|||
class PaymentURIState extends State<PaymentURIPage> {
|
||||
var _memoController = TextEditingController(text: '');
|
||||
var qrText = "";
|
||||
var address = "";
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final amountKey = GlobalKey<DualMoneyInputState>();
|
||||
final hasUA = active.coinDef.supportsUA;
|
||||
var uaType = settings.uaType;
|
||||
List<String> uaList = [];
|
||||
|
||||
@override
|
||||
void 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(() {
|
||||
priceStore.fetchCoinPrice(active.coin);
|
||||
});
|
||||
|
@ -53,6 +59,22 @@ class PaymentURIState extends State<PaymentURIPage> {
|
|||
size: qrSize,
|
||||
backgroundColor: Colors.white)),
|
||||
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),
|
||||
TextFormField(
|
||||
decoration:
|
||||
|
@ -78,26 +100,49 @@ class PaymentURIState extends State<PaymentURIPage> {
|
|||
]))))));
|
||||
}
|
||||
|
||||
void _updateQR() {
|
||||
String _getQR() {
|
||||
final amount = amountKey.currentState!.amount;
|
||||
final memo = _memoController.text;
|
||||
|
||||
final String _qrText;
|
||||
if (amount > 0) {
|
||||
_qrText = WarpApi.makePaymentURI(widget.address, amount, memo);
|
||||
} else
|
||||
_qrText = widget.address;
|
||||
return WarpApi.makePaymentURI(address, amount, memo);
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
_onAddressCopy() {
|
||||
Clipboard.setData(ClipboardData(text: qrText));
|
||||
showSnackBar(S.of(context).addressCopiedToClipboard);
|
||||
}
|
||||
|
||||
void _onUAType(List<String>? types) {
|
||||
if (types == null) { return; }
|
||||
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() {
|
||||
_memoController.clear();
|
||||
amountKey.currentState?.clear();
|
||||
setState(() {
|
||||
qrText = widget.address;
|
||||
qrText = address;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -105,7 +150,9 @@ class PaymentURIState extends State<PaymentURIPage> {
|
|||
final form = _formKey.currentState!;
|
||||
if (form.validate()) {
|
||||
form.save();
|
||||
_updateQR();
|
||||
setState(() {
|
||||
qrText = _getQR();
|
||||
});
|
||||
FocusScope.of(context).unfocus();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -449,9 +449,14 @@ Future<void> send(BuildContext context, List<Recipient> recipients) async {
|
|||
|
||||
if (recipients.length == 1)
|
||||
active.setDraftRecipient(recipients[0]);
|
||||
final txPlan = await WarpApi.prepareTx(active.coin, active.id, recipients,
|
||||
settings.anchorOffset);
|
||||
Navigator.pushReplacementNamed(context, '/txplan', arguments: txPlan);
|
||||
try {
|
||||
final txPlan = await WarpApi.prepareTx(active.coin, active.id, recipients,
|
||||
settings.anchorOffset);
|
||||
Navigator.pushReplacementNamed(context, '/txplan', arguments: txPlan);
|
||||
}
|
||||
on String catch (message) {
|
||||
showSnackBar(message);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Suggestion {
|
||||
|
|
|
@ -255,16 +255,6 @@ class SettingsState extends State<SettingsPage>
|
|||
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)
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
|
|
Loading…
Reference in New Issue