diff --git a/android/app/build.gradle b/android/app/build.gradle index 095df97e4a5f7e09a2afff80313e95ce7510f955..799e480b86b9dda0dcf9849a20f45b0de2381645 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -45,8 +45,8 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "gecko.axiomteam.fr" - minSdkVersion 16 - targetSdkVersion 30 + minSdkVersion 19 + targetSdkVersion 31 versionCode flutterVersionCode.toInteger() versionName flutterVersionName multiDexEnabled true diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index b6701eeeec53c343f74cc74a7de4794b7f7aae76..6ed90149273463a1fab5059f03e054db0d9510dd 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -9,9 +9,12 @@ <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> - <application android:requestLegacyExternalStorage="true" + <application + android:requestLegacyExternalStorage="true" android:name="${applicationName}" - android:label="Ğecko"> + android:label="Ğecko" + android:usesCleartextTraffic="true"> + <!-- TODO: Remove usesCleartextTraffic for production mode ! kopa --> <!-- android:icon="@mipmap/ic_launcher"> --> <activity android:requestLegacyExternalStorage="true" diff --git a/lib/main.dart b/lib/main.dart index e59041ff737208b1da28730ac7895b87bad4fd16..75e0142f8974ae044f3935f83e7c76c065f3a39c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -25,6 +25,7 @@ import 'package:gecko/models/chest_data.dart'; import 'package:gecko/providers/chest_provider.dart'; import 'package:gecko/models/g1_wallets_list.dart'; import 'package:gecko/providers/generate_wallets.dart'; +import 'package:gecko/providers/substrate_sdk.dart'; import 'package:gecko/providers/wallets_profiles.dart'; import 'package:gecko/providers/home.dart'; import 'package:gecko/providers/my_wallets.dart'; @@ -154,7 +155,8 @@ class Gecko extends StatelessWidget { ChangeNotifierProvider(create: (_) => WalletOptionsProvider()), ChangeNotifierProvider(create: (_) => ChangePinProvider()), ChangeNotifierProvider(create: (_) => SearchProvider()), - ChangeNotifierProvider(create: (_) => CesiumPlusProvider()) + ChangeNotifierProvider(create: (_) => CesiumPlusProvider()), + ChangeNotifierProvider(create: (_) => SubstrateSdk()) ], child: GraphQLProvider( client: _client, @@ -178,8 +180,8 @@ class Gecko extends StatelessWidget { ), primaryColor: const Color(0xffFFD58D), textTheme: const TextTheme( - bodyText1: TextStyle(), - bodyText2: TextStyle(), + bodyText1: TextStyle(fontSize: 20), + bodyText2: TextStyle(fontSize: 18), ).apply( bodyColor: const Color(0xFF000000), ), diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart new file mode 100644 index 0000000000000000000000000000000000000000..6fa3ca1dfd0cdd335e13f7c2600de87d4493f57d --- /dev/null +++ b/lib/providers/substrate_sdk.dart @@ -0,0 +1,45 @@ +import 'package:flutter/material.dart'; +import 'package:polkawallet_sdk/api/types/networkParams.dart'; +import 'package:polkawallet_sdk/polkawallet_sdk.dart'; +import 'package:polkawallet_sdk/storage/keyring.dart'; + +class SubstrateSdk with ChangeNotifier { + final String subNode = '192.168.1.85:9944'; + final bool isSsl = false; + + final WalletSDK sdk = WalletSDK(); + final Keyring keyring = Keyring(); + bool sdkReady = false; + bool nodeConnected = false; + int blocNumber = 0; + + Future<void> initApi() async { + await keyring.init([0, 2]); + + await sdk.init(keyring); + sdkReady = true; + notifyListeners(); + } + + Future<void> connectNode() async { + final String socketKind = isSsl ? 'wss' : 'ws'; + final node = NetworkParams(); + node.name = 'pokaniter'; + node.endpoint = '$socketKind://$subNode'; + node.ss58 = 42; + final res = await sdk.api.connectNode(keyring, [node]).timeout( + const Duration(seconds: 10), + onTimeout: () => null, + ); + if (res != null) { + nodeConnected = true; + notifyListeners(); + } + + // Subscribe bloc number + sdk.api.setting.subscribeBestNumber((res) { + blocNumber = int.parse(res.toString()); + notifyListeners(); + }); + } +} diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 23d47591ac01af9d7d68cf165972772198743112..7be0ce5c3d4adf90ca22e1fbf4e4aaee37d92212 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -12,6 +12,7 @@ import 'package:gecko/screens/onBoarding/1.dart'; import 'package:gecko/screens/search.dart'; import 'package:gecko/screens/settings.dart'; import 'package:flutter/services.dart'; +import 'package:gecko/screens/substrate_sandbox.dart'; import 'package:provider/provider.dart'; class HomeScreen extends StatelessWidget { @@ -176,9 +177,28 @@ Widget geckHome(context) { ), ], ), - ) + ), ]), ), + const SizedBox(height: 15), + Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ + ElevatedButton( + style: ElevatedButton.styleFrom( + primary: yellowC, // background + onPrimary: Colors.black, // foreground + ), + onPressed: () => Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return const SubstrateSandBox(); + }), + ), + child: const Text( + 'SUBSTRATE SANDBOX', + style: TextStyle(fontSize: 20), + ), + ), + ]), Expanded( flex: 1, child: Container( diff --git a/lib/screens/substrate_sandbox.dart b/lib/screens/substrate_sandbox.dart new file mode 100644 index 0000000000000000000000000000000000000000..89b4997b761fe0c8869d611e1591f4488b64371a --- /dev/null +++ b/lib/screens/substrate_sandbox.dart @@ -0,0 +1,64 @@ +import 'package:flutter/material.dart'; +import 'package:gecko/globals.dart'; +import 'package:gecko/providers/substrate_sdk.dart'; +import 'package:provider/provider.dart'; + +class SubstrateSandBox extends StatelessWidget { + const SubstrateSandBox({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false); + + return StatefulWrapper( + onInit: () async { + await _sub.initApi(); + await _sub.connectNode(); + }, + child: Scaffold( + appBar: AppBar( + toolbarHeight: 60 * ratio, + title: const SizedBox( + height: 22, + child: Text('Substrate Sandbox'), + ), + ), + body: SafeArea( + child: Consumer<SubstrateSdk>(builder: (context, _sub, _) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + Text('js-api chargé ?: ${_sub.sdkReady}'), + Text( + 'Noeud connecté ?: ${_sub.nodeConnected} (${_sub.subNode})'), + if (_sub.nodeConnected) + Text('Numéro de bloc: ${_sub.blocNumber}'), + ]); + }), + ), + ), + ); + } +} + +class StatefulWrapper extends StatefulWidget { + final Function onInit; + final Widget child; + const StatefulWrapper({Key? key, required this.onInit, required this.child}) + : super(key: key); + @override + _StatefulWrapperState createState() => _StatefulWrapperState(); +} + +class _StatefulWrapperState extends State<StatefulWrapper> { + @override + void initState() { + widget.onInit(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return widget.child; + } +} diff --git a/pubspec.lock b/pubspec.lock index 5d802dea1429f4abef689278e7059b557f7bd268..9d8eb230b5801c046612b29965913928aaa0e090 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -8,6 +8,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "30.0.0" + aes_ecb_pkcs5_flutter: + dependency: transitive + description: + name: aes_ecb_pkcs5_flutter + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.2" analyzer: dependency: transitive description: @@ -43,6 +50,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.8.2" + auth_header: + dependency: transitive + description: + name: auth_header + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" barcode: dependency: transitive description: @@ -347,6 +361,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_inappwebview: + dependency: transitive + description: + name: flutter_inappwebview + url: "https://pub.dartlang.org" + source: hosted + version: "5.3.2" flutter_launcher_icons: dependency: "direct main" description: @@ -404,6 +425,20 @@ packages: description: flutter source: sdk version: "0.0.0" + get: + dependency: transitive + description: + name: get + url: "https://pub.dartlang.org" + source: hosted + version: "4.6.1" + get_storage: + dependency: transitive + description: + name: get_storage + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.3" glob: dependency: transitive description: @@ -530,6 +565,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.0.0" + http_server: + dependency: transitive + description: + name: http_server + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" image: dependency: transitive description: @@ -591,6 +633,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.3" + jaguar: + dependency: transitive + description: + name: jaguar + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.12" + jaguar_common: + dependency: transitive + description: + name: jaguar_common + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" + jaguar_flutter_asset: + dependency: transitive + description: + name: jaguar_flutter_asset + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" jdenticon_dart: dependency: "direct main" description: @@ -668,6 +731,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.1" + mobx: + dependency: transitive + description: + name: mobx + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.6+1" nested: dependency: transitive description: @@ -815,6 +885,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.3" + path_tree: + dependency: transitive + description: + name: path_tree + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" pdf: dependency: "direct main" description: @@ -885,6 +962,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.4.0" + polkawallet_sdk: + dependency: "direct main" + description: + name: polkawallet_sdk + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.1" pool: dependency: transitive description: @@ -1258,6 +1342,34 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.0" + webview_flutter: + dependency: transitive + description: + name: webview_flutter + url: "https://pub.dartlang.org" + source: hosted + version: "2.8.0" + webview_flutter_android: + dependency: transitive + description: + name: webview_flutter_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.8.3" + webview_flutter_platform_interface: + dependency: transitive + description: + name: webview_flutter_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.0" + webview_flutter_wkwebview: + dependency: transitive + description: + name: webview_flutter_wkwebview + url: "https://pub.dartlang.org" + source: hosted + version: "2.7.1" win32: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index ee0dde1cfc12d0dda8da9207ab56dd65c7fffcc2..ade132266269899da42086bd59617a09f645b6ad 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -72,6 +72,7 @@ dependencies: desktop_window: ^0.4.0 durt: ^0.1.6 package_info_plus: ^1.3.0 + polkawallet_sdk: ^0.4.1 flutter_icons: android: "ic_launcher"