From 89ae21cde95950c85c406959867150e7a7151e03 Mon Sep 17 00:00:00 2001 From: poka Date: Wed, 2 Mar 2022 21:33:50 +0100 Subject: [PATCH] Decompose seed getting --- lib/providers/substrate_sdk.dart | 22 ++++++++++++++-------- lib/screens/substrate_sandbox.dart | 4 ++-- pubspec.lock | 6 +++--- pubspec.yaml | 1 + 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart index c4cdd7c..2319f94 100644 --- a/lib/providers/substrate_sdk.dart +++ b/lib/providers/substrate_sdk.dart @@ -1,6 +1,5 @@ // ignore_for_file: avoid_print -import 'dart:convert'; import 'package:crypto/crypto.dart'; import 'package:fast_base58/fast_base58.dart'; import 'package:flutter/material.dart'; @@ -10,13 +9,10 @@ import 'package:polkawallet_sdk/api/types/networkParams.dart'; import 'package:polkawallet_sdk/api/types/txInfoData.dart'; import 'package:polkawallet_sdk/polkawallet_sdk.dart'; import 'package:polkawallet_sdk/storage/keyring.dart'; -import 'package:polkawallet_sdk/storage/localStorage.dart'; -import 'package:polkawallet_sdk/utils/localStorage.dart'; import 'package:truncate/truncate.dart'; -import 'package:get_storage/get_storage.dart'; class SubstrateSdk with ChangeNotifier { - final List subNode = ['127.0.0.1:9944', '192.168.1.45:9944']; + final List subNode = ['127.0.0.1:9944', '192.168.1.72:9944']; final bool isSsl = false; final int ss58 = 42; @@ -97,7 +93,8 @@ class SubstrateSdk with ChangeNotifier { key: keyToImport, name: 'testKey', password: keystorePassword.text, - derivePath: derivePath) + derivePath: derivePath, + cryptoType: CryptoType.sr25519) .catchError((e) { importIsLoading = false; notifyListeners(); @@ -178,12 +175,13 @@ class SubstrateSdk with ChangeNotifier { onStatusChange: (status) { print('status: ' + status); if (status == 'Ready') { - snack(context, 'Paiement effectué avec succès !'); + snack(context, 'Transaction terminé'); } }, ); print(hash.toString()); } catch (err) { + print('taterror'); print(err.toString()); } } @@ -196,7 +194,15 @@ class SubstrateSdk with ChangeNotifier { final seedMap = await keyring.store.getDecryptedSeed(keypair.pubKey, password); print(seedMap); - generatedMnemonic = seedMap!['seed']; + if (seedMap!['type'] != 'mnemonic') return; + final List seedList = seedMap['seed'].split('/'); + generatedMnemonic = seedList[0]; + int sourceDerivation = -1; // To get derivation number of this account + if (seedList.length > 1) { + sourceDerivation = int.parse(seedMap['seed'].split('/')[1]); + } + print(generatedMnemonic); + print(sourceDerivation); importAccount(fromMnemonic: true, derivePath: '/$number'); } diff --git a/lib/screens/substrate_sandbox.dart b/lib/screens/substrate_sandbox.dart index 8a320f7..04036ca 100644 --- a/lib/screens/substrate_sandbox.dart +++ b/lib/screens/substrate_sandbox.dart @@ -94,7 +94,7 @@ class SubstrateSandBox extends StatelessWidget { child: const Text("Dériver"), ) ]) - ]); + ]); }), const SizedBox(height: 20), const Text('Mot de passe du trousseau:'), @@ -141,7 +141,7 @@ class SubstrateSandBox extends StatelessWidget { onPrimary: Colors.black, // foreground ), onPressed: () async { - final res = await _sub.generateMnemonic(); + await _sub.generateMnemonic(); _sub.importIsLoading = false; _sub.reload(); snack(context, 'Le mnemonic a été copié'); diff --git a/pubspec.lock b/pubspec.lock index 37ddc2b..c0140c0 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -967,10 +967,10 @@ packages: description: path: "." ref: fixAndroidActivityVersion - resolved-ref: bcb33239d99605258361951f447ab097ff03208a + resolved-ref: "05d80150def4d5b3cac02ba4db96a39550719c9b" url: "git://github.com/poka-IT/sdk.git" source: git - version: "0.4.1" + version: "0.4.2" pool: dependency: transitive description: @@ -1350,7 +1350,7 @@ packages: name: webview_flutter url: "https://pub.dartlang.org" source: hosted - version: "2.8.0" + version: "3.0.1" webview_flutter_android: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 688cbdd..afc1b57 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -73,6 +73,7 @@ dependencies: durt: ^0.1.6 package_info_plus: ^1.3.0 polkawallet_sdk: #^0.4.1 ## Wait for merging PR: https://github.com/polkawallet-io/sdk/pull/19 + # path: ../substrate-sdk git: url: git://github.com/poka-IT/sdk.git ref: fixAndroidActivityVersion