diff --git a/assets/translations/en.json b/assets/translations/en.json index cfcd2e3..87d92a1 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -176,5 +176,7 @@ "addContact": "Add\nto contacts", "removeContact": "Remove\nthis contact", "derivationsScanProgress": "Scan address {}/{}", - "youAreOffline": "You are offline..." + "youAreOffline": "You are offline...", + "importG1v1": "Import old G1v1 account", + "selectDestWallet": "Select a target wallet:" } \ No newline at end of file diff --git a/assets/translations/es.json b/assets/translations/es.json index 99f6f1b..ab3fb87 100644 --- a/assets/translations/es.json +++ b/assets/translations/es.json @@ -176,5 +176,7 @@ "addContact": "Add\nto contacts", "removeContact": "Remove\nthis contact", "derivationsScanProgress": "Scan address {}/{}", - "youAreOffline": "You are offline..." + "youAreOffline": "You are offline...", + "importG1v1": "Import old G1v1 account", + "selectDestWallet": "Select a target wallet:" } \ No newline at end of file diff --git a/assets/translations/fr.json b/assets/translations/fr.json index 120c128..be333dc 100644 --- a/assets/translations/fr.json +++ b/assets/translations/fr.json @@ -177,5 +177,7 @@ "addContact": "Ajouter\naux contacts", "removeContact": "Supprimer\nce contact", "derivationsScanProgress": "Scan de l'adresse {}/{}", - "youAreOffline": "Vous êtes hors ligne..." + "youAreOffline": "Vous êtes hors ligne...", + "importG1v1": "Importer son compte G1v1", + "selectDestWallet": "Sélectionner un portefeuille cible:" } \ No newline at end of file diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart index c06d102..dde57f3 100644 --- a/lib/providers/substrate_sdk.dart +++ b/lib/providers/substrate_sdk.dart @@ -1,3 +1,5 @@ +// ignore_for_file: use_build_context_synchronously + import 'dart:typed_data'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; @@ -31,6 +33,10 @@ class SubstrateSdk with ChangeNotifier { String transactionStatus = ''; final int initSs58 = 42; Map currencyParameters = {}; + TextEditingController csSalt = TextEditingController(); + TextEditingController csPassword = TextEditingController(); + String g1V1NewAddress = ''; + bool isCesiumIDVisible = true; ///////////////////////////////////// ////////// 1: API METHODS /////////// @@ -570,7 +576,7 @@ class SubstrateSdk with ChangeNotifier { return await sdk.api.keyring.checkMnemonicValid(mnemonic); } - Future csToV2(String salt, String password) async { + Future csToV2Address(String salt, String password) async { final scrypt = pc.KeyDerivator('scrypt'); scrypt.init( @@ -586,29 +592,32 @@ class SubstrateSdk with ChangeNotifier { final rawSeedHex = '0x${HEX.encode(rawSeed)}'; // Just get the address without keystore - // final newAddress1 = await sdk.api.keyring.addressFromRawSeed(ss58, - // cryptoType: CryptoType.ed25519, rawSeed: '0x$rawSeedString'); - // log.d('csconvert address: ${newAddress1.address}'); + final newAddress = await sdk.api.keyring.addressFromRawSeed( + currencyParameters['ss58']!, + cryptoType: CryptoType.ed25519, + rawSeed: rawSeedHex); - final json = await sdk.api.keyring.importAccount(keyring, - keyType: KeyType.rawSeed, - key: rawSeedHex, - name: 'test', - password: 'password', - derivePath: '', - cryptoType: CryptoType.ed25519); + // final json = await sdk.api.keyring.importAccount(keyring, + // keyType: KeyType.rawSeed, + // key: rawSeedHex, + // name: 'test', + // password: 'password', + // derivePath: '', + // cryptoType: CryptoType.ed25519); - final keypair = await sdk.api.keyring.addAccount( - keyring, - keyType: KeyType.rawSeed, - acc: json!, - password: password, - ); - await sdk.api.keyring.deleteAccount(keyring, keypair); + // final keypair = await sdk.api.keyring.addAccount( + // keyring, + // keyType: KeyType.rawSeed, + // acc: json!, + // password: password, + // ); + // await sdk.api.keyring.deleteAccount(keyring, keypair); // final keypair2 = KeyPairData.fromJson(json as Map); - log.d(keypair.address); + // g1V1NewAddress = keypair.address!; + g1V1NewAddress = newAddress.address!; + notifyListeners(); } ////////////////////////////////////// @@ -776,6 +785,11 @@ class SubstrateSdk with ChangeNotifier { return await executeCall(txInfo, txOptions, password); } + void cesiumIDisVisible() { + isCesiumIDVisible = !isCesiumIDVisible; + notifyListeners(); + } + void reload() { notifyListeners(); } diff --git a/lib/screens/myWallets/import_g1_v1.dart b/lib/screens/myWallets/import_g1_v1.dart new file mode 100644 index 0000000..7557d49 --- /dev/null +++ b/lib/screens/myWallets/import_g1_v1.dart @@ -0,0 +1,156 @@ +import 'dart:async'; + +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/services.dart'; +import 'package:gecko/globals.dart'; +import 'package:flutter/material.dart'; +import 'package:gecko/providers/my_wallets.dart'; +import 'package:gecko/providers/substrate_sdk.dart'; +import 'package:gecko/providers/wallet_options.dart'; +import 'package:provider/provider.dart'; + +class ImportG1v1 extends StatelessWidget { + const ImportG1v1({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); + // HomeProvider _homeProvider = Provider.of(context); + WalletOptionsProvider walletOptions = + Provider.of(context, listen: false); + MyWalletsProvider myWalletProvider = + Provider.of(context, listen: false); + + Timer? debounce; + const int debouneTime = 300; + String selectedWallet = myWalletProvider.getDefaultWallet().name!; + + return Scaffold( + backgroundColor: backgroundColor, + appBar: AppBar( + toolbarHeight: 60 * ratio, + title: const SizedBox( + height: 22, + child: Text('Importer son ancien compte'), + )), + body: + SafeArea(child: Consumer(builder: (context, sub, _) { + return Column(children: [ + const SizedBox(height: 20), + TextFormField( + autofocus: true, + onChanged: (text) { + if (debounce?.isActive ?? false) { + debounce!.cancel(); + } + debounce = Timer(const Duration(milliseconds: debouneTime), () { + sub.csToV2Address(sub.csSalt.text, sub.csPassword.text); + }); + }, + keyboardType: TextInputType.text, + controller: sub.csSalt, + obscureText: + sub.isCesiumIDVisible, //This will obscure text dynamically + decoration: InputDecoration( + hintText: 'Entrez votre identifiant Cesium', + suffixIcon: IconButton( + icon: Icon( + sub.isCesiumIDVisible + ? Icons.visibility + : Icons.visibility_off, + color: Colors.black, + ), + onPressed: () { + sub.cesiumIDisVisible(); + }, + ), + ), + ), + const SizedBox(height: 20), + TextFormField( + autofocus: true, + onChanged: (text) { + if (debounce?.isActive ?? false) { + debounce!.cancel(); + } + debounce = Timer(const Duration(milliseconds: debouneTime), () { + sub.csToV2Address(sub.csSalt.text, sub.csPassword.text); + }); + }, + keyboardType: TextInputType.text, + controller: sub.csPassword, + obscureText: + sub.isCesiumIDVisible, //This will obscure text dynamically + decoration: InputDecoration( + hintText: 'Entrez votre mot de passe Cesium', + suffixIcon: IconButton( + icon: Icon( + sub.isCesiumIDVisible + ? Icons.visibility + : Icons.visibility_off, + color: Colors.black, + ), + onPressed: () { + sub.cesiumIDisVisible(); + }, + ), + ), + ), + const SizedBox(height: 20), + Text( + sub.g1V1NewAddress, + style: const TextStyle( + fontSize: 14.0, + color: Colors.black, + fontWeight: FontWeight.bold, + fontFamily: 'Monospace'), + ), + const SizedBox(height: 20), + balance(context, sub.g1V1NewAddress, 17), + walletOptions.idtyStatus(context, sub.g1V1NewAddress, + isOwner: false, color: Colors.black), + getCerts(context, sub.g1V1NewAddress, 14), + const SizedBox(height: 30), + Text('selectDestWallet'.tr()), + const SizedBox(height: 10), + DropdownButtonHideUnderline( + child: DropdownButton( + // alignment: AlignmentDirectional.topStart, + value: selectedWallet, + icon: const Icon(Icons.keyboard_arrow_down), + items: myWalletProvider.listWallets.map((wallet) { + return DropdownMenuItem( + value: wallet.name, + child: Text(wallet.name!), + ); + }).toList(), + onChanged: (newSelectedWallet) { + selectedWallet = newSelectedWallet.toString(); + sub.reload(); + }, + ), + ), + const SizedBox(height: 30), + SizedBox( + width: 380 * ratio, + height: 60 * ratio, + child: ElevatedButton( + style: ElevatedButton.styleFrom( + elevation: 4, + primary: orangeC, // background + onPrimary: Colors.white, // foreground + ), + onPressed: () { + log.d('GOOO'); + }, + child: Text( + 'validate'.tr(), + style: TextStyle( + fontSize: 23 * ratio, fontWeight: FontWeight.w600), + ), + ), + ) + ]); + }))); + } +} diff --git a/lib/screens/myWallets/wallets_home.dart b/lib/screens/myWallets/wallets_home.dart index 6fcd74f..b288f65 100644 --- a/lib/screens/myWallets/wallets_home.dart +++ b/lib/screens/myWallets/wallets_home.dart @@ -14,6 +14,7 @@ import 'package:gecko/providers/wallet_options.dart'; import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/myWallets/chest_options.dart'; import 'package:gecko/screens/myWallets/choose_chest.dart'; +import 'package:gecko/screens/myWallets/import_g1_v1.dart'; import 'package:gecko/screens/myWallets/unlocking_wallet.dart'; import 'package:gecko/screens/myWallets/wallet_options.dart'; import 'package:provider/provider.dart'; @@ -64,12 +65,10 @@ class WalletsHome extends StatelessWidget { ), bottomNavigationBar: homeProvider.bottomAppBar(context), body: SafeArea( - child: Stack( - children: [ - myWalletsTiles(context, currentChestNumber), - CommonElements().offlineInfo(context), - ], - ), + child: Stack(children: [ + myWalletsTiles(context, currentChestNumber), + CommonElements().offlineInfo(context), + ]), ), ), ); @@ -79,8 +78,30 @@ class WalletsHome extends StatelessWidget { BuildContext context, MyWalletsProvider myWalletProvider) { return Column(children: [ const SizedBox(height: 50), + InkWell( + key: const Key('importG1v1'), + onTap: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return const ImportG1v1(); + }), + ); + }, + child: SizedBox( + width: 400, + height: 50, + child: Center( + child: Text('importG1v1'.tr(), + style: TextStyle( + fontSize: 22, + color: orangeC, + fontWeight: FontWeight.w500))), + ), + ), + const SizedBox(height: 30), SizedBox( - height: 90, + height: 80, width: 420, child: ElevatedButton.icon( icon: Image.asset( @@ -168,7 +189,6 @@ class WalletsHome extends StatelessWidget { return CustomScrollView(slivers: [ const SliverToBoxAdapter(child: SizedBox(height: 20)), - SliverGrid.count( key: const Key('listWallets'), crossAxisCount: nTule,