enh: improve derivations scan informations on import

This commit is contained in:
poka 2023-11-29 00:18:54 +01:00
parent 8df05ea069
commit ff29ff8086
10 changed files with 104 additions and 62 deletions

View File

@ -177,7 +177,9 @@
"noContacts": "You don't have any contact", "noContacts": "You don't have any contact",
"addContact": "Add\nto contacts", "addContact": "Add\nto contacts",
"removeContact": "Remove\nthis contact", "removeContact": "Remove\nthis contact",
"derivationsScanProgress": "Scan address {}/{}", "scanRootDerivationInProgress": "Scan root address",
"derivationsScanProgress": "Scan {} firsts addresses",
"importDerivationsInProgress": "Import address {}/{}",
"youAreOffline": "You are offline...", "youAreOffline": "You are offline...",
"importG1v1": "Import old G1v1 account", "importG1v1": "Import old G1v1 account",
"selectDestWallet": "Select a target wallet:", "selectDestWallet": "Select a target wallet:",

View File

@ -178,7 +178,9 @@
"noContacts": "No tienes ningún contacto", "noContacts": "No tienes ningún contacto",
"addContact": "Añadir\na contactos", "addContact": "Añadir\na contactos",
"removeContact": "Eliminar\neste contacto", "removeContact": "Eliminar\neste contacto",
"derivationsScanProgress": "Escaneado de la dirección {}/{}", "scanRootDerivationInProgress": "Scan root address",
"derivationsScanProgress": "Scan {} firsts addresses",
"importDerivationsInProgress": "Import address {}/{}",
"youAreOffline": "Estás desconectado...", "youAreOffline": "Estás desconectado...",
"importG1v1": "Importar la cuenta antigua de G1v1", "importG1v1": "Importar la cuenta antigua de G1v1",
"selectDestWallet": "Selecciona un monedero destino:", "selectDestWallet": "Selecciona un monedero destino:",

View File

@ -177,7 +177,9 @@
"noContacts": "Vous n'avez aucun contact", "noContacts": "Vous n'avez aucun contact",
"addContact": "Ajouter\naux contacts", "addContact": "Ajouter\naux contacts",
"removeContact": "Supprimer\nce contact", "removeContact": "Supprimer\nce contact",
"derivationsScanProgress": "Scan de l'adresse {}/{}", "scanRootDerivationInProgress": "Scan de l'adresse racine",
"derivationsScanProgress": "Scan des {} premières adresses",
"importDerivationsInProgress": "Importation de l'adresse {}/{}",
"youAreOffline": "Vous êtes hors ligne...", "youAreOffline": "Vous êtes hors ligne...",
"importG1v1": "Importer un ancien compte G1v1", "importG1v1": "Importer un ancien compte G1v1",
"selectDestWallet": "Sélectionnez un portefeuille cible:", "selectDestWallet": "Sélectionnez un portefeuille cible:",

View File

@ -9,6 +9,7 @@ import 'package:gecko/models/bip39_words.dart';
import 'package:gecko/models/chest_data.dart'; import 'package:gecko/models/chest_data.dart';
import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/models/wallet_data.dart';
import 'package:gecko/providers/substrate_sdk.dart'; import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/widgets/scan_derivations_info.dart';
import 'package:polkawallet_sdk/api/apiKeyring.dart'; import 'package:polkawallet_sdk/api/apiKeyring.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import "package:unorm_dart/unorm_dart.dart" as unorm; import "package:unorm_dart/unorm_dart.dart" as unorm;
@ -19,6 +20,7 @@ class GenerateWalletsProvider with ChangeNotifier {
final walletNameFocus = FocusNode(); final walletNameFocus = FocusNode();
Color? askedWordColor = Colors.black; Color? askedWordColor = Colors.black;
bool isAskedWordValid = false; bool isAskedWordValid = false;
var scanStatus = ScanDerivationsStatus.none;
int scanedValidWalletNumber = -1; int scanedValidWalletNumber = -1;
int scanedWalletNumber = -1; int scanedWalletNumber = -1;
int numberScan = 60; int numberScan = 60;
@ -296,7 +298,6 @@ class GenerateWalletsProvider with ChangeNotifier {
final sub = Provider.of<SubstrateSdk>(context, listen: false); final sub = Provider.of<SubstrateSdk>(context, listen: false);
final currentChestNumber = configBox.get('currentChest'); final currentChestNumber = configBox.get('currentChest');
bool isAlive = false; bool isAlive = false;
scanedValidWalletNumber = 0;
scanedWalletNumber = 0; scanedWalletNumber = 0;
Map<String, int> addressToScan = {}; Map<String, int> addressToScan = {};
notifyListeners(); notifyListeners();
@ -305,14 +306,14 @@ class GenerateWalletsProvider with ChangeNotifier {
return false; return false;
} }
scanStatus = ScanDerivationsStatus.rootScanning;
final hasRoot = await scanRootBalance(sub, currentChestNumber); final hasRoot = await scanRootBalance(sub, currentChestNumber);
scanedWalletNumber = 1;
notifyListeners(); notifyListeners();
if (hasRoot) { if (hasRoot) {
scanedValidWalletNumber = 1;
isAlive = true; isAlive = true;
} }
scanStatus = ScanDerivationsStatus.scanning;
for (int derivationNbr in [for (var i = 0; i < numberScan; i += 1) i]) { for (int derivationNbr in [for (var i = 0; i < numberScan; i += 1) i]) {
final addressData = await sub.sdk.api.keyring.addressFromMnemonic( final addressData = await sub.sdk.api.keyring.addressFromMnemonic(
sub.currencyParameters['ss58']!, sub.currencyParameters['ss58']!,
@ -328,35 +329,37 @@ class GenerateWalletsProvider with ChangeNotifier {
onTimeout: () => {}, onTimeout: () => {},
); );
for (String scannedWallet in balanceList.keys) { // Remove unused wallets
if (balanceList[scannedWallet]!['transferableBalance'] != 0) { balanceList.removeWhere((key, value) => value['transferableBalance'] == 0);
isAlive = true; scanedValidWalletNumber = balanceList.length + scanedWalletNumber;
String walletName = scanedValidWalletNumber == 0
? 'currentWallet'.tr()
: '${'wallet'.tr()} ${scanedValidWalletNumber + 1}';
await sub.importAccount(
mnemonic: generatedMnemonic!,
derivePath: "//${addressToScan[scannedWallet]}",
password: pin.text);
WalletData myWallet = WalletData( scanStatus = ScanDerivationsStatus.import;
chest: currentChestNumber, for (String scannedWallet in balanceList.keys) {
address: scannedWallet, isAlive = true;
number: scanedValidWalletNumber, String walletName = scanedWalletNumber == 0
name: walletName, ? 'currentWallet'.tr()
derivation: addressToScan[scannedWallet], : '${'wallet'.tr()} ${scanedWalletNumber + 1}';
imageDefaultPath: '${scanedValidWalletNumber % 4}.png', await sub.importAccount(
isOwned: true); mnemonic: generatedMnemonic!,
await walletBox.put(myWallet.address, myWallet); derivePath: "//${addressToScan[scannedWallet]}",
scanedValidWalletNumber = scanedValidWalletNumber + 1; password: pin.text);
}
scanedWalletNumber = scanedWalletNumber + 1; WalletData myWallet = WalletData(
chest: currentChestNumber,
address: scannedWallet,
number: scanedWalletNumber,
name: walletName,
derivation: addressToScan[scannedWallet],
imageDefaultPath: '${scanedWalletNumber % 4}.png',
isOwned: true);
await walletBox.put(myWallet.address, myWallet);
scanedWalletNumber++;
notifyListeners(); notifyListeners();
} }
log.d(scanedWalletNumber); log.d(scanedWalletNumber);
scanedWalletNumber = -1; scanStatus = ScanDerivationsStatus.none;
scanedValidWalletNumber = -1; scanedWalletNumber = scanedValidWalletNumber = -1;
notifyListeners(); notifyListeners();
return isAlive; return isAlive;
} }
@ -387,6 +390,7 @@ class GenerateWalletsProvider with ChangeNotifier {
imageDefaultPath: '0.png', imageDefaultPath: '0.png',
isOwned: true); isOwned: true);
await walletBox.put(myWallet.address, myWallet); await walletBox.put(myWallet.address, myWallet);
scanedWalletNumber++;
return true; return true;
} else { } else {
return false; return false;

View File

@ -43,6 +43,7 @@ class MyWalletsProvider with ChangeNotifier {
Map<String, WalletData> walletsToScan = {}; Map<String, WalletData> walletsToScan = {};
for (var walletFromBox in wallets) { for (var walletFromBox in wallets) {
if (walletFromBox.chest == chest) { if (walletFromBox.chest == chest) {
// log.d('${walletFromBox.number} - ${walletFromBox.name}');
if (walletFromBox.identityStatus == IdtyStatus.unknown) { if (walletFromBox.identityStatus == IdtyStatus.unknown) {
walletsToScan.putIfAbsent( walletsToScan.putIfAbsent(
walletFromBox.address, (() => walletFromBox)); walletFromBox.address, (() => walletFromBox));
@ -61,7 +62,6 @@ class MyWalletsProvider with ChangeNotifier {
listWallets.add(wallet); listWallets.add(wallet);
n++; n++;
} }
return listWallets; return listWallets;
} }
@ -201,6 +201,7 @@ class MyWalletsProvider with ChangeNotifier {
isOwned: true); isOwned: true);
await walletBox.put(newWallet.address, newWallet); await walletBox.put(newWallet.address, newWallet);
await readAllWallets();
isNewDerivationLoading = false; isNewDerivationLoading = false;
notifyListeners(); notifyListeners();

View File

@ -135,8 +135,8 @@ class _CustomDerivationState extends State<CustomDerivation> {
int.parse(dropdownValue!), int.parse(dropdownValue!),
); );
} }
Navigator.pop(context); Navigator.popUntil(
Navigator.pop(context); context, ModalRoute.withName('/mywallets'));
} }
}, },
child: Text( child: Text(

View File

@ -560,7 +560,8 @@ class WalletOptions extends StatelessWidget {
walletOptions.balanceCache[walletOptions.address.text] ?? -1; walletOptions.balanceCache[walletOptions.address.text] ?? -1;
final bool canDelete = !isDefaultWallet && final bool canDelete = !isDefaultWallet &&
!hasConsumers.data! && !hasConsumers.data! &&
(balance > 2 || balance == 0); (balance > 2 || balance == 0) &&
!wallet.hasIdentity();
return InkWell( return InkWell(
key: keyDeleteWallet, key: keyDeleteWallet,
onTap: canDelete onTap: canDelete

View File

@ -16,6 +16,7 @@ import 'package:gecko/widgets/commons/build_text.dart';
import 'package:gecko/screens/onBoarding/11_congratulations.dart'; import 'package:gecko/screens/onBoarding/11_congratulations.dart';
import 'package:gecko/widgets/commons/fader_transition.dart'; import 'package:gecko/widgets/commons/fader_transition.dart';
import 'package:gecko/widgets/commons/offline_info.dart'; import 'package:gecko/widgets/commons/offline_info.dart';
import 'package:gecko/widgets/scan_derivations_info.dart';
import 'package:pin_code_fields/pin_code_fields.dart'; import 'package:pin_code_fields/pin_code_fields.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -66,30 +67,7 @@ class OnboardingStepTen extends StatelessWidget {
SizedBox(height: isTall ? 40 : 20), SizedBox(height: isTall ? 40 : 20),
BuildText(text: "geckoWillCheckPassword".tr()), BuildText(text: "geckoWillCheckPassword".tr()),
SizedBox(height: isTall ? 60 : 10), SizedBox(height: isTall ? 60 : 10),
Visibility( const ScanDerivationsInfo(),
visible: generateWalletProvider.scanedValidWalletNumber != -1,
child: Padding(
padding: const EdgeInsets.only(bottom: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("derivationsScanProgress".tr(args: [
'${generateWalletProvider.scanedWalletNumber}',
'${generateWalletProvider.numberScan + 1}'
])),
const SizedBox(width: 10),
const SizedBox(
height: 22,
width: 22,
child: CircularProgressIndicator(
color: orangeC,
strokeWidth: 3,
),
),
],
),
),
),
Consumer<MyWalletsProvider>(builder: (context, mw, _) { Consumer<MyWalletsProvider>(builder: (context, mw, _) {
return Visibility( return Visibility(
visible: !myWalletProvider.isPinValid && visible: !myWalletProvider.isPinValid &&

View File

@ -27,7 +27,7 @@ class TransactionInProgress extends StatelessWidget {
Provider.of<WalletsProfilesProvider>(context, listen: false); Provider.of<WalletsProfilesProvider>(context, listen: false);
final myWalletProvider = final myWalletProvider =
Provider.of<MyWalletsProvider>(context, listen: false); Provider.of<MyWalletsProvider>(context, listen: false);
var txStatus = TransactionStatus.nothing; var txStatus = TransactionStatus.none;
final result = sub.transactionStatus; final result = sub.transactionStatus;
final from = fromAddress ?? final from = fromAddress ??
@ -68,7 +68,7 @@ class TransactionInProgress extends StatelessWidget {
}; };
if (result == null) { if (result == null) {
txStatus = TransactionStatus.nothing; txStatus = TransactionStatus.none;
} else if (result.contains('blockHash: ')) { } else if (result.contains('blockHash: ')) {
txStatus = TransactionStatus.success; txStatus = TransactionStatus.success;
resultText = 'extrinsicValidated' resultText = 'extrinsicValidated'
@ -192,7 +192,7 @@ class TransactionInProgress extends StatelessWidget {
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
Visibility( Visibility(
visible: txStatus != TransactionStatus.nothing, visible: txStatus != TransactionStatus.none,
child: Text( child: Text(
resultText, resultText,
textAlign: TextAlign.center, textAlign: TextAlign.center,
@ -235,4 +235,4 @@ class TransactionInProgress extends StatelessWidget {
} }
} }
enum TransactionStatus { loading, failed, success, nothing } enum TransactionStatus { loading, failed, success, none }

View File

@ -0,0 +1,52 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/providers/generate_wallets.dart';
import 'package:provider/provider.dart';
class ScanDerivationsInfo extends StatelessWidget {
const ScanDerivationsInfo({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final generateWalletProvider =
Provider.of<GenerateWalletsProvider>(context);
return Visibility(
visible: generateWalletProvider.scanStatus != ScanDerivationsStatus.none,
child: Padding(
padding: const EdgeInsets.only(bottom: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (generateWalletProvider.scanStatus ==
ScanDerivationsStatus.rootScanning)
Text('scanRootDerivationInProgress'.tr()),
if (generateWalletProvider.scanStatus ==
ScanDerivationsStatus.scanning)
Text('derivationsScanProgress'
.tr(args: [generateWalletProvider.numberScan.toString()])),
if (generateWalletProvider.scanStatus ==
ScanDerivationsStatus.import)
Text("importDerivationsInProgress".tr(args: [
'${generateWalletProvider.scanedWalletNumber}',
'${generateWalletProvider.scanedValidWalletNumber}'
])),
const SizedBox(width: 10),
const SizedBox(
height: 22,
width: 22,
child: CircularProgressIndicator(
color: orangeC,
strokeWidth: 3,
),
),
],
),
),
);
}
}
enum ScanDerivationsStatus { none, rootScanning, scanning, import }