From 36bc2f571fb53566bed56668e1450171a27b4a5e Mon Sep 17 00:00:00 2001 From: poka Date: Sat, 4 Jun 2022 23:32:44 +0200 Subject: [PATCH] improve idty confirmation --- lib/globals.dart | 2 +- lib/providers/substrate_sdk.dart | 42 ++++++++++++++++++----- lib/providers/wallet_options.dart | 38 ++++++++++++++++---- lib/screens/myWallets/wallet_options.dart | 6 ++-- lib/screens/myWallets/wallets_home.dart | 2 +- lib/screens/transaction_in_progress.dart | 21 +++++++++++- pubspec.yaml | 2 +- 7 files changed, 92 insertions(+), 21 deletions(-) diff --git a/lib/globals.dart b/lib/globals.dart index 2a3f1da..6bf48de 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -47,7 +47,7 @@ Color backgroundColor = const Color(0xFFF5F5F5); // Substrate settings const int ss58 = 42; -String currencyName = 'Ğdev'; +String currencyName = 'ĞD'; // Debug const debugPin = true; diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart index c2b89f3..44dec68 100644 --- a/lib/providers/substrate_sdk.dart +++ b/lib/providers/substrate_sdk.dart @@ -106,6 +106,7 @@ class SubstrateSdk with ChangeNotifier { notifyListeners(); }); + // currencyName = await getCurencyName(); notifyListeners(); _homeProvider.changeMessage( 'Vous êtes bien connecté aux noeud\n${getConnectedEndpoint()!.split('/')[2]}', @@ -527,15 +528,34 @@ class SubstrateSdk with ChangeNotifier { ); try { - final result = await sdk.api.tx.signAndSend( + final hash = await sdk.api.tx.signAndSend( txInfo, [name], password, + onStatusChange: (status) { + log.d('Transaction status: ' + status); + transactionStatus = status; + notifyListeners(); + }, + ).timeout( + const Duration(seconds: 12), + onTimeout: () => {}, ); - log.d(result); - return 'confirmed'; + log.d(hash); + if (hash.isEmpty) { + transactionStatus = 'timeout'; + notifyListeners(); + + return 'timeout'; + } else { + transactionStatus = hash.toString(); + notifyListeners(); + return hash.toString(); + } } on Exception catch (e) { log.e(e); + transactionStatus = e.toString(); + notifyListeners(); return e.toString(); } } @@ -545,18 +565,22 @@ class SubstrateSdk with ChangeNotifier { } Future canCertify(String from, String to) async { - bool _result = false; if (from != to && await isMember(from)) { final _certData = await getCertData(from, to); final _certMeta = await getCertMeta(from); final int _removableOn = _certData['removableOn'] ?? 0; + final int _renewableOn = _certData['renewableOn'] ?? 0; final int _nextIssuableOn = _certMeta['nextIssuableOn'] ?? 0; - log.d(_removableOn); - if (_removableOn == 0 && _nextIssuableOn == 0) { - _result = true; + log.d(_renewableOn.toString() + + '\n' + + _removableOn.toString() + + '\n' + + _nextIssuableOn.toString()); + if (_renewableOn == 0 && _nextIssuableOn == 0) { + return true; } } - return _result; + return false; } Future getCertMeta(String address) async { @@ -572,6 +596,8 @@ class SubstrateSdk with ChangeNotifier { return _certMeta; } + Future getCurencyName() async {} + Future derive( BuildContext context, String address, int number, String password) async { final keypair = getKeypair(address); diff --git a/lib/providers/wallet_options.dart b/lib/providers/wallet_options.dart index b05ebc2..5e7aa7e 100644 --- a/lib/providers/wallet_options.dart +++ b/lib/providers/wallet_options.dart @@ -6,6 +6,8 @@ import 'package:gecko/providers/my_wallets.dart'; import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/providers/substrate_sdk.dart'; import 'package:gecko/screens/common_elements.dart'; +import 'package:gecko/screens/myWallets/unlocking_wallet.dart'; +import 'package:gecko/screens/transaction_in_progress.dart'; import 'package:image_picker/image_picker.dart'; import 'package:provider/provider.dart'; @@ -217,12 +219,36 @@ class WalletOptionsProvider with ChangeNotifier { ), onPressed: () async { if (idtyName.text.length >= 2) { - final _wallet = _myWalletProvider - .getWalletDataByAddress(address.text); - await _sub.setCurrentWallet(_wallet!); - _sub.confirmIdentity(_walletOptions.address.text, - idtyName.text, _myWalletProvider.pinCode); - Navigator.pop(context); + WalletData? defaultWallet = + _myWalletProvider.getDefaultWallet(); + + String? _pin; + if (_myWalletProvider.pinCode == '') { + _pin = await Navigator.push( + context, + MaterialPageRoute( + builder: (homeContext) { + return UnlockingWallet(wallet: defaultWallet); + }, + ), + ); + } + if (_pin != null || _myWalletProvider.pinCode != '') { + final _wallet = _myWalletProvider + .getWalletDataByAddress(address.text); + await _sub.setCurrentWallet(_wallet!); + _sub.confirmIdentity(_walletOptions.address.text, + idtyName.text, _myWalletProvider.pinCode); + Navigator.pop(context); + + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return const TransactionInProgress( + transType: 'comfirmIdty'); + }), + ); + } } }, ); diff --git a/lib/screens/myWallets/wallet_options.dart b/lib/screens/myWallets/wallet_options.dart index 04d4ba8..a694f96 100644 --- a/lib/screens/myWallets/wallet_options.dart +++ b/lib/screens/myWallets/wallet_options.dart @@ -169,13 +169,13 @@ class WalletOptions extends StatelessWidget { width: 110, ) : Container( - width: 180, - height: 180, + width: 150, + height: 150, decoration: BoxDecoration( shape: BoxShape.circle, color: Colors.transparent, image: DecorationImage( - fit: BoxFit.contain, + fit: BoxFit.cover, image: FileImage( File(wallet.imageCustomPath!), ), diff --git a/lib/screens/myWallets/wallets_home.dart b/lib/screens/myWallets/wallets_home.dart index 14fbc39..5c1ec88 100644 --- a/lib/screens/myWallets/wallets_home.dart +++ b/lib/screens/myWallets/wallets_home.dart @@ -229,7 +229,7 @@ class WalletsHome extends StatelessWidget { shape: BoxShape.circle, color: Colors.transparent, image: DecorationImage( - fit: BoxFit.contain, + fit: BoxFit.fitHeight, image: FileImage( File( _repository.imageCustomPath!), diff --git a/lib/screens/transaction_in_progress.dart b/lib/screens/transaction_in_progress.dart index 8a5e54f..a75f402 100644 --- a/lib/screens/transaction_in_progress.dart +++ b/lib/screens/transaction_in_progress.dart @@ -46,6 +46,11 @@ class TransactionInProgress extends StatelessWidget { _actionName = 'Certification'; } break; + case 'comfirmIdty': + { + _actionName = "Confirmation d'identité"; + } + break; default: { _actionName = 'Transaction étrange'; @@ -77,7 +82,14 @@ class TransactionInProgress extends StatelessWidget { _resultText = '$_actionName validé !'; } else { _resultText = "Une erreur s'est produite:\n"; - final String _exception = _result.split('Exception: ')[1]; + final List _exceptionSplit = _result.split('Exception: '); + String _exception; + if (_exceptionSplit.length > 1) { + _exception = _exceptionSplit[1]; + } else { + _exception = _exceptionSplit[0]; + } + switch (_exception) { case 'cert.NotRespectCertPeriod': case 'identity.CreatorNotAllowedToCreateIdty': @@ -92,6 +104,12 @@ class TransactionInProgress extends StatelessWidget { "Vous ne pouvez pas vous certifier\nvous même ..."; } break; + case 'identity.IdtyNameAlreadyExist': + { + _resultText += "Ce nom est déjà pris"; + } + break; + default: { _resultText += "\n$_exception"; @@ -208,6 +226,7 @@ class TransactionInProgress extends StatelessWidget { ), onPressed: () { Navigator.pop(context); + _sub.transactionStatus = ''; if (transType == 'pay') Navigator.pop(context); }, child: Text( diff --git a/pubspec.yaml b/pubspec.yaml index f014ccb..f790dad 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ description: Pay with G1. # pub.dev using `pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 0.0.7+11 +version: 0.0.7+12 environment: sdk: '>=2.12.0 <3.0.0'