ens working

This commit is contained in:
fosse 2023-09-21 10:16:27 -04:00
parent d8d2335a5f
commit a52c7b053e
33 changed files with 133 additions and 63 deletions

View file

@ -211,9 +211,9 @@ I/flutter ( 4474): Gas Used: 53000
}
}
Future<String?> checkEnsName(String ensName) async {
Future<String> checkEnsName(String ensName) async {
if (_client == null) {
return null;
return "";
}
try {
final ens = Ens(client: _client!);
@ -222,7 +222,7 @@ I/flutter ( 4474): Gas Used: 53000
return addr.hex;
} catch (e) {
print(e);
return null;
return "";
}
}

View file

@ -508,4 +508,8 @@ abstract class EthereumWalletBase
@override
String signMessage(String message, {String? address = null}) =>
bytesToHex(_ethPrivateKey.signPersonalMessageToUint8List(ascii.encode(message)));
Future<String> fetchEnsAddress(String name) async {
return await _client.checkEnsName(name);
}
}

View file

@ -1,13 +1,17 @@
import 'package:cake_wallet/core/address_validator.dart';
import 'package:cake_wallet/core/yat_service.dart';
import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/entities/openalias_record.dart';
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/ethereum/ethereum.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/twitter/twitter_api.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/entities/fio_address_provider.dart';
import 'package:cw_ethereum/ethereum_wallet.dart';
class AddressResolver {
AddressResolver({required this.yatService, required this.walletType});
@ -104,6 +108,15 @@ class AddressResolver {
return ParsedAddress.fetchOpenAliasAddress(record: record, name: text);
}
}
if (text.contains(".")) {
var wallet = getIt.get<AppStore>().wallet!;
if (wallet.type == WalletType.ethereum) {
final address = await ethereum!.fetchEnsAddress(wallet, text);
if (address.isNotEmpty) {
return ParsedAddress.fetchEnsAddress(name: text, address: address);
}
}
}
} catch (e) {
print(e.toString());
}

View file

@ -1,7 +1,7 @@
import 'package:cake_wallet/entities/openalias_record.dart';
import 'package:cake_wallet/entities/yat_record.dart';
enum ParseFrom { unstoppableDomains, openAlias, yatRecord, fio, notParsed, twitter, contact }
enum ParseFrom { unstoppableDomains, openAlias, yatRecord, fio, notParsed, twitter, ens, contact }
class ParsedAddress {
ParsedAddress({
@ -77,8 +77,17 @@ class ParsedAddress {
);
}
factory ParsedAddress.fetchEnsAddress({required String address, required String name}) {
return ParsedAddress(
addresses: [address],
name: name,
parseFrom: ParseFrom.ens,
);
}
final List<String> addresses;
final String name;
final String description;
final ParseFrom parseFrom;
}

View file

@ -131,4 +131,9 @@ class CWEthereum extends Ethereum {
void updateEtherscanUsageState(WalletBase wallet, bool isEnabled) {
(wallet as EthereumWallet).updateEtherscanUsageState(isEnabled);
}
@override
Future<String> fetchEnsAddress(WalletBase wallet, String name) async {
return (wallet as EthereumWallet).fetchEnsAddress(name);
}
}

View file

@ -18,6 +18,11 @@ Future<String> extractAddressFromParsed(
content = S.of(context).address_from_domain(parsedAddress.name);
address = parsedAddress.addresses.first;
break;
case ParseFrom.ens:
title = S.of(context).address_detected;
content = S.of(context).address_from_ens(parsedAddress.name);
address = parsedAddress.addresses.first;
break;
case ParseFrom.openAlias:
title = S.of(context).address_detected;
content = S.of(context).extracted_address_content('${parsedAddress.name} (OpenAlias)');

View file

@ -688,5 +688,6 @@
"onramper_option_description": "شراء بسرعة التشفير مع العديد من طرق الدفع. متوفر في معظم البلدان. ينتشر وتختلف الرسوم.",
"default_buy_provider": "مزود شراء الافتراضي",
"ask_each_time": "اسأل في كل مرة",
"buy_provider_unavailable": "مزود حاليا غير متوفر."
"buy_provider_unavailable": "مزود حاليا غير متوفر.",
"address_from_ens": "هذا ${domain} العنوان من ON ENS"
}

View file

@ -684,5 +684,6 @@
"onramper_option_description": "Бързо купувайте криптовалута с много методи за плащане. Предлага се в повечето страни. Разпространенията и таксите варират.",
"default_buy_provider": "Доставчик по подразбиране купува",
"ask_each_time": "Питайте всеки път",
"buy_provider_unavailable": "Понастоящем доставчик не е наличен."
"buy_provider_unavailable": "Понастоящем доставчик не е наличен.",
"address_from_ens": "Този адрес ${domain} е от on ens"
}

View file

@ -684,5 +684,6 @@
"onramper_option_description": "Rychle si koupte krypto s mnoha metodami plateb. K dispozici ve většině zemí. Rozpětí a poplatky se liší.",
"default_buy_provider": "Výchozí poskytovatel nákupu",
"ask_each_time": "Zeptejte se pokaždé",
"buy_provider_unavailable": "Poskytovatel aktuálně nedostupný."
"buy_provider_unavailable": "Poskytovatel aktuálně nedostupný.",
"address_from_ens": "Tato adresa je z ${domain} On On ENS"
}

View file

@ -692,5 +692,6 @@
"onramper_option_description": "Kaufen Sie schnell Krypto mit vielen Zahlungsmethoden. In den meisten Ländern erhältlich. Spreads und Gebühren variieren.",
"default_buy_provider": "Standard-Kaufanbieter",
"ask_each_time": "Jedes Mal fragen",
"buy_provider_unavailable": "Anbieter derzeit nicht verfügbar."
"buy_provider_unavailable": "Anbieter derzeit nicht verfügbar.",
"address_from_ens": "Diese Adresse ${domain} stammt von one"
}

View file

@ -693,5 +693,6 @@
"default_buy_provider": "Default Buy Provider",
"ask_each_time": "Ask each time",
"robinhood_option_description": "Buy and transfer instantly using your debit card, bank account, or Robinhood balance. USA only.",
"buy_provider_unavailable": "Provider currently unavailable."
"buy_provider_unavailable": "Provider currently unavailable.",
"address_from_ens": "This address is from ${domain} on ENS"
}

View file

@ -692,5 +692,6 @@
"onramper_option_description": "Compre rápidamente cripto con muchos métodos de pago. Disponible en la mayoría de los países. Los diferenciales y las tarifas varían.",
"default_buy_provider": "Proveedor de compra predeterminado",
"ask_each_time": "Pregunta cada vez",
"buy_provider_unavailable": "Proveedor actualmente no disponible."
"buy_provider_unavailable": "Proveedor actualmente no disponible.",
"address_from_ens": "Esta dirección ${domain} es de en ENS"
}

View file

@ -692,5 +692,6 @@
"onramper_option_description": "Achetez rapidement la crypto avec de nombreux méthodes de paiement. Disponible dans la plupart des pays. Les écarts et les frais varient.",
"default_buy_provider": "Fournisseur d'achat par défaut",
"ask_each_time": "Demandez à chaque fois",
"buy_provider_unavailable": "Fournisseur actuellement indisponible."
"buy_provider_unavailable": "Fournisseur actuellement indisponible.",
"address_from_ens": "Cette adresse ${domain} est d'où"
}

View file

@ -670,5 +670,6 @@
"onramper_option_description": "Da sauri sayi Crypto tare da hanyoyin biyan kuɗi da yawa. Akwai a yawancin ƙasashe. Yaduwa da kudade sun bambanta.",
"default_buy_provider": "Tsohuwar Siyarwa",
"ask_each_time": "Tambaya kowane lokaci",
"buy_provider_unavailable": "Mai ba da kyauta a halin yanzu babu."
"buy_provider_unavailable": "Mai ba da kyauta a halin yanzu babu.",
"address_from_ens": "Wannan adireshin ${domain} yana fitowa ne"
}

View file

@ -692,5 +692,6 @@
"onramper_option_description": "जल्दी से कई भुगतान विधियों के साथ क्रिप्टो खरीदें। अधिकांश देशों में उपलब्ध है। फैलता है और फीस अलग -अलग होती है।",
"default_buy_provider": "डिफ़ॉल्ट खरीद प्रदाता",
"ask_each_time": "हर बार पूछें",
"buy_provider_unavailable": "वर्तमान में प्रदाता अनुपलब्ध है।"
"buy_provider_unavailable": "वर्तमान में प्रदाता अनुपलब्ध है।",
"address_from_ens": "यह पता ${domain} ENS से ​​है"
}

View file

@ -692,5 +692,6 @@
"onramper_option_description": "Brzo kupite kriptovalute s mnogim načinima plaćanja. Dostupno u većini zemalja. Širenja i naknade variraju.",
"default_buy_provider": "Zadani davatelj kupnje",
"ask_each_time": "Pitajte svaki put",
"buy_provider_unavailable": "Davatelj trenutno nije dostupan."
"buy_provider_unavailable": "Davatelj trenutno nije dostupan.",
"address_from_ens": "Ova adresa je ${domain} iz ENS -a"
}

View file

@ -680,5 +680,6 @@
"onramper_option_description": "Beli crypto dengan cepat dengan banyak metode pembayaran. Tersedia di sebagian besar negara. Spread dan biaya bervariasi.",
"default_buy_provider": "Penyedia beli default",
"ask_each_time": "Tanyakan setiap kali",
"buy_provider_unavailable": "Penyedia saat ini tidak tersedia."
"buy_provider_unavailable": "Penyedia saat ini tidak tersedia.",
"address_from_ens": "Alamat ini ${domain} berasal dari ENS"
}

View file

@ -692,5 +692,6 @@
"onramper_option_description": "Acquista rapidamente la criptovaluta con molti metodi di pagamento. Disponibile nella maggior parte dei paesi. Gli spread e le commissioni variano.",
"default_buy_provider": "Provider di acquisto predefinito",
"ask_each_time": "Chiedi ogni volta",
"buy_provider_unavailable": "Provider attualmente non disponibile."
"buy_provider_unavailable": "Provider attualmente non disponibile.",
"address_from_ens": "Questo indirizzo ${domain} è da On ENS"
}

View file

@ -692,5 +692,6 @@
"onramper_option_description": "多くの支払い方法で暗号をすばやく購入してください。ほとんどの国で利用可能です。スプレッドと料金は異なります。",
"default_buy_provider": "デフォルトの購入プロバイダー",
"ask_each_time": "毎回尋ねてください",
"buy_provider_unavailable": "現在、プロバイダーは利用できません。"
"buy_provider_unavailable": "現在、プロバイダーは利用できません。",
"address_from_ens": "このアドレスは ${domain} onsからです"
}

View file

@ -692,5 +692,6 @@
"onramper_option_description": "많은 결제 방법으로 암호화를 신속하게 구입하십시오. 대부분의 국가에서 사용할 수 있습니다. 스프레드와 수수료는 다양합니다.",
"default_buy_provider": "기본 구매 제공자",
"ask_each_time": "매번 물어보십시오",
"buy_provider_unavailable": "제공자는 현재 사용할 수 없습니다."
"buy_provider_unavailable": "제공자는 현재 사용할 수 없습니다.",
"address_from_ens": "이 주소는 ${domain} ON ENS에서 나온 것입니다"
}

View file

@ -690,5 +690,6 @@
"onramper_option_description": "ငွေပေးချေမှုနည်းလမ်းများစွာဖြင့် Crypto ကိုလျင်မြန်စွာ 0 ယ်ပါ။ နိုင်ငံအများစုတွင်ရရှိနိုင်ပါသည်။ ဖြန့်ဖြူးနှင့်အခကြေးငွေကွဲပြားခြားနားသည်။",
"default_buy_provider": "Default Provider ကိုဝယ်ပါ",
"ask_each_time": "တစ်ခုချင်းစီကိုအချိန်မေးပါ",
"buy_provider_unavailable": "လက်ရှိတွင်လက်ရှိမရနိုင်ပါ။"
"buy_provider_unavailable": "လက်ရှိတွင်လက်ရှိမရနိုင်ပါ။",
"address_from_ens": "ဒီလိပ်စာ ${domain} ens ကနေဖြစ်ပါတယ်"
}

View file

@ -692,5 +692,6 @@
"onramper_option_description": "Koop snel crypto met veel betaalmethoden. Beschikbaar in de meeste landen. Spreads en vergoedingen variëren.",
"default_buy_provider": "Standaard Koopprovider",
"ask_each_time": "Vraag het elke keer",
"buy_provider_unavailable": "Provider momenteel niet beschikbaar."
"buy_provider_unavailable": "Provider momenteel niet beschikbaar.",
"address_from_ens": "Dit adres ${domain} is van ON ENS"
}

View file

@ -692,5 +692,6 @@
"onramper_option_description": "Szybko kup kryptowaluty z wieloma metodami płatności. Dostępne w większości krajów. Spready i opłaty różnią się.",
"default_buy_provider": "Domyślny dostawca zakupu",
"ask_each_time": "Zapytaj za każdym razem",
"buy_provider_unavailable": "Dostawca obecnie niedostępny."
"buy_provider_unavailable": "Dostawca obecnie niedostępny.",
"address_from_ens": "Ten adres ${domain} pochodzi z end"
}

View file

@ -691,5 +691,6 @@
"onramper_option_description": "Compre rapidamente criptografia com muitos métodos de pagamento. Disponível na maioria dos países. Os spreads e taxas variam.",
"default_buy_provider": "Provedor de compra padrão",
"ask_each_time": "Pergunte cada vez",
"buy_provider_unavailable": "Provedor atualmente indisponível."
"buy_provider_unavailable": "Provedor atualmente indisponível.",
"address_from_ens": "Este endereço ${domain} é de ON ENS"
}

View file

@ -692,5 +692,6 @@
"onramper_option_description": "Быстро купите крипто со многими способами оплаты. Доступно в большинстве стран. Спреды и сборы различаются.",
"default_buy_provider": "По умолчанию поставщик покупки",
"ask_each_time": "Спросите каждый раз",
"buy_provider_unavailable": "Поставщик в настоящее время недоступен."
"buy_provider_unavailable": "Поставщик в настоящее время недоступен.",
"address_from_ens": "Этот адрес ${domain} с On ons"
}

View file

@ -690,5 +690,6 @@
"onramper_option_description": "ซื้อ crypto อย่างรวดเร็วด้วยวิธีการชำระเงินจำนวนมาก มีให้บริการในประเทศส่วนใหญ่ สเปรดและค่าธรรมเนียมแตกต่างกันไป",
"default_buy_provider": "ผู้ให้บริการซื้อเริ่มต้น",
"ask_each_time": "ถามทุกครั้ง",
"buy_provider_unavailable": "ผู้ให้บริการไม่สามารถใช้งานได้ในปัจจุบัน"
"buy_provider_unavailable": "ผู้ให้บริการไม่สามารถใช้งานได้ในปัจจุบัน",
"address_from_ens": "ที่อยู่นี้มาจาก ${domain} ENS"
}

View file

@ -690,5 +690,6 @@
"onramper_option_description": "Birçok ödeme yöntemi ile hızlı bir şekilde kripto satın alın. Çoğu ülkede mevcuttur. Forma ve ücretler değişir.",
"default_buy_provider": "Varsayılan Satın Alma Sağlayıcısı",
"ask_each_time": "Her seferinde sor",
"buy_provider_unavailable": "Sağlayıcı şu anda kullanılamıyor."
"buy_provider_unavailable": "Sağlayıcı şu anda kullanılamıyor.",
"address_from_ens": "Bu adres ${domain} ON ENS'ten"
}

View file

@ -692,5 +692,6 @@
"onramper_option_description": "Швидко купуйте криптовалюту з багатьма методами оплати. Доступний у більшості країн. Поширення та збори різняться.",
"default_buy_provider": "Постачальник покупки за замовчуванням",
"ask_each_time": "Запитайте кожен раз",
"buy_provider_unavailable": "В даний час постачальник недоступний."
"buy_provider_unavailable": "В даний час постачальник недоступний.",
"address_from_ens": "Ця адреса ${domain} з ENS"
}

View file

@ -684,5 +684,6 @@
"onramper_option_description": "ادائیگی کے بہت سے طریقوں سے جلدی سے کرپٹو خریدیں۔ زیادہ تر ممالک میں دستیاب ہے۔ پھیلاؤ اور فیس مختلف ہوتی ہے۔",
"default_buy_provider": "پہلے سے طے شدہ خریدنے والا",
"ask_each_time": "ہر بار پوچھیں",
"buy_provider_unavailable": "فراہم کنندہ فی الحال دستیاب نہیں ہے۔"
"buy_provider_unavailable": "فراہم کنندہ فی الحال دستیاب نہیں ہے۔",
"address_from_ens": "یہ پتہ آن ${domain}پر ہے"
}

View file

@ -686,5 +686,6 @@
"onramper_option_description": "Ni kiakia Ra Crypto pẹlu ọpọlọpọ awọn ọna isanwo. Wa ni ọpọlọpọ awọn orilẹ-ede. Itankale ati awọn idiyele yatọ.",
"default_buy_provider": "Aiyipada Ra Olupese",
"ask_each_time": "Beere lọwọ kọọkan",
"buy_provider_unavailable": "Olupese lọwọlọwọ ko si."
"buy_provider_unavailable": "Olupese lọwọlọwọ ko si.",
"address_from_ens": "Adirẹsi yii ti ${domain} wa ni ens"
}

View file

@ -691,5 +691,6 @@
"onramper_option_description": "快速使用许多付款方式购买加密货币。在大多数国家 /地区可用。利差和费用各不相同。",
"default_buy_provider": "默认购买提供商",
"ask_each_time": "每次问",
"buy_provider_unavailable": "提供者目前不可用。"
"buy_provider_unavailable": "提供者目前不可用。",
"address_from_ens": "此地址${domain}来自ENS"
}

View file

@ -18,8 +18,10 @@ Future<void> main(List<String> args) async {
await generateMonero(hasMonero);
await generateHaven(hasHaven);
await generateEthereum(hasEthereum);
await generatePubspec(hasMonero: hasMonero, hasBitcoin: hasBitcoin, hasHaven: hasHaven, hasEthereum: hasEthereum);
await generateWalletTypes(hasMonero: hasMonero, hasBitcoin: hasBitcoin, hasHaven: hasHaven, hasEthereum: hasEthereum);
await generatePubspec(
hasMonero: hasMonero, hasBitcoin: hasBitcoin, hasHaven: hasHaven, hasEthereum: hasEthereum);
await generateWalletTypes(
hasMonero: hasMonero, hasBitcoin: hasBitcoin, hasHaven: hasHaven, hasEthereum: hasEthereum);
}
Future<void> generateBitcoin(bool hasImplementation) async {
@ -88,12 +90,12 @@ abstract class Bitcoin {
const bitcoinEmptyDefinition = 'Bitcoin? bitcoin;\n';
const bitcoinCWDefinition = 'Bitcoin? bitcoin = CWBitcoin();\n';
final output = '$bitcoinCommonHeaders\n'
+ (hasImplementation ? '$bitcoinCWHeaders\n' : '\n')
+ (hasImplementation ? '$bitcoinCwPart\n\n' : '\n')
+ (hasImplementation ? bitcoinCWDefinition : bitcoinEmptyDefinition)
+ '\n'
+ bitcoinContent;
final output = '$bitcoinCommonHeaders\n' +
(hasImplementation ? '$bitcoinCWHeaders\n' : '\n') +
(hasImplementation ? '$bitcoinCwPart\n\n' : '\n') +
(hasImplementation ? bitcoinCWDefinition : bitcoinEmptyDefinition) +
'\n' +
bitcoinContent;
if (outputFile.existsSync()) {
await outputFile.delete();
@ -268,12 +270,12 @@ abstract class MoneroAccountList {
const moneroEmptyDefinition = 'Monero? monero;\n';
const moneroCWDefinition = 'Monero? monero = CWMonero();\n';
final output = '$moneroCommonHeaders\n'
+ (hasImplementation ? '$moneroCWHeaders\n' : '\n')
+ (hasImplementation ? '$moneroCwPart\n\n' : '\n')
+ (hasImplementation ? moneroCWDefinition : moneroEmptyDefinition)
+ '\n'
+ moneroContent;
final output = '$moneroCommonHeaders\n' +
(hasImplementation ? '$moneroCWHeaders\n' : '\n') +
(hasImplementation ? '$moneroCwPart\n\n' : '\n') +
(hasImplementation ? moneroCWDefinition : moneroEmptyDefinition) +
'\n' +
moneroContent;
if (outputFile.existsSync()) {
await outputFile.delete();
@ -283,7 +285,6 @@ abstract class MoneroAccountList {
}
Future<void> generateHaven(bool hasImplementation) async {
final outputFile = File(havenOutputPath);
const havenCommonHeaders = """
import 'package:mobx/mobx.dart';
@ -448,12 +449,12 @@ abstract class HavenAccountList {
const havenEmptyDefinition = 'Haven? haven;\n';
const havenCWDefinition = 'Haven? haven = CWHaven();\n';
final output = '$havenCommonHeaders\n'
+ (hasImplementation ? '$havenCWHeaders\n' : '\n')
+ (hasImplementation ? '$havenCwPart\n\n' : '\n')
+ (hasImplementation ? havenCWDefinition : havenEmptyDefinition)
+ '\n'
+ havenContent;
final output = '$havenCommonHeaders\n' +
(hasImplementation ? '$havenCWHeaders\n' : '\n') +
(hasImplementation ? '$havenCwPart\n\n' : '\n') +
(hasImplementation ? havenCWDefinition : havenEmptyDefinition) +
'\n' +
havenContent;
if (outputFile.existsSync()) {
await outputFile.delete();
@ -463,7 +464,6 @@ abstract class HavenAccountList {
}
Future<void> generateEthereum(bool hasImplementation) async {
final outputFile = File(ethereumOutputPath);
const ethereumCommonHeaders = """
import 'package:cake_wallet/view_model/send/output.dart';
@ -525,18 +525,19 @@ abstract class Ethereum {
CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction);
void updateEtherscanUsageState(WalletBase wallet, bool isEnabled);
Future<String> fetchEnsAddress(WalletBase wallet, String name);
}
""";
const ethereumEmptyDefinition = 'Ethereum? ethereum;\n';
const ethereumCWDefinition = 'Ethereum? ethereum = CWEthereum();\n';
final output = '$ethereumCommonHeaders\n'
+ (hasImplementation ? '$ethereumCWHeaders\n' : '\n')
+ (hasImplementation ? '$ethereumCwPart\n\n' : '\n')
+ (hasImplementation ? ethereumCWDefinition : ethereumEmptyDefinition)
+ '\n'
+ ethereumContent;
final output = '$ethereumCommonHeaders\n' +
(hasImplementation ? '$ethereumCWHeaders\n' : '\n') +
(hasImplementation ? '$ethereumCwPart\n\n' : '\n') +
(hasImplementation ? ethereumCWDefinition : ethereumEmptyDefinition) +
'\n' +
ethereumContent;
if (outputFile.existsSync()) {
await outputFile.delete();
@ -545,8 +546,12 @@ abstract class Ethereum {
await outputFile.writeAsString(output);
}
Future<void> generatePubspec({required bool hasMonero, required bool hasBitcoin, required bool hasHaven, required bool hasEthereum}) async {
const cwCore = """
Future<void> generatePubspec(
{required bool hasMonero,
required bool hasBitcoin,
required bool hasHaven,
required bool hasEthereum}) async {
const cwCore = """
cw_core:
path: ./cw_core
""";
@ -606,7 +611,11 @@ Future<void> generatePubspec({required bool hasMonero, required bool hasBitcoin,
await outputFile.writeAsString(outputContent);
}
Future<void> generateWalletTypes({required bool hasMonero, required bool hasBitcoin, required bool hasHaven, required bool hasEthereum}) async {
Future<void> generateWalletTypes(
{required bool hasMonero,
required bool hasBitcoin,
required bool hasHaven,
required bool hasEthereum}) async {
final walletTypesFile = File(walletTypesPath);
if (walletTypesFile.existsSync()) {