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

feat: first wallet is root, then inscrease one to one derivations from 0

parent d026b902
Branches
Tags v0.1.11+82
No related merge requests found
Pipeline #38434 failed
......@@ -23,7 +23,7 @@ class GenerateWalletsProvider with ChangeNotifier {
var scanStatus = ScanDerivationsStatus.none;
int scanedValidWalletNumber = -1;
int scanedWalletNumber = -1;
int numberScan = 60;
int numberScan = 30;
late int nbrWord;
String? nbrWordAlpha;
......@@ -84,8 +84,7 @@ class GenerateWalletsProvider with ChangeNotifier {
final expectedWord = mnemo.split(' ')[nbrWord];
final normInputWord = unorm.nfkd(inputWord);
if (expectedWord == normInputWord ||
(kDebugMode && inputWord == 'triche')) {
if (expectedWord == normInputWord || (kDebugMode && inputWord == 'triche')) {
isAskedWordValid = true;
askedWordColor = Colors.green[600];
notifyListeners();
......@@ -95,10 +94,8 @@ class GenerateWalletsProvider with ChangeNotifier {
}
String removeDiacritics(String str) {
var withDia =
'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
var withoutDia =
'AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz';
var withDia = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
var withoutDia = 'AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz';
for (int i = 0; i < withDia.length; i++) {
str = str.replaceAll(withDia[i], withoutDia[i]);
......@@ -136,8 +133,7 @@ class GenerateWalletsProvider with ChangeNotifier {
notifyListeners();
}
Future<void> generateCesiumWalletPubkey(
String cesiumID, String cesiumPWD) async {
Future<void> generateCesiumWalletPubkey(String cesiumID, String cesiumPWD) async {
cesiumWallet = durt.CesiumWallet(cesiumID, cesiumPWD);
String walletPubkey = cesiumWallet.pubkey;
......@@ -205,11 +201,8 @@ class GenerateWalletsProvider with ChangeNotifier {
}
void resetImportView() {
cellController0.text = cellController1.text = cellController2.text =
cellController3.text = cellController4.text = cellController5.text =
cellController6.text = cellController7.text = cellController8.text =
cellController9.text =
cellController10.text = cellController11.text = '';
cellController0.text = cellController1.text = cellController2.text = cellController3.text = cellController4.text = cellController5.text =
cellController6.text = cellController7.text = cellController8.text = cellController9.text = cellController10.text = cellController11.text = '';
isFirstTimeSentenceComplete = true;
notifyListeners();
}
......@@ -295,16 +288,12 @@ class GenerateWalletsProvider with ChangeNotifier {
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']!,
cryptoType: CryptoType.sr25519,
mnemonic: generatedMnemonic!,
derivePath: '//$derivationNbr');
final addressData = await sub.sdk.api.keyring
.addressFromMnemonic(sub.currencyParameters['ss58']!, cryptoType: CryptoType.sr25519, mnemonic: generatedMnemonic!, derivePath: '//$derivationNbr');
addressToScan.putIfAbsent(addressData.address!, () => derivationNbr);
}
final balanceList =
await sub.getBalanceMulti(addressToScan.keys.toList()).timeout(
final balanceList = await sub.getBalanceMulti(addressToScan.keys.toList()).timeout(
const Duration(seconds: 20),
onTimeout: () => {},
);
......@@ -316,13 +305,8 @@ class GenerateWalletsProvider with ChangeNotifier {
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: pinCode);
String walletName = scanedWalletNumber == 0 ? 'currentWallet'.tr() : '${'wallet'.tr()} ${scanedWalletNumber + 1}';
await sub.importAccount(mnemonic: generatedMnemonic!, derivePath: "//${addressToScan[scannedWallet]}", password: pinCode);
WalletData myWallet = WalletData(
chest: currentChestNumber,
......@@ -343,12 +327,9 @@ class GenerateWalletsProvider with ChangeNotifier {
return isAlive;
}
Future<bool> scanRootBalance(
SubstrateSdk sub, int currentChestNumber, String pinCode) async {
final addressData = await sub.sdk.api.keyring.addressFromMnemonic(
sub.currencyParameters['ss58']!,
cryptoType: CryptoType.sr25519,
mnemonic: generatedMnemonic!);
Future<bool> scanRootBalance(SubstrateSdk sub, int currentChestNumber, String pinCode) async {
final addressData =
await sub.sdk.api.keyring.addressFromMnemonic(sub.currencyParameters['ss58']!, cryptoType: CryptoType.sr25519, mnemonic: generatedMnemonic!);
final balance = await sub.getBalance(addressData.address!).timeout(
const Duration(seconds: 1),
......@@ -360,13 +341,7 @@ class GenerateWalletsProvider with ChangeNotifier {
await sub.importAccount(mnemonic: generatedMnemonic!, password: pinCode);
WalletData myWallet = WalletData(
chest: currentChestNumber,
address: addressData.address!,
number: 0,
name: walletName,
derivation: -1,
imageDefaultPath: '0.png',
isOwned: true);
chest: currentChestNumber, address: addressData.address!, number: 0, name: walletName, derivation: -1, imageDefaultPath: '0.png', isOwned: true);
await walletBox.put(myWallet.address, myWallet);
scanedWalletNumber++;
return true;
......
......@@ -110,20 +110,17 @@ class MyWalletsProvider with ChangeNotifier {
} else {
chest ??= getCurrentChest();
int? defaultWalletNumber = chestBox.get(chest)!.defaultWallet;
return getWalletDataById([chest, defaultWalletNumber]) ??
WalletData(address: '', chest: chest, number: 0, isOwned: true);
return getWalletDataById([chest, defaultWalletNumber]) ?? WalletData(address: '', chest: chest, number: 0, isOwned: true);
}
}
Future<int> deleteAllWallet(context) async {
final sub = Provider.of<SubstrateSdk>(context, listen: false);
final myWalletProvider =
Provider.of<MyWalletsProvider>(context, listen: false);
final myWalletProvider = Provider.of<MyWalletsProvider>(context, listen: false);
try {
log.w('DELETE ALL WALLETS ?');
final bool? answer =
await (confirmPopup(context, 'areYouSureForgetAllChests'.tr()));
final bool? answer = await (confirmPopup(context, 'areYouSureForgetAllChests'.tr()));
if (answer!) {
await walletBox.clear();
await chestBox.clear();
......@@ -139,8 +136,7 @@ class MyWalletsProvider with ChangeNotifier {
myWalletProvider.pinCode = '';
await Navigator.of(context)
.pushNamedAndRemoveUntil('/', (Route<dynamic> route) => false);
await Navigator.of(context).pushNamedAndRemoveUntil('/', (Route<dynamic> route) => false);
}
return 0;
} catch (e) {
......@@ -148,8 +144,7 @@ class MyWalletsProvider with ChangeNotifier {
}
}
Future<void> generateNewDerivation(context, String name,
[int? number]) async {
Future<void> generateNewDerivation(context, String name, [int? number]) async {
isNewDerivationLoading = true;
notifyListeners();
......@@ -163,8 +158,7 @@ class MyWalletsProvider with ChangeNotifier {
WalletData defaultWallet = getDefaultWallet();
final address = await sub.derive(
context, defaultWallet.address, newDerivationNbr, pinCode);
final address = await sub.derive(context, defaultWallet.address, newDerivationNbr, pinCode);
WalletData newWallet = WalletData(
chest: chest,
......@@ -183,8 +177,7 @@ class MyWalletsProvider with ChangeNotifier {
}
Future<void> generateRootWallet(context, String name) async {
final myWalletProvider =
Provider.of<MyWalletsProvider>(context, listen: false);
final myWalletProvider = Provider.of<MyWalletsProvider>(context, listen: false);
isNewDerivationLoading = true;
notifyListeners();
......@@ -205,17 +198,10 @@ class MyWalletsProvider with ChangeNotifier {
WalletData defaultWallet = myWalletProvider.getDefaultWallet();
final address =
await sub.generateRootKeypair(defaultWallet.address, pinCode);
final address = await sub.generateRootKeypair(defaultWallet.address, pinCode);
WalletData newWallet = WalletData(
chest: chest,
address: address,
number: newWalletNbr,
name: name,
derivation: -1,
imageDefaultPath: '${newWalletNbr % 4}.png',
isOwned: true);
chest: chest, address: address, number: newWalletNbr, name: name, derivation: -1, imageDefaultPath: '${newWalletNbr % 4}.png', isOwned: true);
await walletBox.put(newWallet.address, newWallet);
await readAllWallets();
......@@ -224,31 +210,20 @@ class MyWalletsProvider with ChangeNotifier {
notifyListeners();
}
Future<List<int>> getNextWalletNumberAndDerivation(
{int? chestNumber, bool isOneshoot = false}) async {
int newDerivationNbr = 0;
int newWalletNbr = 0;
Future<List<int>> getNextWalletNumberAndDerivation({int? chestNumber}) async {
chestNumber ??= getCurrentChest();
listWallets.sort((p1, p2) {
return Comparable.compare(p1.number!, p2.number!);
});
listWallets.sort((p1, p2) => p1.number!.compareTo(p2.number!));
if (listWallets.isEmpty) {
newDerivationNbr = 2;
} else {
final lastWallet = listWallets.reduce(
(curr, next) => curr.derivation! > next.derivation! ? curr : next);
if (lastWallet.derivation == -1) {
newDerivationNbr = 2;
} else {
newDerivationNbr = lastWallet.derivation! + (isOneshoot ? 1 : 2);
return [0, 0];
}
newWalletNbr = listWallets.last.number! + 1;
}
final maxDerivation = listWallets.map((w) => w.derivation ?? -1).reduce((max, value) => value > max ? value : max);
final newDerivationNbr = maxDerivation == -1 ? 0 : maxDerivation + 1;
final newWalletNbr = listWallets.last.number! + 1;
return [newWalletNbr, newDerivationNbr];
}
......@@ -257,8 +232,7 @@ class MyWalletsProvider with ChangeNotifier {
Future debounceResetPinCode([int minutes = 15]) async {
lockPin++;
final actualLock = lockPin;
await Future.delayed(
Duration(seconds: configBox.get('isCacheChecked') ? minutes * 60 : 1));
await Future.delayed(Duration(seconds: configBox.get('isCacheChecked') ? minutes * 60 : 1));
log.i('reset pin code, lock $actualLock ...');
if (actualLock == lockPin) pinCode = '';
}
......
......@@ -54,8 +54,7 @@ class _OnboardingStepTenState extends State<OnboardingStepTen> {
Widget build(BuildContext context) {
final walletOptions = Provider.of<WalletOptionsProvider>(context);
final sub = Provider.of<SubstrateSdk>(context);
final myWalletProvider =
Provider.of<MyWalletsProvider>(context, listen: false);
final myWalletProvider = Provider.of<MyWalletsProvider>(context, listen: false);
final pinLenght = widget.pinCode.length;
return PopScope(
......@@ -77,14 +76,10 @@ class _OnboardingStepTenState extends State<OnboardingStepTen> {
const ScanDerivationsInfo(),
Consumer<MyWalletsProvider>(builder: (context, mw, _) {
return Visibility(
visible: !myWalletProvider.isPinValid &&
!myWalletProvider.isPinLoading,
visible: !myWalletProvider.isPinValid && !myWalletProvider.isPinLoading,
child: Text(
"thisIsNotAGoodCode".tr(),
style: scaledTextStyle(
fontSize: 15,
color: Colors.red,
fontWeight: FontWeight.w500),
style: scaledTextStyle(fontSize: 15, color: Colors.red, fontWeight: FontWeight.w500),
),
);
}),
......@@ -92,9 +87,7 @@ class _OnboardingStepTenState extends State<OnboardingStepTen> {
Consumer<SubstrateSdk>(builder: (context, sub, _) {
return sub.nodeConnected
? pinForm(context, walletOptions, pinLenght, 1, 2)
: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Text(
"youHaveToBeConnectedToValidateChest".tr(),
style: scaledTextStyle(
......@@ -106,8 +99,7 @@ class _OnboardingStepTenState extends State<OnboardingStepTen> {
),
]);
}),
Consumer<WalletOptionsProvider>(
builder: (context, walletOptions, _) {
Consumer<WalletOptionsProvider>(builder: (context, walletOptions, _) {
return sub.nodeConnected
? InkWell(
key: keyCachePassword,
......@@ -118,17 +110,14 @@ class _OnboardingStepTenState extends State<OnboardingStepTen> {
ScaledSizedBox(height: isTall ? 30 : 0),
const Spacer(),
Icon(
configBox.get('isCacheChecked') ?? false
? Icons.check_box
: Icons.check_box_outline_blank,
configBox.get('isCacheChecked') ?? false ? Icons.check_box : Icons.check_box_outline_blank,
color: orangeC,
size: scaleSize(22),
),
ScaledSizedBox(width: 8),
Text(
'rememberPassword'.tr(),
style: scaledTextStyle(
fontSize: 14, color: Colors.grey[700]),
style: scaledTextStyle(fontSize: 14, color: Colors.grey[700]),
),
const Spacer()
]))
......@@ -141,11 +130,9 @@ class _OnboardingStepTenState extends State<OnboardingStepTen> {
);
}
Widget pinForm(
context, final walletOptions, pinLenght, int walletNbr, int derivation) {
Widget pinForm(context, final walletOptions, pinLenght, int walletNbr, int derivation) {
final myWalletProvider = Provider.of<MyWalletsProvider>(context);
final generateWalletProvider =
Provider.of<GenerateWalletsProvider>(context);
final generateWalletProvider = Provider.of<GenerateWalletsProvider>(context);
final sub = Provider.of<SubstrateSdk>(context, listen: false);
final currentChest = myWalletProvider.getCurrentChest();
......@@ -216,20 +203,18 @@ class _OnboardingStepTenState extends State<OnboardingStepTen> {
await generateWalletProvider.storeHDWChest(context);
bool isAlive = false;
if (widget.scanDerivation) {
isAlive = await generateWalletProvider.scanDerivations(
context, widget.pinCode);
isAlive = await generateWalletProvider.scanDerivations(context, widget.pinCode);
}
if (!isAlive) {
final address = await sub.importAccount(
mnemonic: generateWalletProvider.generatedMnemonic!,
derivePath: '//2',
password: widget.pinCode);
password: widget.pinCode,
);
WalletData myWallet = WalletData(
chest: configBox.get('currentChest'),
address: address,
number: 0,
name: 'currentWallet'.tr(),
derivation: 2,
imageDefaultPath: '0.png',
isOwned: true);
await walletBox.put(myWallet.address, myWallet);
......@@ -241,8 +226,7 @@ class _OnboardingStepTenState extends State<OnboardingStepTen> {
myWalletProvider.debounceResetPinCode();
Navigator.push(
context,
FaderTransition(
page: const OnboardingStepEleven(), isFast: false),
FaderTransition(page: const OnboardingStepEleven(), isFast: false),
);
} else {
hasError = true;
......
......@@ -2,7 +2,7 @@ name: gecko
description: Pay with G1.
publish_to: "none"
version: 0.1.10+81
version: 0.1.11+82
environment:
sdk: ^3.5.3
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment