diff --git a/lib/providers/duniter_indexer.dart b/lib/providers/duniter_indexer.dart index fbe9c7a..801e11c 100644 --- a/lib/providers/duniter_indexer.dart +++ b/lib/providers/duniter_indexer.dart @@ -5,6 +5,7 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:gecko/globals.dart'; +import 'package:gecko/models/g1_wallets_list.dart'; import 'package:gecko/models/queries_indexer.dart'; import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/providers/cesium_plus.dart'; @@ -207,6 +208,13 @@ class DuniterIndexer with ChangeNotifier { walletNameIndexer[address] = result.data?['account_by_pk']?['identity']?['name']; + g1WalletsBox.put( + address, + G1WalletsList( + pubkey: address, username: walletNameIndexer[address])); + + // log.d(g1WalletsBox.toMap().values.first.username); + if (walletNameIndexer[address] == null) { if (wallet == null) { return const SizedBox(); diff --git a/lib/providers/wallets_profiles.dart b/lib/providers/wallets_profiles.dart index 0acf9ab..f1fcc50 100644 --- a/lib/providers/wallets_profiles.dart +++ b/lib/providers/wallets_profiles.dart @@ -187,29 +187,29 @@ class WalletsProfilesProvider with ChangeNotifier { walletOptions.idtyStatus(context, address, isOwner: false, color: Colors.black), getCerts(context, address, 14), - if (username == null && - g1WalletsBox.get(address)?.username != null) - SizedBox( - width: 230, - child: Text( - g1WalletsBox.get(address)?.username ?? '', - style: const TextStyle( - fontSize: 27, - color: Color(0xff814C00), - ), - ), - ), - if (username != null) - SizedBox( - width: 230, - child: Text( - username, - style: const TextStyle( - fontSize: 27, - color: Color(0xff814C00), - ), - ), - ), + // if (username == null && + // g1WalletsBox.get(address)?.username != null) + // SizedBox( + // width: 230, + // child: Text( + // g1WalletsBox.get(address)?.username ?? '', + // style: const TextStyle( + // fontSize: 27, + // color: Color(0xff814C00), + // ), + // ), + // ), + // if (username != null) + // SizedBox( + // width: 230, + // child: Text( + // username, + // style: const TextStyle( + // fontSize: 27, + // color: Color(0xff814C00), + // ), + // ), + // ), const SizedBox(height: 55), ]), const Spacer(), @@ -229,12 +229,12 @@ class WalletsProfilesProvider with ChangeNotifier { return contactsBox.containsKey(address); } - void addContact(G1WalletsList profile) { - log.d(profile.username); + Future addContact(G1WalletsList profile) async { + // log.d(profile.username); if (isContact(profile.pubkey!)) { - contactsBox.delete(profile.pubkey); + await contactsBox.delete(profile.pubkey); } else { - contactsBox.put(profile.pubkey, profile); + await contactsBox.put(profile.pubkey, profile); } notifyListeners(); } diff --git a/lib/screens/my_contacts.dart b/lib/screens/my_contacts.dart index 939513d..31ab42c 100644 --- a/lib/screens/my_contacts.dart +++ b/lib/screens/my_contacts.dart @@ -22,7 +22,7 @@ class ContactsScreen extends StatelessWidget { CesiumPlusProvider cesiumPlusProvider = Provider.of(context, listen: false); WalletsProfilesProvider walletsProfilesClass = - Provider.of(context, listen: false); + Provider.of(context, listen: true); HomeProvider homeProvider = Provider.of(context, listen: false); DuniterIndexer duniterIndexer = @@ -32,11 +32,15 @@ class ContactsScreen extends StatelessWidget { double avatarSize = 55; final myContacts = contactsBox.toMap().values.toList(); - // myContacts.sort((a, b) { - // final aa = a.username?.toLowerCase() ?? ''; - // final bb = b.username?.toLowerCase() ?? ''; - // return aa.compareTo(bb); - // }); + + // for (var element in myContacts) { + // log.d('yooo: ${element.pubkey} ${element.username}'); + // } + + myContacts.sort((p1, p2) { + return Comparable.compare(p1.username?.toLowerCase() ?? 'zz', + p2.username?.toLowerCase() ?? 'zz'); + }); return Scaffold( backgroundColor: backgroundColor, diff --git a/lib/screens/wallet_view.dart b/lib/screens/wallet_view.dart index 33463f2..1593780 100644 --- a/lib/screens/wallet_view.dart +++ b/lib/screens/wallet_view.dart @@ -60,10 +60,14 @@ class WalletViewScreen extends StatelessWidget { Consumer( builder: (context, walletProfile, _) { return IconButton( - onPressed: () { - final newContact = - G1WalletsList(pubkey: pubkey!, username: username); - walletProfile.addContact(newContact); + onPressed: () async { + G1WalletsList? newContact; + g1WalletsBox.toMap().forEach((key, value) { + if (key == pubkey) newContact = value; + }); + // G1WalletsList(pubkey: pubkey!, username: username); + await walletProfile.addContact( + newContact ?? G1WalletsList(pubkey: pubkey!)); }, icon: Icon( walletProfile.isContact(pubkey!)