mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-18 05:51:34 +02:00
* fix: send all for lightning * fix: adjust crypto amount parsing logic for send page outputs * feat: add event handling for deposit transactions in Bitcoin and Lightning wallets - Introduced `onCreateDepositTransactionEvent` and `onUpdateDepositTransactionEvent` callbacks to manage deposit transaction updates. - Updated event listener logic to handle unclaimed and claimed deposit events. - Added support for processing deposit transaction info with `ElectrumTransactionInfo`. * fix: handle network errors on username validation and improve Lightning address setup - Added network error handling for username validation with a fallback error. - Enhanced Lightning address setup logic with error handling and a fail-safe mechanism to disable Lightning usage if the setup fails. * fix: enhance error handling for Lightning and update validation patterns * fix: remove redundant raw string mark from amount validation pattern * fix: normalize crypto amount input by replacing commas with dots
77 lines
2.0 KiB
Dart
77 lines
2.0 KiB
Dart
import 'package:cw_core/crypto_currency.dart';
|
|
import 'package:cw_core/lnurl.dart';
|
|
import 'package:cw_core/utils/print_verbose.dart';
|
|
import 'package:cw_core/utils/proxy_wrapper.dart';
|
|
|
|
class LNUrlPayRecord {
|
|
LNUrlPayRecord({
|
|
required this.address,
|
|
required this.name,
|
|
});
|
|
|
|
final String name;
|
|
final String address;
|
|
|
|
static Future<String?> checkWellKnownUsername(String username, CryptoCurrency currency,
|
|
{bool allowRethrow = false}) async {
|
|
if (![CryptoCurrency.btc, CryptoCurrency.btcln].contains(currency)) return null;
|
|
|
|
// split the string by the @ symbol:
|
|
try {
|
|
final List<String> splitStrs = username.split("@");
|
|
String name = splitStrs.first.toLowerCase();
|
|
final String domain = splitStrs.last;
|
|
|
|
if (splitStrs.length == 3) {
|
|
// for username like @alice@domain.org instead of alice@domain.org
|
|
name = splitStrs[1];
|
|
}
|
|
|
|
if (name.isEmpty) {
|
|
name = "_";
|
|
}
|
|
|
|
final expectedUrl = "https://$domain/.well-known/lnurlp/$name";
|
|
final response = await ProxyWrapper().get(
|
|
clearnetUri: Uri.parse(expectedUrl),
|
|
headers: <String, String>{"Accept": "application/json"},
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
return LNURL.encode(expectedUrl);
|
|
}
|
|
} catch (e) {
|
|
if (allowRethrow) rethrow;
|
|
printV("error checking well-known username: $e");
|
|
}
|
|
return null;
|
|
}
|
|
|
|
static String formatDomainName(String name) {
|
|
String formattedName = name;
|
|
|
|
if (name.contains("@")) {
|
|
formattedName = name.replaceAll("@", ".");
|
|
}
|
|
|
|
return formattedName;
|
|
}
|
|
|
|
static Future<LNUrlPayRecord?> fetchAddressAndName({
|
|
required String formattedName,
|
|
required CryptoCurrency currency,
|
|
}) async {
|
|
final name = formattedName;
|
|
|
|
printV("formattedName: $formattedName");
|
|
|
|
final address = await checkWellKnownUsername(formattedName, currency);
|
|
|
|
if (address == null) {
|
|
return null;
|
|
}
|
|
|
|
return LNUrlPayRecord(address: address, name: name);
|
|
}
|
|
}
|