Skip to content
Snippets Groups Projects
Commit e3dc579d authored by poka's avatar poka
Browse files

feat: Load idtyStatus on readAllWallets method

parent 6be89a36
Branches
Tags
No related merge requests found
...@@ -35,18 +35,84 @@ class MyWalletsProvider with ChangeNotifier { ...@@ -35,18 +35,84 @@ class MyWalletsProvider with ChangeNotifier {
} }
} }
List<WalletData> readAllWallets([int? chest]) { Future<List<WalletData>> readAllWallets([int? chest]) async {
final sub = Provider.of<SubstrateSdk>(homeContext, listen: false);
chest = chest ?? configBox.get('currentChest') ?? 0; chest = chest ?? configBox.get('currentChest') ?? 0;
listWallets.clear(); listWallets.clear();
walletBox.toMap().forEach((key, value) { final wallets = walletBox.toMap().values.toList();
if (value.chest == chest) { for (var walletFromBox in wallets) {
listWallets.add(value); if (walletFromBox.chest == chest) {
if (walletFromBox.identityStatus == IdtyStatus.unknown) {
walletFromBox.identityStatus =
await sub.idtyStatus(walletFromBox.address);
walletBox.put(walletFromBox.address, walletFromBox);
}
listWallets.add(walletFromBox);
}
} }
});
return listWallets; return listWallets;
} }
// List<WalletData> readAllWallets([int? chest]) {
// final sub = Provider.of<SubstrateSdk>(homeContext, listen: false);
// bool hasFetchStatus = false;
// List<Future> futures = [];
// chest = chest ?? configBox.get('currentChest') ?? 0;
// listWallets.clear();
// walletBox.toMap().forEach((key, walletFromBox) {
// if (walletFromBox.chest == chest) {
// if (walletFromBox.identityStatus == IdtyStatus.unknown) {
// hasFetchStatus = true;
// futures.add(sub.idtyStatus(walletFromBox.address).then((valueStatus) {
// walletFromBox.identityStatus = valueStatus;
// listWallets.add(walletFromBox);
// // walletBox.put(key, walletFromBox);
// }));
// } else {
// listWallets.add(walletFromBox);
// }
// }
// });
// // if (hasFetchStatus) {
// // sleep(const Duration(milliseconds: 300));
// // log.d('yoooooooooo');
// // readAllWallets(chest);
// // }
// if (hasFetchStatus) {
// Future.wait(futures).then((_) {
// return listWallets;
// // while (listWallets.any((element) =>
// // element.chest == chest &&
// // element.identityStatus == IdtyStatus.unknown)) {
// // List tata = listWallets.toList();
// // log.d(listWallets);
// // while (tata.length < walletBox.length) {
// // tata = listWallets.toList();
// // sleep(const Duration(milliseconds: 500));
// // Map status = {};
// // for (var walletInList in tata) {
// // status.putIfAbsent(
// // walletInList.name, () => walletInList.identityStatus);
// // }
// // log.d(status);
// // log.d('yoooooo');
// // status.clear();
// // }
// });
// }
// // if (hasFetchStatus) {
// // walletBox.putAll(
// // Map.fromEntries(listWallets.map((e) => MapEntry(e.address, e))));
// // }
// return listWallets;
// }
WalletData? getWalletDataById(List<int?> id) { WalletData? getWalletDataById(List<int?> id) {
if (id.isEmpty) return WalletData(address: '', isOwned: true); if (id.isEmpty) return WalletData(address: '', isOwned: true);
int? chest = id[0]; int? chest = id[0];
...@@ -118,7 +184,7 @@ class MyWalletsProvider with ChangeNotifier { ...@@ -118,7 +184,7 @@ class MyWalletsProvider with ChangeNotifier {
isNewDerivationLoading = true; isNewDerivationLoading = true;
notifyListeners(); notifyListeners();
final List idList = getNextWalletNumberAndDerivation(); final List idList = await getNextWalletNumberAndDerivation();
int newWalletNbr = idList[0]; int newWalletNbr = idList[0];
int newDerivationNbr = number ?? idList[1]; int newDerivationNbr = number ?? idList[1];
...@@ -155,7 +221,7 @@ class MyWalletsProvider with ChangeNotifier { ...@@ -155,7 +221,7 @@ class MyWalletsProvider with ChangeNotifier {
int newWalletNbr; int newWalletNbr;
int? chest = getCurrentChest(); int? chest = getCurrentChest();
List<WalletData> walletConfig = readAllWallets(chest); List<WalletData> walletConfig = await readAllWallets(chest);
walletConfig.sort((p1, p2) { walletConfig.sort((p1, p2) {
return Comparable.compare(p1.number!, p2.number!); return Comparable.compare(p1.number!, p2.number!);
}); });
...@@ -187,14 +253,14 @@ class MyWalletsProvider with ChangeNotifier { ...@@ -187,14 +253,14 @@ class MyWalletsProvider with ChangeNotifier {
notifyListeners(); notifyListeners();
} }
List<int> getNextWalletNumberAndDerivation( Future<List<int>> getNextWalletNumberAndDerivation(
{int? chestNumber, bool isOneshoot = false}) { {int? chestNumber, bool isOneshoot = false}) async {
int newDerivationNbr = 0; int newDerivationNbr = 0;
int newWalletNbr = 0; int newWalletNbr = 0;
chestNumber ??= getCurrentChest(); chestNumber ??= getCurrentChest();
List<WalletData> walletConfig = readAllWallets(chestNumber); List<WalletData> walletConfig = await readAllWallets(chestNumber);
walletConfig.sort((p1, p2) { walletConfig.sort((p1, p2) {
return Comparable.compare(p1.number!, p2.number!); return Comparable.compare(p1.number!, p2.number!);
}); });
......
...@@ -35,9 +35,7 @@ class _CustomDerivationState extends State<CustomDerivation> { ...@@ -35,9 +35,7 @@ class _CustomDerivationState extends State<CustomDerivation> {
for (var i = 0; i < 51; i += 1) i.toString() for (var i = 0; i < 51; i += 1) i.toString()
]; ];
final listWallets = myWalletProvider.readAllWallets(); for (WalletData wallet in myWalletProvider.listWallets) {
for (WalletData wallet in listWallets) {
derivationList.remove(wallet.derivation.toString()); derivationList.remove(wallet.derivation.toString());
if (wallet.derivation == -1) { if (wallet.derivation == -1) {
derivationList.remove('root'); derivationList.remove('root');
......
...@@ -41,8 +41,6 @@ class _WalletsHomeState extends State<WalletsHome> { ...@@ -41,8 +41,6 @@ class _WalletsHomeState extends State<WalletsHome> {
final currentChestNumber = myWalletProvider.getCurrentChest(); final currentChestNumber = myWalletProvider.getCurrentChest();
final ChestData currentChest = chestBox.get(currentChestNumber)!; final ChestData currentChest = chestBox.get(currentChestNumber)!;
myWalletProvider.listWallets =
myWalletProvider.readAllWallets(currentChestNumber);
return WillPopScope( return WillPopScope(
onWillPop: () { onWillPop: () {
...@@ -83,12 +81,29 @@ class _WalletsHomeState extends State<WalletsHome> { ...@@ -83,12 +81,29 @@ class _WalletsHomeState extends State<WalletsHome> {
actualRoute: 'safeHome', actualRoute: 'safeHome',
) )
: dragInfo(context), : dragInfo(context),
body: SafeArea( body: FutureBuilder(
future: myWalletProvider.readAllWallets(currentChestNumber),
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done ||
snapshot.hasError) {
return const Center(
child: SizedBox(
height: 50,
width: 50,
child: CircularProgressIndicator(
color: orangeC,
strokeWidth: 3,
),
),
);
}
return SafeArea(
child: Stack(children: [ child: Stack(children: [
myWalletsTiles(context, currentChestNumber), myWalletsTiles(context, currentChestNumber),
const OfflineInfo(), const OfflineInfo(),
]), ]),
), );
}),
), ),
); );
} }
......
...@@ -253,7 +253,7 @@ class OnboardingStepTen extends StatelessWidget { ...@@ -253,7 +253,7 @@ class OnboardingStepTen extends StatelessWidget {
isOwned: true); isOwned: true);
await walletBox.put(myWallet.address, myWallet); await walletBox.put(myWallet.address, myWallet);
} }
myWalletProvider.readAllWallets(currentChest); await myWalletProvider.readAllWallets(currentChest);
myWalletProvider.reload(); myWalletProvider.reload();
generateWalletProvider.generatedMnemonic = ''; generateWalletProvider.generatedMnemonic = '';
......
...@@ -66,10 +66,8 @@ void paymentPopup(BuildContext context, String toAddress, String username) { ...@@ -66,10 +66,8 @@ void paymentPopup(BuildContext context, String toAddress, String username) {
} }
} }
myWalletProvider.readAllWallets(); myWalletProvider.readAllWallets().then((value) => myWalletProvider.listWallets
myWalletProvider.listWallets .sort((a, b) => a.derivation!.compareTo(b.derivation!)));
.sort((a, b) => a.derivation!.compareTo(b.derivation!));
log.d(myWalletProvider.listWallets);
showModalBottomSheet<void>( showModalBottomSheet<void>(
shape: const RoundedRectangleBorder( shape: const RoundedRectangleBorder(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment