Cw 428 send to nostr addresses (#1271)

* add nostr address resolver

* Add Nostr localization

---------

Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
Serhii 2024-01-27 04:34:38 +02:00 committed by GitHub
parent 89fdc0f4d1
commit fc352a6da3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 370 additions and 33 deletions

View file

@ -6,12 +6,14 @@ import 'package:cake_wallet/entities/parsed_address.dart';
import 'package:cake_wallet/entities/unstoppable_domain_address.dart';
import 'package:cake_wallet/entities/emoji_string_extension.dart';
import 'package:cake_wallet/mastodon/mastodon_api.dart';
import 'package:cake_wallet/nostr/nostr_api.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/twitter/twitter_api.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/entities/fio_address_provider.dart';
import 'package:flutter/cupertino.dart';
class AddressResolver {
AddressResolver({required this.yatService, required this.wallet, required this.settingsStore})
@ -58,7 +60,16 @@ class AddressResolver {
});
}
Future<ParsedAddress> resolve(String text, String ticker) async {
bool isEmailFormat(String address) {
final RegExp emailRegex = RegExp(
r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$',
caseSensitive: false,
);
return emailRegex.hasMatch(address);
}
Future<ParsedAddress> resolve(BuildContext context, String text, String ticker) async {
try {
if (text.startsWith('@') && !text.substring(1).contains('@')) {
if(settingsStore.lookupsTwitter) {
@ -165,6 +176,21 @@ class AddressResolver {
}
}
}
if (isEmailFormat(text)) {
final nostrProfile = await NostrProfileHandler.queryProfile(context, text);
if (nostrProfile?.relays != null) {
final nostrUserData =
await NostrProfileHandler.processRelays(context, nostrProfile!, text);
if (nostrUserData != null) {
String? addressFromBio = extractAddressByType(
raw: nostrUserData.about, type: CryptoCurrency.fromString(ticker));
if (addressFromBio != null) {
return ParsedAddress.nostrAddress(address: addressFromBio, name: text);
}
}
}
}
} catch (e) {
print(e.toString());
}