mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
* v6.0.2 Release candidate * v6.0.2 Release candidate * move btc ln up in the currency picker * disable bsc for swapsxyz * minor [skip ci] * hide dex/rate selection on swap screen * temp fix for evm tokens swaps icons until hive migration is done * minor [skip ci] * disable force dex providers for existing users and let them pick it from settings preference * Show bitcoin address types in swap picker (#3096) * Show bitcoin address types in swap picker * remove wrong conversion to bolt11 [skip ci] * feat: add Lightning invoice resolution and address normalization * automatically select contact wallet address based on the selected swap currency (whether it's bitcoin or lightning) * minor [skip ci] * default to bolt11 invoice for lightning swaps --------- Co-authored-by: Konstantin Ullrich <konstantinullrich12@gmail.com> --------- Co-authored-by: Konstantin Ullrich <konstantinullrich12@gmail.com>
59 lines
1.7 KiB
Dart
59 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 {
|
|
final String callback;
|
|
final int maxSendable;
|
|
final int minSendable;
|
|
final String tag;
|
|
final String metadata;
|
|
|
|
const _LNURLPResponseDTO(
|
|
this.callback, this.maxSendable, this.minSendable, this.tag, this.metadata);
|
|
|
|
static _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);
|
|
}
|
|
|
|
class _LNURLPCallbackResponseDTO {
|
|
final String pr;
|
|
|
|
const _LNURLPCallbackResponseDTO(this.pr);
|
|
|
|
static _LNURLPCallbackResponseDTO fromJson(Map<String, dynamic> map) =>
|
|
_LNURLPCallbackResponseDTO(map["pr"] as String);
|
|
}
|