mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-04-15 02:31:57 +00:00
feat: use _applyUri for paste
This commit is contained in:
parent
15a7a34ece
commit
3fbc6daba0
2 changed files with 118 additions and 122 deletions
lib
pages/send_view
pages_desktop_specific/my_stack_view/wallet_view/sub_widgets
|
@ -135,6 +135,44 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
|
||||
Set<UTXO> selectedUTXOs = {};
|
||||
|
||||
void _applyUri(PaymentUriData paymentData) {
|
||||
try {
|
||||
// auto fill address
|
||||
_address = paymentData.address.trim();
|
||||
sendToController.text = _address!;
|
||||
|
||||
// autofill notes field
|
||||
if (paymentData.message != null) {
|
||||
noteController.text = paymentData.message!;
|
||||
} else if (paymentData.label != null) {
|
||||
noteController.text = paymentData.label!;
|
||||
}
|
||||
|
||||
// autofill amount field
|
||||
if (paymentData.amount != null) {
|
||||
final Amount amount = Decimal.parse(paymentData.amount!).toAmount(
|
||||
fractionDigits: coin.fractionDigits,
|
||||
);
|
||||
cryptoAmountController.text = ref.read(pAmountFormatter(coin)).format(
|
||||
amount,
|
||||
withUnitName: false,
|
||||
);
|
||||
ref.read(pSendAmount.notifier).state = amount;
|
||||
}
|
||||
|
||||
_setValidAddressProviders(_address);
|
||||
setState(() {
|
||||
_addressToggleFlag = sendToController.text.isNotEmpty;
|
||||
});
|
||||
} catch (e, s) {
|
||||
Logging.instance.e(
|
||||
"Failed to apply uri in SendView: ",
|
||||
error: e,
|
||||
stackTrace: s,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _scanQr() async {
|
||||
try {
|
||||
// ref
|
||||
|
@ -167,35 +205,7 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
|
||||
if (paymentData != null &&
|
||||
paymentData.coin?.uriScheme == coin.uriScheme) {
|
||||
// auto fill address
|
||||
_address = paymentData.address.trim();
|
||||
sendToController.text = _address!;
|
||||
|
||||
// autofill notes field
|
||||
if (paymentData.message != null) {
|
||||
noteController.text = paymentData.message!;
|
||||
} else if (paymentData.label != null) {
|
||||
noteController.text = paymentData.label!;
|
||||
}
|
||||
|
||||
// autofill amount field
|
||||
if (paymentData.amount != null) {
|
||||
final Amount amount = Decimal.parse(paymentData.amount!).toAmount(
|
||||
fractionDigits: coin.fractionDigits,
|
||||
);
|
||||
cryptoAmountController.text = ref.read(pAmountFormatter(coin)).format(
|
||||
amount,
|
||||
withUnitName: false,
|
||||
);
|
||||
ref.read(pSendAmount.notifier).state = amount;
|
||||
}
|
||||
|
||||
_setValidAddressProviders(_address);
|
||||
setState(() {
|
||||
_addressToggleFlag = sendToController.text.isNotEmpty;
|
||||
});
|
||||
|
||||
// now check for non standard encoded basic address
|
||||
_applyUri(paymentData);
|
||||
} else {
|
||||
_address = qrResult.rawContent.split("\n").first.trim();
|
||||
sendToController.text = _address ?? "";
|
||||
|
@ -1353,27 +1363,24 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
final trimmed = newValue.trim();
|
||||
|
||||
if ((trimmed.length - (_address?.length ?? 0)).abs() > 1) {
|
||||
if (coin is Monero && Uri.parse(trimmed).scheme == "monero") {
|
||||
final parsedUri = Uri.parse(trimmed);
|
||||
final addr = parsedUri.path;
|
||||
sendToController.text = addr;
|
||||
_address = addr;
|
||||
cryptoAmountController.text = parsedUri.queryParameters["tx_amount"] ?? "";
|
||||
} else if (coin is Bitcoin && Uri.parse(trimmed).scheme == "bitcoin") {
|
||||
final parsedUri = Uri.parse(trimmed);
|
||||
final addr = parsedUri.path;
|
||||
sendToController.text = addr;
|
||||
_address = addr;
|
||||
cryptoAmountController.text = parsedUri.queryParameters["amount"] ?? "";
|
||||
final parsed = AddressUtils.parsePaymentUri(
|
||||
trimmed,
|
||||
logging: Logging.instance,
|
||||
);
|
||||
if (parsed != null) {
|
||||
_applyUri(parsed);
|
||||
} else {
|
||||
_address = newValue;
|
||||
sendToController.text = newValue;
|
||||
}
|
||||
} else {
|
||||
_address = trimmed;
|
||||
_address = newValue;
|
||||
}
|
||||
|
||||
_setValidAddressProviders(_address);
|
||||
|
||||
setState(() {
|
||||
_addressToggleFlag = trimmed.isNotEmpty;
|
||||
_addressToggleFlag = newValue.isNotEmpty;
|
||||
});
|
||||
},
|
||||
focusNode: _addressFocusNode,
|
||||
|
@ -1454,32 +1461,26 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
}
|
||||
|
||||
final trimmed = content.trim();
|
||||
|
||||
if (coin is Monero && Uri.parse(trimmed).scheme == "monero") {
|
||||
final parsedUri = Uri.parse(trimmed);
|
||||
final addr = parsedUri.path;
|
||||
sendToController.text = addr;
|
||||
_address = addr;
|
||||
cryptoAmountController.text = parsedUri.queryParameters["tx_amount"] ?? "";
|
||||
} else if (coin is Bitcoin && Uri.parse(trimmed).scheme == "bitcoin") {
|
||||
final parsedUri = Uri.parse(trimmed);
|
||||
final addr = parsedUri.path;
|
||||
sendToController.text = addr;
|
||||
_address = addr;
|
||||
cryptoAmountController.text = parsedUri.queryParameters["amount"] ?? "";
|
||||
final parsed = AddressUtils.parsePaymentUri(
|
||||
trimmed,
|
||||
logging: Logging.instance,
|
||||
);
|
||||
if (parsed != null) {
|
||||
_applyUri(parsed);
|
||||
} else {
|
||||
sendToController.text = trimmed;
|
||||
_address = trimmed;
|
||||
sendToController.text =
|
||||
content;
|
||||
_address = content;
|
||||
|
||||
_setValidAddressProviders(_address,);
|
||||
|
||||
setState(() {
|
||||
_addressToggleFlag =
|
||||
sendToController
|
||||
.text
|
||||
.isNotEmpty;
|
||||
});
|
||||
}
|
||||
|
||||
_setValidAddressProviders(_address,);
|
||||
|
||||
setState(() {
|
||||
_addressToggleFlag =
|
||||
sendToController
|
||||
.text
|
||||
.isNotEmpty;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: sendToController
|
||||
|
|
|
@ -660,33 +660,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
|
|||
|
||||
if (paymentData != null &&
|
||||
paymentData.coin?.uriScheme == coin.uriScheme) {
|
||||
// Auto fill address.
|
||||
_address = paymentData.address.trim();
|
||||
sendToController.text = _address!;
|
||||
|
||||
// Amount.
|
||||
if (paymentData.amount != null) {
|
||||
final Amount amount = Decimal.parse(paymentData.amount!).toAmount(
|
||||
fractionDigits: coin.fractionDigits,
|
||||
);
|
||||
cryptoAmountController.text = ref.read(pAmountFormatter(coin)).format(
|
||||
amount,
|
||||
withUnitName: false,
|
||||
);
|
||||
ref.read(pSendAmount.notifier).state = amount;
|
||||
}
|
||||
|
||||
// Note/message.
|
||||
if (paymentData.message != null) {
|
||||
_note = paymentData.message;
|
||||
} else if (paymentData.label != null) {
|
||||
_note = paymentData.label;
|
||||
}
|
||||
|
||||
_setValidAddressProviders(_address);
|
||||
setState(() {
|
||||
_addressToggleFlag = sendToController.text.isNotEmpty;
|
||||
});
|
||||
_applyUri(paymentData);
|
||||
} else {
|
||||
_address = qrCodeData.split("\n").first.trim();
|
||||
sendToController.text = _address ?? "";
|
||||
|
@ -736,6 +710,40 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
|
|||
}
|
||||
}
|
||||
|
||||
void _applyUri(PaymentUriData paymentData) {
|
||||
try {
|
||||
// auto fill address
|
||||
_address = paymentData.address;
|
||||
sendToController.text = _address!;
|
||||
|
||||
// autofill notes field.
|
||||
if (paymentData.message != null) {
|
||||
_note = paymentData.message;
|
||||
} else if (paymentData.label != null) {
|
||||
_note = paymentData.label;
|
||||
}
|
||||
|
||||
// autofill amount field
|
||||
if (paymentData.amount != null) {
|
||||
final amount = Decimal.parse(paymentData.amount!).toAmount(
|
||||
fractionDigits: coin.fractionDigits,
|
||||
);
|
||||
cryptoAmountController.text = ref
|
||||
.read(pAmountFormatter(coin))
|
||||
.format(amount, withUnitName: false);
|
||||
ref.read(pSendAmount.notifier).state = amount;
|
||||
}
|
||||
|
||||
// Trigger validation after pasting.
|
||||
_setValidAddressProviders(_address);
|
||||
setState(() {
|
||||
_addressToggleFlag = sendToController.text.isNotEmpty;
|
||||
});
|
||||
} catch (e, s) {
|
||||
Logging.instance.e("Error applying URI", error: e, stackTrace: s);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> pasteAddress() async {
|
||||
final ClipboardData? data = await clipboard.getData(Clipboard.kTextPlain);
|
||||
if (data?.text != null && data!.text!.isNotEmpty) {
|
||||
|
@ -751,33 +759,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
|
|||
);
|
||||
if (paymentData != null &&
|
||||
paymentData.coin?.uriScheme == coin.uriScheme) {
|
||||
// auto fill address
|
||||
_address = paymentData.address;
|
||||
sendToController.text = _address!;
|
||||
|
||||
// autofill notes field.
|
||||
if (paymentData.message != null) {
|
||||
_note = paymentData.message;
|
||||
} else if (paymentData.label != null) {
|
||||
_note = paymentData.label;
|
||||
}
|
||||
|
||||
// autofill amoutn field
|
||||
if (paymentData.amount != null) {
|
||||
final amount = Decimal.parse(paymentData.amount!).toAmount(
|
||||
fractionDigits: coin.fractionDigits,
|
||||
);
|
||||
cryptoAmountController.text = ref
|
||||
.read(pAmountFormatter(coin))
|
||||
.format(amount, withUnitName: false);
|
||||
ref.read(pSendAmount.notifier).state = amount;
|
||||
}
|
||||
|
||||
// Trigger validation after pasting.
|
||||
_setValidAddressProviders(_address);
|
||||
setState(() {
|
||||
_addressToggleFlag = sendToController.text.isNotEmpty;
|
||||
});
|
||||
_applyUri(paymentData);
|
||||
} else {
|
||||
content = content.split("\n").first.trim();
|
||||
if (coin is Epiccash) {
|
||||
|
@ -1439,7 +1421,20 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
|
|||
selectAll: false,
|
||||
),
|
||||
onChanged: (newValue) {
|
||||
_address = newValue;
|
||||
final trimmed = newValue;
|
||||
|
||||
if ((trimmed.length - (_address?.length ?? 0)).abs() > 1) {
|
||||
final parsed = AddressUtils.parsePaymentUri(trimmed, logging: Logging.instance);
|
||||
if (parsed != null) {
|
||||
_applyUri(parsed);
|
||||
} else {
|
||||
_address = newValue;
|
||||
sendToController.text = newValue;
|
||||
}
|
||||
} else {
|
||||
_address = newValue;
|
||||
}
|
||||
|
||||
_setValidAddressProviders(_address);
|
||||
|
||||
setState(() {
|
||||
|
|
Loading…
Reference in a new issue