enh: improve derivations scan informations on import
This commit is contained in:
parent
8df05ea069
commit
ff29ff8086
|
@ -177,7 +177,9 @@
|
|||
"noContacts": "You don't have any contact",
|
||||
"addContact": "Add\nto contacts",
|
||||
"removeContact": "Remove\nthis contact",
|
||||
"derivationsScanProgress": "Scan address {}/{}",
|
||||
"scanRootDerivationInProgress": "Scan root address",
|
||||
"derivationsScanProgress": "Scan {} firsts addresses",
|
||||
"importDerivationsInProgress": "Import address {}/{}",
|
||||
"youAreOffline": "You are offline...",
|
||||
"importG1v1": "Import old G1v1 account",
|
||||
"selectDestWallet": "Select a target wallet:",
|
||||
|
|
|
@ -178,7 +178,9 @@
|
|||
"noContacts": "No tienes ningún contacto",
|
||||
"addContact": "Añadir\na contactos",
|
||||
"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...",
|
||||
"importG1v1": "Importar la cuenta antigua de G1v1",
|
||||
"selectDestWallet": "Selecciona un monedero destino:",
|
||||
|
|
|
@ -177,7 +177,9 @@
|
|||
"noContacts": "Vous n'avez aucun contact",
|
||||
"addContact": "Ajouter\naux contacts",
|
||||
"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...",
|
||||
"importG1v1": "Importer un ancien compte G1v1",
|
||||
"selectDestWallet": "Sélectionnez un portefeuille cible:",
|
||||
|
|
|
@ -9,6 +9,7 @@ import 'package:gecko/models/bip39_words.dart';
|
|||
import 'package:gecko/models/chest_data.dart';
|
||||
import 'package:gecko/models/wallet_data.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:provider/provider.dart';
|
||||
import "package:unorm_dart/unorm_dart.dart" as unorm;
|
||||
|
@ -19,6 +20,7 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
final walletNameFocus = FocusNode();
|
||||
Color? askedWordColor = Colors.black;
|
||||
bool isAskedWordValid = false;
|
||||
var scanStatus = ScanDerivationsStatus.none;
|
||||
int scanedValidWalletNumber = -1;
|
||||
int scanedWalletNumber = -1;
|
||||
int numberScan = 60;
|
||||
|
@ -296,7 +298,6 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
||||
final currentChestNumber = configBox.get('currentChest');
|
||||
bool isAlive = false;
|
||||
scanedValidWalletNumber = 0;
|
||||
scanedWalletNumber = 0;
|
||||
Map<String, int> addressToScan = {};
|
||||
notifyListeners();
|
||||
|
@ -305,14 +306,14 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
return false;
|
||||
}
|
||||
|
||||
scanStatus = ScanDerivationsStatus.rootScanning;
|
||||
final hasRoot = await scanRootBalance(sub, currentChestNumber);
|
||||
scanedWalletNumber = 1;
|
||||
notifyListeners();
|
||||
if (hasRoot) {
|
||||
scanedValidWalletNumber = 1;
|
||||
isAlive = true;
|
||||
}
|
||||
|
||||
scanStatus = ScanDerivationsStatus.scanning;
|
||||
for (int derivationNbr in [for (var i = 0; i < numberScan; i += 1) i]) {
|
||||
final addressData = await sub.sdk.api.keyring.addressFromMnemonic(
|
||||
sub.currencyParameters['ss58']!,
|
||||
|
@ -328,35 +329,37 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
onTimeout: () => {},
|
||||
);
|
||||
|
||||
for (String scannedWallet in balanceList.keys) {
|
||||
if (balanceList[scannedWallet]!['transferableBalance'] != 0) {
|
||||
isAlive = true;
|
||||
String walletName = scanedValidWalletNumber == 0
|
||||
? 'currentWallet'.tr()
|
||||
: '${'wallet'.tr()} ${scanedValidWalletNumber + 1}';
|
||||
await sub.importAccount(
|
||||
mnemonic: generatedMnemonic!,
|
||||
derivePath: "//${addressToScan[scannedWallet]}",
|
||||
password: pin.text);
|
||||
// Remove unused wallets
|
||||
balanceList.removeWhere((key, value) => value['transferableBalance'] == 0);
|
||||
scanedValidWalletNumber = balanceList.length + scanedWalletNumber;
|
||||
|
||||
WalletData myWallet = WalletData(
|
||||
chest: currentChestNumber,
|
||||
address: scannedWallet,
|
||||
number: scanedValidWalletNumber,
|
||||
name: walletName,
|
||||
derivation: addressToScan[scannedWallet],
|
||||
imageDefaultPath: '${scanedValidWalletNumber % 4}.png',
|
||||
isOwned: true);
|
||||
await walletBox.put(myWallet.address, myWallet);
|
||||
scanedValidWalletNumber = scanedValidWalletNumber + 1;
|
||||
}
|
||||
scanedWalletNumber = scanedWalletNumber + 1;
|
||||
scanStatus = ScanDerivationsStatus.import;
|
||||
for (String scannedWallet in balanceList.keys) {
|
||||
isAlive = true;
|
||||
String walletName = scanedWalletNumber == 0
|
||||
? 'currentWallet'.tr()
|
||||
: '${'wallet'.tr()} ${scanedWalletNumber + 1}';
|
||||
await sub.importAccount(
|
||||
mnemonic: generatedMnemonic!,
|
||||
derivePath: "//${addressToScan[scannedWallet]}",
|
||||
password: pin.text);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
log.d(scanedWalletNumber);
|
||||
scanedWalletNumber = -1;
|
||||
scanedValidWalletNumber = -1;
|
||||
scanStatus = ScanDerivationsStatus.none;
|
||||
scanedWalletNumber = scanedValidWalletNumber = -1;
|
||||
notifyListeners();
|
||||
return isAlive;
|
||||
}
|
||||
|
@ -387,6 +390,7 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
imageDefaultPath: '0.png',
|
||||
isOwned: true);
|
||||
await walletBox.put(myWallet.address, myWallet);
|
||||
scanedWalletNumber++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -43,6 +43,7 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
Map<String, WalletData> walletsToScan = {};
|
||||
for (var walletFromBox in wallets) {
|
||||
if (walletFromBox.chest == chest) {
|
||||
// log.d('${walletFromBox.number} - ${walletFromBox.name}');
|
||||
if (walletFromBox.identityStatus == IdtyStatus.unknown) {
|
||||
walletsToScan.putIfAbsent(
|
||||
walletFromBox.address, (() => walletFromBox));
|
||||
|
@ -61,7 +62,6 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
listWallets.add(wallet);
|
||||
n++;
|
||||
}
|
||||
|
||||
return listWallets;
|
||||
}
|
||||
|
||||
|
@ -201,6 +201,7 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
isOwned: true);
|
||||
|
||||
await walletBox.put(newWallet.address, newWallet);
|
||||
await readAllWallets();
|
||||
|
||||
isNewDerivationLoading = false;
|
||||
notifyListeners();
|
||||
|
|
|
@ -135,8 +135,8 @@ class _CustomDerivationState extends State<CustomDerivation> {
|
|||
int.parse(dropdownValue!),
|
||||
);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context);
|
||||
Navigator.popUntil(
|
||||
context, ModalRoute.withName('/mywallets'));
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
|
|
|
@ -560,7 +560,8 @@ class WalletOptions extends StatelessWidget {
|
|||
walletOptions.balanceCache[walletOptions.address.text] ?? -1;
|
||||
final bool canDelete = !isDefaultWallet &&
|
||||
!hasConsumers.data! &&
|
||||
(balance > 2 || balance == 0);
|
||||
(balance > 2 || balance == 0) &&
|
||||
!wallet.hasIdentity();
|
||||
return InkWell(
|
||||
key: keyDeleteWallet,
|
||||
onTap: canDelete
|
||||
|
|
|
@ -16,6 +16,7 @@ import 'package:gecko/widgets/commons/build_text.dart';
|
|||
import 'package:gecko/screens/onBoarding/11_congratulations.dart';
|
||||
import 'package:gecko/widgets/commons/fader_transition.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:provider/provider.dart';
|
||||
|
||||
|
@ -66,30 +67,7 @@ class OnboardingStepTen extends StatelessWidget {
|
|||
SizedBox(height: isTall ? 40 : 20),
|
||||
BuildText(text: "geckoWillCheckPassword".tr()),
|
||||
SizedBox(height: isTall ? 60 : 10),
|
||||
Visibility(
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const ScanDerivationsInfo(),
|
||||
Consumer<MyWalletsProvider>(builder: (context, mw, _) {
|
||||
return Visibility(
|
||||
visible: !myWalletProvider.isPinValid &&
|
||||
|
|
|
@ -27,7 +27,7 @@ class TransactionInProgress extends StatelessWidget {
|
|||
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
||||
final myWalletProvider =
|
||||
Provider.of<MyWalletsProvider>(context, listen: false);
|
||||
var txStatus = TransactionStatus.nothing;
|
||||
var txStatus = TransactionStatus.none;
|
||||
final result = sub.transactionStatus;
|
||||
|
||||
final from = fromAddress ??
|
||||
|
@ -68,7 +68,7 @@ class TransactionInProgress extends StatelessWidget {
|
|||
};
|
||||
|
||||
if (result == null) {
|
||||
txStatus = TransactionStatus.nothing;
|
||||
txStatus = TransactionStatus.none;
|
||||
} else if (result.contains('blockHash: ')) {
|
||||
txStatus = TransactionStatus.success;
|
||||
resultText = 'extrinsicValidated'
|
||||
|
@ -192,7 +192,7 @@ class TransactionInProgress extends StatelessWidget {
|
|||
),
|
||||
const SizedBox(height: 10),
|
||||
Visibility(
|
||||
visible: txStatus != TransactionStatus.nothing,
|
||||
visible: txStatus != TransactionStatus.none,
|
||||
child: Text(
|
||||
resultText,
|
||||
textAlign: TextAlign.center,
|
||||
|
@ -235,4 +235,4 @@ class TransactionInProgress extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
enum TransactionStatus { loading, failed, success, nothing }
|
||||
enum TransactionStatus { loading, failed, success, none }
|
||||
|
|
|
@ -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 }
|
Loading…
Reference in New Issue