mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-17 01:37:40 +00:00
update address resolv func
This commit is contained in:
parent
7321840dfe
commit
208057fa0f
7 changed files with 155 additions and 49 deletions
|
@ -248,6 +248,9 @@ class BackupService {
|
|||
final useEtherscan = data[PreferencesKey.useEtherscan] as bool?;
|
||||
final looksUpTwitter = data[PreferencesKey.looksUpTwitter] as bool?;
|
||||
final looksUpMastodon = data[PreferencesKey.looksUpMastodon] as bool?;
|
||||
final looksUpYatService = data[PreferencesKey.looksUpYatService] as bool?;
|
||||
final looksUpUnstoppableDomains = data[PreferencesKey.looksUpUnstoppableDomains] as bool?;
|
||||
final looksUpOpenAlias = data[PreferencesKey.looksUpOpenAlias] as bool?;
|
||||
final looksUpENS = data[PreferencesKey.looksUpENS] as bool?;
|
||||
final syncAll = data[PreferencesKey.syncAllKey] as bool?;
|
||||
final syncMode = data[PreferencesKey.syncModeKey] as int?;
|
||||
|
@ -382,6 +385,15 @@ class BackupService {
|
|||
if (looksUpMastodon != null)
|
||||
await _sharedPreferences.setBool(PreferencesKey.looksUpMastodon, looksUpMastodon);
|
||||
|
||||
if (looksUpYatService != null)
|
||||
await _sharedPreferences.setBool(PreferencesKey.looksUpYatService, looksUpYatService);
|
||||
|
||||
if (looksUpUnstoppableDomains != null)
|
||||
await _sharedPreferences.setBool(PreferencesKey.looksUpUnstoppableDomains, looksUpUnstoppableDomains);
|
||||
|
||||
if (looksUpOpenAlias != null)
|
||||
await _sharedPreferences.setBool(PreferencesKey.looksUpOpenAlias, looksUpOpenAlias);
|
||||
|
||||
if (looksUpENS != null)
|
||||
await _sharedPreferences.setBool(PreferencesKey.looksUpENS, looksUpENS);
|
||||
|
||||
|
@ -545,6 +557,12 @@ class BackupService {
|
|||
_sharedPreferences.getBool(PreferencesKey.looksUpTwitter),
|
||||
PreferencesKey.looksUpMastodon:
|
||||
_sharedPreferences.getBool(PreferencesKey.looksUpMastodon),
|
||||
PreferencesKey.looksUpYatService:
|
||||
_sharedPreferences.getBool(PreferencesKey.looksUpYatService),
|
||||
PreferencesKey.looksUpUnstoppableDomains:
|
||||
_sharedPreferences.getBool(PreferencesKey.looksUpUnstoppableDomains),
|
||||
PreferencesKey.looksUpOpenAlias:
|
||||
_sharedPreferences.getBool(PreferencesKey.looksUpOpenAlias),
|
||||
PreferencesKey.looksUpENS:
|
||||
_sharedPreferences.getBool(PreferencesKey.looksUpENS),
|
||||
PreferencesKey.syncModeKey:
|
||||
|
|
|
@ -983,7 +983,10 @@ Future<void> setup({
|
|||
getIt.registerFactory(() => YatService());
|
||||
|
||||
getIt.registerFactory(() =>
|
||||
AddressResolver(yatService: getIt.get<YatService>(), wallet: getIt.get<AppStore>().wallet!));
|
||||
AddressResolver(
|
||||
yatService: getIt.get<YatService>(),
|
||||
wallet: getIt.get<AppStore>().wallet!,
|
||||
settingsStore: getIt.get<SettingsStore>()));
|
||||
|
||||
getIt.registerFactoryParam<FullscreenQRPage, QrViewData, void>(
|
||||
(QrViewData viewData, _) => FullscreenQRPage(qrViewData: viewData));
|
||||
|
|
|
@ -6,6 +6,7 @@ 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/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';
|
||||
|
@ -13,11 +14,13 @@ import 'package:cw_core/wallet_type.dart';
|
|||
import 'package:cake_wallet/entities/fio_address_provider.dart';
|
||||
|
||||
class AddressResolver {
|
||||
AddressResolver({required this.yatService, required this.wallet}) : walletType = wallet.type;
|
||||
AddressResolver({required this.yatService, required this.wallet, required this.settingsStore})
|
||||
: walletType = wallet.type;
|
||||
|
||||
final YatService yatService;
|
||||
final WalletType walletType;
|
||||
final WalletBase wallet;
|
||||
final SettingsStore settingsStore;
|
||||
|
||||
static const unstoppableDomains = [
|
||||
'crypto',
|
||||
|
@ -58,51 +61,55 @@ class AddressResolver {
|
|||
Future<ParsedAddress> resolve(String text, String ticker) async {
|
||||
try {
|
||||
if (text.startsWith('@') && !text.substring(1).contains('@')) {
|
||||
final formattedName = text.substring(1);
|
||||
final twitterUser = await TwitterApi.lookupUserByName(userName: formattedName);
|
||||
final addressFromBio = extractAddressByType(
|
||||
raw: twitterUser.description, type: CryptoCurrency.fromString(ticker));
|
||||
if (addressFromBio != null) {
|
||||
return ParsedAddress.fetchTwitterAddress(address: addressFromBio, name: text);
|
||||
}
|
||||
if(settingsStore.looksUpTwitter) {
|
||||
final formattedName = text.substring(1);
|
||||
final twitterUser = await TwitterApi.lookupUserByName(userName: formattedName);
|
||||
final addressFromBio = extractAddressByType(
|
||||
raw: twitterUser.description, type: CryptoCurrency.fromString(ticker));
|
||||
if (addressFromBio != null) {
|
||||
return ParsedAddress.fetchTwitterAddress(address: addressFromBio, name: text);
|
||||
}
|
||||
|
||||
final pinnedTweet = twitterUser.pinnedTweet?.text;
|
||||
if (pinnedTweet != null) {
|
||||
final addressFromPinnedTweet =
|
||||
extractAddressByType(raw: pinnedTweet, type: CryptoCurrency.fromString(ticker));
|
||||
if (addressFromPinnedTweet != null) {
|
||||
return ParsedAddress.fetchTwitterAddress(address: addressFromPinnedTweet, name: text);
|
||||
final pinnedTweet = twitterUser.pinnedTweet?.text;
|
||||
if (pinnedTweet != null) {
|
||||
final addressFromPinnedTweet =
|
||||
extractAddressByType(raw: pinnedTweet, type: CryptoCurrency.fromString(ticker));
|
||||
if (addressFromPinnedTweet != null) {
|
||||
return ParsedAddress.fetchTwitterAddress(address: addressFromPinnedTweet, name: text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (text.startsWith('@') && text.contains('@', 1) && text.contains('.', 1)) {
|
||||
final subText = text.substring(1);
|
||||
final hostNameIndex = subText.indexOf('@');
|
||||
final hostName = subText.substring(hostNameIndex + 1);
|
||||
final userName = subText.substring(0, hostNameIndex);
|
||||
if (settingsStore.looksUpMastodon) {
|
||||
final subText = text.substring(1);
|
||||
final hostNameIndex = subText.indexOf('@');
|
||||
final hostName = subText.substring(hostNameIndex + 1);
|
||||
final userName = subText.substring(0, hostNameIndex);
|
||||
|
||||
final mastodonUser =
|
||||
await MastodonAPI.lookupUserByUserName(userName: userName, apiHost: hostName);
|
||||
final mastodonUser =
|
||||
await MastodonAPI.lookupUserByUserName(userName: userName, apiHost: hostName);
|
||||
|
||||
if (mastodonUser != null) {
|
||||
String? addressFromBio =
|
||||
extractAddressByType(raw: mastodonUser.note, type: CryptoCurrency.fromString(ticker));
|
||||
if (mastodonUser != null) {
|
||||
String? addressFromBio =
|
||||
extractAddressByType(raw: mastodonUser.note, type: CryptoCurrency.fromString(ticker));
|
||||
|
||||
if (addressFromBio != null) {
|
||||
return ParsedAddress.fetchMastodonAddress(address: addressFromBio, name: text);
|
||||
} else {
|
||||
final pinnedPosts =
|
||||
await MastodonAPI.getPinnedPosts(userId: mastodonUser.id, apiHost: hostName);
|
||||
if (addressFromBio != null) {
|
||||
return ParsedAddress.fetchMastodonAddress(address: addressFromBio, name: text);
|
||||
} else {
|
||||
final pinnedPosts =
|
||||
await MastodonAPI.getPinnedPosts(userId: mastodonUser.id, apiHost: hostName);
|
||||
|
||||
if (pinnedPosts.isNotEmpty) {
|
||||
final userPinnedPostsText = pinnedPosts.map((item) => item.content).join('\n');
|
||||
String? addressFromPinnedPost = extractAddressByType(
|
||||
raw: userPinnedPostsText, type: CryptoCurrency.fromString(ticker));
|
||||
if (pinnedPosts.isNotEmpty) {
|
||||
final userPinnedPostsText = pinnedPosts.map((item) => item.content).join('\n');
|
||||
String? addressFromPinnedPost = extractAddressByType(
|
||||
raw: userPinnedPostsText, type: CryptoCurrency.fromString(ticker));
|
||||
|
||||
if (addressFromPinnedPost != null) {
|
||||
return ParsedAddress.fetchMastodonAddress(
|
||||
address: addressFromPinnedPost, name: text);
|
||||
if (addressFromPinnedPost != null) {
|
||||
return ParsedAddress.fetchMastodonAddress(
|
||||
address: addressFromPinnedPost, name: text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,9 +124,11 @@ class AddressResolver {
|
|||
}
|
||||
}
|
||||
if (text.hasOnlyEmojis) {
|
||||
if (walletType != WalletType.haven) {
|
||||
final addresses = await yatService.fetchYatAddress(text, ticker);
|
||||
return ParsedAddress.fetchEmojiAddress(addresses: addresses, name: text);
|
||||
if(settingsStore.looksUpYatService) {
|
||||
if (walletType != WalletType.haven) {
|
||||
final addresses = await yatService.fetchYatAddress(text, ticker);
|
||||
return ParsedAddress.fetchEmojiAddress(addresses: addresses, name: text);
|
||||
}
|
||||
}
|
||||
}
|
||||
final formattedName = OpenaliasRecord.formatDomainName(text);
|
||||
|
@ -131,23 +140,29 @@ class AddressResolver {
|
|||
}
|
||||
|
||||
if (unstoppableDomains.any((domain) => name.trim() == domain)) {
|
||||
final address = await fetchUnstoppableDomainAddress(text, ticker);
|
||||
return ParsedAddress.fetchUnstoppableDomainAddress(address: address, name: text);
|
||||
if(settingsStore.looksUpUnstoppableDomains) {
|
||||
final address = await fetchUnstoppableDomainAddress(text, ticker);
|
||||
return ParsedAddress.fetchUnstoppableDomainAddress(address: address, name: text);
|
||||
}
|
||||
}
|
||||
|
||||
if (text.endsWith(".eth")) {
|
||||
final address = await EnsRecord.fetchEnsAddress(text, wallet: wallet);
|
||||
if (address.isNotEmpty && address != "0x0000000000000000000000000000000000000000") {
|
||||
return ParsedAddress.fetchEnsAddress(name: text, address: address);
|
||||
if (settingsStore.looksUpENS) {
|
||||
final address = await EnsRecord.fetchEnsAddress(text, wallet: wallet);
|
||||
if (address.isNotEmpty && address != "0x0000000000000000000000000000000000000000") {
|
||||
return ParsedAddress.fetchEnsAddress(name: text, address: address);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (formattedName.contains(".")) {
|
||||
final txtRecord = await OpenaliasRecord.lookupOpenAliasRecord(formattedName);
|
||||
if (txtRecord != null) {
|
||||
final record = await OpenaliasRecord.fetchAddressAndName(
|
||||
formattedName: formattedName, ticker: ticker, txtRecord: txtRecord);
|
||||
return ParsedAddress.fetchOpenAliasAddress(record: record, name: text);
|
||||
if(settingsStore.looksUpOpenAlias) {
|
||||
final txtRecord = await OpenaliasRecord.lookupOpenAliasRecord(formattedName);
|
||||
if (txtRecord != null) {
|
||||
final record = await OpenaliasRecord.fetchAddressAndName(
|
||||
formattedName: formattedName, ticker: ticker, txtRecord: txtRecord);
|
||||
return ParsedAddress.fetchOpenAliasAddress(record: record, name: text);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
|
@ -52,6 +52,9 @@ class PreferencesKey {
|
|||
static const useEtherscan = 'use_etherscan';
|
||||
static const looksUpTwitter = 'looks_up_twitter';
|
||||
static const looksUpMastodon = 'looks_up_mastodon';
|
||||
static const looksUpYatService = 'looks_up_mastodon';
|
||||
static const looksUpUnstoppableDomains = 'looks_up_mastodon';
|
||||
static const looksUpOpenAlias = 'looks_up_mastodon';
|
||||
static const looksUpENS = 'looks_up_ens';
|
||||
|
||||
static String moneroWalletUpdateV1Key(String name) =>
|
||||
|
|
|
@ -28,10 +28,23 @@ class DomainLookupsPage extends BasePage {
|
|||
title: 'S.current.settings_display_balance',
|
||||
value: _privacySettingsViewModel.looksUpMastodon,
|
||||
onValueChange: (_, bool value) => _privacySettingsViewModel.setLooksUpMastodon(value)),
|
||||
SettingsSwitcherCell(
|
||||
title: 'S.current.settings_display_balance',
|
||||
value: _privacySettingsViewModel.looksUpYatService,
|
||||
onValueChange: (_, bool value) => _privacySettingsViewModel.setLooksUpYatService(value)),
|
||||
SettingsSwitcherCell(
|
||||
title: 'S.current.settings_display_balance',
|
||||
value: _privacySettingsViewModel.looksUpUnstoppableDomains,
|
||||
onValueChange: (_, bool value) => _privacySettingsViewModel.setLooksUpUnstoppableDomains(value)),
|
||||
SettingsSwitcherCell(
|
||||
title: 'S.current.settings_display_balance',
|
||||
value: _privacySettingsViewModel.looksUpOpenAlias,
|
||||
onValueChange: (_, bool value) => _privacySettingsViewModel.setLooksUpOpenAlias(value)),
|
||||
SettingsSwitcherCell(
|
||||
title: 'S.current.settings_display_balance',
|
||||
value: _privacySettingsViewModel.looksUpENS,
|
||||
onValueChange: (_, bool value) => _privacySettingsViewModel.setLooksUpENS(value)),
|
||||
|
||||
//if (!isHaven) it does not work correctly
|
||||
],
|
||||
),
|
||||
|
|
|
@ -84,6 +84,9 @@ abstract class SettingsStoreBase with Store {
|
|||
required this.useEtherscan,
|
||||
required this.looksUpTwitter,
|
||||
required this.looksUpMastodon,
|
||||
required this.looksUpYatService,
|
||||
required this.looksUpUnstoppableDomains,
|
||||
required this.looksUpOpenAlias,
|
||||
required this.looksUpENS,
|
||||
TransactionPriority? initialBitcoinTransactionPriority,
|
||||
TransactionPriority? initialMoneroTransactionPriority,
|
||||
|
@ -366,6 +369,21 @@ abstract class SettingsStoreBase with Store {
|
|||
(bool looksUpMastodon) =>
|
||||
_sharedPreferences.setBool(PreferencesKey.looksUpMastodon, looksUpMastodon));
|
||||
|
||||
reaction(
|
||||
(_) => looksUpYatService,
|
||||
(bool looksUpYatService) =>
|
||||
_sharedPreferences.setBool(PreferencesKey.looksUpYatService, looksUpYatService));
|
||||
|
||||
reaction(
|
||||
(_) => looksUpUnstoppableDomains,
|
||||
(bool looksUpUnstoppableDomains) =>
|
||||
_sharedPreferences.setBool(PreferencesKey.looksUpUnstoppableDomains, looksUpUnstoppableDomains));
|
||||
|
||||
reaction(
|
||||
(_) => looksUpOpenAlias,
|
||||
(bool looksUpOpenAlias) =>
|
||||
_sharedPreferences.setBool(PreferencesKey.looksUpOpenAlias, looksUpOpenAlias));
|
||||
|
||||
reaction(
|
||||
(_) => looksUpENS,
|
||||
(bool looksUpENS) =>
|
||||
|
@ -500,6 +518,15 @@ abstract class SettingsStoreBase with Store {
|
|||
@observable
|
||||
bool looksUpMastodon;
|
||||
|
||||
@observable
|
||||
bool looksUpYatService;
|
||||
|
||||
@observable
|
||||
bool looksUpUnstoppableDomains;
|
||||
|
||||
@observable
|
||||
bool looksUpOpenAlias;
|
||||
|
||||
@observable
|
||||
bool looksUpENS;
|
||||
|
||||
|
@ -661,6 +688,9 @@ abstract class SettingsStoreBase with Store {
|
|||
final useEtherscan = sharedPreferences.getBool(PreferencesKey.useEtherscan) ?? true;
|
||||
final looksUpTwitter = sharedPreferences.getBool(PreferencesKey.looksUpTwitter) ?? true;
|
||||
final looksUpMastodon = sharedPreferences.getBool(PreferencesKey.looksUpMastodon) ?? true;
|
||||
final looksUpYatService = sharedPreferences.getBool(PreferencesKey.looksUpYatService) ?? true;
|
||||
final looksUpUnstoppableDomains = sharedPreferences.getBool(PreferencesKey.looksUpUnstoppableDomains) ?? true;
|
||||
final looksUpOpenAlias = sharedPreferences.getBool(PreferencesKey.looksUpOpenAlias) ?? true;
|
||||
final looksUpENS = sharedPreferences.getBool(PreferencesKey.looksUpENS) ?? true;
|
||||
|
||||
// If no value
|
||||
|
@ -771,6 +801,9 @@ abstract class SettingsStoreBase with Store {
|
|||
useEtherscan: useEtherscan,
|
||||
looksUpTwitter: looksUpTwitter,
|
||||
looksUpMastodon: looksUpMastodon,
|
||||
looksUpYatService: looksUpYatService,
|
||||
looksUpUnstoppableDomains: looksUpUnstoppableDomains,
|
||||
looksUpOpenAlias: looksUpOpenAlias,
|
||||
looksUpENS: looksUpENS,
|
||||
initialMoneroTransactionPriority: moneroTransactionPriority,
|
||||
initialBitcoinTransactionPriority: bitcoinTransactionPriority,
|
||||
|
@ -909,6 +942,9 @@ abstract class SettingsStoreBase with Store {
|
|||
useEtherscan = sharedPreferences.getBool(PreferencesKey.useEtherscan) ?? true;
|
||||
looksUpTwitter = sharedPreferences.getBool(PreferencesKey.looksUpTwitter) ?? true;
|
||||
looksUpMastodon = sharedPreferences.getBool(PreferencesKey.looksUpMastodon) ?? true;
|
||||
looksUpYatService = sharedPreferences.getBool(PreferencesKey.looksUpYatService) ?? true;
|
||||
looksUpUnstoppableDomains = sharedPreferences.getBool(PreferencesKey.looksUpUnstoppableDomains) ?? true;
|
||||
looksUpOpenAlias = sharedPreferences.getBool(PreferencesKey.looksUpOpenAlias) ?? true;
|
||||
looksUpENS = sharedPreferences.getBool(PreferencesKey.looksUpENS) ?? true;
|
||||
|
||||
final nodeId = sharedPreferences.getInt(PreferencesKey.currentNodeIdKey);
|
||||
|
|
|
@ -64,6 +64,15 @@ abstract class PrivacySettingsViewModelBase with Store {
|
|||
@computed
|
||||
bool get looksUpMastodon => _settingsStore.looksUpMastodon;
|
||||
|
||||
@computed
|
||||
bool get looksUpYatService => _settingsStore.looksUpYatService;
|
||||
|
||||
@computed
|
||||
bool get looksUpUnstoppableDomains => _settingsStore.looksUpUnstoppableDomains;
|
||||
|
||||
@computed
|
||||
bool get looksUpOpenAlias => _settingsStore.looksUpOpenAlias;
|
||||
|
||||
@computed
|
||||
bool get looksUpENS => _settingsStore.looksUpENS;
|
||||
|
||||
|
@ -97,6 +106,15 @@ abstract class PrivacySettingsViewModelBase with Store {
|
|||
@action
|
||||
void setLooksUpENS(bool value) => _settingsStore.looksUpENS = value;
|
||||
|
||||
@action
|
||||
void setLooksUpYatService(bool value) => _settingsStore.looksUpYatService = value;
|
||||
|
||||
@action
|
||||
void setLooksUpUnstoppableDomains(bool value) => _settingsStore.looksUpUnstoppableDomains = value;
|
||||
|
||||
@action
|
||||
void setLooksUpOpenAlias(bool value) => _settingsStore.looksUpOpenAlias = value;
|
||||
|
||||
@action
|
||||
void setUseEtherscan(bool value) {
|
||||
_settingsStore.useEtherscan = value;
|
||||
|
|
Loading…
Reference in a new issue