feat: Load idtyStatus on readAllWallets method
This commit is contained in:
parent
6be89a3622
commit
e3dc579da7
|
@ -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;
|
||||
listWallets.clear();
|
||||
walletBox.toMap().forEach((key, value) {
|
||||
if (value.chest == chest) {
|
||||
listWallets.add(value);
|
||||
final wallets = walletBox.toMap().values.toList();
|
||||
for (var walletFromBox in wallets) {
|
||||
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;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
if (id.isEmpty) return WalletData(address: '', isOwned: true);
|
||||
int? chest = id[0];
|
||||
|
@ -118,7 +184,7 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
isNewDerivationLoading = true;
|
||||
notifyListeners();
|
||||
|
||||
final List idList = getNextWalletNumberAndDerivation();
|
||||
final List idList = await getNextWalletNumberAndDerivation();
|
||||
int newWalletNbr = idList[0];
|
||||
int newDerivationNbr = number ?? idList[1];
|
||||
|
||||
|
@ -155,7 +221,7 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
int newWalletNbr;
|
||||
int? chest = getCurrentChest();
|
||||
|
||||
List<WalletData> walletConfig = readAllWallets(chest);
|
||||
List<WalletData> walletConfig = await readAllWallets(chest);
|
||||
walletConfig.sort((p1, p2) {
|
||||
return Comparable.compare(p1.number!, p2.number!);
|
||||
});
|
||||
|
@ -187,14 +253,14 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
notifyListeners();
|
||||
}
|
||||
|
||||
List<int> getNextWalletNumberAndDerivation(
|
||||
{int? chestNumber, bool isOneshoot = false}) {
|
||||
Future<List<int>> getNextWalletNumberAndDerivation(
|
||||
{int? chestNumber, bool isOneshoot = false}) async {
|
||||
int newDerivationNbr = 0;
|
||||
int newWalletNbr = 0;
|
||||
|
||||
chestNumber ??= getCurrentChest();
|
||||
|
||||
List<WalletData> walletConfig = readAllWallets(chestNumber);
|
||||
List<WalletData> walletConfig = await readAllWallets(chestNumber);
|
||||
walletConfig.sort((p1, p2) {
|
||||
return Comparable.compare(p1.number!, p2.number!);
|
||||
});
|
||||
|
|
|
@ -35,9 +35,7 @@ class _CustomDerivationState extends State<CustomDerivation> {
|
|||
for (var i = 0; i < 51; i += 1) i.toString()
|
||||
];
|
||||
|
||||
final listWallets = myWalletProvider.readAllWallets();
|
||||
|
||||
for (WalletData wallet in listWallets) {
|
||||
for (WalletData wallet in myWalletProvider.listWallets) {
|
||||
derivationList.remove(wallet.derivation.toString());
|
||||
if (wallet.derivation == -1) {
|
||||
derivationList.remove('root');
|
||||
|
|
|
@ -41,8 +41,6 @@ class _WalletsHomeState extends State<WalletsHome> {
|
|||
|
||||
final currentChestNumber = myWalletProvider.getCurrentChest();
|
||||
final ChestData currentChest = chestBox.get(currentChestNumber)!;
|
||||
myWalletProvider.listWallets =
|
||||
myWalletProvider.readAllWallets(currentChestNumber);
|
||||
|
||||
return WillPopScope(
|
||||
onWillPop: () {
|
||||
|
@ -83,12 +81,29 @@ class _WalletsHomeState extends State<WalletsHome> {
|
|||
actualRoute: 'safeHome',
|
||||
)
|
||||
: dragInfo(context),
|
||||
body: SafeArea(
|
||||
child: Stack(children: [
|
||||
myWalletsTiles(context, currentChestNumber),
|
||||
const OfflineInfo(),
|
||||
]),
|
||||
),
|
||||
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: [
|
||||
myWalletsTiles(context, currentChestNumber),
|
||||
const OfflineInfo(),
|
||||
]),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -253,7 +253,7 @@ class OnboardingStepTen extends StatelessWidget {
|
|||
isOwned: true);
|
||||
await walletBox.put(myWallet.address, myWallet);
|
||||
}
|
||||
myWalletProvider.readAllWallets(currentChest);
|
||||
await myWalletProvider.readAllWallets(currentChest);
|
||||
myWalletProvider.reload();
|
||||
|
||||
generateWalletProvider.generatedMnemonic = '';
|
||||
|
|
|
@ -66,10 +66,8 @@ void paymentPopup(BuildContext context, String toAddress, String username) {
|
|||
}
|
||||
}
|
||||
|
||||
myWalletProvider.readAllWallets();
|
||||
myWalletProvider.listWallets
|
||||
.sort((a, b) => a.derivation!.compareTo(b.derivation!));
|
||||
log.d(myWalletProvider.listWallets);
|
||||
myWalletProvider.readAllWallets().then((value) => myWalletProvider.listWallets
|
||||
.sort((a, b) => a.derivation!.compareTo(b.derivation!)));
|
||||
|
||||
showModalBottomSheet<void>(
|
||||
shape: const RoundedRectangleBorder(
|
||||
|
|
Loading…
Reference in New Issue