From 175334457af88021db3c3974b3c77d1d121de406 Mon Sep 17 00:00:00 2001 From: poka Date: Mon, 8 Aug 2022 18:56:59 +0200 Subject: [PATCH] Add dead methode to get ss58 prefix from const storage; remove unused comments --- lib/globals.dart | 1 - lib/providers/generate_wallets.dart | 4 +- lib/providers/substrate_sdk.dart | 71 +++++++---------------------- lib/screens/settings.dart | 5 -- pubspec.yaml | 2 +- 5 files changed, 19 insertions(+), 64 deletions(-) diff --git a/lib/globals.dart b/lib/globals.dart index ba6d8d4..991afe7 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -46,7 +46,6 @@ Color floattingYellow = const Color(0xffEFEFBF); Color backgroundColor = const Color(0xFFF5F5F5); // Substrate settings -const int ss58 = 42; String currencyName = 'ĞD'; // Debug diff --git a/lib/providers/generate_wallets.dart b/lib/providers/generate_wallets.dart index 6039e53..65b8982 100644 --- a/lib/providers/generate_wallets.dart +++ b/lib/providers/generate_wallets.dart @@ -385,7 +385,7 @@ class GenerateWalletsProvider with ChangeNotifier { } for (var derivationNbr in [for (var i = 0; i < numberScan; i += 1) i]) { - final addressData = await sub.sdk.api.keyring.addressFromMnemonic(ss58, + final addressData = await sub.sdk.api.keyring.addressFromMnemonic(sub.ss58, cryptoType: CryptoType.sr25519, mnemonic: generatedMnemonic!, derivePath: '//$derivationNbr'); @@ -426,7 +426,7 @@ class GenerateWalletsProvider with ChangeNotifier { } Future scanRootBalance(SubstrateSdk sub, int currentChestNumber) async { - final addressData = await sub.sdk.api.keyring.addressFromMnemonic(ss58, + final addressData = await sub.sdk.api.keyring.addressFromMnemonic(sub.ss58, cryptoType: CryptoType.sr25519, mnemonic: generatedMnemonic!); final balance = await sub.getBalance(addressData.address!).timeout( diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart index d56efd7..dccacc4 100644 --- a/lib/providers/substrate_sdk.dart +++ b/lib/providers/substrate_sdk.dart @@ -28,6 +28,7 @@ class SubstrateSdk with ChangeNotifier { bool isLoadingEndpoint = false; String debugConnection = ''; String transactionStatus = ''; + int ss58 = 42; TextEditingController jsonKeystore = TextEditingController(); TextEditingController keystorePassword = TextEditingController(); @@ -46,12 +47,6 @@ class SubstrateSdk with ChangeNotifier { Future connectNode(BuildContext ctx) async { HomeProvider homeProvider = Provider.of(ctx, listen: false); - // var connectivityResult = await (Connectivity().checkConnectivity()); - // if (connectivityResult == ConnectivityResult.mobile || - // connectivityResult == ConnectivityResult.wifi) { - // _homeProvider.changeMessage("Vous n'êtes pas connecté à internet", 0); - // return; - // } homeProvider.changeMessage("connectionPending".tr(), 0); // configBox.delete('customEndpoint'); @@ -60,31 +55,8 @@ class SubstrateSdk with ChangeNotifier { ? [getDuniterCustomEndpoint()] : getDuniterBootstrap(); - // final nodes = getDuniterBootstrap(); - int timeout = 10000; - // if (n.endpoint!.startsWith('ws://')) { - // timeout = 5000; - // } - - //// Check websocket conenction - only for wss - // final channel = IOWebSocketChannel.connect( - // Uri.parse('wss://192.168.1.72:9944'), - // ); - - // channel.stream.listen( - // (dynamic message) { - // log.d('message $message'); - // }, - // onDone: () { - // log.d('ws channel closed'); - // }, - // onError: (error) { - // log.d('ws error $error'); - // }, - // ); - if (sdk.api.connectedNode?.endpoint != null) { await sdk.api.setting.unsubscribeBestNumber(); } @@ -99,6 +71,7 @@ class SubstrateSdk with ChangeNotifier { notifyListeners(); if (res != null) { nodeConnected = true; + // await getSs58Prefix(); // Subscribe bloc number sdk.api.setting.subscribeBestNumber((res) { @@ -197,7 +170,7 @@ class SubstrateSdk with ChangeNotifier { notifyListeners(); }); if (json == null) return ''; - log.d(json); + // log.d(json); try { await sdk.api.keyring.addAccount( keyring, @@ -205,7 +178,6 @@ class SubstrateSdk with ChangeNotifier { acc: json, password: password, ); - // Clipboard.setData(ClipboardData(text: jsonEncode(acc.toJson()))); } catch (e) { log.e(e); importIsLoading = false; @@ -225,14 +197,8 @@ class SubstrateSdk with ChangeNotifier { Future> getKeyStoreAddress() async { List result = []; - // sdk.api.account.unsubscribeBalance(); for (var element in keyring.allAccounts) { - // Clipboard.setData(ClipboardData(text: jsonEncode(element))); final account = AddressInfo(address: element.address); - // await sdk.api.account.subscribeBalance(element.address, (p0) { - // account.balance = int.parse(p0.freeBalance) / 100; - // }); - // sdk.api.setting.unsubscribeBestNumber(); account.balance = await getBalance(element.address!); result.add(account); } @@ -248,8 +214,6 @@ class SubstrateSdk with ChangeNotifier { Future> getCerts(String address) async { final idtyIndex = await getIdentityIndexOf(address); - // log.d('u32: ' + idtyIndex.toString()); - final certsReceiver = await sdk.webView! .evalJavascript('api.query.cert.storageIdtyCertMeta($idtyIndex)') ?? []; @@ -288,14 +252,12 @@ class SubstrateSdk with ChangeNotifier { final accountInfo = await sdk.webView! .evalJavascript('api.query.system.account("$address")'); final consumers = accountInfo['consumers']; - // log.d('Consumers: $_consumers'); return consumers == 0 ? false : true; } Future getBalance(String address, {bool isUd = false}) async { double balance = 0.0; - // log.d('nodeConnected: ' + nodeConnected.toString()); if (nodeConnected) { final brutBalance = await sdk.api.account.queryBalance(address); balance = int.parse(brutBalance!.freeBalance) / 100; @@ -324,7 +286,6 @@ class SubstrateSdk with ChangeNotifier { Future checkPassword(String address, String pass) async { final account = getKeypair(address); - // log.d(account.address); return await sdk.api.keyring.checkPassword(account, pass); } @@ -380,8 +341,6 @@ class SubstrateSdk with ChangeNotifier { final gen = await sdk.api.keyring.generateMnemonic(ss58); generatedMnemonic = gen.mnemonic!; - // final res = await importAccount(fromMnemonic: true); - // await Clipboard.setData(ClipboardData(text: generatedMnemonic)); return gen.mnemonic!; } @@ -416,12 +375,9 @@ class SubstrateSdk with ChangeNotifier { required String password}) async { transactionStatus = ''; - // setCurrentWallet(fromAddress); - log.d(keyring.current.address); log.d(fromAddress); log.d(password); - // log.d(await checkPassword(fromAddress, password)); final fromPubkey = await sdk.api.account.decodeAddress([fromAddress]); log.d(fromPubkey!.keys.first); @@ -469,7 +425,6 @@ class SubstrateSdk with ChangeNotifier { String fromAddress, String password, String toAddress) async { transactionStatus = ''; - // setCurrentWallet(fromAddress); log.d('me: $fromAddress'); log.d('to: $toAddress'); @@ -507,7 +462,7 @@ class SubstrateSdk with ChangeNotifier { toIdtyStatus == 'ConfirmedByOwner') { if (toCerts[0] >= currencyParameters['wotMinCertForMembership'] && toIdtyStatus != 'Validated') { - log.d('Batch cert and membership validation'); + log.i('Batch cert and membership validation'); txInfo = TxInfoData( 'utility', 'batchAll', @@ -572,9 +527,6 @@ class SubstrateSdk with ChangeNotifier { } Future idtyStatus(String address, [bool smooth = true]) async { - // var tata = await sdk.webView! - // .evalJavascript('api.query.system.account("$address")'); - var idtyIndex = await getIdentityIndexOf(address); if (idtyIndex == 0) { @@ -586,7 +538,7 @@ class SubstrateSdk with ChangeNotifier { if (idtyStatus != null) { final String status = idtyStatus['status']; - // log.d('Status $address: $_status'); + return (status); } else { return 'expired'; @@ -595,8 +547,6 @@ class SubstrateSdk with ChangeNotifier { Future confirmIdentity( String fromAddress, String name, String password) async { - // Confirm identity - // setCurrentWallet(fromAddress); log.d('me: ${keyring.current.address!}'); final sender = TxSenderData( @@ -788,6 +738,17 @@ class SubstrateSdk with ChangeNotifier { String? getConnectedEndpoint() { return sdk.api.connectedNode?.endpoint; } + + Future getSs58Prefix() async { + final List res = await sdk.webView!.evalJavascript( + 'api.consts.system.ss58Prefix.words', + wrapPromise: false) ?? + [42]; + + ss58 = res[0]; + log.d(ss58); + return ss58; + } } void snack(BuildContext context, String message, {int duration = 2}) { diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index c5611f2..08ef20f 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -77,14 +77,9 @@ class SettingsScreen extends StatelessWidget { sub.getConnectedEndpoint() ?? duniterBootstrapNodes.first.endpoint; final customEndpoint = NetworkParams(); - customEndpoint.name = currencyName; customEndpoint.endpoint = 'Personnalisé'; - customEndpoint.ss58 = ss58; - final automaticEndpoint = NetworkParams(); - automaticEndpoint.name = currencyName; automaticEndpoint.endpoint = 'Auto'; - automaticEndpoint.ss58 = ss58; // duniterBootstrapNodes.add(_sub.getDuniterCustomEndpoint()); duniterBootstrapNodes.insert(0, automaticEndpoint); duniterBootstrapNodes.add(customEndpoint); diff --git a/pubspec.yaml b/pubspec.yaml index 1475c89..1f0d806 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -60,7 +60,7 @@ dependencies: desktop_window: ^0.4.0 durt: ^0.1.6 package_info_plus: ^1.4.2 - polkawallet_sdk: #^0.4.8 + polkawallet_sdk: #^0.4.9 git: url: https://github.com/poka-IT/sdk.git ref: gecko-old