mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
* feat: add Lightning transaction URL support in transaction details view model * fix: update currency selection logic in WalletAddressListViewModel and ReceivePage * feat: integrate computed transaction amount and fee getters in TransactionDetailsViewModel, refactor CopyWrapper logic in TransactionDetailsModal * refactor: apply lint rules * refactor: apply lint rules and improve LNURL handling with new methods for withdrawal requests and error checks * auto-reformat * fix: receive_page regression * fix: Withdraw lightning to other btc wallet gives LN address * chore: update .lock files [skip ci] --------- Co-authored-by: Robert Malikowski <malikowskirobert@gmail.com> Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
65 lines
1.7 KiB
Dart
65 lines
1.7 KiB
Dart
import "dart:convert";
|
|
|
|
import "package:cw_core/utils/proxy_wrapper.dart";
|
|
|
|
Future<String?> getBolt11FromLightingAddress(String lightningAddress, {int amount = 0}) async {
|
|
try {
|
|
final uri = getURlOfLightningAddress(lightningAddress);
|
|
|
|
var response = await ProxyWrapper().get(clearnetUri: uri);
|
|
final responseBody =
|
|
_LNURLPResponseDTO.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
|
|
|
|
response =
|
|
await ProxyWrapper().get(clearnetUri: Uri.parse("${responseBody.callback}?amount=$amount"));
|
|
|
|
final callbackResponseBody =
|
|
_LNURLPCallbackResponseDTO.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
|
|
|
|
return callbackResponseBody.pr;
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
Uri getURlOfLightningAddress(String lightningAddress) {
|
|
final parts = lightningAddress.split("@");
|
|
|
|
final name = parts.first;
|
|
final domain = parts.last;
|
|
return Uri.parse("https://$domain/.well-known/lnurlp/$name");
|
|
}
|
|
|
|
class _LNURLPResponseDTO {
|
|
const _LNURLPResponseDTO(
|
|
this.callback,
|
|
this.maxSendable,
|
|
this.minSendable,
|
|
this.tag,
|
|
this.metadata,
|
|
);
|
|
|
|
factory _LNURLPResponseDTO.fromJson(Map<String, dynamic> map) => _LNURLPResponseDTO(
|
|
map["callback"] as String,
|
|
map["maxSendable"] as int,
|
|
map["minSendable"] as int,
|
|
map["tag"] as String,
|
|
map["metadata"] as String,
|
|
);
|
|
|
|
final String callback;
|
|
final int maxSendable;
|
|
final int minSendable;
|
|
final String tag;
|
|
final String metadata;
|
|
}
|
|
|
|
class _LNURLPCallbackResponseDTO {
|
|
const _LNURLPCallbackResponseDTO(this.pr);
|
|
|
|
factory _LNURLPCallbackResponseDTO.fromJson(Map<String, dynamic> map) =>
|
|
_LNURLPCallbackResponseDTO(map["pr"] as String);
|
|
|
|
final String pr;
|
|
}
|