Skip to content

Commit

Permalink
prepa 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
byackee committed Nov 25, 2024
1 parent 0bfd5ab commit b56955c
Show file tree
Hide file tree
Showing 17 changed files with 2,128 additions and 3,352 deletions.
147 changes: 69 additions & 78 deletions lib/api/data_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ class DataManager extends ChangeNotifier {
List<Map<String, dynamic>> yamMarketFetched = [];
List<Map<String, dynamic>> yamMarketData = [];
List<Map<String, dynamic>> yamMarket = [];
List<Map<String, dynamic>> yamHistory = [];

List<Map<String, dynamic>> yamHistory = [];

var customInitPricesBox = Hive.box('CustomInitPrices');

Expand Down Expand Up @@ -267,18 +266,18 @@ class DataManager extends ChangeNotifier {
}

// Mise à jour des Yam History
var yamHistoryData = await ApiService.fetchTokenVolumes(forceFetch: forceFetch);
if (yamHistoryData.isNotEmpty) {
logger.i("Mise à jour de l'historiques YAM avec de nouvelles valeurs.");

// Sauvegarder les balances dans Hive
box.put('yamHistory', json.encode(yamHistoryData));
rmmBalances = yamHistoryData.cast<Map<String, dynamic>>();
fetchYamHistory();
notifyListeners(); // Notifier les listeners après la mise à jour
} else {
logger.d("Les RMM Balances sont vides, pas de mise à jour.");
}
var yamHistoryData = await ApiService.fetchTokenVolumes(forceFetch: forceFetch);
if (yamHistoryData.isNotEmpty) {
logger.i("Mise à jour de l'historiques YAM avec de nouvelles valeurs.");

// Sauvegarder les balances dans Hive
box.put('yamHistory', json.encode(yamHistoryData));
rmmBalances = yamHistoryData.cast<Map<String, dynamic>>();
fetchYamHistory();
notifyListeners(); // Notifier les listeners après la mise à jour
} else {
logger.d("Les RMM Balances sont vides, pas de mise à jour.");
}

loadWalletBalanceHistory();
loadRoiHistory();
Expand Down Expand Up @@ -605,7 +604,7 @@ class DataManager extends ChangeNotifier {

var box = Hive.box('realTokens');
initialTotalValue = 0.0;
yamTotalValue = 0.0;
yamTotalValue = 0.0;

// Charger les données en cache si disponibles
final cachedGnosisTokens = box.get('cachedTokenData_gnosis');
Expand Down Expand Up @@ -758,15 +757,14 @@ class DataManager extends ChangeNotifier {
List<String> parts3 = fullName.split(',');
String city = parts3.length >= 2 ? parts[1].trim() : 'Unknown City';


// Chercher la valeur Yam associée au token
final yamData = yamHistory.firstWhere(
(yam) => yam['id'].toLowerCase() == tokenContractAddress,
orElse: () => <String, dynamic>{},
);
final yamData = yamHistory.firstWhere(
(yam) => yam['id'].toLowerCase() == tokenContractAddress,
orElse: () => <String, dynamic>{},
);

final double yamTotalVolume = yamData['totalVolume'] ?? 0.0;
final double yamAverageValue = yamData['averageValue'] ?? tokenPrice;
final double yamTotalVolume = yamData['totalVolume'] ?? 0.0;
final double yamAverageValue = yamData['averageValue'] ?? tokenPrice;

// Ajouter au Portfolio
newPortfolio.add({
Expand Down Expand Up @@ -831,7 +829,7 @@ class DataManager extends ChangeNotifier {
});

initialTotalValue += double.parse(walletToken['amount']) * initPrice;
yamTotalValue += double.parse(walletToken['amount']) * yamAverageValue;
yamTotalValue += double.parse(walletToken['amount']) * yamAverageValue;

if (tokenContractAddress.isNotEmpty) {
// Récupérer les informations de loyer pour ce token
Expand Down Expand Up @@ -915,13 +913,13 @@ class DataManager extends ChangeNotifier {
String city = parts3.length >= 2 ? parts[1].trim() : 'Unknown';

// Chercher la valeur Yam associée au token
final yamData = yamHistory.firstWhere(
(yam) => yam['id'].toLowerCase() == tokenContractAddress,
orElse: () => <String, dynamic>{},
);
final yamData = yamHistory.firstWhere(
(yam) => yam['id'].toLowerCase() == tokenContractAddress,
orElse: () => <String, dynamic>{},
);

final double yamTotalVolume = yamData['totalVolume'] ?? 0.0;
final double yamAverageValue = yamData['averageValue'] ?? tokenPrice;
final double yamTotalVolume = yamData['totalVolume'] ?? 0.0;
final double yamAverageValue = yamData['averageValue'] ?? tokenPrice;

// Ajouter au Portfolio
newPortfolio.add({
Expand Down Expand Up @@ -982,8 +980,8 @@ class DataManager extends ChangeNotifier {
'initPrice': initPrice,
'section8paid': matchingRealToken['section8paid'] ?? 0.0,

'yamTotalVolume': yamTotalVolume, // Ajout de la valeur Yam calculée
'yamAverageValue': yamData['averageValue'], // Ajout de la valeur moyenne Yam calculée
'yamTotalVolume': yamTotalVolume, // Ajout de la valeur Yam calculée
'yamAverageValue': yamData['averageValue'], // Ajout de la valeur moyenne Yam calculée
});

initialTotalValue += amount * initPrice;
Expand All @@ -1010,7 +1008,8 @@ class DataManager extends ChangeNotifier {
}

// Mise à jour des variables pour le Dashboard
totalWalletValue = walletValueSum + rmmValueSum + rwaValue + totalUsdcDepositBalance + totalXdaiDepositBalance - totalUsdcBorrowBalance - totalXdaiBorrowBalance;
totalWalletValue =
walletValueSum + rmmValueSum + rwaValue + totalUsdcDepositBalance + totalXdaiDepositBalance - totalUsdcBorrowBalance - totalXdaiBorrowBalance;
archiveTotalWalletValue(totalWalletValue);

walletValue = double.parse(walletValueSum.toStringAsFixed(3));
Expand Down Expand Up @@ -1822,62 +1821,54 @@ class DataManager extends ChangeNotifier {
}
}

void fetchYamHistory() {
var box = Hive.box('realTokens');
final yamHistoryJson = box.get('yamHistory');

if (yamHistoryJson == null) {
logger.w("fetchYamHistory -> Aucune donnée Yam History trouvée dans Hive.");
return;
}

List<dynamic> yamHistoryData = json.decode(yamHistoryJson);

List<Map<String, dynamic>> tokenStatistics = yamHistoryData.map((tokenData) {
final tokenDecimals = int.tryParse(tokenData['decimals'].toString()) ?? 18;
final volumes = tokenData['volumes'] ?? [];
void fetchYamHistory() {
var box = Hive.box('realTokens');
final yamHistoryJson = box.get('yamHistory');

double totalVolume = 0;
double totalQuantity = 0;
if (yamHistoryJson == null) {
logger.w("fetchYamHistory -> Aucune donnée Yam History trouvée dans Hive.");
return;
}

for (var volume in volumes) {
final volumeTokenDecimals = int.tryParse(volume['token']['decimals'].toString()) ?? 6;
final volumeDays = volume['volumeDays'] ?? [];
List<dynamic> yamHistoryData = json.decode(yamHistoryJson);

List<Map<String, dynamic>> tokenStatistics = yamHistoryData.map((tokenData) {
final tokenDecimals = int.tryParse(tokenData['decimals'].toString()) ?? 18;
final volumes = tokenData['volumes'] ?? [];

for (var day in volumeDays) {
double totalVolume = 0;
double totalQuantity = 0;

final dayVolume = (day['volume'] != null)
? (double.tryParse(day['volume'].toString()) ?? 0) / pow(10, volumeTokenDecimals)
: 0;
final dayQuantity = (day['quantity'] != null)
? (double.tryParse(day['quantity'].toString()) ?? 0) / pow(10, tokenDecimals)
: 0;
for (var volume in volumes) {
final volumeTokenDecimals = int.tryParse(volume['token']['decimals'].toString()) ?? 6;
final volumeDays = volume['volumeDays'] ?? [];

for (var day in volumeDays) {
final dayVolume = (day['volume'] != null) ? (double.tryParse(day['volume'].toString()) ?? 0) / pow(10, volumeTokenDecimals) : 0;
final dayQuantity = (day['quantity'] != null) ? (double.tryParse(day['quantity'].toString()) ?? 0) / pow(10, tokenDecimals) : 0;

totalVolume += dayVolume;
totalQuantity += dayQuantity;
totalVolume += dayVolume;
totalQuantity += dayQuantity;
}
}
}

double averageValue = 0;
if (totalQuantity > 1e-10) {
averageValue = totalVolume / totalQuantity;
} else {
logger.w("Valeur aberrante détectée : totalQuantity=$totalQuantity pour token ${tokenData['id']}");
}

return {
'id': tokenData['id'],
'totalVolume': totalVolume,
'averageValue': averageValue,
};
}).toList();
double averageValue = 0;
if (totalQuantity > 1e-10) {
averageValue = totalVolume / totalQuantity;
} else {
logger.w("Valeur aberrante détectée : totalQuantity=$totalQuantity pour token ${tokenData['id']}");
}

logger.i("fetchyamHistory -> Mise à jour des statistiques des tokens Yam.");
yamHistory = tokenStatistics;
return {
'id': tokenData['id'],
'totalVolume': totalVolume,
'averageValue': averageValue,
};
}).toList();

notifyListeners();
}
logger.i("fetchyamHistory -> Mise à jour des statistiques des tokens Yam.");
yamHistory = tokenStatistics;

notifyListeners();
}
}
7 changes: 2 additions & 5 deletions lib/generated/intl/messages_all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ MessageLookupByLibrary? _findExact(String localeName) {

/// User programs should call this before using [localeName] for messages.
Future<bool> initializeMessages(String localeName) {
var availableLocale = Intl.verifiedLocale(
localeName, (locale) => _deferredLibraries[locale] != null,
onFailure: (_) => null);
var availableLocale = Intl.verifiedLocale(localeName, (locale) => _deferredLibraries[locale] != null, onFailure: (_) => null);
if (availableLocale == null) {
return new SynchronousFuture(false);
}
Expand All @@ -76,8 +74,7 @@ bool _messagesExistFor(String locale) {
}

MessageLookupByLibrary? _findGeneratedMessagesFor(String locale) {
var actualLocale =
Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null);
var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null);
if (actualLocale == null) return null;
return _findExact(actualLocale);
}
Loading

0 comments on commit b56955c

Please sign in to comment.