mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-16 17:27:37 +00:00
ens review fixes
This commit is contained in:
parent
b5852509f3
commit
8b2b3bda16
8 changed files with 52 additions and 20 deletions
|
@ -226,6 +226,10 @@ I/flutter ( 4474): Gas Used: 53000
|
|||
}
|
||||
}
|
||||
|
||||
dynamic getWeb3Client() {
|
||||
return _client;
|
||||
}
|
||||
|
||||
// Future<int> _getDecimalPlacesForContract(DeployedContract contract) async {
|
||||
// final String abi = await rootBundle.loadString("assets/abi_json/erc20_abi.json");
|
||||
// final contractAbi = ContractAbi.fromJson(abi, "ERC20");
|
||||
|
|
|
@ -509,7 +509,5 @@ abstract class EthereumWalletBase
|
|||
String signMessage(String message, {String? address = null}) =>
|
||||
bytesToHex(_ethPrivateKey.signPersonalMessageToUint8List(ascii.encode(message)));
|
||||
|
||||
Future<String> fetchEnsAddress(String name) async {
|
||||
return await _client.checkEnsName(name);
|
||||
}
|
||||
dynamic getWeb3Client() => _client;
|
||||
}
|
||||
|
|
|
@ -21,10 +21,6 @@ dependencies:
|
|||
hex: ^0.2.0
|
||||
http: ^1.1.0
|
||||
shared_preferences: ^2.0.15
|
||||
ens_dart:
|
||||
git:
|
||||
url: https://github.com/cake-tech/ens_dart.git
|
||||
ref: main
|
||||
cw_core:
|
||||
path: ../cw_core
|
||||
|
||||
|
|
30
lib/entities/ens_record.dart
Normal file
30
lib/entities/ens_record.dart
Normal file
|
@ -0,0 +1,30 @@
|
|||
import 'package:cake_wallet/ethereum/ethereum.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:ens_dart/ens_dart.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:web3dart/web3dart.dart';
|
||||
|
||||
class EnsRecord {
|
||||
static Future<String> fetchEnsAddress(String name, {WalletBase? wallet}) async {
|
||||
Web3Client? _client;
|
||||
|
||||
if (wallet != null && wallet.type == WalletType.ethereum) {
|
||||
_client = ethereum!.getWeb3Client(wallet) as Web3Client?;
|
||||
}
|
||||
|
||||
if (_client == null) {
|
||||
_client = Web3Client("ethereum.publicnode.com", Client());
|
||||
}
|
||||
|
||||
try {
|
||||
final ens = Ens(client: _client);
|
||||
|
||||
final addr = await ens.withName(name).getAddress();
|
||||
return addr.hex;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
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/ens_record.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';
|
||||
|
@ -99,6 +100,14 @@ class AddressResolver {
|
|||
return ParsedAddress.fetchUnstoppableDomainAddress(address: address, name: text);
|
||||
}
|
||||
|
||||
if (text.contains(".")) {
|
||||
var wallet = getIt.get<AppStore>().wallet!;
|
||||
final address = await EnsRecord.fetchEnsAddress(text, wallet: wallet);
|
||||
if (address.isNotEmpty) {
|
||||
return ParsedAddress.fetchEnsAddress(name: text, address: address);
|
||||
}
|
||||
}
|
||||
|
||||
if (formattedName.contains(".")) {
|
||||
final txtRecord = await OpenaliasRecord.lookupOpenAliasRecord(formattedName);
|
||||
if (txtRecord != null) {
|
||||
|
@ -107,15 +116,6 @@ 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());
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ class CWEthereum extends Ethereum {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<String> fetchEnsAddress(WalletBase wallet, String name) async {
|
||||
return (wallet as EthereumWallet).fetchEnsAddress(name);
|
||||
dynamic getWeb3Client(WalletBase wallet) async {
|
||||
return (wallet as EthereumWallet).getWeb3Client();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,6 +82,10 @@ dependencies:
|
|||
shared_preferences_android: 2.0.17
|
||||
url_launcher_android: 6.0.24
|
||||
sensitive_clipboard: ^1.0.0
|
||||
ens_dart:
|
||||
git:
|
||||
url: https://github.com/cake-tech/ens_dart.git
|
||||
ref: main
|
||||
bitcoin_flutter:
|
||||
git:
|
||||
url: https://github.com/cake-tech/bitcoin_flutter.git
|
||||
|
|
|
@ -525,7 +525,7 @@ abstract class Ethereum {
|
|||
|
||||
CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction);
|
||||
void updateEtherscanUsageState(WalletBase wallet, bool isEnabled);
|
||||
Future<String> fetchEnsAddress(WalletBase wallet, String name);
|
||||
dynamic getWeb3Client(WalletBase wallet);
|
||||
}
|
||||
""";
|
||||
|
||||
|
|
Loading…
Reference in a new issue