From 9301eaf1a76df381d62ebcce340c6bbd15ff4f5d Mon Sep 17 00:00:00 2001 From: poka Date: Mon, 29 Aug 2022 06:03:05 +0200 Subject: [PATCH] add test: migrate Cesium wallet identity --- integration_test/cert_state.dart | 10 +- .../duniter/data/gecko_tests.json | 5 + integration_test/gecko_complete.dart | 84 +++++++------- integration_test/general_actions.dart | 47 ++++---- integration_test/migrate_cesium_identity.dart | 66 +++++++++++ integration_test/tests_utility.dart | 106 ++++++++++++++---- integration_test/ud_creation_state.dart | 6 +- lib/models/widgets_keys.dart | 6 + lib/providers/generate_wallets.dart | 1 + lib/providers/substrate_sdk.dart | 3 +- lib/screens/myWallets/import_g1_v1.dart | 31 +++-- 11 files changed, 251 insertions(+), 114 deletions(-) create mode 100644 integration_test/migrate_cesium_identity.dart diff --git a/integration_test/cert_state.dart b/integration_test/cert_state.dart index bbfe692..f36dc5c 100644 --- a/integration_test/cert_state.dart +++ b/integration_test/cert_state.dart @@ -10,21 +10,21 @@ void main() async { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); await dotenv.load(); - testWidgets('Gecko complete', (testerLoc) async { + testWidgets('Certifications state', (testerLoc) async { tester = testerLoc; // Connect local node and import test chest in background - await fastStart(); + await bkFastStart(); // Open chest await firstOpenChest(); await goBack(); // Go wallet 5 view - await goKey(keyOpenSearch); + await tapKey(keyOpenSearch); await enterText(keySearchField, test5.address); - await goKey(keyConfirmSearch); + await tapKey(keyConfirmSearch); await waitFor(test5.shortAddress()); - await goKey(keySearchResult(test5.address)); + await tapKey(keySearchResult(test5.address)); await waitFor('Certifier'); await waitFor('Vous devez ', reverse: true); await waitFor('Vous pourrez renouveler ', reverse: true); diff --git a/integration_test/duniter/data/gecko_tests.json b/integration_test/duniter/data/gecko_tests.json index ccd5486..804b3de 100644 --- a/integration_test/duniter/data/gecko_tests.json +++ b/integration_test/duniter/data/gecko_tests.json @@ -29,6 +29,11 @@ "balance": 10000, "certs": ["test1", "test2", "test3"], "pubkey": "5DXJ4CusmCg8S1yF6JGVn4fxgk5oFx42WctXqHZ17mykgje5" + }, + "testCesium1": { + "balance": 10000, + "certs": ["test1", "test2", "test3"], + "pubkey": "5GAT6CJW8yVKwUuQc7sM5Kk9GZVTpbZYk9PfjNXtvnNgAJZ1" } }, "parameters": { diff --git a/integration_test/gecko_complete.dart b/integration_test/gecko_complete.dart index e49447e..7157f11 100644 --- a/integration_test/gecko_complete.dart +++ b/integration_test/gecko_complete.dart @@ -1,9 +1,7 @@ -import 'package:flutter/services.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:gecko/models/widgets_keys.dart'; import 'package:integration_test/integration_test.dart'; -import 'package:gecko/main.dart' as app; import 'general_actions.dart'; import 'tests_utility.dart'; @@ -12,11 +10,11 @@ void main() async { await dotenv.load(); testWidgets('Gecko complete', (testerLoc) async { + // Share WidgetTester to test provider tester = testerLoc; - app.main(); - await waitFor('Test starting...', reverse: true); - await tester.pumpAndSettle(const Duration(milliseconds: 100)); - await sleep(2000); + + // Start app and wait finish starting + await startWait(); // Change Duniter endpoint to local await changeNode(); @@ -27,7 +25,7 @@ void main() async { // Restore the test chest await restoreChest(); - // Execute a transaction to test2 + // Execute a transaction to test5 await payTest2(); // Certify test5 account with 3 accounts to become member @@ -37,23 +35,23 @@ void main() async { Future payTest2() async { await waitFor('Rechercher'); - await goKey(keyOpenSearch); - final addressToSearch = (await Clipboard.getData('text/plain'))!.text; - final endAddress = addressToSearch!.substring(addressToSearch.length - 6); + await tapKey(keyOpenSearch); + final addressToSearch = await clipPaste(); + final endAddress = addressToSearch.substring(addressToSearch.length - 6); expect(addressToSearch, test5.address); await enterText(keySearchField, addressToSearch); - await goKey(keyConfirmSearch); + await tapKey(keyConfirmSearch); await waitFor(endAddress); - await goKey(keySearchResult(addressToSearch)); + await tapKey(keySearchResult(addressToSearch)); await waitFor(endAddress); await waitFor('0.0 ĞD'); - await goKey(keyPay); + await tapKey(keyPay); await enterText(keyAmountField, '12.14'); - await goKey(keyConfirmPayment); + await tapKey(keyConfirmPayment); spawnBlock(duration: 500); await waitFor('validé !', timeout: const Duration(seconds: 1)); - await goKey(keyCloseTransactionScreen, duration: 0); + await tapKey(keyCloseTransactionScreen, duration: 0); await waitFor('12.14'); spawnBlock(duration: 500); await waitFor('9.14'); @@ -62,70 +60,70 @@ Future payTest2() async { Future certifyTest5() async { // Create identity with Test1 account - await goKey(keyCertify); - await goKey(keyConfirm); + await tapKey(keyCertify); + await tapKey(keyConfirm); spawnBlock(duration: 500); await waitFor('validé !', timeout: const Duration(seconds: 1)); - await goKey(keyCloseTransactionScreen); + await tapKey(keyCloseTransactionScreen); await waitFor('Identité créée'); // Confirm Identity Test5 - await goKey(keyAppBarChest, duration: 300); - await goKey(keyOpenWallet(test5.address)); - await goKey(keyCopyAddress); + await tapKey(keyAppBarChest, duration: 300); + await tapKey(keyOpenWallet(test5.address)); + await tapKey(keyCopyAddress); humanRead(3); - await goKey(keyConfirmIdentity); + await tapKey(keyConfirmIdentity); await enterText(keyEnterIdentityUsername, test5.name); - await goKey(keyConfirm); + await tapKey(keyConfirm); spawnBlock(duration: 500); await waitFor('validé !', timeout: const Duration(seconds: 1)); - await goKey(keyCloseTransactionScreen); + await tapKey(keyCloseTransactionScreen); await waitFor('Identité confirmée'); humanRead(2); // Set wallet 2 as default wallet await goBack(); - await goKey(keyOpenWallet(test2.address)); - await goKey(keySetDefaultWallet); + await tapKey(keyOpenWallet(test2.address)); + await tapKey(keySetDefaultWallet); await waitFor('Ce portefeuille est celui par defaut'); // Search Wallet 5 again - await goKey(keyAppBarSearch); - final addressToSearch = (await Clipboard.getData('text/plain'))!.text; - final endAddress = addressToSearch!.substring(addressToSearch.length - 6); + await tapKey(keyAppBarSearch); + final addressToSearch = await clipPaste(); + final endAddress = addressToSearch.substring(addressToSearch.length - 6); expect(addressToSearch, test5.address); await enterText(keySearchField, addressToSearch); - await goKey(keyConfirmSearch); + await tapKey(keyConfirmSearch); await waitFor(endAddress); - await goKey(keySearchResult(addressToSearch)); + await tapKey(keySearchResult(addressToSearch)); await waitFor(endAddress); await waitFor('1'); // Certify with test2 account - await goKey(keyCertify); - await goKey(keyConfirm); + await tapKey(keyCertify); + await tapKey(keyConfirm); spawnBlock(duration: 500); await waitFor('validé !', timeout: const Duration(seconds: 1)); - await goKey(keyCloseTransactionScreen); + await tapKey(keyCloseTransactionScreen); await waitFor('2'); // Change default wallet to test3 - await goKey(keyPay); - await goKey(keyChangeChest); - await goKey(keySelectThisWallet(test3.address)); - await goKey(keyConfirm); + await tapKey(keyPay); + await tapKey(keyChangeChest); + await tapKey(keySelectThisWallet(test3.address)); + await tapKey(keyConfirm); await sleep(); // Certify with test3 account - await goKey(keyCertify); - await goKey(keyConfirm); + await tapKey(keyCertify); + await tapKey(keyConfirm); spawnBlock(duration: 500); await waitFor('validé !', timeout: const Duration(seconds: 1)); - await goKey(keyCloseTransactionScreen); + await tapKey(keyCloseTransactionScreen); await waitFor('Vous devez attendre'); // Check if test5 is member - await goKey(keyAppBarChest, duration: 300); - await goKey(keyOpenWallet(test5.address)); + await tapKey(keyAppBarChest, duration: 300); + await tapKey(keyOpenWallet(test5.address)); await waitFor('Membre validé !'); // spawn 20 blocs and check if ud is creating diff --git a/integration_test/general_actions.dart b/integration_test/general_actions.dart index ee4fb35..cf8dfc1 100644 --- a/integration_test/general_actions.dart +++ b/integration_test/general_actions.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:gecko/globals.dart'; @@ -12,12 +11,12 @@ Future changeNode() async { final ipAddress = dotenv.env['ip_address'] ?? '127.0.0.1'; log.d('ip address: $ipAddress'); - await goKey(keyDrawerMenu); - await goKey(keyParameters); - await goKey(keySelectDuniterNodeDropDown, duration: 5); - await goKey(keySelectDuniterNode('Personnalisé'), selectLast: true); + await tapKey(keyDrawerMenu); + await tapKey(keyParameters); + await tapKey(keySelectDuniterNodeDropDown, duration: 5); + await tapKey(keySelectDuniterNode('Personnalisé'), selectLast: true); await enterText(keyCustomDuniterEndpoint, 'ws://$ipAddress:9944'); - await goKey(keyConnectToEndpoint); + await tapKey(keyConnectToEndpoint); await isIconPresent(Icons.add_card_sharp, timeout: const Duration(seconds: 8)); await goBack(); @@ -25,35 +24,35 @@ Future changeNode() async { Future deleteAllWallets() async { if (await isPresent('Rechercher')) { - await goKey(keyDrawerMenu); - await goKey(keyParameters); - await goKey(keyDeleteAllWallets); - await goKey(keyConfirm); + await tapKey(keyDrawerMenu); + await tapKey(keyParameters); + await tapKey(keyDeleteAllWallets); + await tapKey(keyConfirm); await tester.pumpAndSettle(); } } Future restoreChest() async { // Copy test mnemonic in clipboard - Clipboard.setData(const ClipboardData(text: testMnemonic)); + await clipCopy(testMnemonic); // Open screen import chest - await goKey(keyRestoreChest, duration: 0); + await tapKey(keyRestoreChest, duration: 0); // Tap on button to paste mnemonic - await goKey(keyPastMnemonic); + await tapKey(keyPastMnemonic); // Tap on next button 4 times to skip 3 screen - await goKey(keyGoNext); - await goKey(keyGoNext); - await goKey(keyGoNext); - await goKey(keyGoNext); + await tapKey(keyGoNext); + await tapKey(keyGoNext); + await tapKey(keyGoNext); + await tapKey(keyGoNext); // Check if cached password checkbox is checked final isCached = await isIconPresent(Icons.check_box); // If not, tap on to cache password - if (!isCached) await goKey(keyCachePassword, duration: 0); + if (!isCached) await tapKey(keyCachePassword, duration: 0); // Enter password await enterText(keyPinForm, 'AAAAA', 0); @@ -62,7 +61,7 @@ Future restoreChest() async { await waitFor('Accéder à mon coffre'); // Go to wallets home - await goKey(keyGoWalletsHome, duration: 0); + await tapKey(keyGoWalletsHome, duration: 0); // Check if string "ĞD" is present in screen await waitFor('ĞD'); @@ -71,10 +70,10 @@ Future restoreChest() async { await addDerivation(); // Tap on Wallet 5 - await goKey(keyOpenWallet(test5.address)); + await tapKey(keyOpenWallet(test5.address)); // Copy address of Wallet 5 - await goKey(keyCopyAddress); + await tapKey(keyCopyAddress); // Check if string "Cette adresse a été copié" is present in screen await waitFor('Cette adresse a été copié'); @@ -85,15 +84,15 @@ Future restoreChest() async { } Future addDerivation() async { - await goKey(keyAddDerivation); + await tapKey(keyAddDerivation); await waitFor('Portefeuille 5'); } Future firstOpenChest() async { - await goKey(keyOpenWalletsHomme); + await tapKey(keyOpenWalletsHomme); sleep(300); final isCached = await isIconPresent(Icons.check_box); - if (!isCached) await goKey(keyCachePassword, duration: 0); + if (!isCached) await tapKey(keyCachePassword, duration: 0); await enterText(keyPinForm, 'AAAAA', 0); await waitFor('100.0 $currencyName'); } diff --git a/integration_test/migrate_cesium_identity.dart b/integration_test/migrate_cesium_identity.dart new file mode 100644 index 0000000..79cb510 --- /dev/null +++ b/integration_test/migrate_cesium_identity.dart @@ -0,0 +1,66 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:gecko/globals.dart'; +import 'package:gecko/models/widgets_keys.dart'; +import 'package:integration_test/integration_test.dart'; +import 'general_actions.dart'; +import 'tests_utility.dart'; + +void main() async { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + await dotenv.load(); + + testWidgets('Migrate Cesium identity and balance', (testerLoc) async { + tester = testerLoc; + // Connect local node and import test chest in background + await bkFastStart(); + + // Open chest + await firstOpenChest(); + + // Go to test1 options and check if balance growup with UDs creations + await tapKey(keyAddDerivation); + await waitFor('Portefeuille 6'); + + await scrollUntil(keyImportG1v1); + await tapKey(keyImportG1v1); + await enterText(keyCesiumId, 'test'); + await enterText(keyCesiumPassword, 'test'); + await waitFor(cesiumTest1.shortAddress()); + await waitFor('100.0 $currencyName'); + await waitFor('3', exactMatch: true); + + isObscureText(); + await tapKey(keyCesiumIdVisible); + await tester.pumpAndSettle(); + isObscureText(false); + await tapKey(keyCesiumIdVisible); + await tester.pumpAndSettle(); + isObscureText(); + + await tapKey(keySelectWallet); + await tapKey(keySelectThisWallet(test6.address), selectLast: true); + await waitForButtonEnabled(keyConfirm); + await tapKey(keyConfirm); + spawnBlock(duration: 2000); + await waitFor('validé !'); + await tapKey(keyCloseTransactionScreen, duration: 0); + + await tapKey(keyOpenWallet(test6.address), duration: 300); + await waitFor('3', exactMatch: true); + await waitFor('Membre validé !'); + + // TODO: fix batch for transfertAll + // await waitFor('100.0 $currencyName'); + }, timeout: testTimeout()); +} + +isObscureText([bool isObscure = true]) { + final passwordTextFormField = find.descendant( + of: find.byKey(keyCesiumId), + matching: find.byType(EditableText), + ); + final input = tester.widget(passwordTextFormField); + expect(input.obscureText, isObscure ? isTrue : isFalse); +} diff --git a/integration_test/tests_utility.dart b/integration_test/tests_utility.dart index 77b3189..bb39cab 100644 --- a/integration_test/tests_utility.dart +++ b/integration_test/tests_utility.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:gecko/globals.dart'; @@ -30,12 +31,20 @@ final test4 = TestWallet('5DXJ4CusmCg8S1yF6JGVn4fxgk5oFx42WctXqHZ17mykgje5', 'test4'); final test5 = TestWallet('5Dq3giahrBfykJogPetZJ2jjSmhw49Fa7i6qKkseUvRJ2T3R', 'test5'); -// final test6 = -// TestWallet('5FeggKqw2AbnGZF9Y9WPM2QTgzENS3Hit94Ewgmzdg5a3LNa', 'test6'); -// final test7 = -// TestWallet('5FeggKqw2AbnGZF9Y9WPM2QTgzENS3Hit94Ewgmzdg5a3LNa', 'test7'); -// final test8 = -// TestWallet('5FeggKqw2AbnGZF9Y9WPM2QTgzENS3Hit94Ewgmzdg5a3LNa', 'test8'); +final test6 = + TestWallet('5GxEp3do81j97kNaH4JyZgDXuPoKWoTuxXXWGyyNXeKeVLHb', 'test6'); +final test7 = + TestWallet('5FZ1sSvREbQLCtSSCvMUx7KCAnpJkB7q5mfz2oixiZq2ChET', 'test7'); +final test8 = + TestWallet('5CoKV9EEgwb2NmWamTXUAa6ycfNb2k1iNfVGvJAkg7dLq9RH', 'test8'); +final cesiumTest1 = TestWallet( + '5GAT6CJW8yVKwUuQc7sM5Kk9GZVTpbZYk9PfjNXtvnNgAJZ1', 'cesiumTest1'); +final cesiumTest2 = TestWallet( + '5DTnny1tTkUs1SXHZTx98RUAj76Z88FfFhsQjd48dXnk8gHR', 'cesiumTest2'); +final cesiumTest3 = TestWallet( + '5EJct9jTDNKco4YiYfETAseq1gaduBtsJUcNnFicfvh3bTV6', 'cesiumTest3'); +final cesiumTest4 = TestWallet( + '5HD1oSv6A7VNxPYos6F86JFZ3bhz5LnEaWC4hkwLMj84v4ww', 'cesiumTest4'); // CUSTOM FUNCTIONS @@ -43,11 +52,17 @@ Future sleep([int time = 1000]) async { await Future.delayed(Duration(milliseconds: time)); } +Future clipPaste() async => + (await Clipboard.getData('text/plain'))?.text ?? ''; + +clipCopy(String text) async => + await Clipboard.setData(ClipboardData(text: text)); + Future humanRead([int time = 1, bool force = false]) async { if (isHumanReading || force) io.sleep(Duration(seconds: time)); } -Future goKey(Key buttonKey, +Future tapKey(Key buttonKey, {Finder? customFinder, int duration = 100, bool selectLast = false}) async { if (duration != 0) { await tester.pumpAndSettle(Duration(milliseconds: duration)); @@ -58,6 +73,42 @@ Future goKey(Key buttonKey, humanRead(); } +Finder findByKey(Key key) { + return find.byKey(key); +} + +bool isButtonEnabled(Key key) { + return tester.widget(findByKey(key)).enabled; +} + +Future scrollUntil(Key element) async { + final findList = find.byType(Scrollable); + final findElement = findByKey(element); + await tester.scrollUntilVisible( + findElement, + 500.0, + scrollable: findList, + ); +} + +Future waitForButtonEnabled(Key key, + {Duration timeout = const Duration(seconds: 5), + bool reverse = false}) async { + final end = DateTime.now().add(timeout); + + log.d('INTEGRATION TEST: Wait for $key to be enabled'); + + do { + if (DateTime.now().isAfter(end)) { + throw Exception('Timed out waiting for button enabled: $key'); + } + + await tester.pumpAndSettle(); + await Future.delayed(const Duration(milliseconds: 100)); + } while (reverse ? isButtonEnabled(key) : !isButtonEnabled(key)); + humanRead(); +} + Future goBack() async { final NavigatorState navigator = tester.state(find.byType(Navigator)); log.d('INTEGRATION TEST: Go back'); @@ -129,6 +180,7 @@ Future spawnBlock({int number = 1, int duration = 200, int? until}) async { await sleep(200); } +// Pay in background Future bkPay( {required String fromAddress, required String destAddress, @@ -142,6 +194,7 @@ Future bkPay( await sleep(500); } +// Certify in background Future bkCertify( {required String fromAddress, required String destAddress}) async { sub.certify(fromAddress, destAddress, 'AAAAA'); @@ -149,6 +202,7 @@ Future bkCertify( await sleep(500); } +// Confirm my identity in background Future bkConfirmIdentity( {required String fromAddress, required String name}) async { sub.confirmIdentity(fromAddress, name, 'AAAAA'); @@ -156,16 +210,7 @@ Future bkConfirmIdentity( await sleep(500); } -class TestWallet { - String address; - String name; - - TestWallet(this.address, this.name); - - endAddress() => address.substring(address.length - 6); - shortAddress() => getShortPubkey(address); -} - +// Change node in background Future bkSetNode([String? endpoint]) async { if (endpoint == null) { final ipAddress = dotenv.env['ip_address'] ?? '127.0.0.1'; @@ -175,6 +220,7 @@ Future bkSetNode([String? endpoint]) async { sub.connectNode(homeContext); } +// Restore chest in background Future bkRestoreChest([String mnemonic = testMnemonic]) async { final myWalletProvider = Provider.of(homeContext, listen: false); @@ -215,6 +261,7 @@ Future _addImportAccount( return myWallet; } +// Delete all wallets in background Future bkDeleteAllWallets() async { final myWalletProvider = Provider.of(homeContext, listen: false); @@ -224,11 +271,9 @@ Future bkDeleteAllWallets() async { } } -Future fastStart() async { - app.main(); - await waitFor('Test starting...', reverse: true); - await tester.pumpAndSettle(const Duration(milliseconds: 100)); - await sleep(2000); +Future bkFastStart() async { + // Start app and wait finish starting + await startWait(); // Connect to local endpoint await bkSetNode(); @@ -241,3 +286,20 @@ Future fastStart() async { await bkRestoreChest(); await waitFor("y'a pas de lézard"); } + +Future startWait() async { + app.main(); + await waitFor('Test starting...', reverse: true); + await tester.pumpAndSettle(const Duration(milliseconds: 300)); + await sleep(2000); +} + +class TestWallet { + String address; + String name; + + TestWallet(this.address, this.name); + + endAddress() => address.substring(address.length - 6); + shortAddress() => getShortPubkey(address); +} diff --git a/integration_test/ud_creation_state.dart b/integration_test/ud_creation_state.dart index bbf9fe7..88e9abd 100644 --- a/integration_test/ud_creation_state.dart +++ b/integration_test/ud_creation_state.dart @@ -10,16 +10,16 @@ void main() async { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); await dotenv.load(); - testWidgets('Gecko complete', (testerLoc) async { + testWidgets('UDs creation state', (testerLoc) async { tester = testerLoc; // Connect local node and import test chest in background - await fastStart(); + await bkFastStart(); // Open chest await firstOpenChest(); // Go to test1 options and check if balance growup with UDs creations - await goKey(keyOpenWallet(test1.address)); + await tapKey(keyOpenWallet(test1.address)); await waitFor('100.0 $currencyName'); await spawnBlock(until: 10); await waitFor('200.0 $currencyName'); diff --git a/lib/models/widgets_keys.dart b/lib/models/widgets_keys.dart index 58b3935..e10c39d 100644 --- a/lib/models/widgets_keys.dart +++ b/lib/models/widgets_keys.dart @@ -83,6 +83,12 @@ const keyGoWalletsHome = Key('keyGoWalletsHome'); const keySearchField = Key('keySearchField'); const keyConfirmSearch = Key('keyConfirmSearch'); +// Import Cesium wallet +const keyCesiumId = Key('keyCesiumId'); +const keyCesiumPassword = Key('keyCesiumPassword'); +const keySelectWallet = Key('keySelectWallet'); +const keyCesiumIdVisible = Key('keyCesiumIdVisible'); + // Items keys Key keyTransaction(int keyId) => Key('keyTransaction$keyId'); Key keyMnemonicWord(String word) => Key('keyMnemonicWord$word'); diff --git a/lib/providers/generate_wallets.dart b/lib/providers/generate_wallets.dart index 24aef78..43355a7 100644 --- a/lib/providers/generate_wallets.dart +++ b/lib/providers/generate_wallets.dart @@ -354,6 +354,7 @@ class GenerateWalletsProvider with ChangeNotifier { cellController10, cellController11 ]; + if (sentence?.text == null) return; for (var word in sentence!.text!.split(' ')) { bool isValid = isBipWord(word, false); diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart index 781b417..d08a74a 100644 --- a/lib/providers/substrate_sdk.dart +++ b/lib/providers/substrate_sdk.dart @@ -38,7 +38,8 @@ class SubstrateSdk with ChangeNotifier { TextEditingController csSalt = TextEditingController(); TextEditingController csPassword = TextEditingController(); String g1V1NewAddress = ''; - bool isCesiumIDVisible = true; + bool isCesiumIDVisible = false; + bool isCesiumAddresLoading = false; ///////////////////////////////////// ////////// 1: API METHODS /////////// diff --git a/lib/screens/myWallets/import_g1_v1.dart b/lib/screens/myWallets/import_g1_v1.dart index 5b8b332..2683757 100644 --- a/lib/screens/myWallets/import_g1_v1.dart +++ b/lib/screens/myWallets/import_g1_v1.dart @@ -22,7 +22,6 @@ class ImportG1v1 extends StatelessWidget { @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); - // HomeProvider _homeProvider = Provider.of(context); WalletOptionsProvider walletOptions = Provider.of(context, listen: false); MyWalletsProvider myWalletProvider = @@ -110,6 +109,7 @@ class ImportG1v1 extends StatelessWidget { return Column(children: [ const SizedBox(height: 20), TextFormField( + key: keyCesiumId, autofocus: true, onChanged: (text) { if (debounce?.isActive ?? false) { @@ -117,21 +117,23 @@ class ImportG1v1 extends StatelessWidget { } debounce = Timer( const Duration(milliseconds: debouneTime), () { + sub.reload(); sub.csToV2Address( sub.csSalt.text, sub.csPassword.text); }); }, keyboardType: TextInputType.text, controller: sub.csSalt, - obscureText: sub + obscureText: !sub .isCesiumIDVisible, //This will obscure text dynamically decoration: InputDecoration( hintText: 'enterCesiumId'.tr(), suffixIcon: IconButton( + key: keyCesiumIdVisible, icon: Icon( sub.isCesiumIDVisible - ? Icons.visibility - : Icons.visibility_off, + ? Icons.visibility_off + : Icons.visibility, color: Colors.black, ), onPressed: () { @@ -142,6 +144,7 @@ class ImportG1v1 extends StatelessWidget { ), const SizedBox(height: 20), TextFormField( + key: keyCesiumPassword, autofocus: true, onChanged: (text) { if (debounce?.isActive ?? false) { @@ -149,21 +152,23 @@ class ImportG1v1 extends StatelessWidget { } debounce = Timer( const Duration(milliseconds: debouneTime), () { + sub.g1V1NewAddress = ''; + sub.reload(); sub.csToV2Address( sub.csSalt.text, sub.csPassword.text); }); }, keyboardType: TextInputType.text, controller: sub.csPassword, - obscureText: sub + obscureText: !sub .isCesiumIDVisible, //This will obscure text dynamically decoration: InputDecoration( hintText: 'enterCesiumPassword'.tr(), suffixIcon: IconButton( icon: Icon( sub.isCesiumIDVisible - ? Icons.visibility - : Icons.visibility_off, + ? Icons.visibility_off + : Icons.visibility, color: Colors.black, ), onPressed: () { @@ -188,14 +193,6 @@ class ImportG1v1 extends StatelessWidget { ), ), ), - // Text( - // getShortPubkey(sub.g1V1NewAddress), - // style: const TextStyle( - // fontSize: 18, - // color: Colors.black, - // fontWeight: FontWeight.bold, - // fontFamily: 'Monospace'), - // ), const SizedBox(height: 20), Text( '${balance['transferableBalance']} $currencyName', @@ -214,12 +211,14 @@ class ImportG1v1 extends StatelessWidget { Text('selectDestWallet'.tr()), const SizedBox(height: 5), DropdownButtonHideUnderline( + key: keySelectWallet, child: DropdownButton( // alignment: AlignmentDirectional.topStart, value: selectedWallet, icon: const Icon(Icons.keyboard_arrow_down), items: myWalletProvider.listWallets.map((wallet) { return DropdownMenuItem( + key: keySelectThisWallet(wallet.address!), value: wallet, child: Text( wallet.name!, @@ -238,6 +237,7 @@ class ImportG1v1 extends StatelessWidget { width: 380 * ratio, height: 60 * ratio, child: ElevatedButton( + key: keyConfirm, style: ElevatedButton.styleFrom( elevation: 4, primary: orangeC, // background @@ -245,7 +245,6 @@ class ImportG1v1 extends StatelessWidget { ), onPressed: canValidate ? () async { - log.d('GOOO'); WalletData? defaultWallet = myWalletProvider.getDefaultWallet();