2024-05-23 00:37:06 +00:00
|
|
|
import 'wallets/crypto_currency/crypto_currency.dart';
|
|
|
|
import 'wallets/crypto_currency/intermediate/frost_currency.dart';
|
2024-05-22 19:38:49 +00:00
|
|
|
|
|
|
|
part 'app_config.g.dart';
|
2024-05-21 18:48:48 +00:00
|
|
|
|
2024-06-05 18:05:22 +00:00
|
|
|
enum AppFeature {
|
|
|
|
themeSelection,
|
|
|
|
buy,
|
|
|
|
swap;
|
|
|
|
}
|
|
|
|
|
2024-05-13 19:44:19 +00:00
|
|
|
abstract class AppConfig {
|
2024-05-22 19:38:49 +00:00
|
|
|
static const appName = _prefix + _separator + suffix;
|
|
|
|
|
|
|
|
static const prefix = _prefix;
|
|
|
|
static const suffix = _suffix;
|
2024-05-13 17:48:05 +00:00
|
|
|
|
2024-05-23 15:20:11 +00:00
|
|
|
static String get appDefaultDataDirName => _appDataDirName;
|
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);
|
|
|
|
|
2024-05-23 21:38:37 +00:00
|
|
|
static ({String light, String dark})? get appIconAsset => _appIconAsset;
|
|
|
|
|
2024-05-22 19:38:49 +00:00
|
|
|
static List<CryptoCurrency> get coins => _supportedCoins;
|
2024-05-13 17:48:05 +00:00
|
|
|
|
2024-06-06 21:40:10 +00:00
|
|
|
static bool get isSingleCoinApp => coins.length == 1;
|
|
|
|
|
2024-05-23 17:05:30 +00:00
|
|
|
static CryptoCurrency? getCryptoCurrencyFor(String coinIdentifier) {
|
|
|
|
try {
|
|
|
|
return coins.firstWhere((e) => e.identifier == coinIdentifier);
|
|
|
|
} catch (_) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2024-05-13 18:02:39 +00:00
|
|
|
|
2024-05-23 17:05:30 +00:00
|
|
|
static CryptoCurrency? getCryptoCurrencyForTicker(
|
2024-05-22 19:38:49 +00:00
|
|
|
final String ticker, {
|
|
|
|
bool caseInsensitive = true,
|
|
|
|
}) {
|
|
|
|
final _ticker = caseInsensitive ? ticker.toLowerCase() : ticker;
|
2024-05-23 17:05:30 +00:00
|
|
|
try {
|
|
|
|
return coins.firstWhere(
|
|
|
|
caseInsensitive
|
|
|
|
? (e) => e.ticker.toLowerCase() == _ticker && e is! FrostCurrency
|
|
|
|
: (e) => e.ticker == _ticker && e is! FrostCurrency,
|
|
|
|
);
|
|
|
|
} catch (_) {
|
|
|
|
return null;
|
|
|
|
}
|
2024-05-22 19:38:49 +00:00
|
|
|
}
|
2024-05-21 18:48:48 +00:00
|
|
|
|
2024-05-23 17:26:58 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-22 19:38:49 +00:00
|
|
|
/// 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
|
|
|
}
|