From 237e581d0f990693a47fda5ea4ece94d374224ba Mon Sep 17 00:00:00 2001 From: poka Date: Thu, 18 Aug 2022 18:22:36 +0200 Subject: [PATCH] Ready to migrate identity, wait for signMessage methode in sdk https://github.com/polkawallet-io/sdk/issues/31 --- assets/translations/en.json | 3 +- assets/translations/es.json | 3 +- assets/translations/fr.json | 3 +- lib/providers/substrate_sdk.dart | 63 ++++++++++++++++++++++-- lib/screens/myWallets/import_g1_v1.dart | 5 +- lib/screens/transaction_in_progress.dart | 1 + pubspec.yaml | 2 + 7 files changed, 71 insertions(+), 9 deletions(-) diff --git a/assets/translations/en.json b/assets/translations/en.json index 81e472f..3bdb47f 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -184,5 +184,6 @@ "youCannotMigrateIdentityToExistingIdentity": "You cannot migrate an identity\nto an account that already has an identity", "importOldAccount": "Import your old account", "enterCesiumId": "Enter your Cesium ID", - "enterCesiumPassword": "Enter your Cesium password" + "enterCesiumPassword": "Enter your Cesium password", + "migrateAccount": "Migrate account" } \ No newline at end of file diff --git a/assets/translations/es.json b/assets/translations/es.json index 567af90..a081ff7 100644 --- a/assets/translations/es.json +++ b/assets/translations/es.json @@ -184,5 +184,6 @@ "youCannotMigrateIdentityToExistingIdentity": "You cannot migrate an identity\nto an account that already has an identity", "importOldAccount": "Import your old account", "enterCesiumId": "Enter your Cesium ID", - "enterCesiumPassword": "Enter your Cesium password" + "enterCesiumPassword": "Enter your Cesium password", + "migrateAccount": "Migrate account" } \ No newline at end of file diff --git a/assets/translations/fr.json b/assets/translations/fr.json index b22d86b..43c01b4 100644 --- a/assets/translations/fr.json +++ b/assets/translations/fr.json @@ -185,5 +185,6 @@ "youCannotMigrateIdentityToExistingIdentity": "Vous ne pouvez pas migrer une identité\nvers un compte disposant déjà d'une identité", "importOldAccount": "Importer son ancien compte", "enterCesiumId": "Entrez votre identifiant Cesium", - "enterCesiumPassword": "Entrez votre mot de passe Cesium" + "enterCesiumPassword": "Entrez votre mot de passe Cesium", + "migrateAccount": "Migrer le compte" } \ No newline at end of file diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart index d42a865..8af5406 100644 --- a/lib/providers/substrate_sdk.dart +++ b/lib/providers/substrate_sdk.dart @@ -270,9 +270,19 @@ class SubstrateSdk with ChangeNotifier { } } - // Future addressToPubkey(String address) async { - // await sdk.api.account.decodeAddress([address]); - // } + Future getGenesisHash() async { + final String genesisHash = await sdk.webView!.evalJavascript( + 'api.genesisHash.toHex()', + wrapPromise: false, + ) ?? + ''; + // log.d('genesisHash: $genesisHash'); + return genesisHash; + } + + Future addressToPubkey(String address) async { + await sdk.api.account.decodeAddress([address]); + } // Future pubkeyToAddress(String pubkey) async { // await sdk.api.account.encodeAddress([pubkey]); @@ -784,6 +794,45 @@ class SubstrateSdk with ChangeNotifier { return await executeCall(txInfo, txOptions, password); } + Future migrateIdentity( + {required String fromAddress, + required String destAddress, + required String password}) async { + transactionStatus = ''; + final fromPubkey = await sdk.api.account.decodeAddress([fromAddress]); + final sender = TxSenderData( + fromAddress, + fromPubkey!.keys.first, + ); + + // final globalBalance = await getBalance(fromAddress); + TxInfoData txInfo; + List txOptions = []; + String? rawParams; + // final destKeyring = getKeypair(destAddress); + + final genesisHash = await getGenesisHash(); + final idtyIndex = await getIdentityIndexOf(destAddress); + // final oldPubkey = await addressToPubkey(fromAddress); + final messageToSign = 'icok$genesisHash$idtyIndex$fromAddress'; + final newKeySig = messageToSign; + + txInfo = TxInfoData( + 'utility', + 'batchAll', + sender, + ); + const tx1 = 'api.tx.universalDividend.claimUds()'; + final tx2 = 'api.tx.identity.changeOwnerKey("$destAddress", "$newKeySig")'; + const tx3 = 'api.tx.balances.transferAll(false)'; + + rawParams = '[[$tx1, $tx2, $tx3]]'; + + log.d( + 'g1migration args: ${txInfo.module}, ${txInfo.call}, $txOptions, $rawParams'); + return await executeCall(txInfo, txOptions, password, rawParams); + } + Future revokeIdentity(String address, String password) async { final idtyIndex = await getIdentityIndexOf(address); @@ -837,7 +886,13 @@ class SubstrateSdk with ChangeNotifier { password: password, ); - if (balance != 0) { + log.d('g1migration idtyStatus: $idtyStatus'); + if (idtyStatus != 'noid') { + await migrateIdentity( + fromAddress: keypair.address!, + destAddress: destAddress, + password: 'password'); + } else if (balance != 0) { await pay( fromAddress: keypair.address!, destAddress: destAddress, diff --git a/lib/screens/myWallets/import_g1_v1.dart b/lib/screens/myWallets/import_g1_v1.dart index 7892d3b..259ec6e 100644 --- a/lib/screens/myWallets/import_g1_v1.dart +++ b/lib/screens/myWallets/import_g1_v1.dart @@ -62,6 +62,8 @@ class ImportG1v1 extends StatelessWidget { final myIdtyStatus = status.data?[2]; final hasConsumer = status.data?[3] ?? false; + // log.d('hasconsumer: $hasConsumer'); + if (balance != 0 && !hasConsumer) { canValidate = true; validationStatus = ''; @@ -216,7 +218,6 @@ class ImportG1v1 extends StatelessWidget { selectedWallet.address!, balance: balance, idtyStatus: idtyStatus); - Navigator.push( context, MaterialPageRoute(builder: (context) { @@ -227,7 +228,7 @@ class ImportG1v1 extends StatelessWidget { } : null, child: Text( - 'validate'.tr(), + 'migrateAccount'.tr(), style: TextStyle( fontSize: 23 * ratio, fontWeight: FontWeight.w600), diff --git a/lib/screens/transaction_in_progress.dart b/lib/screens/transaction_in_progress.dart index 548ba06..d63e166 100644 --- a/lib/screens/transaction_in_progress.dart +++ b/lib/screens/transaction_in_progress.dart @@ -88,6 +88,7 @@ class TransactionInProgress extends StatelessWidget { if (result.contains('blockHash: ')) { isValid = true; resultText = 'extrinsicValidated'.tr(args: [actionName]); + log.i('Bloc of last transaction: ${sub.blocNumber} --- $result'); } else { isValid = false; resultText = "${"anErrorOccured".tr()}:\n"; diff --git a/pubspec.yaml b/pubspec.yaml index aad5a24..a04320a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -62,6 +62,8 @@ dependencies: package_info_plus: ^1.4.2 polkawallet_sdk: #^0.4.9 git: + # url: https://github.com/polkawallet-io/sdk.git + # ref: develop url: https://github.com/poka-IT/sdk.git ref: gecko-old dots_indicator: ^2.1.0