stack_wallet/lib/app_config.dart

88 lines
2.3 KiB
Dart
Raw Normal View History

import 'wallets/crypto_currency/crypto_currency.dart';
import 'wallets/crypto_currency/intermediate/frost_currency.dart';
part 'app_config.g.dart';
2024-06-05 18:05:22 +00:00
enum AppFeature {
themeSelection,
buy,
swap;
}
abstract class AppConfig {
static const appName = _prefix + _separator + suffix;
static const prefix = _prefix;
static const suffix = _suffix;
2024-05-13 17:48:05 +00:00
2024-07-08 17:27:20 +00:00
static const emptyWalletsMessage = _emptyWalletsMessage;
2024-05-23 15:20:11 +00:00
static String get appDefaultDataDirName => _appDataDirName;
2024-06-20 16:36:02 +00:00
static String get shortDescriptionText => _shortDescriptionText;
2024-05-24 19:56:14 +00:00
static String get commitHash => _commitHash;
2024-05-23 15:20:11 +00:00
2024-06-05 18:05:22 +00:00
static bool hasFeature(AppFeature feature) => _features.contains(feature);
static ({String light, String dark})? get appIconAsset => _appIconAsset;
static List<CryptoCurrency> get coins => _supportedCoins;
2024-05-13 17:48:05 +00:00
2024-10-01 18:55:50 +00:00
static ({String from, String to}) get swapDefaults => _swapDefaults;
static bool get isSingleCoinApp => coins.length == 1;
static CryptoCurrency? getCryptoCurrencyFor(String coinIdentifier) {
try {
return coins.firstWhere((e) => e.identifier == coinIdentifier);
} catch (_) {
return null;
}
}
2024-05-13 18:02:39 +00:00
static CryptoCurrency? getCryptoCurrencyForTicker(
final String ticker, {
bool caseInsensitive = true,
}) {
final _ticker = caseInsensitive ? ticker.toLowerCase() : ticker;
try {
return coins.firstWhere(
caseInsensitive
? (e) => e.ticker.toLowerCase() == _ticker && e is! FrostCurrency
: (e) => e.ticker == _ticker && e is! FrostCurrency,
);
} catch (_) {
return null;
}
}
static bool isStackCoin(String? ticker) {
if (ticker == null) {
return false;
}
if (getCryptoCurrencyForTicker(ticker, caseInsensitive: false) != null) {
return true;
}
try {
getCryptoCurrencyByPrettyName(ticker);
return true;
} catch (_) {
return false;
}
}
/// Fuzzy logic. Use with caution!!
@Deprecated("dangerous")
static CryptoCurrency getCryptoCurrencyByPrettyName(final String prettyName) {
final name = prettyName.replaceAll(" ", "").toLowerCase();
try {
return coins.firstWhere(
(e) => e.identifier.toLowerCase() == name || e.prettyName == prettyName,
);
} catch (_) {
throw Exception("getCryptoCurrencyByPrettyName($prettyName) failed!");
}
}
2024-05-13 17:48:05 +00:00
}