Skip to content

Commit

Permalink
V1.5.0
Browse files Browse the repository at this point in the history
- Add Yam value projection on. wallet
- Add history off transactions
- Add rent graph repartition by city/region/country
- Add RMM infos in dashboard
  • Loading branch information
byackee committed Nov 26, 2024
1 parent e46ebf3 commit 68335c3
Show file tree
Hide file tree
Showing 21 changed files with 1,187 additions and 2,158 deletions.
100 changes: 49 additions & 51 deletions lib/api/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -753,34 +753,34 @@ class ApiService {
}
}

static Future<List<dynamic>> fetchTransactionsHistory({
required List<Map<String, dynamic>> portfolio,
bool forceFetch = false,
}) async {
logger.i("apiService: fetchTransferEvents -> Lancement de la requête");
static Future<List<dynamic>> fetchTransactionsHistory({
required List<Map<String, dynamic>> portfolio,
bool forceFetch = false,
}) async {
logger.i("apiService: fetchTransferEvents -> Lancement de la requête");

SharedPreferences prefs = await SharedPreferences.getInstance();
List<String> destinations = prefs.getStringList('evmAddresses') ?? [];
SharedPreferences prefs = await SharedPreferences.getInstance();
List<String> destinations = prefs.getStringList('evmAddresses') ?? [];

if (destinations.isEmpty) {
logger.w("apiService: fetchTransferEvents -> Pas d'adresses de destination disponibles");
return [];
}
if (destinations.isEmpty) {
logger.w("apiService: fetchTransferEvents -> Pas d'adresses de destination disponibles");
return [];
}

// Extraire les UUID des tokens depuis le portfolio
List<String> tokenAddresses = portfolio.map((token) => token['uuid'] as String).toList();
// Extraire les UUID des tokens depuis le portfolio
List<String> tokenAddresses = portfolio.map((token) => token['uuid'] as String).toList();

if (tokenAddresses.isEmpty) {
logger.w("apiService: fetchTransferEvents -> Pas de tokens disponibles dans le portfolio");
return [];
}
if (tokenAddresses.isEmpty) {
logger.w("apiService: fetchTransferEvents -> Pas de tokens disponibles dans le portfolio");
return [];
}

// Requête GraphQL
final response = await http.post(
Uri.parse(Parameters.gnosisUrl),
headers: {'Content-Type': 'application/json'},
body: json.encode({
"query": '''
// Requête GraphQL
final response = await http.post(
Uri.parse(Parameters.gnosisUrl),
headers: {'Content-Type': 'application/json'},
body: json.encode({
"query": '''
query GetTransferEvents(\$tokenAddresses: [String!], \$destinations: [String!]) {
transferEvents(
where: {
Expand All @@ -805,43 +805,41 @@ static Future<List<dynamic>> fetchTransactionsHistory({
}
}
''',
"variables": {
"tokenAddresses": tokenAddresses,
"destinations": destinations,
}
}),
);
"variables": {
"tokenAddresses": tokenAddresses,
"destinations": destinations,
}
}),
);

if (response.statusCode == 200) {
logger.i("apiService: fetchTransferEvents -> Requête lancée avec succès");
if (response.statusCode == 200) {
logger.i("apiService: fetchTransferEvents -> Requête lancée avec succès");

final decodedResponse = json.decode(response.body);
final decodedResponse = json.decode(response.body);

// Vérifiez si "data" et "transferEvents" existent
if (decodedResponse['data'] != null &&
decodedResponse['data']['transferEvents'] != null) {
final List<dynamic> transferEvents = decodedResponse['data']['transferEvents'];
// Vérifiez si "data" et "transferEvents" existent
if (decodedResponse['data'] != null && decodedResponse['data']['transferEvents'] != null) {
final List<dynamic> transferEvents = decodedResponse['data']['transferEvents'];

if (transferEvents.isNotEmpty) {
// Mettre les données dans le cache
var box = Hive.box('realTokens');
final now = DateTime.now();
box.put('cachedTransferEventsData', json.encode(transferEvents));
box.put('lastTransferEventsFetchTime', now.toIso8601String());
box.put('lastExecutionTime_TransferEvents', now.toIso8601String());
if (transferEvents.isNotEmpty) {
// Mettre les données dans le cache
var box = Hive.box('realTokens');
final now = DateTime.now();
box.put('cachedTransferEventsData', json.encode(transferEvents));
box.put('lastTransferEventsFetchTime', now.toIso8601String());
box.put('lastExecutionTime_TransferEvents', now.toIso8601String());

return transferEvents;
return transferEvents;
} else {
logger.w("apiService: fetchTransferEvents -> Aucun événement de transfert trouvé");
return [];
}
} else {
logger.w("apiService: fetchTransferEvents -> Aucun événement de transfert trouvé");
logger.w("apiService: fetchTransferEvents -> Aucune donnée dans la réponse");
return [];
}
} else {
logger.w("apiService: fetchTransferEvents -> Aucune donnée dans la réponse");
return [];
throw Exception('apiService: fetchTransferEvents -> Échec de la requête');
}
} else {
throw Exception('apiService: fetchTransferEvents -> Échec de la requête');
}
}

}
Loading

0 comments on commit 68335c3

Please sign in to comment.