Skip to content

Add basic FACT0RN support #1119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/models/isar/models/blockchain_data/address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ class Address extends CryptoCurrencyAddress {
}

@override
String toString() => "{ "
String toString() =>
"{ "
"id: $id, "
"walletId: $walletId, "
"value: $value, "
Expand Down Expand Up @@ -130,10 +131,7 @@ class Address extends CryptoCurrencyAddress {
return jsonEncode(result);
}

static Address fromJsonString(
String jsonString, {
String? overrideWalletId,
}) {
static Address fromJsonString(String jsonString, {String? overrideWalletId}) {
final json = jsonDecode(jsonString);
final derivationPathString = json["derivationPath"] as String?;

Expand Down Expand Up @@ -176,7 +174,8 @@ enum AddressType {
p2tr,
solana,
cardanoShelley,
xelis;
xelis,
fact0rn;

String get readableName {
switch (this) {
Expand Down Expand Up @@ -216,6 +215,8 @@ enum AddressType {
return "Cardano Shelley";
case AddressType.xelis:
return "Xelis";
case AddressType.fact0rn:
return "FACT0RN";
}
}
}
Expand Down
67 changes: 37 additions & 30 deletions lib/services/price.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class PriceAPI {
Epiccash: "epic-cash",
Ecash: "ecash",
Ethereum: "ethereum",
Fact0rn: "fact0rn",
Firo: "zcoin",
Monero: "monero",
Particl: "particl",
Expand All @@ -54,13 +55,15 @@ class PriceAPI {
static const refreshInterval = 60;

// initialize to older than current time minus at least refreshInterval
static DateTime _lastCalled =
DateTime.now().subtract(const Duration(seconds: refreshInterval + 10));
static DateTime _lastCalled = DateTime.now().subtract(
const Duration(seconds: refreshInterval + 10),
);

static String _lastUsedBaseCurrency = "";

static const Duration refreshIntervalDuration =
Duration(seconds: refreshInterval);
static const Duration refreshIntervalDuration = Duration(
seconds: refreshInterval,
);

final HTTP client;

Expand All @@ -85,15 +88,18 @@ class PriceAPI {
}
}

await DB.instance
.put<dynamic>(boxName: DB.boxNamePriceCache, key: 'cache', value: map);
await DB.instance.put<dynamic>(
boxName: DB.boxNamePriceCache,
key: 'cache',
value: map,
);
}

Map<CryptoCurrency, Tuple2<Decimal, double>> get _cachedPrices {
final map =
DB.instance.get<dynamic>(boxName: DB.boxNamePriceCache, key: 'cache')
as Map? ??
{};
as Map? ??
{};
// init with 0
final result = {
for (final coin in AppConfig.coins) coin: Tuple2(Decimal.zero, 0.0),
Expand Down Expand Up @@ -132,9 +138,7 @@ class PriceAPI {
final externalCalls = Prefs.instance.externalCalls;
if ((!Util.isTestEnv && !externalCalls) ||
!(await Prefs.instance.isExternalCallsSet())) {
Logging.instance.i(
"User does not want to use external calls",
);
Logging.instance.i("User does not want to use external calls");
return _cachedPrices;
}
final Map<CryptoCurrency, Tuple2<Decimal, double>> result = {};
Expand All @@ -148,9 +152,10 @@ class PriceAPI {
final coinGeckoResponse = await client.get(
url: uri,
headers: {'Content-Type': 'application/json'},
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
proxyInfo:
Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);

final coinGeckoData = jsonDecode(coinGeckoResponse.body) as List<dynamic>;
Expand All @@ -160,9 +165,10 @@ class PriceAPI {
final coin = AppConfig.getCryptoCurrencyByPrettyName(coinName);

final price = Decimal.parse(map["current_price"].toString());
final change24h = map["price_change_percentage_24h"] != null
? double.parse(map["price_change_percentage_24h"].toString())
: 0.0;
final change24h =
map["price_change_percentage_24h"] != null
? double.parse(map["price_change_percentage_24h"].toString())
: 0.0;

result[coin] = Tuple2(price, change24h);
}
Expand All @@ -172,8 +178,11 @@ class PriceAPI {

return _cachedPrices;
} catch (e, s) {
Logging.instance
.e("getPricesAnd24hChange($baseCurrency): ", error: e, stackTrace: s);
Logging.instance.e(
"getPricesAnd24hChange($baseCurrency): ",
error: e,
stackTrace: s,
);
// return previous cached values
return _cachedPrices;
}
Expand All @@ -185,9 +194,7 @@ class PriceAPI {

if ((!Util.isTestEnv && !externalCalls) ||
!(await Prefs.instance.isExternalCallsSet())) {
Logging.instance.i(
"User does not want to use external calls",
);
Logging.instance.i("User does not want to use external calls");
return null;
}
const uriString =
Expand All @@ -197,9 +204,10 @@ class PriceAPI {
final response = await client.get(
url: uri,
headers: {'Content-Type': 'application/json'},
proxyInfo: Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
proxyInfo:
Prefs.instance.useTor
? TorService.sharedInstance.getProxyInfo()
: null,
);

final json = jsonDecode(response.body) as List<dynamic>;
Expand All @@ -215,21 +223,20 @@ class PriceAPI {
}

Future<Map<String, Tuple2<Decimal, double>>>
getPricesAnd24hChangeForEthTokens({
getPricesAnd24hChangeForEthTokens({
required Set<String> contractAddresses,
required String baseCurrency,
}) async {
final Map<String, Tuple2<Decimal, double>> tokenPrices = {};

if (AppConfig.coins.whereType<Ethereum>().isEmpty ||
contractAddresses.isEmpty) return tokenPrices;
contractAddresses.isEmpty)
return tokenPrices;

final externalCalls = Prefs.instance.externalCalls;
if ((!Util.isTestEnv && !externalCalls) ||
!(await Prefs.instance.isExternalCallsSet())) {
Logging.instance.i(
"User does not want to use external calls",
);
Logging.instance.i("User does not want to use external calls");
return tokenPrices;
}

Expand Down
Loading