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