improve idty confirmation

This commit is contained in:
poka 2022-06-04 23:32:44 +02:00
parent 9eacbef2a8
commit 36bc2f571f
7 changed files with 92 additions and 21 deletions

View File

@ -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;

View File

@ -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<bool> 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<Map> getCertMeta(String address) async {
@ -572,6 +596,8 @@ class SubstrateSdk with ChangeNotifier {
return _certMeta;
}
Future getCurencyName() async {}
Future<String> derive(
BuildContext context, String address, int number, String password) async {
final keypair = getKeypair(address);

View File

@ -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');
}),
);
}
}
},
);

View File

@ -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!),
),

View File

@ -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!),

View File

@ -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(

View File

@ -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'